2022-04-21 21:19:53 +00:00
|
|
|
#!/bin/bash
|
2022-06-10 19:40:35 +00:00
|
|
|
|
2022-07-27 16:27:12 +00:00
|
|
|
# cd to script, this ensures the script can find the source scripts below, even when ran from a seperate directory
|
2022-07-27 15:47:19 +00:00
|
|
|
script=$(readlink -f "$0")
|
|
|
|
script_path=$(dirname "$script")
|
2022-07-27 22:56:29 +00:00
|
|
|
script_name="heavy_script.sh"
|
2022-07-27 23:03:03 +00:00
|
|
|
cd "$script_path" || { echo "Error: Failed to change to script directory" ; exit ; }
|
2022-07-26 21:06:30 +00:00
|
|
|
|
2022-07-27 22:56:29 +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
|
2022-07-26 19:08:33 +00:00
|
|
|
# shellcheck source=functions/menu.sh
|
|
|
|
source functions/menu.sh
|
2022-07-25 02:29:58 +00:00
|
|
|
# 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
|
|
|
|
2022-07-26 19:10:09 +00:00
|
|
|
#If no argument is passed, kill the script.
|
|
|
|
[[ -z "$*" || "-" == "$*" || "--" == "$*" ]] && menu
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
number_of_backups=$OPTARG
|
2022-07-26 22:45:52 +00:00
|
|
|
! [[ $OPTARG =~ ^[0-9]+$ ]] && echo -e "Error: -b needs to be assigned an interger\n\"""$number_of_backups""\" is not an interger" >&2 && exit
|
2022-06-11 06:13:09 +00:00
|
|
|
[[ "$number_of_backups" -le 0 ]] && echo "Error: Number of backups is required to be at least 1" && exit
|
2022-07-27 02:23:52 +00:00
|
|
|
backup="true"
|
2022-06-11 06:13:09 +00:00
|
|
|
;;
|
|
|
|
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)
|
|
|
|
timeout=$OPTARG
|
2022-07-26 22:45:52 +00:00
|
|
|
! [[ $timeout =~ ^[0-9]+$ ]] && echo -e "Error: -t needs to be assigned an interger\n\"""$timeout""\" is not an interger" >&2 && exit
|
2022-06-11 06:13:09 +00:00
|
|
|
;;
|
|
|
|
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-07-26 21:02:20 +00:00
|
|
|
|
2022-07-26 19:36:22 +00:00
|
|
|
#exit if incompatable functions are called
|
2022-05-14 18:25:00 +00:00
|
|
|
[[ "$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
|
2022-05-12 04:28:27 +00:00
|
|
|
[[ "$restore" == "true" ]] && restore && exit
|
|
|
|
[[ "$mount" == "true" ]] && mount && exit
|
2022-07-27 00:28:23 +00:00
|
|
|
if [[ "$backup" == "true" && "$sync" == "true" ]]; then # Run backup and sync at the same time
|
2022-07-28 19:50:34 +00:00
|
|
|
echo "🅁 🅄 🄽 🄽 🄸 🄽 🄶 🅃 🄰 🅂 🄺 🅂 :"
|
2022-07-26 23:43:06 +00:00
|
|
|
echo -e "Backing up ix-applications dataset\nSyncing catalog(s)"
|
|
|
|
echo -e "This can take a LONG time, please wait for the output..\n"
|
2022-07-26 06:23:27 +00:00
|
|
|
backup &
|
|
|
|
sync &
|
|
|
|
wait
|
|
|
|
fi
|
2022-07-27 00:28:23 +00:00
|
|
|
[[ "$backup" == "true" && -z "$sync" ]] && echo "Backing up \"ix-applications\" dataset, please wait.." && backup
|
|
|
|
[[ "$sync" == "true" && -z "$backup" ]] && echo "Syncing catalogs, this takes a LONG time, please wait.." && sync
|
2022-07-25 04:11:04 +00:00
|
|
|
[[ "$update_all_apps" == "true" || "$update_apps" == "true" ]] && commander
|
2022-07-26 06:53:53 +00:00
|
|
|
[[ "$prune" == "true" ]] && prune
|