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,14 +31,14 @@ export -f backup
deleteBackup(){ deleteBackup(){
while true
do
clear -x && echo "pulling all restore points.." clear -x && echo "pulling all restore points.."
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) 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 if [[ -z "$list_backups" ]]; then
echo "No restore points available" echo "No restore points available"
exit exit
fi fi
#Select a restore point
while true while true
do do
clear -x clear -x
@ -63,6 +63,8 @@ do
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
#Confirm deletion
while true while true
do do
clear -x clear -x
@ -87,6 +89,8 @@ do
;; ;;
esac esac
done done
#Check if there are more backups to delete
while true while true
do 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; }
@ -106,20 +110,19 @@ do
esac esac
done done
done
} }
export -f deleteBackup export -f deleteBackup
restore(){ restore(){
while true
do
clear -x && echo "pulling restore points.." 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) 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 if [[ -z "$list_backups" ]]; then
echo "No HeavyScript restore points available" echo "No HeavyScript restore points available"
exit exit
fi fi
#Select a restore point
while true while true
do do
clear -x clear -x
@ -157,7 +160,8 @@ do
# 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,9 +183,10 @@ do
;; ;;
esac esac
fi fi
fi done
#Confirm restore
while true while true
do do
clear -x clear -x
@ -230,6 +236,6 @@ do
;; ;;
esac esac
done done
done
} }
export -f restore export -f restore