scale-catalog/heavy_script.sh

148 lines
4.4 KiB
Bash
Raw Normal View History

2022-04-21 21:19:53 +00:00
#!/bin/bash
2022-06-10 19:40:35 +00:00
2022-05-16 23:49:48 +00:00
#If no argument is passed, kill the script.
2022-06-10 19:40:35 +00:00
[[ -z "$*" || "-" == "$*" || "--" == "$*" ]] && echo "This script requires an argument, use --help for help" && exit
2022-05-18 03:31:55 +00:00
2022-06-13 21:34:33 +00:00
2022-07-25 02:29:58 +00:00
# shellcheck source=functions/backup.sh
source functions/backup.sh
# 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/self_update.sh
source functions/self_update.sh
# shellcheck source=functions/update_apps.sh
source functions/update_apps.sh
2022-06-10 19:40:35 +00:00
2022-06-11 06:13:09 +00:00
# Parse script options
2022-07-26 04:19:07 +00:00
while getopts ":sirb:t:uUpSRv-:" opt
2022-06-11 06:13:09 +00:00
do
case $opt in
-)
case "${OPTARG}" in
2022-07-25 01:15:56 +00:00
help)
2022-06-11 06:13:09 +00:00
help="true"
;;
2022-07-25 01:15:56 +00:00
self-update)
2022-06-13 19:55:49 +00:00
self_update="true"
;;
2022-06-11 06:13:09 +00:00
dns)
dns="true"
;;
restore)
restore="true"
;;
mount)
mount="true"
;;
delete-backup)
deleteBackup="true"
;;
*)
echo -e "Invalid Option \"--$OPTARG\"\n" && help
exit
;;
esac
;;
2022-07-26 04:19:07 +00:00
:)
echo -e "Option: \"-$OPTARG\" requires an argument\n" && help
exit
;;
2022-06-11 06:13:09 +00:00
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)
2022-07-26 04:19:07 +00:00
# Check next positional parameter
eval nextopt=${!OPTIND}
# existing or starting with dash?
if [[ -n $nextopt && $nextopt != -* ]] ; then
2022-07-26 06:04:39 +00:00
OPTIND=$((OPTIND + 1))
2022-07-26 04:40:05 +00:00
ignore+=("$nextopt")
2022-07-26 04:19:07 +00:00
else
echo "Option: \"-i\" requires an argument"
2022-07-26 04:20:06 +00:00
exit
2022-07-26 04:19:07 +00:00
fi
2022-06-11 06:13:09 +00:00
;;
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"
2022-07-26 04:24:26 +00:00
# Check next positional parameter
eval nextopt=${!OPTIND}
# existing or starting with dash?
if [[ -n $nextopt && $nextopt != -* ]] ; then
2022-07-26 06:04:39 +00:00
OPTIND=$((OPTIND + 1))
2022-07-26 04:37:21 +00:00
update_limit="$nextopt"
2022-07-26 04:24:26 +00:00
else
update_limit=1
fi
2022-06-11 06:13:09 +00:00
;;
u)
update_apps="true"
2022-07-26 04:24:26 +00:00
# Check next positional parameter
eval nextopt=${!OPTIND}
# existing or starting with dash?
if [[ -n $nextopt && $nextopt != -* ]] ; then
2022-07-26 06:04:39 +00:00
OPTIND=$((OPTIND + 1))
2022-07-26 04:37:21 +00:00
update_limit="$nextopt"
2022-07-26 04:24:26 +00:00
else
update_limit=1
fi
2022-06-11 06:13:09 +00:00
;;
S)
stop_before_update="true"
;;
p)
prune="true"
;;
v)
verbose="true"
;;
2022-07-26 04:05:55 +00:00
\?)
echo -e "Invalid Option \"-$OPTARG\"\n" && help
exit
;;
2022-06-11 06:13:09 +00:00
*)
2022-07-26 03:49:47 +00:00
echo -e "Invalid Option \"-$OPTARG\"\n" && help
2022-06-11 06:13:09 +00:00
exit
;;
esac
done
2022-05-14 18:25:00 +00:00
#exit if incompatable functions are called
[[ "$update_all_apps" == "true" && "$update_apps" == "true" ]] && echo -e "-U and -u cannot BOTH be called" && exit
2022-06-10 20:32:39 +00:00
2022-05-14 18:25:00 +00:00
#Continue to call functions in specific order
2022-06-11 06:13:09 +00:00
[[ "$help" == "true" ]] && help
2022-07-25 01:15:56 +00:00
[[ "$self_update" == "true" ]] && self_update
2022-06-11 01:48:34 +00:00
[[ "$deleteBackup" == "true" ]] && deleteBackup && exit
2022-06-10 19:40:35 +00:00
[[ "$dns" == "true" ]] && dns && exit
[[ "$restore" == "true" ]] && restore && exit
[[ "$mount" == "true" ]] && mount && exit
2022-07-26 06:23:27 +00:00
if [[ "$number_of_backups" -ge 1 && "$sync" == "true" ]]; then # Run backup and sync at the same time
2022-07-26 06:39:25 +00:00
echo -e "Backing up and syncing catalogs at the same time, please wait for output..\n"
2022-07-26 06:23:27 +00:00
backup &
sync &
wait
fi
2022-07-26 06:42:58 +00:00
[[ "$number_of_backups" -ge 1 && "$sync" == "false" ]] && echo "Please wait for output, this could take a while.." && backup
[[ "$sync" == "true" && "$number_of_backups" -le 1 ]] && echo "Please wait for output, this could take a while.." && sync
2022-07-25 04:11:04 +00:00
[[ "$update_all_apps" == "true" || "$update_apps" == "true" ]] && commander
2022-07-25 01:22:10 +00:00
[[ "$prune" == "true" ]] && prune