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