From 75f2e5975b841eb46cb2f2ac213f83ecc57d804b Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 23 May 2020 18:26:12 -0500 Subject: [PATCH] Rebuilt pull in new style --- gravity-sync.sh | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 88a072a..3ba7936 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -77,19 +77,35 @@ function pull_gs { MESSAGE="Pulling ${GRAVITY_FI} from ${REMOTE_HOST}" echo -e "${STAT} ${MESSAGE}" rsync -v -e 'ssh -p 22' ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull - if_validate - - echo -e "[${CYAN}STAT${NC}] Backing Up Current ${GRAVITY_FI} on $HOSTNAME" + error_validate + + MESSAGE="Backing Up ${GRAVITY_FI} on $HOSTNAME" + echo -e "${STAT} ${MESSAGE}" cp -v ${PIHOLE_DIR}/${GRAVITY_FI} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.backup - echo -e "[${CYAN}STAT${NC}] Replacing ${GRAVITY_FI} on $HOSTNAME" + error_validate + + MESSAGE="Replacing ${GRAVITY_FI} on $HOSTNAME" + echo -e "${STAT} ${MESSAGE}" sudo cp -v $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull ${PIHOLE_DIR}/${GRAVITY_FI} + error_validate + + MESSAGE="Setting Permissions on ${GRAVITY_FI}" + echo -e "${STAT} ${MESSAGE}" sudo chmod 644 ${PIHOLE_DIR}/${GRAVITY_FI} + error_validate + + MESSAGE="Setting Ownership on ${GRAVITY_FI}" + echo -e "${STAT} ${MESSAGE}" sudo chown pihole:pihole ${PIHOLE_DIR}/${GRAVITY_FI} - echo -e "${GRAVITY_FI} ownership and file permissions reset" - echo -e "[${CYAN}STAT${NC}] Reloading FTLDNS Configuration" + error_validate + + MESSAGE="Reloading FTLDNS Configuration" + echo -e "${STAT} ${MESSAGE}" pihole restartdns reloadlists pihole restartdns - logs_export + error_validate + + logs_export exit_withchange } @@ -210,8 +226,8 @@ function exit_withchange { exit } - -function if_validate { +# Error Validation +function error_validate { if [ "$?" != "0" ]; then echo -e "${FAIL} ${MESSAGE}" exit 1