diff --git a/functions/backup.sh b/functions/backup.sh index f0c2baf6..c94b0afb 100755 --- a/functions/backup.sh +++ b/functions/backup.sh @@ -5,8 +5,8 @@ backup(){ echo_backup+=("🄱 🄰 🄲 🄺 🅄 🄿 🅂") echo_backup+=("Number of backups was set to $number_of_backups") date=$(date '+%Y_%m_%d_%H_%M_%S') -[[ "$verbose" == "true" ]] && cli -c 'app kubernetes backup_chart_releases backup_name=''"'HeavyScript_"$date"'"' &> /dev/null && echo_backup+=(HeavyScript_"$date") -[[ -z "$verbose" ]] && echo_backup+=("\nNew Backup Name:") && cli -c 'app kubernetes backup_chart_releases backup_name=''"'HeavyScript_"$date"'"' | tail -n 1 &> /dev/null && echo_backup+=(HeavyScript_"$date") +[[ "$verbose" == "true" ]] && cli -c 'app kubernetes backup_chart_releases backup_name=''"'TrueTool_"$date"'"' &> /dev/null && echo_backup+=(TrueTool_"$date") +[[ -z "$verbose" ]] && echo_backup+=("\nNew Backup Name:") && cli -c 'app kubernetes backup_chart_releases backup_name=''"'TrueTool_"$date"'"' | tail -n 1 &> /dev/null && echo_backup+=(TrueTool_"$date") mapfile -t list_backups < <(cli -c 'app kubernetes list_backups' | grep -E "HeavyScript_|TrueTool_" | sort -t '_' -Vr -k2,7 | awk -F '|' '{print $2}'| tr -d " \t\r") if [[ ${#list_backups[@]} -gt "$number_of_backups" ]]; then echo_backup+=("\nDeleted the oldest backup(s) for exceeding limit:") @@ -45,7 +45,7 @@ while true do clear -x title - echo -e "Choose a Restore Point to Delete\nThese may be out of order if they are not HeavyScript backups" + echo -e "Choose a Restore Point to Delete\nThese may be out of order if they are not TrueTool backups" echo "$list_backups" echo echo "0) Exit" @@ -120,7 +120,7 @@ restore(){ clear -x && echo "pulling restore points.." list_backups=$(cli -c 'app kubernetes list_backups' | grep -E "HeavyScript_|TrueTool_" | sort -t '_' -Vr -k2,7 | tr -d " \t\r" | awk -F '|' '{print $2}' | nl -s ") " | column -t) if [[ -z "$list_backups" ]]; then - echo "No HeavyScript restore points available" + echo "No TrueTool restore points available" exit fi @@ -198,7 +198,7 @@ if [[ $borked == True ]]; then echo "If you were to restore, you would lose all of your application data" echo "If you are on Bluefin version: 22.12.0, and have not yet ran the patch, you will need to run it" echo "Afterwards you will be able to create backups and restore them" - echo "This is a known ix-systems bug, and has nothing to do with HeavyScript" + echo "This is a known ix-systems bug and has nothing to do with TrueTool" exit fi diff --git a/functions/menu.sh b/functions/menu.sh deleted file mode 100755 index 8f808c57..00000000 --- a/functions/menu.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/bash - - -menu(){ -clear -x -title -echo "Available Utilities" -echo "-------------------" -echo "1) Help" -echo "2) List DNS Names" -echo "3) Mount and Unmount PVC storage" -echo "4) Backup Options" -echo "5) Update HeavyScript" -echo "6) Update Applications" -echo "7) Command to Container" -echo "8) Patch 22.12.0" -echo "9) Patch 22.12.0 (2)" -echo -echo "0) Exit" -read -rt 120 -p "Please select an option by number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; } - -case $selection in - 0) - echo "Exiting.." - exit - ;; - 1) - help - ;; - 2) - dns - ;; - 3) - mount - ;; - 4) - while [[ $backup_selection != true ]] - do - clear -x - title - echo "Backup Menu" - echo "-----------" - echo "1) Create Backup" - echo "2) Delete Backup" - echo "3) Restore Backup" - echo - echo "0) Exit" - read -rt 120 -p "Please select an option by number: " backup_selection || { echo -e "\nFailed to make a selection in time" ; exit; } - case $backup_selection in - 0) - echo "Exiting.." - exit - ;; - 1) - read -rt 120 -p "What is the maximun number of backups you would like?: " number_of_backups || { echo -e "\nFailed to make a selection in time" ; exit; } - ! [[ $number_of_backups =~ ^[0-9]+$ ]] && echo -e "Error: The input must be an interger\n\"""$number_of_backups""\" is not an interger" >&2 && exit - [[ "$number_of_backups" -le 0 ]] && echo "Error: Number of backups is required to be at least 1" && exit - backup_selection=true - ;; - 2) - backup_selection=true - deleteBackup - ;; - 3) - backup_selection=true - restore - ;; - *) - echo "\"$selection\" was not an option, please try agian" && sleep 3 && continue - ;; - esac - done - ;; - - 5) - self_update - ;; - 6) - script_create - ;; - 7) - cmd_to_container - ;; - 8) - patch_2212_backups - ;; - 9) - patch_2212_backups2 - ;; - *) - echo "\"$selection\" was not an option, please try agian" && sleep 3 && menu - ;; -esac -echo -} -export -f menu diff --git a/functions/misc.sh b/functions/misc.sh index dd1ae239..4cd09905 100755 --- a/functions/misc.sh +++ b/functions/misc.sh @@ -14,219 +14,3 @@ echo echo } export -f sync - - -prune(){ -echo -e "🄿 🅁 🅄 🄽 🄴" -version="$(cli -c 'system version' | awk -F '-' '{print $3}' | awk -F '.' '{print $1 $2}' | tr -d " \t\r\.")" -if (( "$version" >= 2212 )); then - if ! cli -c 'app container config prune prune_options={"remove_unused_images": true, "remove_stopped_containers": true}' | head -n -4; then - echo "Failed to Prune Docker Images" - fi -else - if ! docker image prune -af | grep "^Total"; then - echo "Failed to Prune Docker Images" - fi -fi -} -export -f prune - - -title(){ -echo ' _ _ _____ _ _ ' -echo '| | | | / ___| (_) | | ' -echo '| |_| | ___ __ ___ ___ _\ `--. ___ _ __ _ _ __ | |_' -echo "| _ |/ _ \/ _\` \ \ / / | | |\`--. \/ __| '__| | '_ \| __|" -echo '| | | | __/ (_| |\ V /| |_| /\__/ / (__| | | | |_) | |_ ' -echo '\_| |_/\___|\__,_| \_/ \__, \____/ \___|_| |_| .__/ \__|' -echo ' __/ | | | ' -echo ' |___/ |_| ' -echo "$hs_version" -echo -} -export -f title - - -help(){ -[[ $help == "true" ]] && clear -x - -echo "Access the HeavyScript Menu" -echo "---------------------------" -echo "bash heavy_script.sh" -echo -echo "Utilities" -echo "---------" -echo "--mount | Initiates mounting feature, choose between unmounting and mounting PVC data" -echo "--restore | Opens a menu to restore a \"heavy_script\" backup that was taken on your \"ix-applications\" dataset" -echo "--delete-backup | Opens a menu to delete backups on your system" -echo "--dns | list all of your applications DNS names and their web ports" -echo "--cmd | Open a shell for one of your applications" -echo -echo "Update Types" -echo "------------" -echo "-U | Update all applications, ignores versions" -echo "-U 5 | Same as above, but updates 5 applications at one time" -echo "-u | Update all applications, does not update Major releases" -echo "-u 5 | Same as above, but updates 5 applications at one time" -echo -echo "Update Options" -echo "--------------" -echo "-r | Roll-back applications if they fail to update" -echo "-i | Add application to ignore list, one by one, see example below." -echo "-S | Shutdown applications prior to updating" -echo "-v | verbose output" -echo "-t 500| The amount of time HS will wait for an application to be ACTIVE. Defaults to 500 seconds" -echo -echo "Additional Options" -echo "------------------" -echo "-b 14 | Back-up your ix-applications dataset, specify a number after -b" -echo "-s | sync catalog" -echo "-p | Prune unused/old docker images" -echo "--ignore-img | Ignore container image updates" -echo "--self-update | Updates HeavyScript prior to running any other commands" -echo -echo "Examples" -echo "--------" -echo "bash heavy_script.sh" -echo "bash heavy_script.sh -b 14 -i portainer -i arch -i sonarr -t 600 -vrsUp --self-update" -echo "bash heavy_script.sh -b 14 -i portainer -i arch -i sonarr -t 600 -vrsp -U 10 --self-update" -echo "bash /mnt/tank/scripts/heavy_script.sh -t 150 --mount" -echo "bash /mnt/tank/scripts/heavy_script.sh --dns" -echo "bash heavy_script.sh --restore" -echo "bash /mnt/tank/scripts/heavy_script.sh --delete-backup" -echo -exit -} -export -f help - - - -patch_2212_backups(){ -clear -x -#Check TrueNAS version, skip if not 22.12.0 -if ! [ "$(cli -m csv -c 'system version' | awk -F '-' '{print $3}')" == "22.12.0" ]; then - echo "This patch does not apply to your version of TrueNAS" - return -fi - - -#Description -echo "This patch will fix the issue with backups not restoring properly" -echo "Due to Ix-Systems not saving PVC in backups, this patch will fix that" -echo "Otherwise backups will not restore properly" -echo "You only need to run this patch once, it will not run again" -echo - - -#Download patch -echo "Downloading Backup Patch" -if ! wget -q https://github.com/truecharts/truetool/raw/main/hotpatch/2212/HP1.patch; then - echo "Failed to download Backup Patch" - exit -else - echo "Downloaded Backup Patch" -fi - -echo - -# Apply patch -echo "Applying Backup Patch" -if patch -N --reject-file=/dev/null -s -p0 -d /usr/lib/python3/dist-packages/middlewared/ < HP1.patch &>/dev/null; then - echo "Backup Patch applied" - rm -rf HP1.patch -else - echo "Backup Patch already applied" - rm -rf HP1.patch - exit -fi - -echo - -#Restart middlewared -while true -do - echo "We need to restart middlewared to finish the patch" - echo "This will cause a short downtime for some minor services approximately 10-30 seconds" - echo "Applications should not be affected" - read -rt 120 -p "Would you like to proceed? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; } - case $yesno in - [Yy] | [Yy][Ee][Ss]) - echo "Restarting middlewared" - service middlewared restart & - wait $! - echo "Restarted middlewared" - echo "You are set, there is no need to run this patch again" - break - ;; - [Nn] | [Nn][Oo]) - echo "Exiting" - echo "Please restart middlewared manually" - echo "You can do: service middlewared restart" - exit - ;; - *) - echo "That was not an option, try again" - sleep 3 - continue - ;; - esac -done -} - - -patch_2212_backups2(){ -clear -x -#Check TrueNAS version, skip if not 22.12.0 -if ! [ "$(cli -m csv -c 'system version' | awk -F '-' '{print $3}')" == "22.12.0" ]; then - echo "This patch does not apply to your version of TrueNAS" - return -fi - - -#Description -echo "This patch will fix the issue certain applicattions breaking backups" -echo "You only need to run this patch once, it will not run again" -echo - - -# Apply patch -echo "Applying Backup Patch" -if patch -N --reject-file=/dev/null -s -p0 /usr/lib/python3/dist-packages/middlewared/plugins/kubernetes_linux/backup.py < patches/backups.patch &>/dev/null; then - echo "Backup Patch applied" -else - echo "Backup Patch already applied" - exit -fi - -echo - -#Restart middlewared -while true -do - echo "We need to restart middlewared to finish the patch" - echo "This will cause a short downtime for some minor services approximately 10-30 seconds" - echo "Applications should not be affected" - read -rt 120 -p "Would you like to proceed? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; } - case $yesno in - [Yy] | [Yy][Ee][Ss]) - echo "Restarting middlewared" - service middlewared restart & - wait $! - echo "Restarted middlewared" - echo "You are set, there is no need to run this patch again" - break - ;; - [Nn] | [Nn][Oo]) - echo "Exiting" - echo "Please restart middlewared manually" - echo "You can do: service middlewared restart" - exit - ;; - *) - echo "That was not an option, try again" - sleep 3 - continue - ;; - esac -done -} diff --git a/functions/mount.sh b/functions/mount.sh index 371c98d7..1e7137e3 100755 --- a/functions/mount.sh +++ b/functions/mount.sh @@ -63,7 +63,7 @@ do else echo -e "\nMounted\n$data_name" fi - echo -e "\nUnmount with:\nzfs set mountpoint=legacy $full_path && rmdir /mnt/heavyscript/$data_name\n\nOr use the Unmount All option\n" + echo -e "\nUnmount with:\nzfs set mountpoint=legacy $full_path && rmdir /mnt/truetool/$data_name\n\nOr use the Unmount All option\n" #Ask if user would like to mount something else while true @@ -89,7 +89,7 @@ do done ;; 2) - mapfile -t unmount_array < <(basename -a /mnt/heavyscript/* | sed "s/*//") + mapfile -t unmount_array < <(basename -a /mnt/truetool/* | sed "s/*//") [[ -z ${unmount_array[*]} ]] && echo "Theres nothing to unmount" && sleep 3 && continue for i in "${unmount_array[@]}" do @@ -98,9 +98,9 @@ do pvc=$(echo "$main" | awk '{print $3}') full_path=$(find /mnt/"$pool"/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6-) zfs set mountpoint=legacy "$full_path""$pvc" - echo "$i unmounted" && rmdir /mnt/heavyscript/"$i" || echo "failed to unmount $i" + echo "$i unmounted" && rmdir /mnt/truetool/"$i" || echo "failed to unmount $i" done - rmdir /mnt/heavyscript + rmdir /mnt/truetool sleep 3 ;; *) diff --git a/functions/script_create.sh b/functions/script_create.sh deleted file mode 100755 index 3f1c26e4..00000000 --- a/functions/script_create.sh +++ /dev/null @@ -1,180 +0,0 @@ -#!/bin/bash - - -script_create(){ -while true -do - clear -x - title - echo "Choose Your Update Type" - echo "-----------------------" - echo "1) -U | Update all applications, ignores versions" - echo "2) -u | Update all applications, does not update Major releases" - echo - echo "0) Exit" - echo - read -rt 120 -p "Type the Number or Flag: " current_selection || { echo -e "\nFailed to make a selection in time" ; exit; } - case $current_selection in - 0 | [Ee][Xx][Ii][Tt]) - echo "Exiting.." - exit - ;; - 1 | -U) - while true - do - echo -e "\nHow many applications do you want updating at the same time?" - read -rt 120 -p "Please type an integer greater than 0: " up_async || { echo -e "\nFailed to make a selection in time" ; exit; } - if [[ $up_async == 0 ]]; then - echo "Error: \"$up_async\" is less than 1" - echo "NOT adding it to the list" - sleep 3 - continue - elif ! [[ $up_async =~ ^[0-9]+$ ]]; then - echo "Error: \"$up_async\" is invalid, it needs to be an integer" - echo "NOT adding it to the list" - sleep 3 - continue - else - update_selection+=("-U" "$up_async") - break - fi - done - break - ;; - 2 | -u) - while true - do - echo -e "\nHow many applications do you want updating at the same time?" - read -rt 120 -p "Please type an integer greater than 0: " up_async || { echo -e "\nFailed to make a selection in time" ; exit; } - if [[ $up_async == 0 ]]; then - echo "Error: \"$up_async\" is less than 1" - echo "NOT adding it to the list" - sleep 3 - continue - elif ! [[ $up_async =~ ^[0-9]+$ ]]; then - echo "Error: \"$up_async\" is invalid, it needs to be an integer" - echo "NOT adding it to the list" - sleep 3 - continue - else - update_selection+=("-u" "$up_async") - break - fi - done - break - ;; - *) - echo "$current_selection was not an option, try again" && sleep 3 - continue - ;; - esac -done -while true -do - clear -x - title - echo "Update Options" - echo "--------------" - echo "1) -r | Roll-back applications if they fail to update" - echo "2) -i | Add application to ignore list" - echo "3) -S | Shutdown applications prior to updating" - echo "4) -v | verbose output" - echo "5) -t | Set a custom timeout in seconds when checking if either an App or Mountpoint correctly Started, Stopped or (un)Mounted. Defaults to 500 seconds" - echo - echo "Additional Options" - echo "------------------" - echo "6) -b | Back-up your ix-applications dataset" - echo "7) -s | sync catalog" - echo "8) -p | Prune unused/old docker images" - echo "9) --ignore-img | Ignore container image updates" - echo "10) --self-update | Updates HeavyScript prior to running any other commands" - echo - echo "99) Remove Update Options, Restart" - echo "00) Done making selections, proceed with update" - echo - echo "0) Exit" - echo - echo "Current Choices" - echo "---------------" - echo "bash heavy_script.sh ${update_selection[*]}" - echo - read -rt 600 -p "Type the Number or Flag: " current_selection || { echo -e "\nFailed to make a selection in time" ; exit; } - case $current_selection in - 0 | [Ee][Xx][Ii][Tt]) - echo "Exiting.." - exit - ;; - 00) - clear -x - echo "Running \"bash heavy_script.sh ${update_selection[*]}\"" - echo - exec bash "$script_name" "${update_selection[@]}" - exit - ;; - 1 | -r) - printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "-r" && echo -e "\"-r\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it - update_selection+=("-r") - ;; - 2 | -i) - read -rt 120 -p "What is the name of the application we should ignore?: " up_ignore || { echo -e "\nFailed to make a selection in time" ; exit; } - ! [[ $up_ignore =~ ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$ ]] && echo -e "Error: \"$up_ignore\" is not a possible option for an application name" && sleep 3 && continue - update_selection+=("-i" "$up_ignore") - ;; - 3 | -S) - printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "-S" && echo -e "\"-S\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it - update_selection+=("-S") - ;; - 4 | -v) - printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "-v" && echo -e "\"-v\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it - update_selection+=("-v") - ;; - 5 | -t) - printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "-t" && echo -e "\"-t\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it - echo "What do you want your timeout to be?" - read -rt 120 -p "Please type an integer: " up_timeout || { echo -e "\nFailed to make a selection in time" ; exit; } - ! [[ $up_timeout =~ ^[0-9]+$ ]] && echo -e "Error: \"$up_timeout\" is invalid, it needs to be an integer\nNOT adding it to the list" && sleep 3 && continue - update_selection+=("-t" "$up_timeout") - ;; - 6 | -b) - printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "-b" && echo -e "\"-b\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it - echo "Up to how many backups should we keep?" - read -rt 120 -p "Please type an integer: " up_backups || { echo -e "\nFailed to make a selection in time" ; exit; } - ! [[ $up_backups =~ ^[0-9]+$ ]] && echo -e "Error: \"$up_backups\" is invalid, it needs to be an integer\nNOT adding it to the list" && sleep 3 && continue - [[ $up_backups == 0 ]] && echo -e "Error: Number of backups cannot be 0\nNOT adding it to the list" && sleep 3 && continue - update_selection+=("-b" "$up_backups") - ;; - 7 | -s) - printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "-s" && echo -e "\"-s\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it - update_selection+=("-s") - ;; - 8 | -p) - printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "-p" && echo -e "\"-p\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it - update_selection+=("-p") - ;; - 9 | --ignore-img ) - printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "--ignore-img" && echo -e "\"--ignore-img\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it - update_selection+=("--ignore-img") - ;; - 10 | --self-update ) - printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "--self-update" && echo -e "\"--self-update\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it - update_selection+=("--self-update") - ;; - 99) - count=2 - echo "restarting" - for i in "${update_selection[@]:2}" - do - unset "update_selection[$count]" - echo "$i removed" - ((count++)) - done - sleep 3 - continue - ;; - *) - echo "\"$current_selection\" was not an option, try again" && sleep 3 && continue - ;; - esac -done -} -export -f script_create diff --git a/functions/self_update.sh b/functions/self_update.sh deleted file mode 100755 index 32795d01..00000000 --- a/functions/self_update.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - - -args=("$@") -self_update() { - -git fetch --tags &>/dev/null -git reset --hard &>/dev/null -latest_ver=$(git describe --tags "$(git rev-list --tags --max-count=1)") -echo "🅂 🄴 🄻 🄵" -echo "🅄 🄿 🄳 🄰 🅃 🄴" -if [[ "$hs_version" != "$latest_ver" ]] ; then - echo "Found a new version of HeavyScript, updating myself..." - git checkout "$latest_ver" &>/dev/null - count=0 - for i in "${args[@]}" - do - [[ "$i" == "--self-update" ]] && unset "args[$count]" && break - ((count++)) - done - echo "Updating from: $hs_version" - echo "Updating To: $latest_ver" - echo "Changelog:" - curl --silent "https://api.github.com/repos/HeavyBullets8/heavy_script/releases/latest" | jq -r .body - echo - [[ -z ${args[*]} ]] && echo -e "No more arguments, exiting..\n\n" && exit - echo -e "Running the new version...\n\n" - sleep 5 - exec bash "$script_name" "${args[@]}" - # Now exit this old instance - exit -else - echo "HeavyScript is already the latest version:" - echo -e "$hs_version\n\n" -fi -} -export -f self_update diff --git a/heavy_script.sh b/heavy_script.sh deleted file mode 100755 index 065a4c76..00000000 --- a/heavy_script.sh +++ /dev/null @@ -1,161 +0,0 @@ -#!/bin/bash - - -# cd to script, this ensures the script can find the source scripts below, even when ran from a seperate directory -script=$(readlink -f "$0") -script_path=$(dirname "$script") -script_name="heavy_script.sh" -cd "$script_path" || { echo "Error: Failed to change to script directory" ; exit ; } - -#Version -hs_version=$(git describe --tags) - -source functions/backup.sh -source functions/dns.sh -source functions/menu.sh -source functions/misc.sh -source functions/mount.sh -source functions/self_update.sh -source functions/update_apps.sh -source functions/cmd_to_container.sh -source functions/script_create.sh - - -#If no argument is passed, kill the script. -[[ -z "$*" || "-" == "$*" || "--" == "$*" ]] && menu - - -# Parse script options -while getopts ":si:rb:t:uUpSRv-:" opt -do - case $opt in - -) - case "${OPTARG}" in - help) - help="true" - ;; - self-update) - self_update="true" - ;; - dns) - dns="true" - ;; - cmd) - cmd="true" - ;; - restore) - restore="true" - ;; - mount) - mount="true" - ;; - delete-backup) - deleteBackup="true" - ;; - ignore-img) - ignore_image_update="true" - ;; - *) - echo -e "Invalid Option \"--$OPTARG\"\n" - help - ;; - esac - ;; - :) - echo -e "Option: \"-$OPTARG\" requires an argument\n" - help - ;; - b) - number_of_backups=$OPTARG - ! [[ $OPTARG =~ ^[0-9]+$ ]] && echo -e "Error: -b needs to be assigned an interger\n\"""$number_of_backups""\" is not an interger" >&2 && exit - [[ "$number_of_backups" -le 0 ]] && echo "Error: Number of backups is required to be at least 1" && exit - ;; - r) - rollback="true" - ;; - i) - if ! [[ $OPTARG =~ ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$ ]]; then # Using case insensitive version of the regex used by Truenas Scale - echo -e "Error: \"$OPTARG\" is not a possible option for an application name" - exit - else - ignore+=("$OPTARG") - fi - ;; - t) - timeout=$OPTARG - ! [[ $timeout =~ ^[0-9]+$ ]] && echo -e "Error: -t needs to be assigned an interger\n\"""$timeout""\" is not an interger" >&2 && exit - ;; - s) - sync="true" - ;; - U) - update_all_apps="true" - # Check next positional parameter - eval nextopt=${!OPTIND} - # existing or starting with dash? - if [[ -n $nextopt && $nextopt != -* ]] ; then - OPTIND=$((OPTIND + 1)) - update_limit="$nextopt" - else - update_limit=1 - fi - ;; - u) - update_apps="true" - # Check next positional parameter - eval nextopt=${!OPTIND} - # existing or starting with dash? - if [[ -n $nextopt && $nextopt != -* ]] ; then - OPTIND=$((OPTIND + 1)) - update_limit="$nextopt" - else - update_limit=1 - fi - ;; - S) - stop_before_update="true" - ;; - p) - prune="true" - ;; - v) - verbose="true" - ;; - *) - echo -e "Invalid Option \"-$OPTARG\"\n" - help - ;; - esac -done - - -#exit if incompatable functions are called -[[ "$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 -[[ "$cmd" == "true" ]] && cmd_to_container && exit -[[ "$deleteBackup" == "true" ]] && deleteBackup && exit -[[ "$dns" == "true" ]] && dns && exit -[[ "$restore" == "true" ]] && restore && exit -[[ "$mount" == "true" ]] && mount && exit -if [[ "$number_of_backups" -gt 1 && "$sync" == "true" ]]; then # Run backup and sync at the same time - echo "🅃 🄰 🅂 🄺 🅂 :" - echo -e "-Backing up ix-applications Dataset\n-Syncing catalog(s)" - echo -e "This can take a LONG time, Please Wait For Both Output..\n\n" - backup & - sync & - wait -elif [[ "$number_of_backups" -gt 1 && -z "$sync" ]]; then # If only backup is true, run it - echo "🅃 🄰 🅂 🄺 :" - echo -e "-Backing up \"ix-applications\" Dataset\nPlease Wait..\n\n" - backup -elif [[ "$sync" == "true" && -z "$number_of_backups" ]]; then # If only sync is true, run it - echo "🅃 🄰 🅂 🄺 :" - echo -e "Syncing Catalog(s)\nThis Takes a LONG Time, Please Wait..\n\n" - sync -fi -[[ "$update_all_apps" == "true" || "$update_apps" == "true" ]] && commander -[[ "$prune" == "true" ]] && prune -exit 0 diff --git a/includes/backup.sh b/includes/backup.sh deleted file mode 100755 index e09449f9..00000000 --- a/includes/backup.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/bash - -## Simple shortcut to just list the backups without promts and such -listBackups(){ -echo -e "${BWhite}Backup Listing Tool${Color_Off}" -clear -x && echo "pulling all restore points.." -list_backups=$(cli -c 'app kubernetes list_backups' | grep -v system-update | sort -t '_' -Vr -k2,7 | tr -d " \t\r" | awk -F '|' '{print $2}' | nl | column -t) -[[ -z "$list_backups" ]] && echo -e "${IRed}No restore points available${Color_Off}" && exit || echo "Detected Backups:" && echo "$list_backups" -} -export -f listBackups - -## Lists backups, except system-created backups, and promts which one to delete -deleteBackup(){ -echo -e "${BWhite}Backup Deletion Tool${Color_Off}" -clear -x && echo "pulling all restore points.." -list_delete_backups=$(cli -c 'app kubernetes list_backups' | grep -v system-update | sort -t '_' -Vr -k2,7 | tr -d " \t\r" | awk -F '|' '{print $2}' | nl | column -t) -clear -x -# shellcheck disable=SC2015 -[[ -z "$list_delete_backups" ]] && echo -e "${IRed}No restore points available${Color_Off}" && exit || { title; echo -e "Choose a restore point to delete\nThese may be out of order if they are not TrueTool backups" ; } -# shellcheck disable=SC2015 -echo "$list_delete_backups" && read -rt 600 -p "Please type a number: " selection && restore_point=$(echo "$list_delete_backups" | grep ^"$selection " | awk '{print $2}') -[[ -z "$selection" ]] && echo "${IRed}Your selection cannot be empty${Color_Off}" && exit #Check for valid selection. If none, kill script -[[ -z "$restore_point" ]] && echo "Invalid Selection: $selection, was not an option" && exit #Check for valid selection. If none, kill script -echo -e "\nWARNING:\nYou CANNOT go back after deleting your restore point" || { echo "${IRed}FAILED${Color_Off}"; exit; } -# shellcheck disable=SC2015 -echo -e "\n\nYou have chosen:\n$restore_point\n\nWould you like to continue?" && echo -e "1 Yes\n2 No" && read -rt 120 -p "Please type a number: " yesno || { echo "${IRed}FAILED${Color_Off}"; exit; } -if [[ $yesno == "1" ]]; then - echo -e "\nDeleting $restore_point" && cli -c 'app kubernetes delete_backup backup_name=''"'"$restore_point"'"' &>/dev/null && echo -e "${IGreen}Sucessfully deleted${Color_Off}" || echo -e "${IRed}Deletion FAILED${Color_Off}" -elif [[ $yesno == "2" ]]; then - echo "You've chosen NO, killing script." -else - echo -e "${IRed}Invalid Selection${Color_Off}" -fi -} -export -f deleteBackup - -## Creates backups and deletes backups if a "backups to keep"-count is exceeded. -# backups-to-keep takes only heavyscript and truetool created backups into account, as other backups aren't guaranteed to be sorted correctly -backup(){ -echo -e "${BWhite}Backup Tool${Color_Off}" -echo -e "\nNumber of backups was set to $number_of_backups" -date=$(date '+%Y_%m_%d_%H_%M_%S') -[[ "$verbose" == "true" ]] && cli -c 'app kubernetes backup_chart_releases backup_name=''"'TrueTool_"$date"'"' -[[ -z "$verbose" ]] && echo -e "\nNew Backup Name:" && cli -c 'app kubernetes backup_chart_releases backup_name=''"'TrueTool_"$date"'"' | tail -n 1 -mapfile -t list_create_backups < <(cli -c 'app kubernetes list_backups' | grep 'HeavyScript\|TrueTool_' | sort -t '_' -Vr -k2,7 | awk -F '|' '{print $2}'| tr -d " \t\r") -# shellcheck disable=SC2309 -if [[ ${#list_create_backups[@]} -gt "number_of_backups" ]]; then - echo -e "\nDeleting the oldest backup(s) for exceeding limit:" - overflow=$(( ${#list_create_backups[@]} - "$number_of_backups" )) - mapfile -t list_overflow < <(cli -c 'app kubernetes list_backups' | grep "TrueTool_" | sort -t '_' -V -k2,7 | awk -F '|' '{print $2}'| tr -d " \t\r" | head -n "$overflow") - for i in "${list_overflow[@]}" - do - cli -c 'app kubernetes delete_backup backup_name=''"'"$i"'"' &> /dev/null || echo "${IRed}FAILED${Color_Off} to delete $i" - echo "$i" - done -fi -} -export -f backup - -## Lists available backup and prompts the users to select a backup to restore -restore(){ -echo -e "${BWhite}Backup Restoration Tool${Color_Off}" -clear -x && echo "pulling restore points.." -list_restore_backups=$(cli -c 'app kubernetes list_backups' | grep "TrueTool_" | sort -t '_' -Vr -k2,7 | tr -d " \t\r" | awk -F '|' '{print $2}' | nl | column -t) -clear -x -# shellcheck disable=SC2015 -[[ -z "$list_restore_backups" ]] && echo "No TrueTool restore points available" && exit || { title; echo "Choose a restore point" ; } -echo "$list_restore_backups" && read -rt 600 -p "Please type a number: " selection && restore_point=$(echo "$list_restore_backups" | grep ^"$selection " | awk '{print $2}') -[[ -z "$selection" ]] && echo "Your selection cannot be empty" && exit #Check for valid selection. If none, kill script -[[ -z "$restore_point" ]] && echo "Invalid Selection: $selection, was not an option" && exit #Check for valid selection. If none, kill script -echo -e "\nWARNING:\nThis is NOT guranteed to work\nThis is ONLY supposed to be used as a LAST RESORT\nConsider rolling back your applications instead if possible" || { echo "${IRed}FAILED${Color_Off}"; exit; } -# shellcheck disable=SC2015 -echo -e "\n\nYou have chosen:\n$restore_point\n\nWould you like to continue?" && echo -e "1 Yes\n2 No" && read -rt 120 -p "Please type a number: " yesno || { echo "${IRed}FAILED${Color_Off}"; exit; } -if [[ $yesno == "1" ]]; then - echo -e "\nStarting Restore, this will take a ${BWhite}LONG${Color_Off} time." - pool=$(cli -c 'app kubernetes config' | grep -E "pool\s\|" | awk -F '|' '{print $3}' | tr -d " \t\n\r") - echo "Correcting PVC mountpoints..." - for pvc in $(zfs list -t filesystem -r "$pool"/ix-applications -o name -H | grep "/ix-applications/" | grep "volumes/pvc") - do - zfs set mountpoint=legacy "${pvc}" || echo "Fixing PVC mountpoints Failed for ${pvc}... Continuing..." - done - # Ensure readonly is turned off - if ! zfs set readonly=off "$pool"/ix-applications;then - echo -e "Error: Failed to set ZFS ReadOnly to \"off\"" - echo -e "After the restore, attempt to run the following command manually:" - echo "zfs set readonly=off $pool/ix-applications" - fi - echo "Triggering restore process..." - cli -c 'app kubernetes restore_backup backup_name=''"'"$restore_point"'"' || echo "Restore ${IRed}FAILED${Color_Off}" -elif [[ $yesno == "2" ]]; then - echo "You've chosen NO, killing script. Good luck." -else - echo -e "${IRed}Invalid Selection${Color_Off}" -fi -} -export -f restore diff --git a/includes/chores.sh b/includes/chores.sh index 9f3cbc6a..95de557d 100755 --- a/includes/chores.sh +++ b/includes/chores.sh @@ -25,18 +25,21 @@ export -f kubeapiEnable # Prune unused docker images to prevent dataset/snapshot bloat related slowdowns on SCALE prune(){ -echo -e "${BWhite}Docker Prune${Color_Off}" -echo "Pruning Docker Images..." -docker image prune -af | grep "^Total" && echo -e "${IGreen}Docker Prune Successfull${Color_Off}" || echo "Docker Prune ${IRed}FAILED${Color_Off}" - -# TODO Switch to middleware prune on next release -# midclt call container.prune '{"remove_unused_images": true, "remove_stopped_containers": true}' &> /dev/null && echo "Docker Prune completed"|| echo "Docker Prune ${IRed}FAILED${Color_Off}" +echo -e "🄿 🅁 🅄 🄽 🄴" +if (( "$scaleVersion" >= 22120 )); then + cli -c 'app container config prune prune_options={"remove_unused_images": true, "remove_stopped_containers": true}' | head -n -4 || echo "Failed to Prune Docker Images" +else + docker image prune -af | grep "^Total" || echo "Failed to Prune Docker Images" +fi } export -f prune -# -sync(){ -echo -e "${BWhite}Starting Catalog Sync...${Color_Off}" -cli -c 'app catalog sync_all' &> /dev/null && echo -e "${IGreen}Catalog sync complete${Color_Off}" || echo -e "${IRed}Catalog Sync Failed${Color_Off}" +middlewareRestart() { + echo "We need to restart middlewared." + echo "This will cause a short downtime for the webui approximately 10-30 seconds" + echo "Restarting middlewared" + service middlewared restart & + wait $! + echo "Restarted middlewared" } -export -f sync +export -f middlewareRestart diff --git a/includes/colors.sh b/includes/colors.sh deleted file mode 100755 index a1f8cbdd..00000000 --- a/includes/colors.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/bin/bash -# shellcheck disable=SC2034 - -# Reset -Color_Off='\033[0m' # Text Reset - -# Regular Colors -Black='\033[0;30m' # Black -Red='\033[0;31m' # Red -Green='\033[0;32m' # Green -Yellow='\033[0;33m' # Yellow -Blue='\033[0;34m' # Blue -Purple='\033[0;35m' # Purple -Cyan='\033[0;36m' # Cyan -White='\033[0;37m' # White - -# Bold -BBlack='\033[1;30m' # Black -BRed='\033[1;31m' # Red -BGreen='\033[1;32m' # Green -BYellow='\033[1;33m' # Yellow -BBlue='\033[1;34m' # Blue -BPurple='\033[1;35m' # Purple -BCyan='\033[1;36m' # Cyan -BWhite='\033[1;37m' # White - -# Underline -UBlack='\033[4;30m' # Black -URed='\033[4;31m' # Red -UGreen='\033[4;32m' # Green -UYellow='\033[4;33m' # Yellow -UBlue='\033[4;34m' # Blue -UPurple='\033[4;35m' # Purple -UCyan='\033[4;36m' # Cyan -UWhite='\033[4;37m' # White - -# High Intensity -IBlack='\033[0;90m' # Black -IRed='\033[0;91m' # Red -IGreen='\033[0;92m' # Green -IYellow='\033[0;93m' # Yellow -IBlue='\033[0;94m' # Blue -IPurple='\033[0;95m' # Purple -ICyan='\033[0;96m' # Cyan -IWhite='\033[0;97m' # White - - -# Bold High Intensity -BIBlack='\033[1;90m' # Black -BIRed='\033[1;91m' # Red -BIGreen='\033[1;92m' # Green -BIYellow='\033[1;93m' # Yellow -BIBlue='\033[1;94m' # Blue -BIPurple='\033[1;95m' # Purple -BICyan='\033[1;96m' # Cyan -BIWhite='\033[1;97m' # White - -noColor(){ -# Reset -Color_Off="" - -# Regular Colors -Black="" -Red="" -Green="" -Yellow="" -Blue="" -Purple="" -Cyan="" -White="" - -# Bold -BBlack="" -BRed="" -BGreen="" -BYellow="" -BBlue="" -BPurple="" -BCyan="" -BWhite="" - -# Underline -UBlack="" -URed="" -UGreen="" -UYellow="" -UBlue="" -UPurple="" -UCyan="" -UWhite="" - -# High Intensity -IBlack="" -IRed="" -IGreen="" -IYellow="" -IBlue="" -IPurple="" -ICyan="" -IWhite="" - - -# Bold High Intensity -BIBlack="" -BIRed="" -BIGreen="" -BIYellow="" -BIBlue="" -BIPurple="" -BICyan="" -BIWhite="" - } - export -f noColor diff --git a/includes/dns.sh b/includes/dns.sh deleted file mode 100755 index 0e12e90a..00000000 --- a/includes/dns.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -dns(){ - echo -e "${BWhite}Service DNS Names Tool${Color_Off}" -clear -x -echo "Generating Internal Service DNS Names..." -#ignored dependency pods, may need to add more in the future. -dep_ignore="\-cronjob\-|^kube-system|\ssvclb|NAME|\-memcached\-.[^custom\-app]|\-postgresql\-.[^custom\-app]|\-redis\-.[^custom\-app]|\-mariadb\-.[^custom\-app]|\-promtail\-.[^custom\-app]" - -# Pulling pod names -mapfile -t main < <(k3s kubectl get pods -A | grep -Ev "$dep_ignore" | sort) - -# Pulling all ports -all_ports=$(k3s kubectl get service -A) - -clear -x -count=0 -for i in "${main[@]}" -do - [[ count -le 0 ]] && echo -e "\n" && ((count++)) - appName=$(echo "$i" | awk '{print $2}' | sed 's/-[^-]*-[^-]*$//' | sed 's/-0//') - ixName=$(echo "$i" | awk '{print $1}') - port=$(echo "$all_ports" | grep -E "\s$appName\s" | awk '{print $6}' | grep -Eo "^[[:digit:]]+{1}") - [[ -n "$port" ]] && echo -e "$appName.$ixName.svc.cluster.local $port" -done | uniq | nl -b t | sed 's/\s\s\s$/- -------- ----/' | column -t -R 1 -N "#,DNS_Name,Port" -L -} -export -f dns diff --git a/includes/patch.sh b/includes/patch.sh index 82393dea..cecbf90d 100755 --- a/includes/patch.sh +++ b/includes/patch.sh @@ -2,17 +2,29 @@ patchv22120(){ echo "Applying 22.12 HotPatch 1" -( wget -q -P /tmp https://github.com/truecharts/truetool/raw/main/hotpatch/2212/HP1.patch && echo "download completed" || echo "download failed" ) && ( patch -N -s -p0 -d /usr/lib/python3/dist-packages/middlewared/ < /tmp/HP1.patch && service middlewared restart && echo "waiting 20 seconds for middleware restart..." && sleep 20 && echo "patch completed" || echo "patch failed or skipped, not critical" ) && rm -rf /tmp/HP1.patch + +( wget -q -P /tmp https://github.com/truecharts/truetool/raw/main/hotpatch/2212/HP1.patch && echo "download completed" || echo "download failed" ) && ( patch -N -s -p0 -d /usr/lib/python3/dist-packages/middlewared/ &>/dev/null < /tmp/HP1.patch && echo "patch completed" || echo "Patch Already Applied" ) && rm -rf /tmp/HP1.patch + echo "Applying 22.12 HotPatch 2" -( wget -q -P /tmp https://github.com/truecharts/truetool/raw/main/hotpatch/2212/HP2.patch && echo "download completed" || echo "download failed" ) && ( patch -N -s -p0 -d /usr/lib/python3/dist-packages/middlewared/ < /tmp/HP2.patch && service middlewared restart && echo "waiting 20 seconds for middleware restart..." && sleep 20 && echo "patch completed" || echo "patch failed or skipped, not critical" ) && rm -rf /tmp/HP2.patch +( wget -q -P /tmp https://github.com/truecharts/truetool/raw/main/hotpatch/2212/HP2.patch && echo "download completed" || echo "download failed" ) && ( patch -N -s -p0 -d /usr/lib/python3/dist-packages/middlewared/ &>/dev/null < /tmp/HP2.patch && echo "patch completed" || echo "Patch Already Applied" ) && rm -rf /tmp/HP2.patch } export -f patchv22120 + + hotpatch(){ echo "Starting hotpatcher..." -if [ "$(cli -m csv -c 'system version' | awk -F '-' '{print $3}')" == "22.12.0" ]; then +restartmiddleware=no +if (( "$scaleVersion" == 22120 )); then patchv22120 + restartmiddleware=yes +else + echo "No hotpatch available for your version, congratulations!" +fi + +if (( "$restartmiddleware" == "yes" )); then + middlewareRestart fi } export -f hotpatch diff --git a/includes/update.sh b/includes/update.sh deleted file mode 100755 index 0aaa7506..00000000 --- a/includes/update.sh +++ /dev/null @@ -1,123 +0,0 @@ -#!/bin/bash - -update_apps(){ -echo -e "${BWhite}App Updater${Color_Off}" -[[ -z $timeout ]] && echo -e "Default 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" - -echo "" -echo "Creating list of Apps to update..." - -# Render a list of ignored applications, so users can verify their ignores got parsed correctly. -if [[ -z ${ignore[*]} ]]; then - echo "No apps added to ignore list, continuing..." -else - echo "ignored applications:" - for ignored in "${ignore[@]}" - do - echo "${ignored}" - done -fi -echo "" - -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) -[[ -z ${array[*]} ]] && echo -e "\nThere are no updates available or middleware timed out" && return 0 || echo -e "\n${#array[@]} update(s) available:" -PIDlist=() - -# Draft a list of app names, seperate from actuall execution -# This prevents outputs getting mixed together -for i in "${array[@]}" -do - app_name=$(echo "$i" | awk -F ',' '{print $1}') #print out first catagory, name. - echo "$app_name" -done - -echo "" -echo "Updating Apps..." - -# Create a background task for each update as async solution -for i in "${array[@]}" -do - executeUpdate "${i}" & - PIDlist+=($!) -done -echo "" -echo "Waiting for update results..." - -# Wait for all the async updates to complete -for p in "${PIDlist[@]}" -do - wait "${p}" ||: -done - -} -export -f update_apps - - - -# This is a combination of stopping previously-stopped apps and apps stuck Deploying after update -after_update_actions(){ -SECONDS=0 -count=0 -sleep 15 - -# Keep this running and exit the endless-loop based on a timer, instead of a countered-while-loop -# shellcheck disable=SC2050 -while [[ "0" != "1" ]] -do - (( count++ )) - status=$(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,status' | grep "^$app_name," | awk -F ',' '{print $2}') - if [[ "$status" == "ACTIVE" && "$startstatus" == "STOPPED" ]]; then - [[ "$verbose" == "true" ]] && echo "Returing to STOPPED state.." - midclt call chart.release.scale "$app_name" '{"replica_count": 0}' &> /dev/null && echo "Stopped"|| echo "FAILED" - break - elif [[ "$SECONDS" -ge "$timeout" && "$status" == "DEPLOYING" && "$failed" != "true" ]]; then - echo -e "Error: Run Time($SECONDS) for $app_name has exceeded Timeout($timeout)\nIf this is a slow starting application, set a higher timeout with -t\nIf this applicaion is always DEPLOYING, you can disable all probes under the Healthcheck Probes Liveness section in the edit configuration\nReverting update.." - midclt call chart.release.rollback "$app_name" "{\"item_version\": \"$rollback_version\"}" &> /dev/null - [[ "$startstatus" == "STOPPED" ]] && failed="true" && after_update_actions && unset failed #run back after_update_actions function if the app was stopped prior to update - break - elif [[ "$SECONDS" -ge "$timeout" && "$status" == "DEPLOYING" && "$failed" == "true" ]]; then - echo -e "Error: Run Time($SECONDS) for $app_name has exceeded Timeout($timeout)\nThe application failed to be ACTIVE even after a rollback,\nManual intervention is required\nAbandoning" - break - elif [[ "$status" == "STOPPED" ]]; then - [[ "$count" -le 1 && "$verbose" == "true" ]] && echo "Verifying Stopped.." && sleep 15 && continue #if reports stopped on FIRST time through loop, double check - [[ "$count" -le 1 && -z "$verbose" ]] && sleep 15 && continue #if reports stopped on FIRST time through loop, double check - echo "Stopped" && break #if reports stopped any time after the first loop, assume its extermal services. - elif [[ "$status" == "ACTIVE" ]]; then - [[ "$count" -le 1 && "$verbose" == "true" ]] && echo "Verifying Active.." && sleep 15 && continue #if reports active on FIRST time through loop, double check - [[ "$count" -le 1 && -z "$verbose" ]] && sleep 15 && continue #if reports active on FIRST time through loop, double check - echo "Active" && break #if reports active any time after the first loop, assume actually active. - else - [[ "$verbose" == "true" ]] && echo "Waiting $((timeout-SECONDS)) more seconds for $app_name to be ACTIVE" - sleep 15 - continue - fi -done -} -export -f after_update_actions - -# Determine what all the required information for the App to update, check it and execute the update using the SCALE API -executeUpdate(){ - app_name=$(echo "$1" | awk -F ',' '{print $1}') #print out first catagory, name. - old_app_ver=$(echo "$1" | awk -F ',' '{print $4}' | awk -F '_' '{print $1}' | awk -F '.' '{print $1}') #previous/current Application MAJOR Version - new_app_ver=$(echo "$1" | awk -F ',' '{print $5}' | awk -F '_' '{print $1}' | awk -F '.' '{print $1}') #new Application MAJOR Version - old_chart_ver=$(echo "$1" | awk -F ',' '{print $4}' | awk -F '_' '{print $2}' | awk -F '.' '{print $1}') # Old Chart MAJOR version - new_chart_ver=$(echo "$1" | awk -F ',' '{print $5}' | awk -F '_' '{print $2}' | awk -F '.' '{print $1}') # New Chart MAJOR version - status=$(echo "$1" | awk -F ',' '{print $2}') #status of the app: STOPPED / DEPLOYING / ACTIVE - startstatus=$status - diff_app=$(diff <(echo "$old_app_ver") <(echo "$new_app_ver")) #caluclating difference in major app versions - diff_chart=$(diff <(echo "$old_chart_ver") <(echo "$new_chart_ver")) #caluclating difference in Chart versions - old_full_ver=$(echo "$1" | awk -F ',' '{print $4}') #Upgraded From - new_full_ver=$(echo "$1" | awk -F ',' '{print $5}') #Upraded To - rollback_version=$(echo "$1" | awk -F ',' '{print $4}' | awk -F '_' '{print $2}') - printf '%s\0' "${ignore[@]}" | grep -iFxqz "${app_name}" && echo -e "\n$app_name\nIgnored, skipping" && return #If application is on ignore list, skip - if [[ "$diff_app" == "$diff_chart" || "$update_all_apps" == "true" ]]; then #continue to update - [[ "$verbose" == "true" ]] && echo "Updating.." - # shellcheck disable=SC2015 - cli -c 'app chart_release upgrade release_name=''"'"$app_name"'"' &> /dev/null && echo -e "Updated $app_name\n$old_full_ver\n$new_full_ver" && after_update_actions || { echo -e "$app_name: update ${IRed}FAILED${Color_Off}"; return; } - else - echo -e "\n$app_name\nMajor Release, update manually" - return - fi -} -export -f executeUpdate diff --git a/truetool.sh b/truetool.sh index 6e03990f..3fd25056 100755 --- a/truetool.sh +++ b/truetool.sh @@ -12,29 +12,32 @@ targetRepo="https://github.com/truecharts/truetool.git" cd "${SCRIPT_DIR}" || echo -e "ERROR: Something went wrong accessing the script directory" # Includes -# shellcheck source=includes/backup.sh -source includes/backup.sh # shellcheck source=includes/chores.sh source includes/chores.sh -# shellcheck source=includes/colors.sh -source includes/colors.sh -# shellcheck source=includes/dns.sh -source includes/dns.sh # shellcheck source=includes/help.sh source includes/help.sh # shellcheck source=includes/help.sh source includes/patch.sh -# shellcheck source=includes/mount.sh -source includes/mount.sh # shellcheck source=includes/no_args.sh source includes/no_args.sh # shellcheck source=includes/title.sh source includes/title.sh -# shellcheck source=includes/update.sh -source includes/update.sh # shellcheck source=includes/update_self.sh source includes/update_self.sh +# Libraries loaded from Heavyscript +# shellcheck source=functions/dns.sh +source functions/dns.sh +# shellcheck source=functions/misc.sh +source functions/misc.sh +# shellcheck source=functions/mount.sh +source functions/mount.sh +# shellcheck source=functions/backup.sh +source functions/backup.sh +# shellcheck source=functions/update_apps.sh +source functions/update_apps.sh + + #If no argument is passed, set flag to show menu if [[ -z "$*" || "-" == "$*" || "--" == "$*" ]]; then no_args="true" @@ -73,9 +76,6 @@ else kubeapi-enable) kubeapiEnable="true" ;; - no-color) - noColor - ;; *) echo -e "Invalid Option \"--$OPTARG\"\n" && help exit @@ -131,6 +131,10 @@ title [[ "$enableUpdate" == "true" ]] && updater "$@" +scaleVersion=$(cli -c 'system version' | awk -F '-' '{print $3}' | awk -F '.' '{print $1 $2 $3}' | tr -d " \t\r\.") +update_limit=$(nproc --all) +rollback="true" + ## Always check if a hotpatch needs to be applied hotpatch @@ -173,7 +177,21 @@ fi [[ "$dns" == "true" ]] && dns && exit [[ "$restore" == "true" ]] && restore && exit [[ "$mountPVC" == "true" ]] && mountPVC && exit -[[ "$number_of_backups" -ge 1 ]] && backup -[[ "$sync" == "true" ]] && sync +if [[ "$number_of_backups" -gt 1 && "$sync" == "true" ]]; then # Run backup and sync at the same time + echo "Running Apps Backup & Syncing Catalog" + if [[ "$prune" == "true" ]]; then + prune & + fi + backup & + sync & + wait +elif [[ "$number_of_backups" -gt 1 && -z "$sync" ]]; then # If only backup is true, run it + echo "Running Apps Backup" + backup +elif [[ "$sync" == "true" && -z "$number_of_backups" ]]; then # If only sync is true, run it + echo "Syncing Catalog" + echo -e "Syncing Catalog(s)\n\n" + sync +fi [[ "$update_all_apps" == "true" || "$update_apps" == "true" ]] && update_apps [[ "$prune" == "true" ]] && prune