From ec6e0884ef1ce5067895a25385975b37cca55ae8 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Wed, 20 Jul 2022 05:52:34 -0600 Subject: [PATCH 1/5] testing new self update --- heavy_script.sh | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/heavy_script.sh b/heavy_script.sh index 176a0582..f52fb90e 100644 --- a/heavy_script.sh +++ b/heavy_script.sh @@ -3,8 +3,6 @@ #If no argument is passed, kill the script. [[ -z "$*" || "-" == "$*" || "--" == "$*" ]] && echo "This script requires an argument, use --help for help" && exit -echo "yep" - args=("$@") self_update() { @@ -14,23 +12,27 @@ SCRIPTNAME="$0" cd $SCRIPTPATH git fetch &> /dev/null -[[ -n $(git diff --name-only origin/beta | grep $SCRIPTNAME) ]] && { +if [[ -n $(git diff --name-only origin/main | grep $SCRIPTNAME) ]]; then echo "Found a new version of HeavyScript, updating myself..." - git pull --force &> /dev/null + git reset --hard -q + git pull --force -q echo -e "Running the new version...\n" count=0 for i in "${args[@]}" do - [[ "$i" == "--self-update" ]] && unset "args[$count]" && break - ((count++)) + [[ "$i" == "--self-update" ]] && unset "args[$count]" && args+=("--updated") && break + ((count++)) done sleep 5 exec bash "$SCRIPTNAME" "${args[@]}" # Now exit this old instance - exit 1 - } - echo -e "Already the latest version.\n" + exit +elif [[ $self_update == "true" ]]; then + echo -e "HeavyScript has been updated\n" +else + echo -e "HeavyScript is already the latest version\n" +fi } @@ -59,7 +61,7 @@ echo "Examples" echo "bash heavy_script.sh -b 14 -i portainer -i arch -i sonarr -i radarr -t 600 -vrsUp" echo "bash /mnt/tank/scripts/heavy_script.sh -t 150 --mount" echo "bash /mnt/tank/scripts/heavy_script.sh --dns" -echo "bash /mnt/tank/scripts/heavy_script.sh --restore" +echo "bash heavy_script.sh --restore" echo "bash /mnt/tank/scripts/heavy_script.sh --delete-backup" echo exit @@ -218,7 +220,7 @@ export -f sync update_apps(){ -mapfile -t array < <(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,container_images_update_available,status' | grep -E ",true(,|$)" | sort) +mapfile -t array < <(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,container_images_update_available,status' | grep -E ",true(,|\b)" | sort) [[ -z $array ]] && echo -e "\nThere are no updates available" && return 0 || echo -e "\n${#array[@]} update(s) available" [[ -z $timeout ]] && echo -e "\nDefault Timeout: 500" && timeout=500 || echo -e "\nCustom Timeout: $timeout" [[ "$timeout" -le 120 ]] && echo "Warning: Your timeout is set low and may lead to premature rollbacks or skips" @@ -269,7 +271,7 @@ do else #user must not be using -S, just update echo -e "\n$app_name" [[ "$verbose" == "true" ]] && echo "Updating.." - cli -c 'app chart_release upgrade release_name=''"'"$app_name"'"' &> /dev/null && echo -e "Updated\n$old_full_ver\n$new_full_ver" && after_update_actions || { echo "FAILED"; continue; } + cli -c 'app chart_release upgrade release_name=''"'"$app_name"'"' &> /dev/null && echo -e "Updated\n$old_full_ver\n$new_full_ver" && after_update_actions || echo "FAILED" fi else echo -e "\n$app_name\nMajor Release, update manually" @@ -372,10 +374,10 @@ do case $opt in -) case "${OPTARG}" in - help) + help) help="true" ;; - self-update) + self-update) self_update="true" ;; dns) @@ -390,6 +392,9 @@ do delete-backup) deleteBackup="true" ;; + updated) + self_update="true" + ;; *) echo -e "Invalid Option \"--$OPTARG\"\n" && help exit @@ -455,8 +460,8 @@ done [[ "$update_all_apps" == "true" && "$update_apps" == "true" ]] && echo -e "-U and -u cannot BOTH be called" && exit #Continue to call functions in specific order -[[ "$self_update" == "true" ]] && self_update [[ "$help" == "true" ]] && help +[[ "$self_update" == "true" ]] && self_update [[ "$deleteBackup" == "true" ]] && deleteBackup && exit [[ "$dns" == "true" ]] && dns && exit [[ "$restore" == "true" ]] && restore && exit @@ -464,4 +469,4 @@ done [[ "$number_of_backups" -ge 1 ]] && backup [[ "$sync" == "true" ]] && sync [[ "$update_all_apps" == "true" || "$update_apps" == "true" ]] && update_apps -[[ "$prune" == "true" ]] && prune \ No newline at end of file +[[ "$prune" == "true" ]] && prune From cf004dd928faa0f627fc23b2d84e5889e31e52a3 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Wed, 20 Jul 2022 05:54:30 -0600 Subject: [PATCH 2/5] beta --- heavy_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heavy_script.sh b/heavy_script.sh index f52fb90e..f04acab5 100644 --- a/heavy_script.sh +++ b/heavy_script.sh @@ -12,7 +12,7 @@ SCRIPTNAME="$0" cd $SCRIPTPATH git fetch &> /dev/null -if [[ -n $(git diff --name-only origin/main | grep $SCRIPTNAME) ]]; then +if [[ -n $(git diff --name-only origin/beta | grep $SCRIPTNAME) ]]; then echo "Found a new version of HeavyScript, updating myself..." git reset --hard -q git pull --force -q From 0237617ba2bf9e31ef7ab9296e767e62a1496647 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Wed, 20 Jul 2022 05:56:59 -0600 Subject: [PATCH 3/5] var name --- heavy_script.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/heavy_script.sh b/heavy_script.sh index f04acab5..042d0d0c 100644 --- a/heavy_script.sh +++ b/heavy_script.sh @@ -28,7 +28,7 @@ if [[ -n $(git diff --name-only origin/beta | grep $SCRIPTNAME) ]]; then # Now exit this old instance exit -elif [[ $self_update == "true" ]]; then +elif [[ $self_updated == "true" ]]; then echo -e "HeavyScript has been updated\n" else echo -e "HeavyScript is already the latest version\n" @@ -393,7 +393,7 @@ do deleteBackup="true" ;; updated) - self_update="true" + self_updated="true" ;; *) echo -e "Invalid Option \"--$OPTARG\"\n" && help From 8d410dfb2e48390a76f11dd37220c7e497c7508b Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Wed, 20 Jul 2022 05:59:54 -0600 Subject: [PATCH 4/5] null change --- heavy_script.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/heavy_script.sh b/heavy_script.sh index 042d0d0c..078b570c 100644 --- a/heavy_script.sh +++ b/heavy_script.sh @@ -36,6 +36,7 @@ fi } + help(){ [[ $help == "true" ]] && clear -x echo "Basic Utilities" From 9468664baec6684b231d5bc25808bd1023afac52 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Wed, 20 Jul 2022 06:04:16 -0600 Subject: [PATCH 5/5] test --- heavy_script.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/heavy_script.sh b/heavy_script.sh index 078b570c..6baba984 100644 --- a/heavy_script.sh +++ b/heavy_script.sh @@ -28,8 +28,6 @@ if [[ -n $(git diff --name-only origin/beta | grep $SCRIPTNAME) ]]; then # Now exit this old instance exit -elif [[ $self_updated == "true" ]]; then - echo -e "HeavyScript has been updated\n" else echo -e "HeavyScript is already the latest version\n" fi @@ -462,6 +460,7 @@ done #Continue to call functions in specific order [[ "$help" == "true" ]] && help +[[ $self_updated == "true" ]] && echo -e "HeavyScript has been updated\n" [[ "$self_update" == "true" ]] && self_update [[ "$deleteBackup" == "true" ]] && deleteBackup && exit [[ "$dns" == "true" ]] && dns && exit