gravity-sync/includes/gs-hashing.sh
Michael Stanclift 6551ae88c7
3.1.0 (#105)
* Begin work on Docker support

* rewrite permission detection

* wrong else

* Change pihole detection based on sudo results

* Write out to devnull

* nosodo handle

* AND then

* scanning

* nosudo more

* clearer wording on failures

* headers

* handle nosudo on docker detection better

* SUDO sudo

* AND THEN

* status report rewrite

* link

* alert on no local install detected

* yellow headers like the rest of GS

* semi critical issues

* purple instead of red

* clean up output of sudo detection

* give me space

* Auto run config script

* added logo

* center logo

* move intro

* trying dev/tty

* advanced config generate

* !=

* logic is hard

* new logo

* image

* fonts

* svg image

* remove h1

* use rihole variable

* New root check

* better method of checking sudo

* remove messages

* rihole

* attempting realpath

* GS_FILEPATH

* remove $HOME call

* remove config requirement for updates

* no config for updates

* all the variables

* all kinds of variable replacements

* double quotes

* it’s like I’ve forgotten how to write this stuff

* removals

* updated requirements

* variable rearrangement

* validation check for docker

* riholes

* placeholder

* more riholes

* even more riholes

* docker examples

* docker rewrite

* docker docker docker

* docker custom checks

* update from anywhere

* correct validation error

* check for current owner only if local install

* give me space

* stuff

* more stuff

* bash alias creation

* cleanup installer

* fix .sh

* config errors, remove sshpass validation

* skip directories if done

* limit config script

* fix for changes when both targets have changed

* RIHOLE

* cleanup warning messages

* stop sign

* big red

* documenting new variables

* master

Co-authored-by: Michael Stanclift <vmstan@sovereign.vmstan.net>
Co-authored-by: Michael Stanclift <vmstan@sovereign.local>
2020-10-19 13:48:23 -05:00

148 lines
4.4 KiB
Bash

# GRAVITY SYNC BY VMSTAN #####################
# gs-hasing.sh ###############################
# For documentation or downloading updates visit https://github.com/vmstan/gravity-sync
# This code is called from the main gravity-sync.sh file and should not execute directly!
## Validate Sync Required
function md5_compare {
HASHMARK='0'
MESSAGE="Analyzing ${GRAVITY_FI} on ${REMOTE_HOST}"
echo_stat
primaryDBMD5=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${RIHOLE_DIR}/${GRAVITY_FI}" | sed 's/\s.*$//')
error_validate
MESSAGE="Analyzing ${GRAVITY_FI} on $HOSTNAME"
echo_stat
secondDBMD5=$(md5sum ${PIHOLE_DIR}/${GRAVITY_FI} | sed 's/\s.*$//')
error_validate
if [ "$primaryDBMD5" == "$last_primaryDBMD5" ] && [ "$secondDBMD5" == "$last_secondDBMD5" ]
then
HASHMARK=$((HASHMARK+0))
else
MESSAGE="Differenced ${GRAVITY_FI} Detected"
echo_warn
HASHMARK=$((HASHMARK+1))
fi
if [ "$SKIP_CUSTOM" != '1' ]
then
if [ -f ${PIHOLE_DIR}/${CUSTOM_DNS} ]
then
if ${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${RIHOLE_DIR}/${CUSTOM_DNS}
then
REMOTE_CUSTOM_DNS="1"
MESSAGE="Analyzing ${CUSTOM_DNS} on ${REMOTE_HOST}"
echo_stat
primaryCLMD5=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${RIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//'")
error_validate
MESSAGE="Analyzing ${CUSTOM_DNS} on $HOSTNAME"
echo_stat
secondCLMD5=$(md5sum ${PIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//')
error_validate
if [ "$primaryCLMD5" == "$last_primaryCLMD5" ] && [ "$secondCLMD5" == "$last_secondCLMD5" ]
then
HASHMARK=$((HASHMARK+0))
else
MESSAGE="Differenced ${CUSTOM_DNS} Detected"
echo_warn
HASHMARK=$((HASHMARK+1))
fi
else
MESSAGE="No ${CUSTOM_DNS} Detected on ${REMOTE_HOST}"
echo_info
fi
else
if ${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${RIHOLE_DIR}/${CUSTOM_DNS}
then
REMOTE_CUSTOM_DNS="1"
MESSAGE="${REMOTE_HOST} has ${CUSTOM_DNS}"
HASHMARK=$((HASHMARK+1))
echo_info
fi
MESSAGE="No ${CUSTOM_DNS} Detected on $HOSTNAME"
echo_info
fi
fi
if [ "$HASHMARK" != "0" ]
then
MESSAGE="Replication Required"
echo_warn
HASHMARK=$((HASHMARK+0))
else
MESSAGE="No Replication Required"
echo_info
exit_nochange
fi
}
function previous_md5 {
if [ -f "${LOG_PATH}/${HISTORY_MD5}" ]
then
last_primaryDBMD5=$(sed "1q;d" ${LOG_PATH}/${HISTORY_MD5})
last_secondDBMD5=$(sed "2q;d" ${LOG_PATH}/${HISTORY_MD5})
last_primaryCLMD5=$(sed "3q;d" ${LOG_PATH}/${HISTORY_MD5})
last_secondCLMD5=$(sed "4q;d" ${LOG_PATH}/${HISTORY_MD5})
else
last_primaryDBMD5="0"
last_secondDBMD5="0"
last_primaryCLMD5="0"
last_secondCLMD5="0"
fi
}
function md5_recheck {
MESSAGE="Performing Replicator Diagnostics"
echo_info
HASHMARK='0'
MESSAGE="Reanalyzing ${GRAVITY_FI} on ${REMOTE_HOST}"
echo_stat
primaryDBMD5=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${RIHOLE_DIR}/${GRAVITY_FI}" | sed 's/\s.*$//')
error_validate
MESSAGE="Reanalyzing ${GRAVITY_FI} on $HOSTNAME"
echo_stat
secondDBMD5=$(md5sum ${PIHOLE_DIR}/${GRAVITY_FI} | sed 's/\s.*$//')
error_validate
if [ "$SKIP_CUSTOM" != '1' ]
then
if [ -f ${PIHOLE_DIR}/${CUSTOM_DNS} ]
then
if ${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${RIHOLE_DIR}/${CUSTOM_DNS}
then
REMOTE_CUSTOM_DNS="1"
MESSAGE="Reanalyzing ${CUSTOM_DNS} on ${REMOTE_HOST}"
echo_stat
primaryCLMD5=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${RIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//'")
error_validate
MESSAGE="Reanalyzing ${CUSTOM_DNS} on $HOSTNAME"
echo_stat
secondCLMD5=$(md5sum ${PIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//')
error_validate
else
MESSAGE="No ${CUSTOM_DNS} Detected on ${REMOTE_HOST}"
echo_info
fi
else
if ${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${RIHOLE_DIR}/${CUSTOM_DNS}
then
REMOTE_CUSTOM_DNS="1"
MESSAGE="${REMOTE_HOST} has ${CUSTOM_DNS}"
echo_info
fi
MESSAGE="No ${CUSTOM_DNS} Detected on $HOSTNAME"
echo_info
fi
fi
}