diff --git a/README.md b/README.md index b0f37e76..a095c6a5 100644 --- a/README.md +++ b/README.md @@ -50,9 +50,9 @@ Download the latest release from [GitHub](https://github.com/vmstan/gravity-sync ``` cd ~ -wget https://github.com/vmstan/gravity-sync/archive/v1.3.3.zip -unzip v1.3.3.zip -mv ~/gravity-sync-1.3.3 ~/gravity-sync +wget https://github.com/vmstan/gravity-sync/archive/v1.3.4.zip +unzip v1.3.4.zip +mv ~/gravity-sync-1.3.4 ~/gravity-sync cd gravity-sync ``` diff --git a/gravity-sync.sh b/gravity-sync.sh index 1159eb97..d329f650 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -2,7 +2,7 @@ # GRAVITY SYNC BY VMSTAN ##################### PROGRAM='Gravity Sync' -VERSION='1.3.3' +VERSION='1.3.4' # Must execute from a location in the home folder of the user who own's it (ex: /home/pi/gravity-sync) # Configure certificate based SSH authentication between the Pi-hole HA nodes - it does not use passwords @@ -106,34 +106,64 @@ function pull_gs { echo -e "${INFO} ${TASKTYPE} Requested" md5_compare - MESSAGE="Pulling ${GRAVITY_FI} from ${REMOTE_HOST}" - echo -en "${STAT} ${MESSAGE}" - ${SSHPASSWORD} rsync -v -e 'ssh -p 22' ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull >/dev/null 2>&1 - error_validate + echo -e "${INFO} ${TASKTYPE} Commencing" MESSAGE="Backing Up ${GRAVITY_FI} on $HOSTNAME" echo -en "${STAT} ${MESSAGE}" - cp -v ${PIHOLE_DIR}/${GRAVITY_FI} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.backup >/dev/null 2>&1 + cp ${PIHOLE_DIR}/${GRAVITY_FI} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.backup >/dev/null 2>&1 error_validate + MESSAGE="Pulling ${GRAVITY_FI} from ${REMOTE_HOST}" + echo -en "${STAT} ${MESSAGE}" + ${SSHPASSWORD} rsync -e 'ssh -p 22' ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull >/dev/null 2>&1 + error_validate + MESSAGE="Replacing ${GRAVITY_FI} on $HOSTNAME" echo -en "${STAT} ${MESSAGE}" - sudo cp -v $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1 + sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1 error_validate - MESSAGE="Setting Permissions on ${GRAVITY_FI}" - echo -en "${STAT} ${MESSAGE}" - sudo chmod 644 ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1 - error_validate + MESSAGE="Validating Ownership on ${GRAVITY_FI}" + echo -en "${STAT} ${MESSAGE}" - MESSAGE="Setting Ownership on ${GRAVITY_FI}" - echo -en "${STAT} ${MESSAGE}" - sudo chown pihole:pihole ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1 - error_validate + GRAVDB_OWN=$(ls -ld ${PIHOLE_DIR}/${GRAVITY_FI} | awk '{print $3 $4}') + if [ $GRAVDB_OWN == "piholepihole" ] + then + echo -e "\r${GOOD} ${MESSAGE}" + else + echo -e "\r${FAIL} $MESSAGE" + + MESSAGE2="Attempting to Compensate" + echo -e "${INFO} ${MESSAGE2}" + + MESSAGE="Setting Ownership on ${GRAVITY_FI}" + echo -en "${STAT} ${MESSAGE}" + sudo chown pihole:pihole ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1 + error_validate + fi + + MESSAGE="Validating Permissions on ${GRAVITY_FI}" + echo -en "${STAT} ${MESSAGE}" + + GRAVDB_RWE=$(namei -m ${PIHOLE_DIR}/${GRAVITY_FI} | grep -v f: | grep ${GRAVITY_FI} | awk '{print $1}') + if [ $GRAVDB_RWE = "-rw-r--r--" ] + then + echo -e "\r${GOOD} ${MESSAGE}" + else + echo -e "\r${FAIL} ${MESSAGE}" + + MESSAGE2="Attempting to Compensate" + echo -e "${INFO} ${MESSAGE2}" + + MESSAGE="Setting Ownership on ${GRAVITY_FI}" + echo -en "${STAT} ${MESSAGE}" + sudo chmod 644 ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1 + error_validate + fi - MESSAGE="Pausing One Second" + MESSAGE="Inverting Tachyon Pulse" echo -e "${INFO} ${MESSAGE}" - sleep 1 + sleep 1 MESSAGE="Updating FTLDNS Configuration" echo -en "${STAT} ${MESSAGE}" @@ -163,12 +193,12 @@ function push_gs { MESSAGE="Backing Up ${GRAVITY_FI} from ${REMOTE_HOST}" echo -en "${STAT} ${MESSAGE}" - ${SSHPASSWORD} rsync -v -e 'ssh -p 22' ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.push >/dev/null 2>&1 + ${SSHPASSWORD} rsync -e 'ssh -p 22' ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.push >/dev/null 2>&1 error_validate MESSAGE="Pushing ${GRAVITY_FI} to ${REMOTE_HOST}" echo -en "${STAT} ${MESSAGE}" - ${SSHPASSWORD} rsync --rsync-path="sudo rsync" -v -e 'ssh -p 22' ${PIHOLE_DIR}/${GRAVITY_FI} ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1 + ${SSHPASSWORD} rsync --rsync-path="sudo rsync" -e 'ssh -p 22' ${PIHOLE_DIR}/${GRAVITY_FI} ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1 error_validate MESSAGE="Setting Permissions on ${GRAVITY_FI}" @@ -181,9 +211,9 @@ function push_gs { ${SSHPASSWORD} ssh ${REMOTE_USER}@${REMOTE_HOST} "sudo chown pihole:pihole ${PIHOLE_DIR}/${GRAVITY_FI}" >/dev/null 2>&1 error_validate - MESSAGE="Pausing One Second" + MESSAGE="Contacting Borg Collective" echo -e "${INFO} ${MESSAGE}" - sleep 1 + sleep 1 MESSAGE="Updating FTLDNS Configuration" echo -en "${STAT} ${MESSAGE}"