gravity-sync/includes/gs-smart.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

156 lines
3.0 KiB
Bash

# GRAVITY SYNC BY VMSTAN #####################
# gs-smart.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!
## Smart Task
function task_smart {
TASKTYPE='SMART'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
show_target
validate_gs_folders
validate_ph_folders
validate_sqlite3
validate_os_sshpass
smart_gs
exit
}
## Smart Sync Function
function smart_gs {
MESSAGE="Starting ${TASKTYPE} Analysis"
echo_info
previous_md5
md5_compare
backup_settime
PRIDBCHANGE="0"
SECDBCHANGE="0"
PRICLCHANGE="0"
SECCLCHANGE="0"
if [ "${primaryDBMD5}" != "${last_primaryDBMD5}" ]
then
PRIDBCHANGE="1"
fi
if [ "${secondDBMD5}" != "${last_secondDBMD5}" ]
then
SECDBCHANGE="1"
fi
if [ "${PRIDBCHANGE}" == "${SECDBCHANGE}" ]
then
if [ "${PRIDBCHANGE}" != "0" ]
then
MESSAGE="Both ${GRAVITY_FI} Have Changed"
echo_warn
PRIDBDATE=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "stat -c %Y ${RIHOLE_DIR}/${GRAVITY_FI}")
SECDBDATE=$(stat -c %Y ${PIHOLE_DIR}/${GRAVITY_FI})
if (( "$PRIDBDATE" >= "$SECDBDATE" ))
then
MESSAGE="Primary ${GRAVITY_FI} Last Changed"
echo_warn
pull_gs_grav
PULLRESTART="1"
else
MESSAGE="Secondary ${GRAVITY_FI} Last Changed"
echo_warn
push_gs_grav
PUSHRESTART="1"
fi
fi
else
if [ "${PRIDBCHANGE}" != "0" ]
then
pull_gs_grav
PULLRESTART="1"
elif [ "${SECDBCHANGE}" != "0" ]
then
push_gs_grav
PUSHRESTART="1"
fi
fi
if [ "${primaryCLMD5}" != "${last_primaryCLMD5}" ]
then
PRICLCHANGE="1"
fi
if [ "${secondCLMD5}" != "${last_secondCLMD5}" ]
then
SECCLCHANGE="1"
fi
if [ "$SKIP_CUSTOM" != '1' ]
then
if [ -f "${PIHOLE_DIR}/${CUSTOM_DNS}" ]
then
if [ "${PRICLCHANGE}" == "${SECCLCHANGE}" ]
then
if [ "${PRICLCHANGE}" != "0" ]
then
MESSAGE="Both ${CUSTOM_DNS} Have Changed"
echo_warn
PRICLDATE=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "stat -c %Y ${RIHOLE_DIR}/${CUSTOM_DNS}")
SECCLDATE=$(stat -c %Y ${PIHOLE_DIR}/${CUSTOM_DNS})
if (( "$PRICLDATE" >= "$SECCLDATE" ))
then
MESSAGE="Primary ${CUSTOM_DNS} Last Changed"
echo_warn
pull_gs_cust
PULLRESTART="1"
else
MESSAGE="Secondary ${CUSTOM_DNS} Last Changed"
echo_warn
push_gs_cust
PUSHRESTART="1"
fi
fi
else
if [ "${PRICLCHANGE}" != "0" ]
then
pull_gs_cust
PULLRESTART="1"
elif [ "${SECCLCHANGE}" != "0" ]
then
push_gs_cust
PUSHRESTART="1"
fi
fi
else
pull_gs_cust
PULLRESTART="1"
fi
fi
if [ "$PULLRESTART" == "1" ]
then
pull_gs_reload
fi
if [ "$PUSHRESTART" == "1" ]
then
push_gs_reload
fi
md5_recheck
logs_export
exit_withchange
}