code cleanup
This commit is contained in:
parent
9e429e2a5b
commit
45127be73a
169
heavy_script.sh
169
heavy_script.sh
@ -4,13 +4,8 @@
|
||||
[[ -z "$*" || "-" == "$*" || "--" == "$*" ]] && echo "This script requires an argument, use --help for help" && exit
|
||||
|
||||
|
||||
while getopts ":si:rb:t:uUpSRv-:" opt
|
||||
do
|
||||
case $opt in
|
||||
-)
|
||||
case "${OPTARG}" in
|
||||
help)
|
||||
clear -x
|
||||
help(){
|
||||
[[ $help == "true" ]] && clear -x
|
||||
echo "Basic Utilities"
|
||||
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"
|
||||
@ -38,74 +33,8 @@ do
|
||||
echo "bash /mnt/tank/scripts/heavy_script.sh --delete-backup"
|
||||
echo
|
||||
exit
|
||||
;;
|
||||
dns)
|
||||
dns="true"
|
||||
;;
|
||||
restore)
|
||||
restore="true"
|
||||
;;
|
||||
mount)
|
||||
mount="true"
|
||||
;;
|
||||
delete-backup)
|
||||
deleteBackup="true"
|
||||
;;
|
||||
*)
|
||||
echo "Invalid Option --$OPTARG, type --help for help"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
\?)
|
||||
echo "Invalid Option -$OPTARG, type --help for help"
|
||||
exit
|
||||
;;
|
||||
:)
|
||||
echo "Option: -$OPTARG requires an argument" >&2
|
||||
exit
|
||||
;;
|
||||
b)
|
||||
re='^[0-9]+$'
|
||||
number_of_backups=$OPTARG
|
||||
! [[ $OPTARG =~ $re ]] && 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)
|
||||
ignore+=("$OPTARG")
|
||||
;;
|
||||
t)
|
||||
re='^[0-9]+$'
|
||||
timeout=$OPTARG
|
||||
! [[ $timeout =~ $re ]] && 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"
|
||||
;;
|
||||
u)
|
||||
update_apps="true"
|
||||
;;
|
||||
S)
|
||||
stop_before_update="true"
|
||||
;;
|
||||
p)
|
||||
prune="true"
|
||||
;;
|
||||
R)
|
||||
rollback="true"
|
||||
echo "WARNING: -R is being transisitioned to -r, this is due to a refactor in the script. Please Make the change ASAP!"
|
||||
;;
|
||||
v)
|
||||
verbose="true"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
export -f help
|
||||
|
||||
|
||||
deleteBackup(){
|
||||
@ -126,6 +55,7 @@ else
|
||||
echo "Invalid Selection"
|
||||
fi
|
||||
}
|
||||
export -f deleteBackup
|
||||
|
||||
|
||||
backup(){
|
||||
@ -245,7 +175,7 @@ elif [[ $selection == "2" ]]; then
|
||||
done
|
||||
rmdir /mnt/heavyscript
|
||||
else
|
||||
echo "Invalid selection, type -h for help"
|
||||
echo "Invalid selection, \"$selection\" was not an option"
|
||||
fi
|
||||
}
|
||||
export -f mount
|
||||
@ -319,6 +249,7 @@ update_apps(){
|
||||
}
|
||||
export -f update_apps
|
||||
|
||||
|
||||
after_update_actions(){
|
||||
SECONDS=0
|
||||
count=0
|
||||
@ -384,11 +315,13 @@ fi
|
||||
}
|
||||
export -f after_update_actions
|
||||
|
||||
|
||||
prune(){
|
||||
echo -e "\nPruning Docker Images" && docker image prune -af | grep "^Total" || echo "Failed to Prune Docker Images"
|
||||
}
|
||||
export -f prune
|
||||
|
||||
|
||||
title(){
|
||||
echo ' _ _ _____ _ _ '
|
||||
echo '| | | | / ___| (_) | | '
|
||||
@ -402,10 +335,94 @@ echo
|
||||
}
|
||||
export -f title
|
||||
|
||||
|
||||
# Parse script options
|
||||
while getopts ":si:rb:t:uUpSRv-:" opt
|
||||
do
|
||||
case $opt in
|
||||
-)
|
||||
case "${OPTARG}" in
|
||||
help)
|
||||
help="true"
|
||||
;;
|
||||
dns)
|
||||
dns="true"
|
||||
;;
|
||||
restore)
|
||||
restore="true"
|
||||
;;
|
||||
mount)
|
||||
mount="true"
|
||||
;;
|
||||
delete-backup)
|
||||
deleteBackup="true"
|
||||
;;
|
||||
*)
|
||||
echo -e "Invalid Option \"--$OPTARG\"\n" && help
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
\?)
|
||||
echo -e "Invalid Option \"-$OPTARG\"\n" && help
|
||||
exit
|
||||
;;
|
||||
:)
|
||||
echo -e "Option: \"-$OPTARG\" requires an argument\n" && help
|
||||
exit
|
||||
;;
|
||||
b)
|
||||
re='^[0-9]+$'
|
||||
number_of_backups=$OPTARG
|
||||
! [[ $OPTARG =~ $re ]] && 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)
|
||||
ignore+=("$OPTARG")
|
||||
;;
|
||||
t)
|
||||
re='^[0-9]+$'
|
||||
timeout=$OPTARG
|
||||
! [[ $timeout =~ $re ]] && 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"
|
||||
;;
|
||||
u)
|
||||
update_apps="true"
|
||||
;;
|
||||
S)
|
||||
stop_before_update="true"
|
||||
;;
|
||||
p)
|
||||
prune="true"
|
||||
;;
|
||||
R)
|
||||
rollback="true"
|
||||
echo "WARNING: -R is being transisitioned to -r, this is due to a refactor in the script. Please Make the change ASAP!"
|
||||
;;
|
||||
v)
|
||||
verbose="true"
|
||||
;;
|
||||
*)
|
||||
echo -e "Invalid Option \"--$OPTARG\"\n" && help
|
||||
exit
|
||||
;;
|
||||
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
|
||||
[[ "$help" == "true" ]] && help
|
||||
[[ "$deleteBackup" == "true" ]] && deleteBackup && exit
|
||||
[[ "$dns" == "true" ]] && dns && exit
|
||||
[[ "$restore" == "true" ]] && restore && exit
|
||||
|
Loading…
Reference in New Issue
Block a user