From 5032acf176d78ae928847d76a0eeeb2bc960c4cd Mon Sep 17 00:00:00 2001 From: Aidyn Torgayev Date: Tue, 24 Nov 2020 04:39:38 +0300 Subject: [PATCH 1/2] delete archive only if successful untar --- update-golang.sh | 3 +++ update-golang.sh.sha256 | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/update-golang.sh b/update-golang.sh index 924b522..c31df01 100755 --- a/update-golang.sh +++ b/update-golang.sh @@ -96,8 +96,10 @@ has_cmd() { tmp='' ;# will be set save_dir=$PWD previous_install='' ;# will be set +tar_to_remove='' ;# will be set cleanup() { [ -n "$tmp" ] && [ -f "$tmp" ] && msg cleanup: $tmp && rm $tmp + [ -n "$tar_to_remove" ] && [ -f "$tar_to_remove" ] && msg cleanup: $tar_to_remove && rm $tar_to_remove [ -n "$save_dir" ] && cd "$save_dir" || exit 2 [ -n "$previous_install" ] && msg remember to delete previous install saved as: "$previous_install" } @@ -261,6 +263,7 @@ untar() { local cmd="tar -x -f $abs_filepath" msg untar: "$cmd" $cmd || die untar: failed: "$abs_filepath" + tar_to_remove="$abs_filepath" } relink() { diff --git a/update-golang.sh.sha256 b/update-golang.sh.sha256 index c0c0ce4..43be5da 100644 --- a/update-golang.sh.sha256 +++ b/update-golang.sh.sha256 @@ -1 +1 @@ -068538c237fee11e217f75742775b0dbef3c2059a48a10b7b566640d88f29fdb update-golang.sh +352e4c1baed43a764e176a9f1382680f1f42dfaa82832dd60ddac42dda23db10 update-golang.sh From 8693c15bd54f9bf4ac84136ed74e9150e731dc0c Mon Sep 17 00:00:00 2001 From: Aidyn Torgayev Date: Sat, 5 Dec 2020 02:05:44 +0300 Subject: [PATCH 2/2] declutter flag to prevent caching tar archive --- README.md | 7 +++++++ update-golang.sh | 9 +++++++-- update-golang.sh.sha256 | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4a9d69a..9cf680f 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,13 @@ You can use the 'remove' option to undo update-golang.sh work: $ sudo ./update-golang.sh remove +Declutter +====== + +You can use the '-declutter' option to prevent caching downloaded archives: + + $ sudo ./update-golang.sh -declutter + Example ======= diff --git a/update-golang.sh b/update-golang.sh index c31df01..883ca32 100755 --- a/update-golang.sh +++ b/update-golang.sh @@ -96,10 +96,11 @@ has_cmd() { tmp='' ;# will be set save_dir=$PWD previous_install='' ;# will be set +declutter='' ;# will be set tar_to_remove='' ;# will be set cleanup() { [ -n "$tmp" ] && [ -f "$tmp" ] && msg cleanup: $tmp && rm $tmp - [ -n "$tar_to_remove" ] && [ -f "$tar_to_remove" ] && msg cleanup: $tar_to_remove && rm $tar_to_remove + [ -n "$declutter" ] && [ -n "$tar_to_remove" ] && [ -f "$tar_to_remove" ] && msg cleanup: $tar_to_remove && rm $tar_to_remove [ -n "$save_dir" ] && cd "$save_dir" || exit 2 [ -n "$previous_install" ] && msg remember to delete previous install saved as: "$previous_install" } @@ -161,6 +162,7 @@ PROFILED=$profiled CACHE=$cache GOPATH=$GOPATH DEBUG=$DEBUG + EOF } @@ -466,11 +468,14 @@ case "$1" in remove_golang exit 0 ;; + -declutter) + declutter="true" + ;; '') ;; *) msg unknown option: "$1" - echo >&2 usage: "$me [-v] [remove]" + echo >&2 usage: "$me [-v] [remove] [-declutter]" exit 1 ;; esac diff --git a/update-golang.sh.sha256 b/update-golang.sh.sha256 index 43be5da..9e64dbb 100644 --- a/update-golang.sh.sha256 +++ b/update-golang.sh.sha256 @@ -1 +1 @@ -352e4c1baed43a764e176a9f1382680f1f42dfaa82832dd60ddac42dda23db10 update-golang.sh +2be4b5e4c0a482364dc89f1b31921713907818abb0f40fd695a947e9361af7e8 update-golang.sh