From b366d8f960293b1ac7f4e22142a9eb0db0d56cf2 Mon Sep 17 00:00:00 2001 From: Daniel Dolezal Date: Tue, 27 Sep 2022 14:20:42 +0200 Subject: [PATCH] move errors localy to functions and move checks around --- pfsense-backup.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pfsense-backup.sh b/pfsense-backup.sh index f6871a5..c96d571 100755 --- a/pfsense-backup.sh +++ b/pfsense-backup.sh @@ -3,11 +3,15 @@ source "/borgBackup.sh" # function definition function check_pfSense_vars_set() { + local errors=0 + if [ -z "$PFSENSE_IP" ]; then echo "Must provide PFSENSE_IP" ; errors=$(($errors + 1)) ; fi if [ -z "$PFSENSE_USER" ]; then echo "Must provide PFSENSE_USER" ; errors=$(($errors + 1)); fi if [ -z "$PFSENSE_PASS" ]; then echo "Must provide PFSENSE_PASS" ; errors=$(($errors + 1)); fi if [ -z "$PFSENSE_SCHEME" ]; then echo "Must provide PFSENSE_SCHEME" ; errors=$(($errors + 1)); fi if [ -z "$BACKUPNAME" ]; then BACKUPNAME=$PFSENSE_IP; fi + + if [ $errors -ne 0 ]; then exit 1; fi } function check_pfSense_optional_vars() { @@ -29,11 +33,15 @@ function check_pfSense_optional_vars() { } function check_borg_backup_vars() { + local errors=0 + if [ ! -z "$BORG_BACKUP_TRUE" ]; then if [ "$BORG_REPO" ]; then echo "Musst provice BORG_REPO"; errors=$(($errors + 1)); fi if [ "$BORG_CREATE_PARAMS" ]; then echo "Musst provice BORG_CREATE_PARAMS"; errors=$(($errors + 1)); fi if [ "$BORG_PRUNE_PARAMS" ]; then echo "Musst provice BORG_PRUNE_PARAMS"; errors=$(($errors + 1)); fi fi + + if [ $errors -ne 0 ]; then exit 1; fi } function load_crontab_when_exists_or_create() { @@ -94,16 +102,14 @@ function cleanup_old_backups_when_set() { # main execution # check for required parameters -errors=0 check_pfSense_vars_set -if [ $errors -ne 0 ]; then exit 1; fi - -# check for optional parameters -check_pfSense_optional_vars # borg backups vars set check_borg_backup_vars +# check for optional parameters +check_pfSense_optional_vars + # set up variables url=${PFSENSE_SCHEME}://${PFSENSE_IP} timestamp=$(date +%Y%m%d%H%M%S)