Break up push and pull into more subfunctions

This commit is contained in:
Michael Stanclift 2020-06-29 13:41:54 -05:00
parent c229d5e12e
commit afc33c5429

View File

@ -135,10 +135,8 @@ function update_gs {
} }
# Gravity Core Functions # Gravity Core Functions
## Pull Function ## Pull Gravity
function pull_gs { function pull_gs_grav {
md5_compare
MESSAGE="Backing Up ${GRAVITY_FI} on $HOSTNAME" MESSAGE="Backing Up ${GRAVITY_FI} on $HOSTNAME"
echo_stat echo_stat
cp ${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
@ -158,45 +156,10 @@ function pull_gs {
MESSAGE="Validating Settings of ${GRAVITY_FI}" MESSAGE="Validating Settings of ${GRAVITY_FI}"
echo_stat echo_stat
}
GRAVDB_OWN=$(ls -ld ${PIHOLE_DIR}/${GRAVITY_FI} | awk '{print $3 $4}') ## Pull Custom
if [ "$GRAVDB_OWN" != "piholepihole" ] function pull_gs_cust {
then
MESSAGE="Validating Ownership on ${GRAVITY_FI}"
echo_fail
MESSAGE="Attempting to Compensate"
echo_warn
MESSAGE="Setting Ownership on ${GRAVITY_FI}"
echo_stat
sudo chown pihole:pihole ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
error_validate
MESSAGE="Continuing Validation of ${GRAVITY_FI}"
echo_stat
fi
GRAVDB_RWE=$(namei -m ${PIHOLE_DIR}/${GRAVITY_FI} | grep -v f: | grep ${GRAVITY_FI} | awk '{print $1}')
if [ "$GRAVDB_RWE" != "-rw-rw-r--" ]
then
MESSAGE="Validating Permissions on ${GRAVITY_FI}"
echo_fail
MESSAGE="Attempting to Compensate"
echo_warn
MESSAGE="Setting Permissions on ${GRAVITY_FI}"
echo_stat
sudo chmod 664 ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
error_validate
MESSAGE="Continuing Validation of ${GRAVITY_FI}"
echo_stat
fi
echo_good
if [ "$SKIP_CUSTOM" != '1' ] if [ "$SKIP_CUSTOM" != '1' ]
then then
if [ "$REMOTE_CUSTOM_DNS" == "1" ] if [ "$REMOTE_CUSTOM_DNS" == "1" ]
@ -263,7 +226,10 @@ function pull_gs {
echo_good echo_good
fi fi
fi fi
}
## Pull Reload
function pull_gs_reload {
MESSAGE="Isolating Regeneration Pathways" MESSAGE="Isolating Regeneration Pathways"
echo_info echo_info
sleep 1 sleep 1
@ -277,17 +243,22 @@ function pull_gs {
echo_stat echo_stat
${PIHOLE_BIN} restartdns >/dev/null 2>&1 ${PIHOLE_BIN} restartdns >/dev/null 2>&1
error_validate error_validate
}
## Pull Function
function pull_gs {
md5_compare
pull_gs_grav
pull_gs_cust
pull_gs_reload
logs_export logs_export
exit_withchange exit_withchange
} }
## Push Function ## Push Gravity
function push_gs { function push_gs_grav {
md5_compare
intent_validate
MESSAGE="Backing Up ${GRAVITY_FI} from ${REMOTE_HOST}" MESSAGE="Backing Up ${GRAVITY_FI} from ${REMOTE_HOST}"
echo_stat echo_stat
RSYNC_REPATH="rsync" RSYNC_REPATH="rsync"
@ -313,7 +284,10 @@ function push_gs {
CMD_TIMEOUT='15' CMD_TIMEOUT='15'
CMD_REQUESTED="sudo chown pihole:pihole ${PIHOLE_DIR}/${GRAVITY_FI}" CMD_REQUESTED="sudo chown pihole:pihole ${PIHOLE_DIR}/${GRAVITY_FI}"
create_sshcmd create_sshcmd
}
## Push Custom
function push_gs_cust {
if [ "$SKIP_CUSTOM" != '1' ] if [ "$SKIP_CUSTOM" != '1' ]
then then
if [ "$REMOTE_CUSTOM_DNS" == "1" ] if [ "$REMOTE_CUSTOM_DNS" == "1" ]
@ -345,28 +319,42 @@ function push_gs {
create_sshcmd create_sshcmd
fi fi
fi fi
}
## Push Reload
function push_gs_reload {
MESSAGE="Inverting Tachyon Pulses" MESSAGE="Inverting Tachyon Pulses"
echo_info echo_info
sleep 1 sleep 1
MESSAGE="Updating FTLDNS Configuration" MESSAGE="Updating Remote FTLDNS Configuration"
echo_stat echo_stat
CMD_TIMEOUT='15' CMD_TIMEOUT='15'
CMD_REQUESTED="${PIHOLE_BIN} restartdns reloadlists" CMD_REQUESTED="${PIHOLE_BIN} restartdns reloadlists"
create_sshcmd create_sshcmd
MESSAGE="Reloading FTLDNS Services" MESSAGE="Reloading Remote FTLDNS Services"
echo_stat echo_stat
CMD_TIMEOUT='15' CMD_TIMEOUT='15'
CMD_REQUESTED="${PIHOLE_BIN} restartdns" CMD_REQUESTED="${PIHOLE_BIN} restartdns"
create_sshcmd create_sshcmd
}
## Push Function
function push_gs {
md5_compare
intent_validate
push_gs_grav
push_gs_cust
push_gs_reload
logs_export logs_export
exit_withchange exit_withchange
} }
## Smart Sync Function
function smart_gs { function smart_gs {
md5_compare md5_compare
@ -385,12 +373,19 @@ function smart_gs {
echo -e ${last_primaryCLMD5} " 7" echo -e ${last_primaryCLMD5} " 7"
echo -e ${last_secondCLMD5} " 8" echo -e ${last_secondCLMD5} " 8"
DB_SMARTPULL="0"
DB_SMARTPUSH="0"
CL_SMARTPULL="0"
CL_SMARTPUSH="0"
if [ "${primaryDBMD5}" != "${last_primaryDBMD5}" ] if [ "${primaryDBMD5}" != "${last_primaryDBMD5}" ]
then then
echo "Primary DB has changed" echo "Primary DB has changed"
DB_SMARTPULL="1"
elif [ "${secondDBMD5}" != "${last_secondDBMD5}" ] elif [ "${secondDBMD5}" != "${last_secondDBMD5}" ]
then then
echo "Secondary DB has changed" echo "Secondary DB has changed"
DB_SMARTPUSH="1"
else else
echo "No DB changes" echo "No DB changes"
fi fi
@ -398,12 +393,16 @@ function smart_gs {
if [ "${primaryCLMD5}" != "${last_primaryCLMD5}" ] if [ "${primaryCLMD5}" != "${last_primaryCLMD5}" ]
then then
echo "Primary CL has changed" echo "Primary CL has changed"
CL_SMARTPULL="1"
elif [ "${secondCLMD5}" != "${last_secondCLMD5}" ] elif [ "${secondCLMD5}" != "${last_secondCLMD5}" ]
then then
echo "Secondary CL has changed" echo "Secondary CL has changed"
CL_SMARTPUSH="1"
else else
echo "No CL changes" echo "No CL changes"
fi fi
} }
function restore_gs { function restore_gs {