move errors localy to functions and move checks around

This commit is contained in:
2022-09-27 14:20:42 +02:00
parent 87eb4c1cb0
commit b366d8f960
+11 -5
View File
@@ -3,11 +3,15 @@ source "/borgBackup.sh"
# function definition # function definition
function check_pfSense_vars_set() { 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_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_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_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 "$PFSENSE_SCHEME" ]; then echo "Must provide PFSENSE_SCHEME" ; errors=$(($errors + 1)); fi
if [ -z "$BACKUPNAME" ]; then BACKUPNAME=$PFSENSE_IP; fi if [ -z "$BACKUPNAME" ]; then BACKUPNAME=$PFSENSE_IP; fi
if [ $errors -ne 0 ]; then exit 1; fi
} }
function check_pfSense_optional_vars() { function check_pfSense_optional_vars() {
@@ -29,11 +33,15 @@ function check_pfSense_optional_vars() {
} }
function check_borg_backup_vars() { function check_borg_backup_vars() {
local errors=0
if [ ! -z "$BORG_BACKUP_TRUE" ]; then if [ ! -z "$BORG_BACKUP_TRUE" ]; then
if [ "$BORG_REPO" ]; then echo "Musst provice BORG_REPO"; errors=$(($errors + 1)); fi 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_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 if [ "$BORG_PRUNE_PARAMS" ]; then echo "Musst provice BORG_PRUNE_PARAMS"; errors=$(($errors + 1)); fi
fi fi
if [ $errors -ne 0 ]; then exit 1; fi
} }
function load_crontab_when_exists_or_create() { function load_crontab_when_exists_or_create() {
@@ -94,16 +102,14 @@ function cleanup_old_backups_when_set() {
# main execution # main execution
# check for required parameters # check for required parameters
errors=0
check_pfSense_vars_set check_pfSense_vars_set
if [ $errors -ne 0 ]; then exit 1; fi
# check for optional parameters
check_pfSense_optional_vars
# borg backups vars set # borg backups vars set
check_borg_backup_vars check_borg_backup_vars
# check for optional parameters
check_pfSense_optional_vars
# set up variables # set up variables
url=${PFSENSE_SCHEME}://${PFSENSE_IP} url=${PFSENSE_SCHEME}://${PFSENSE_IP}
timestamp=$(date +%Y%m%d%H%M%S) timestamp=$(date +%Y%m%d%H%M%S)