add while loop and general improvements

This commit is contained in:
Heavybullets8 2022-12-15 19:57:32 -07:00
parent bcadb12e11
commit 948b3fd5ad

View File

@ -31,16 +31,16 @@ export -f backup
deleteBackup(){ deleteBackup(){
while true clear -x && echo "pulling all restore points.."
do list_backups=$(cli -c 'app kubernetes list_backups' | sort -t '_' -Vr -k2,7 | tr -d " \t\r" | awk -F '|' '{print $2}' | nl -s ") " | column -t)
clear -x && echo "pulling all restore points.." if [[ -z "$list_backups" ]]; then
list_backups=$(cli -c 'app kubernetes list_backups' | sort -t '_' -Vr -k2,7 | tr -d " \t\r" | awk -F '|' '{print $2}' | nl -s ") " | column -t)
if [[ -z "$list_backups" ]]; then
echo "No restore points available" echo "No restore points available"
exit exit
fi fi
while true
do #Select a restore point
while true
do
clear -x clear -x
title 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 HeavyScript backups"
@ -62,9 +62,11 @@ do
continue continue
fi fi
break # Break out of the loop if all of the If statement checks above are untrue break # Break out of the loop if all of the If statement checks above are untrue
done done
while true
do #Confirm deletion
while true
do
clear -x clear -x
echo -e "WARNING:\nYou CANNOT go back after deleting your restore point" echo -e "WARNING:\nYou CANNOT go back after deleting your restore point"
echo -e "\n\nYou have chosen:\n$restore_point\n\n" echo -e "\n\nYou have chosen:\n$restore_point\n\n"
@ -86,9 +88,11 @@ do
continue continue
;; ;;
esac esac
done done
while true
do #Check if there are more backups to delete
while true
do
read -rt 120 -p "Delete more backups? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; } read -rt 120 -p "Delete more backups? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; }
case $yesno in case $yesno in
[Yy] | [Yy][Ee][Ss]) [Yy] | [Yy][Ee][Ss])
@ -105,23 +109,22 @@ do
esac esac
done
done done
} }
export -f deleteBackup export -f deleteBackup
restore(){ restore(){
while true clear -x && echo "pulling restore points.."
do 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)
clear -x && echo "pulling restore points.." if [[ -z "$list_backups" ]]; then
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 HeavyScript restore points available"
exit exit
fi fi
while true
do #Select a restore point
while true
do
clear -x clear -x
title title
echo "Choose a Restore Point" echo "Choose a Restore Point"
@ -143,21 +146,22 @@ do
continue continue
fi fi
break break
done done
# Get the date of system version and when it was updated # Get the date of system version and when it was updated
current_version=$(cli -m csv -c 'system version' | awk -F '-' '{print $3}') current_version=$(cli -m csv -c 'system version' | awk -F '-' '{print $3}')
when_updated=$(cli -m csv -c 'system bootenv query created,realname' | grep "$current_version",\ when_updated=$(cli -m csv -c 'system bootenv query created,realname' | grep "$current_version",\
| awk -F ',' '{print $2}' | sed 's/[T|-]/_/g' | sed 's/:/_/g' | awk -F '_' '{print $1 $2 $3 $4 $5}') | awk -F ',' '{print $2}' | sed 's/[T|-]/_/g' | sed 's/:/_/g' | awk -F '_' '{print $1 $2 $3 $4 $5}')
# Get the date of the chosen restore point # Get the date of the chosen restore point
restore_point_date=$(echo "$restore_point" | awk -F '_' '{print $2 $3 $4 $5 $6}' | tr -d "_") restore_point_date=$(echo "$restore_point" | awk -F '_' '{print $2 $3 $4 $5 $6}' | tr -d "_")
# Compare the dates # Compare the dates
if (("$restore_point_date" < "$when_updated" )); then while (("$restore_point_date" < "$when_updated" ))
do
clear -x clear -x
echo "The restore point you have chosen is from an older version of Truenas Scale" echo "The restore point you have chosen is from an older version of Truenas Scale"
echo "This is not recommended, as it may cause issues with the system" echo "This is not recommended, as it may cause issues with the system"
@ -166,6 +170,7 @@ do
[Yy] | [Yy][Ee][Ss]) [Yy] | [Yy][Ee][Ss])
echo "Proceeding.." echo "Proceeding.."
sleep 3 sleep 3
break
;; ;;
[Nn] | [Nn][Oo]) [Nn] | [Nn][Oo])
echo "Exiting" echo "Exiting"
@ -178,11 +183,12 @@ do
;; ;;
esac esac
fi fi
fi done
while true #Confirm restore
do while true
do
clear -x clear -x
echo -e "WARNING:\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 -e "WARNING:\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 -e "\n\nYou have chosen:\n$restore_point\n\n" echo -e "\n\nYou have chosen:\n$restore_point\n\n"
@ -229,7 +235,7 @@ do
continue continue
;; ;;
esac esac
done
done done
} }
export -f restore export -f restore