2020-10-07 22:45:39 +00:00
|
|
|
# GRAVITY SYNC BY VMSTAN #####################
|
|
|
|
# gs-pull.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!
|
|
|
|
|
|
|
|
## Pull Task
|
|
|
|
function task_pull {
|
|
|
|
TASKTYPE='PULL'
|
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
2020-12-31 02:49:54 +00:00
|
|
|
|
2020-10-07 22:45:39 +00:00
|
|
|
show_target
|
|
|
|
validate_gs_folders
|
|
|
|
validate_ph_folders
|
2021-01-04 20:37:35 +00:00
|
|
|
|
|
|
|
if [ "${INCLUDE_CNAME}" == "1" ]
|
|
|
|
then
|
|
|
|
validate_dns_folders
|
|
|
|
fi
|
|
|
|
|
2020-10-07 22:45:39 +00:00
|
|
|
validate_sqlite3
|
|
|
|
validate_os_sshpass
|
2020-12-31 02:49:54 +00:00
|
|
|
|
2020-10-07 22:45:39 +00:00
|
|
|
pull_gs
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
## Pull Gravity
|
|
|
|
function pull_gs_grav {
|
2020-12-31 02:49:54 +00:00
|
|
|
|
2020-12-31 02:45:47 +00:00
|
|
|
backup_local_gravity
|
|
|
|
backup_remote_gravity
|
|
|
|
|
|
|
|
MESSAGE="Pulling ${GRAVITY_FI} from ${REMOTE_HOST}"
|
|
|
|
echo_stat
|
2020-12-31 02:49:54 +00:00
|
|
|
RSYNC_REPATH="rsync"
|
|
|
|
RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${RIHOLE_DIR}/${GRAVITY_FI}.backup"
|
|
|
|
RSYNC_TARGET="${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull"
|
|
|
|
create_rsynccmd
|
|
|
|
|
2020-12-31 02:45:47 +00:00
|
|
|
MESSAGE="Replacing ${GRAVITY_FI} on $HOSTNAME"
|
2020-12-31 02:49:54 +00:00
|
|
|
echo_stat
|
|
|
|
sudo cp ${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
|
|
|
|
error_validate
|
2020-12-31 02:45:47 +00:00
|
|
|
|
|
|
|
if [ "$FILE_OWNER" != "named:docker" ]
|
|
|
|
then
|
|
|
|
MESSAGE="Validating Settings of ${GRAVITY_FI}"
|
|
|
|
echo_stat
|
|
|
|
|
2020-12-31 02:49:54 +00:00
|
|
|
GRAVDB_OWN=$(ls -ld ${PIHOLE_DIR}/${GRAVITY_FI} | awk 'OFS=":" {print $3,$4}')
|
|
|
|
if [ "$GRAVDB_OWN" != "$FILE_OWNER" ]
|
2020-12-31 02:45:47 +00:00
|
|
|
then
|
2020-12-31 02:49:54 +00:00
|
|
|
MESSAGE="Validating Ownership on ${GRAVITY_FI}"
|
2020-12-31 02:45:47 +00:00
|
|
|
echo_fail
|
2020-12-31 02:49:54 +00:00
|
|
|
|
2020-12-31 02:45:47 +00:00
|
|
|
MESSAGE="Attempting to Compensate"
|
|
|
|
echo_warn
|
2020-12-31 02:49:54 +00:00
|
|
|
|
|
|
|
MESSAGE="Setting Ownership on ${GRAVITY_FI}"
|
2020-12-31 02:45:47 +00:00
|
|
|
echo_stat
|
2020-12-31 02:49:54 +00:00
|
|
|
sudo chown ${FILE_OWNER} ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
|
|
|
|
error_validate
|
|
|
|
|
2020-12-31 02:45:47 +00:00
|
|
|
MESSAGE="Continuing Validation of ${GRAVITY_FI}"
|
|
|
|
echo_stat
|
|
|
|
fi
|
2020-12-31 02:49:54 +00:00
|
|
|
else
|
|
|
|
MESSAGE="Setting Ownership on ${GRAVITY_FI}"
|
|
|
|
echo_stat
|
|
|
|
sudo chown ${FILE_OWNER} ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
|
|
|
|
error_validate
|
|
|
|
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
|
|
|
|
|
2020-12-31 02:45:47 +00:00
|
|
|
echo_good
|
2020-10-07 22:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
## Pull Custom
|
|
|
|
function pull_gs_cust {
|
2020-12-31 02:45:47 +00:00
|
|
|
if [ "$SKIP_CUSTOM" != '1' ]
|
2020-12-31 02:49:54 +00:00
|
|
|
then
|
2020-12-31 02:45:47 +00:00
|
|
|
if [ "$REMOTE_CUSTOM_DNS" == "1" ]
|
|
|
|
then
|
|
|
|
backup_local_custom
|
|
|
|
backup_remote_custom
|
2020-12-31 02:49:54 +00:00
|
|
|
|
2020-12-31 02:45:47 +00:00
|
|
|
MESSAGE="Pulling ${CUSTOM_DNS} from ${REMOTE_HOST}"
|
|
|
|
echo_stat
|
2020-12-31 02:49:54 +00:00
|
|
|
RSYNC_REPATH="rsync"
|
|
|
|
RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${RIHOLE_DIR}/${CUSTOM_DNS}.backup"
|
|
|
|
RSYNC_TARGET="${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.pull"
|
|
|
|
create_rsynccmd
|
|
|
|
|
2020-12-31 02:45:47 +00:00
|
|
|
MESSAGE="Replacing ${CUSTOM_DNS} on $HOSTNAME"
|
2020-12-31 02:49:54 +00:00
|
|
|
echo_stat
|
|
|
|
sudo cp ${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.pull ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1
|
|
|
|
error_validate
|
2020-12-31 02:45:47 +00:00
|
|
|
|
|
|
|
MESSAGE="Validating Settings on ${CUSTOM_DNS}"
|
|
|
|
echo_stat
|
2020-12-31 02:49:54 +00:00
|
|
|
|
|
|
|
CUSTOMLS_OWN=$(ls -ld ${PIHOLE_DIR}/${CUSTOM_DNS} | awk '{print $3 $4}')
|
|
|
|
if [ "$CUSTOMLS_OWN" != "rootroot" ]
|
|
|
|
then
|
|
|
|
MESSAGE="Validating Ownership on ${CUSTOM_DNS}"
|
|
|
|
echo_fail
|
2020-12-31 02:45:47 +00:00
|
|
|
|
2020-12-31 02:49:54 +00:00
|
|
|
MESSAGE="Attempting to Compensate"
|
|
|
|
echo_warn
|
|
|
|
|
|
|
|
MESSAGE="Setting Ownership on ${CUSTOM_DNS}"
|
|
|
|
echo_stat
|
|
|
|
sudo chown root:root ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1
|
|
|
|
error_validate
|
|
|
|
|
|
|
|
MESSAGE="Continuing Validation of ${GRAVITY_FI}"
|
|
|
|
echo_stat
|
|
|
|
fi
|
2020-12-31 02:45:47 +00:00
|
|
|
|
2020-12-31 02:49:54 +00:00
|
|
|
CUSTOMLS_RWE=$(namei -m ${PIHOLE_DIR}/${CUSTOM_DNS} | grep -v f: | grep ${CUSTOM_DNS} | awk '{print $1}')
|
|
|
|
if [ "$CUSTOMLS_RWE" != "-rw-r--r--" ]
|
|
|
|
then
|
|
|
|
MESSAGE="Validating Permissions on ${CUSTOM_DNS}"
|
|
|
|
echo_fail
|
2020-12-31 02:45:47 +00:00
|
|
|
|
2020-12-31 02:49:54 +00:00
|
|
|
MESSAGE="Attempting to Compensate"
|
|
|
|
echo_warn
|
|
|
|
|
|
|
|
MESSAGE="Setting Ownership on ${CUSTOM_DNS}"
|
|
|
|
echo_stat
|
|
|
|
sudo chmod 644 ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1
|
|
|
|
error_validate
|
|
|
|
|
|
|
|
MESSAGE="Continuing Validation of ${GRAVITY_FI}"
|
|
|
|
echo_stat
|
|
|
|
fi
|
|
|
|
|
2020-12-31 02:45:47 +00:00
|
|
|
echo_good
|
|
|
|
fi
|
|
|
|
fi
|
2020-10-07 22:45:39 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 20:37:35 +00:00
|
|
|
## Pull CNAME
|
|
|
|
function pull_gs_cname {
|
|
|
|
if [ "${INCLUDE_CNAME}" == '1' ]
|
|
|
|
then
|
|
|
|
if [ "$REMOTE_CNAME_DNS" == "1" ]
|
|
|
|
then
|
|
|
|
backup_local_cname
|
|
|
|
backup_remote_cname
|
|
|
|
|
|
|
|
MESSAGE="Pulling ${CNAME_CONF} from ${REMOTE_HOST}"
|
|
|
|
echo_stat
|
|
|
|
RSYNC_REPATH="rsync"
|
|
|
|
RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${RIHOLE_DIR}/dnsmasq.d-${CNAME_CONF}.backup"
|
|
|
|
RSYNC_TARGET="${LOCAL_FOLDR}/${BACKUP_FOLD}/${CNAME_CONF}.pull"
|
|
|
|
create_rsynccmd
|
|
|
|
|
|
|
|
MESSAGE="Replacing ${CNAME_CONF} on $HOSTNAME"
|
|
|
|
echo_stat
|
|
|
|
sudo cp ${LOCAL_FOLDR}/${BACKUP_FOLD}/${CNAME_CONF}.pull ${DNSMAQ_DIR}/${CNAME_CONF} >/dev/null 2>&1
|
|
|
|
error_validate
|
|
|
|
|
|
|
|
MESSAGE="Validating Settings on ${CNAME_CONF}"
|
|
|
|
echo_stat
|
|
|
|
|
|
|
|
validate_cname_permissions
|
|
|
|
|
|
|
|
echo_good
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-10-07 22:45:39 +00:00
|
|
|
## Pull Reload
|
|
|
|
function pull_gs_reload {
|
2020-12-31 02:45:47 +00:00
|
|
|
MESSAGE="Isolating Regeneration Pathways"
|
|
|
|
echo_info
|
2020-12-31 02:49:54 +00:00
|
|
|
sleep 1
|
2020-12-31 02:45:47 +00:00
|
|
|
|
|
|
|
MESSAGE="Updating FTLDNS Configuration"
|
|
|
|
echo_stat
|
2020-12-31 02:49:54 +00:00
|
|
|
${PH_EXEC} restartdns reloadlists >/dev/null 2>&1
|
|
|
|
error_validate
|
2020-12-31 02:45:47 +00:00
|
|
|
|
|
|
|
MESSAGE="Reloading FTLDNS Services"
|
|
|
|
echo_stat
|
2020-12-31 02:49:54 +00:00
|
|
|
${PH_EXEC} restartdns >/dev/null 2>&1
|
|
|
|
error_validate
|
2020-10-07 22:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
## Pull Function
|
|
|
|
function pull_gs {
|
2020-12-31 02:45:47 +00:00
|
|
|
previous_md5
|
|
|
|
md5_compare
|
|
|
|
|
|
|
|
backup_settime
|
|
|
|
pull_gs_grav
|
|
|
|
pull_gs_cust
|
2021-01-04 20:37:35 +00:00
|
|
|
pull_gs_cname
|
2020-12-31 02:45:47 +00:00
|
|
|
pull_gs_reload
|
|
|
|
md5_recheck
|
2021-02-04 16:47:40 +00:00
|
|
|
backup_cleanup
|
2020-12-31 02:45:47 +00:00
|
|
|
|
|
|
|
logs_export
|
|
|
|
exit_withchange
|
2020-10-07 22:45:39 +00:00
|
|
|
}
|