move check for backup location to function

This commit is contained in:
AustrianToast 2024-07-13 00:15:05 +02:00
parent 8b5704f397
commit 6593f087c4
Signed by: AustrianToast
GPG Key ID: 378A29F999424B1C
2 changed files with 16 additions and 21 deletions

35
update
View File

@ -9,27 +9,22 @@ DATE="$(date +"%Y-%m-%dT%H:%M:%S%:z")" # RFC 3339 date-time https://datatracker
source "$HOME"/.config/update.conf || exit 1
if [ ! -d $BACKUP_LOCATION ]; then
echo -e "${IYELLOW}Backup location doesn't exist${NO_COLOR}"
read -p "Do you want to create the path and continue? [y/N]" input
case $input in
[Yy]) mkdir --parents "$BACKUP_LOCATION" ;;
[Nn]) exit 0;;
* ) exit 0 ;;
esac
fi
if [ $SECONDARY_BACKUP_LOCATION ]; then
if [ ! -d $SECONDARY_BACKUP_LOCATION ]; then
echo -e "${IYELLOW}Secondary Backup location doesn't exist${NO_COLOR}"
read -p "Do you want to create the path and continue? [y/N]" input
case $input in
[Yy]) mkdir --parents "$SECONDARY_BACKUP_LOCATION" ;;
[Nn]) exit 0;;
* ) exit 0 ;;
esac
check_for_valid_backup_location() {
if [ $1 ]; then
if [ ! -d $1 ]; then
echo -e "${IYELLOW}$1 doesn't exist${NO_COLOR}"
read -p "Do you want to create the path and continue? [y/N]" input
case $input in
[Yy]) mkdir --parents "$1" ;;
[Nn]) exit 0;;
* ) exit 0 ;;
esac
fi
fi
fi
}
check_for_valid_backup_location "$BACKUP_LOCATION"
check_for_valid_backup_location "$SECONDARY_BACKUP_LOCATION"
trap interrupt_function INT

View File

@ -8,4 +8,4 @@ BACKUP_LOCATION=~
PACMAN_WRAPPER=yay
# how many different backups to keep
BACKUP_AMOUNT=2
BACKUP_AMOUNT=10