forked from jomo/imgur-screenshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-update.patch
83 lines (78 loc) · 2.88 KB
/
auto-update.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
From 5a2bb8d53450df35d23a115bc29c7959f0d42c0e Mon Sep 17 00:00:00 2001
From: jomo <[email protected]>
Date: Sun, 6 Dec 2015 21:38:22 +0100
Subject: [PATCH] add auto-update.patch
---
imgur-screenshot.sh | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/imgur-screenshot.sh b/imgur-screenshot.sh
index 81eacae..aa2ec17 100755
--- a/imgur-screenshot.sh
+++ b/imgur-screenshot.sh
@@ -68,6 +68,7 @@ auto_delete=""
copy_url="true"
keep_file="true"
check_update="true"
+auto_update="false"
# NOTICE: if you make changes here, also edit the docs at
# https://github.com/jomo/imgur-screenshot/wiki/Config
@@ -145,6 +146,13 @@ function check_for_update() {
echo "Version ${remote_version} is available (You have ${current_version})"
notify ok "Update found" "Version ${remote_version} is available (You have ${current_version}). https://github.com/jomo/imgur-screenshot"
echo "Check https://github.com/jomo/imgur-screenshot/releases/${remote_version} for more info."
+
+ if [ "${auto_update}" == "true" ]; then
+ run_update
+ else
+ echo "Use --update to install the new version"
+ fi
+
elif [ -z "${current_version}" ] || [ -z "${remote_version}" ]; then
echo "Invalid empty version string"
echo "Current (local) version: '${current_version}'"
@@ -157,6 +165,27 @@ function check_for_update() {
fi
}
+function run_update() {
+ set -e
+ local remote_script="https://github.com/jomo/imgur-screenshot/releases/download/${remote_version}/imgur-screenshot.sh"
+ local that
+ local this_script
+ local tmp_script
+
+ tmp_script="$(mktemp)"
+
+ # determine the script's location
+ that="$(which "$0")"
+ this_script="$(readlink "$that" || echo "$that")"
+
+ # Download latest version
+ echo "Downloading and installing latest version..."
+ curl --compressed -fL -'#' "${remote_script}" > "${tmp_script}"
+ mv "${tmp_script}" "${this_script}"
+ echo "Successfully updated to ${remote_version}."
+}
+
+
function check_oauth2_client_secrets() {
if [ -z "${imgur_acct_key}" ] || [ -z "${imgur_secret}" ]; then
echo "In order to upload to your account, register a new application at:"
@@ -406,7 +435,7 @@ while [ ${#} != 0 ]; do
echo " -A, --album-id <album_id> Override 'album_id' config"
echo " -k, --keep-file <true|false> Override 'keep_file' config"
echo " -d, --auto-delete <s> Automatically delete image after <s> seconds"
- echo " -u, --update Check for updates, exit"
+ echo " -u, --update Check for a newer version, install if available, exit"
echo " file Upload file instead of taking a screenshot"
exit 0;;
-v | --version)
@@ -447,6 +476,7 @@ while [ ${#} != 0 ]; do
auto_delete="${2}"
shift 2;;
-u | --update)
+ auto_update="true"
check_for_update
exit 0;;
*)
--
2.6.1