From 6593f087c4390e20e9bb2a4582f945b49e2325ec Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Sat, 13 Jul 2024 00:15:05 +0200 Subject: [PATCH] move check for backup location to function --- update | 35 +++++++++++++++-------------------- update.conf | 2 +- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/update b/update index fab62c2..328bfd1 100755 --- a/update +++ b/update @@ -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 diff --git a/update.conf b/update.conf index 0452eea..4fd9559 100644 --- a/update.conf +++ b/update.conf @@ -8,4 +8,4 @@ BACKUP_LOCATION=~ PACMAN_WRAPPER=yay # how many different backups to keep -BACKUP_AMOUNT=2 +BACKUP_AMOUNT=10