mirror of
https://github.com/vmstan/gravity-sync.git
synced 2024-08-30 18:22:11 +00:00
Replace all the echos
This commit is contained in:
parent
e08022cfe1
commit
6dfd835988
239
gravity-sync.sh
239
gravity-sync.sh
@ -75,7 +75,7 @@ function import_gs {
|
|||||||
MESSAGE="Using ${REMOTE_USER}@${REMOTE_HOST}"
|
MESSAGE="Using ${REMOTE_USER}@${REMOTE_HOST}"
|
||||||
echo_info
|
echo_info
|
||||||
else
|
else
|
||||||
echo -e "\r${FAIL} ${MESSAGE}"
|
echo_fail
|
||||||
|
|
||||||
MESSAGE="${CONFIG_FILE} Missing"
|
MESSAGE="${CONFIG_FILE} Missing"
|
||||||
echo_info
|
echo_info
|
||||||
@ -126,54 +126,54 @@ function pull_gs {
|
|||||||
echo_info
|
echo_info
|
||||||
|
|
||||||
MESSAGE="Backing Up ${GRAVITY_FI} on $HOSTNAME"
|
MESSAGE="Backing Up ${GRAVITY_FI} on $HOSTNAME"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
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
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
MESSAGE="Pulling ${GRAVITY_FI} from ${REMOTE_HOST}"
|
MESSAGE="Pulling ${GRAVITY_FI} from ${REMOTE_HOST}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
${SSHPASSWORD} rsync -e "ssh -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull >/dev/null 2>&1
|
${SSHPASSWORD} rsync -e "ssh -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull >/dev/null 2>&1
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
MESSAGE="Replacing ${GRAVITY_FI} on $HOSTNAME"
|
MESSAGE="Replacing ${GRAVITY_FI} on $HOSTNAME"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
sudo cp $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
|
error_validate
|
||||||
|
|
||||||
MESSAGE="Validating Ownership on ${GRAVITY_FI}"
|
MESSAGE="Validating Ownership on ${GRAVITY_FI}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
|
|
||||||
GRAVDB_OWN=$(ls -ld ${PIHOLE_DIR}/${GRAVITY_FI} | awk '{print $3 $4}')
|
GRAVDB_OWN=$(ls -ld ${PIHOLE_DIR}/${GRAVITY_FI} | awk '{print $3 $4}')
|
||||||
if [ $GRAVDB_OWN == "piholepihole" ]
|
if [ $GRAVDB_OWN == "piholepihole" ]
|
||||||
then
|
then
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
echo_good
|
||||||
else
|
else
|
||||||
echo -e "\r${FAIL} $MESSAGE"
|
echo_fail
|
||||||
|
|
||||||
MESSAGE2="Attempting to Compensate"
|
MESSAGE="Attempting to Compensate"
|
||||||
echo -e "${INFO} ${MESSAGE2}"
|
echo_info
|
||||||
|
|
||||||
MESSAGE="Setting Ownership on ${GRAVITY_FI}"
|
MESSAGE="Setting Ownership on ${GRAVITY_FI}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
sudo chown pihole:pihole ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
|
sudo chown pihole:pihole ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
|
||||||
error_validate
|
error_validate
|
||||||
fi
|
fi
|
||||||
|
|
||||||
MESSAGE="Validating Permissions on ${GRAVITY_FI}"
|
MESSAGE="Validating Permissions on ${GRAVITY_FI}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
|
|
||||||
GRAVDB_RWE=$(namei -m ${PIHOLE_DIR}/${GRAVITY_FI} | grep -v f: | grep ${GRAVITY_FI} | awk '{print $1}')
|
GRAVDB_RWE=$(namei -m ${PIHOLE_DIR}/${GRAVITY_FI} | grep -v f: | grep ${GRAVITY_FI} | awk '{print $1}')
|
||||||
if [ $GRAVDB_RWE = "-rw-rw-r--" ]
|
if [ $GRAVDB_RWE = "-rw-rw-r--" ]
|
||||||
then
|
then
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
echo_good
|
||||||
else
|
else
|
||||||
echo -e "\r${FAIL} ${MESSAGE}"
|
echo_fail
|
||||||
|
|
||||||
MESSAGE2="Attempting to Compensate"
|
MESSAGE="Attempting to Compensate"
|
||||||
echo -e "${INFO} ${MESSAGE2}"
|
echo_info
|
||||||
|
|
||||||
MESSAGE="Setting Ownership on ${GRAVITY_FI}"
|
MESSAGE="Setting Ownership on ${GRAVITY_FI}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
sudo chmod 664 ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
|
sudo chmod 664 ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
|
||||||
error_validate
|
error_validate
|
||||||
fi
|
fi
|
||||||
@ -183,12 +183,12 @@ function pull_gs {
|
|||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
MESSAGE="Updating FTLDNS Configuration"
|
MESSAGE="Updating FTLDNS Configuration"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
${PIHOLE_BIN} restartdns reloadlists >/dev/null 2>&1
|
${PIHOLE_BIN} restartdns reloadlists >/dev/null 2>&1
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
MESSAGE="Reloading FTLDNS Services"
|
MESSAGE="Reloading FTLDNS Services"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
${PIHOLE_BIN} restartdns >/dev/null 2>&1
|
${PIHOLE_BIN} restartdns >/dev/null 2>&1
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
@ -198,33 +198,31 @@ function pull_gs {
|
|||||||
|
|
||||||
## Push Function
|
## Push Function
|
||||||
function push_gs {
|
function push_gs {
|
||||||
TASKTYPE='PUSH'
|
|
||||||
|
|
||||||
echo -e "${INFO} ${TASKTYPE} Requested"
|
|
||||||
md5_compare
|
md5_compare
|
||||||
|
|
||||||
echo -e "${WARN} Are you sure you want to overwrite the primary PH configuration on ${REMOTE_HOST}?"
|
MESSAGE="Are you sure you want to overwrite ${GRAVITY_DB} on ${REMOTE_HOST}?"
|
||||||
|
echo_warn
|
||||||
select yn in "Yes" "No"; do
|
select yn in "Yes" "No"; do
|
||||||
case $yn in
|
case $yn in
|
||||||
Yes )
|
Yes )
|
||||||
|
|
||||||
MESSAGE="Backing Up ${GRAVITY_FI} from ${REMOTE_HOST}"
|
MESSAGE="Backing Up ${GRAVITY_FI} from ${REMOTE_HOST}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
${SSHPASSWORD} rsync -e "ssh -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${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 ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.push >/dev/null 2>&1
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
MESSAGE="Pushing ${GRAVITY_FI} to ${REMOTE_HOST}"
|
MESSAGE="Pushing ${GRAVITY_FI} to ${REMOTE_HOST}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
${SSHPASSWORD} rsync --rsync-path="sudo rsync" -e "ssh -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${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 ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${PIHOLE_DIR}/${GRAVITY_FI} ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
MESSAGE="Setting Permissions on ${GRAVITY_FI}"
|
MESSAGE="Setting Permissions on ${GRAVITY_FI}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
${SSHPASSWORD} ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo chmod 664 ${PIHOLE_DIR}/${GRAVITY_FI}" >/dev/null 2>&1
|
${SSHPASSWORD} ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo chmod 664 ${PIHOLE_DIR}/${GRAVITY_FI}" >/dev/null 2>&1
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
MESSAGE="Setting Ownership on ${GRAVITY_FI}"
|
MESSAGE="Setting Ownership on ${GRAVITY_FI}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
${SSHPASSWORD} ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo chown pihole:pihole ${PIHOLE_DIR}/${GRAVITY_FI}" >/dev/null 2>&1
|
${SSHPASSWORD} ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo chown pihole:pihole ${PIHOLE_DIR}/${GRAVITY_FI}" >/dev/null 2>&1
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
@ -233,12 +231,12 @@ function push_gs {
|
|||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
MESSAGE="Updating FTLDNS Configuration"
|
MESSAGE="Updating FTLDNS Configuration"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
${SSHPASSWORD} ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "${PIHOLE_BIN} restartdns reloadlists" >/dev/null 2>&1
|
${SSHPASSWORD} ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "${PIHOLE_BIN} restartdns reloadlists" >/dev/null 2>&1
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
MESSAGE="Reloading FTLDNS Services"
|
MESSAGE="Reloading FTLDNS Services"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
${SSHPASSWORD} ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "${PIHOLE_BIN} restartdns" >/dev/null 2>&1
|
${SSHPASSWORD} ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "${PIHOLE_BIN} restartdns" >/dev/null 2>&1
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
@ -257,7 +255,9 @@ function push_gs {
|
|||||||
## Core Logging
|
## Core Logging
|
||||||
### Write Logs Out
|
### Write Logs Out
|
||||||
function logs_export {
|
function logs_export {
|
||||||
echo -e "${INFO} Logging Timestamps to ${SYNCING_LOG}"
|
MESSAGE="Logging Timestamps to ${SYNCING_LOG}"
|
||||||
|
echo_info
|
||||||
|
|
||||||
echo -e $(date) "[${TASKTYPE}]" >> ${LOG_PATH}/${SYNCING_LOG}
|
echo -e $(date) "[${TASKTYPE}]" >> ${LOG_PATH}/${SYNCING_LOG}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,13 +265,16 @@ function logs_export {
|
|||||||
function logs_gs {
|
function logs_gs {
|
||||||
import_gs
|
import_gs
|
||||||
|
|
||||||
echo -e "${INFO} Tailing ${LOG_PATH}/${SYNCING_LOG}"
|
MESSAGE="Tailing ${LOG_PATH}/${SYNCING_LOG}"
|
||||||
|
echo_info
|
||||||
|
|
||||||
echo -e "========================================================"
|
echo -e "========================================================"
|
||||||
echo -e "Recent Complete ${YELLOW}PULL${NC} Executions"
|
echo -e "Recent Complete ${YELLOW}PULL${NC} Executions"
|
||||||
tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PULL
|
tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PULL
|
||||||
echo -e "Recent Complete ${YELLOW}PUSH${NC} Executions"
|
echo -e "Recent Complete ${YELLOW}PUSH${NC} Executions"
|
||||||
tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PUSH
|
tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PUSH
|
||||||
echo -e "========================================================"
|
echo -e "========================================================"
|
||||||
|
|
||||||
exit_nochange
|
exit_nochange
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,27 +284,36 @@ function show_crontab {
|
|||||||
import_gs
|
import_gs
|
||||||
|
|
||||||
MESSAGE="Replaying Last Cronjob"
|
MESSAGE="Replaying Last Cronjob"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
|
|
||||||
if [ -f ${LOG_PATH}/${CRONJOB_LOG} ]
|
if [ -f ${LOG_PATH}/${CRONJOB_LOG} ]
|
||||||
then
|
then
|
||||||
if [ -s ${LOG_PATH}/${CRONJOB_LOG} ]
|
if [ -s ${LOG_PATH}/${CRONJOB_LOG} ]
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
echo_good
|
||||||
|
|
||||||
|
MESSAGE="Tailing ${LOG_PATH}/${CRONJOB_LOG}"
|
||||||
|
echo_info
|
||||||
|
|
||||||
echo -e "${INFO} Tailing ${LOG_PATH}/${CRONJOB_LOG}"
|
|
||||||
echo -e "========================================================"
|
echo -e "========================================================"
|
||||||
date -r ${LOG_PATH}/${CRONJOB_LOG}
|
date -r ${LOG_PATH}/${CRONJOB_LOG}
|
||||||
cat ${LOG_PATH}/${CRONJOB_LOG}
|
cat ${LOG_PATH}/${CRONJOB_LOG}
|
||||||
echo -e "========================================================"
|
echo -e "========================================================"
|
||||||
|
|
||||||
exit_nochange
|
exit_nochange
|
||||||
then
|
then
|
||||||
echo -e "\r${FAIL} ${MESSAGE}"
|
echo_fail
|
||||||
echo -e "${INFO} ${LOG_PATH}/${CRONJOB_LOG} appears empty"
|
|
||||||
|
MESSAGE="${LOG_PATH}/${CRONJOB_LOG} is Empty"
|
||||||
|
echo_info
|
||||||
|
|
||||||
exit_nochange
|
exit_nochange
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo -e "\r${FAIL} ${MESSAGE}"
|
echo_fail
|
||||||
echo -e "${INFO} ${LOG_PATH}/${CRONJOB_LOG} not yet created"
|
|
||||||
|
MESSAGE="${LOG_PATH}/${CRONJOB_LOG} is Missing"
|
||||||
|
echo_info
|
||||||
|
|
||||||
exit_nochange
|
exit_nochange
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -310,22 +322,22 @@ function show_crontab {
|
|||||||
## Validate GS Folders
|
## Validate GS Folders
|
||||||
function validate_gs_folders {
|
function validate_gs_folders {
|
||||||
MESSAGE="Locating $HOME/${LOCAL_FOLDR}"
|
MESSAGE="Locating $HOME/${LOCAL_FOLDR}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
if [ -d $HOME/${LOCAL_FOLDR} ]
|
if [ -d $HOME/${LOCAL_FOLDR} ]
|
||||||
then
|
then
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
echo_good
|
||||||
else
|
else
|
||||||
echo -e "\r${FAIL} ${MESSAGE}"
|
echo_fail
|
||||||
exit_nochange
|
exit_nochange
|
||||||
fi
|
fi
|
||||||
|
|
||||||
MESSAGE="Locating $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}"
|
MESSAGE="Locating $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
if [ -d $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD} ]
|
if [ -d $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD} ]
|
||||||
then
|
then
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
echo_good
|
||||||
else
|
else
|
||||||
echo -e "\r${FAIL} ${MESSAGE}"
|
echo_fail
|
||||||
exit_nochange
|
exit_nochange
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -333,12 +345,12 @@ function validate_gs_folders {
|
|||||||
## Validate PH Folders
|
## Validate PH Folders
|
||||||
function validate_ph_folders {
|
function validate_ph_folders {
|
||||||
MESSAGE="Locating ${PIHOLE_DIR}"
|
MESSAGE="Locating ${PIHOLE_DIR}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
if [ -d ${PIHOLE_DIR} ]
|
if [ -d ${PIHOLE_DIR} ]
|
||||||
then
|
then
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
echo_good
|
||||||
else
|
else
|
||||||
echo -e "\r${FAIL} ${MESSAGE}"
|
echo_fail
|
||||||
exit_nochange
|
exit_nochange
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -373,7 +385,7 @@ function validate_os_sshpass {
|
|||||||
echo_info
|
echo_info
|
||||||
|
|
||||||
MESSAGE="Testing SSH Connection"
|
MESSAGE="Testing SSH Connection"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
timeout 5 ${SSHPASSWORD} ssh -p ${SSH_PORT} -i '$HOME/${SSH_PKIF}' -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} 'exit' >/dev/null 2>&1
|
timeout 5 ${SSHPASSWORD} ssh -p ${SSH_PORT} -i '$HOME/${SSH_PKIF}' -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} 'exit' >/dev/null 2>&1
|
||||||
error_validate
|
error_validate
|
||||||
}
|
}
|
||||||
@ -381,33 +393,36 @@ function validate_os_sshpass {
|
|||||||
## Error Validation
|
## Error Validation
|
||||||
function error_validate {
|
function error_validate {
|
||||||
if [ "$?" != "0" ]; then
|
if [ "$?" != "0" ]; then
|
||||||
echo -e "\r${FAIL} ${MESSAGE}"
|
echo_fail
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
echo_good
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## Validate Sync Required
|
## Validate Sync Required
|
||||||
function md5_compare {
|
function md5_compare {
|
||||||
echo -e "${INFO} Comparing ${GRAVITY_FI} Changes"
|
MESSAGE="Comparing ${GRAVITY_FI} Changes"
|
||||||
|
echo_info
|
||||||
|
|
||||||
MESSAGE="Analyzing Remote ${GRAVITY_FI}"
|
MESSAGE="Analyzing Remote ${GRAVITY_FI}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
primaryMD5=$(${SSHPASSWORD} ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${PIHOLE_DIR}/${GRAVITY_FI}")
|
primaryMD5=$(${SSHPASSWORD} ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${PIHOLE_DIR}/${GRAVITY_FI}")
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
MESSAGE="Analyzing Local ${GRAVITY_FI}"
|
MESSAGE="Analyzing Local ${GRAVITY_FI}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
secondMD5=$(md5sum ${PIHOLE_DIR}/${GRAVITY_FI})
|
secondMD5=$(md5sum ${PIHOLE_DIR}/${GRAVITY_FI})
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
if [ "$primaryMD5" == "$secondMD5" ]
|
if [ "$primaryMD5" == "$secondMD5" ]
|
||||||
then
|
then
|
||||||
echo -e "${INFO} No Differences in ${GRAVITY_FI}"
|
MESSAGE="No Differences in ${GRAVITY_FI}"
|
||||||
|
echo_info
|
||||||
exit_nochange
|
exit_nochange
|
||||||
else
|
else
|
||||||
echo -e "${INFO} Changes Detected in ${GRAVITY_FI}"
|
MESSAGE="Changes Detected in ${GRAVITY_FI}"
|
||||||
|
echo_info
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,25 +430,25 @@ function md5_compare {
|
|||||||
## Generate New Configuration
|
## Generate New Configuration
|
||||||
function config_generate {
|
function config_generate {
|
||||||
MESSAGE="Creating ${CONFIG_FILE} from Template"
|
MESSAGE="Creating ${CONFIG_FILE} from Template"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
cp $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}.example $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
cp $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}.example $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
MESSAGE="Enter IP or DNS of primary Pi-hole server: "
|
MESSAGE="Enter IP or DNS of primary Pi-hole server"
|
||||||
echo -en "${NEED} ${MESSAGE}"
|
echo_need
|
||||||
read INPUT_REMOTE_HOST
|
read INPUT_REMOTE_HOST
|
||||||
|
|
||||||
MESSAGE="Enter SSH user with SUDO rights on primary Pi-hole server: "
|
MESSAGE="Enter SSH user with SUDO rights on primary Pi-hole server: "
|
||||||
echo -en "${NEED} ${MESSAGE}"
|
echo_need
|
||||||
read INPUT_REMOTE_USER
|
read INPUT_REMOTE_USER
|
||||||
|
|
||||||
MESSAGE="Saving Host to ${CONFIG_FILE}"
|
MESSAGE="Saving Host to ${CONFIG_FILE}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
sed -i "/REMOTE_HOST='192.168.1.10'/c\REMOTE_HOST='${INPUT_REMOTE_HOST}'" $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
sed -i "/REMOTE_HOST='192.168.1.10'/c\REMOTE_HOST='${INPUT_REMOTE_HOST}'" $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
MESSAGE="Saving User to ${CONFIG_FILE}"
|
MESSAGE="Saving User to ${CONFIG_FILE}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
sed -i "/REMOTE_USER='pi'/c\REMOTE_USER='${INPUT_REMOTE_USER}'" $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
sed -i "/REMOTE_USER='pi'/c\REMOTE_USER='${INPUT_REMOTE_USER}'" $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
@ -443,16 +458,16 @@ function config_generate {
|
|||||||
echo_info
|
echo_info
|
||||||
|
|
||||||
MESSAGE="Do you want to configure password based SSH authentication?"
|
MESSAGE="Do you want to configure password based SSH authentication?"
|
||||||
echo -e "${WARN} ${MESSAGE}"
|
echo_warn
|
||||||
MESSAGE="Your password will be stored clear-text in the ${CONFIG_FILE}!"
|
MESSAGE="Your password will be stored clear-text in the ${CONFIG_FILE}!"
|
||||||
echo -e "${WARN} ${MESSAGE}"
|
echo_warn
|
||||||
|
|
||||||
MESSAGE="Leave blank to use (preferred) SSH Key-Pair Authentication: "
|
MESSAGE="Leave blank to use (preferred) SSH Key-Pair Authentication"
|
||||||
echo -en "${NEED} ${MESSAGE}"
|
echo_need
|
||||||
read INPUT_REMOTE_PASS
|
read INPUT_REMOTE_PASS
|
||||||
|
|
||||||
MESSAGE="Saving Password to ${CONFIG_FILE}"
|
MESSAGE="Saving Password to ${CONFIG_FILE}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
sed -i "/REMOTE_PASS=''/c\REMOTE_PASS='${INPUT_REMOTE_PASS}'" $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
sed -i "/REMOTE_PASS=''/c\REMOTE_PASS='${INPUT_REMOTE_PASS}'" $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
@ -475,7 +490,7 @@ function config_generate {
|
|||||||
echo_info
|
echo_info
|
||||||
|
|
||||||
MESSAGE="Accept All Defaults"
|
MESSAGE="Accept All Defaults"
|
||||||
echo -e "${WARN} ${MESSAGE}"
|
echo_warn
|
||||||
|
|
||||||
MESSAGE="Complete Key-Pair Creation"
|
MESSAGE="Complete Key-Pair Creation"
|
||||||
echo -e "${NEED} ${MESSAGE}"
|
echo -e "${NEED} ${MESSAGE}"
|
||||||
@ -489,7 +504,7 @@ function config_generate {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
MESSAGE="Importing New ${CONFIG_FILE}"
|
MESSAGE="Importing New ${CONFIG_FILE}"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
source $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
source $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
@ -523,20 +538,20 @@ function config_generate {
|
|||||||
function config_delete {
|
function config_delete {
|
||||||
source $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
source $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
||||||
MESSAGE="Configuration File Exists"
|
MESSAGE="Configuration File Exists"
|
||||||
echo -e "${WARN} ${MESSAGE}"
|
echo_warn
|
||||||
|
|
||||||
echo -e "========================================================"
|
echo -e "========================================================"
|
||||||
cat $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
cat $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
||||||
echo -e "========================================================"
|
echo -e "========================================================"
|
||||||
|
|
||||||
MESSAGE="Are you sure you want to erase this configuration?"
|
MESSAGE="Are you sure you want to erase this configuration?"
|
||||||
echo -e "${WARN} ${MESSAGE}"
|
echo_warn
|
||||||
|
|
||||||
select yn in "Yes" "No"; do
|
select yn in "Yes" "No"; do
|
||||||
case $yn in
|
case $yn in
|
||||||
Yes )
|
Yes )
|
||||||
MESSAGE="Erasing Existing Configuration"
|
MESSAGE="Erasing Existing Configuration"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
rm -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
rm -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
@ -553,7 +568,8 @@ function config_delete {
|
|||||||
# Exit Codes
|
# Exit Codes
|
||||||
## No Changes Made
|
## No Changes Made
|
||||||
function exit_nochange {
|
function exit_nochange {
|
||||||
echo -e "${INFO} ${PROGRAM} ${TASKTYPE} Aborting"
|
MESSAGE="${PROGRAM} ${TASKTYPE} Aborting"
|
||||||
|
echo_info
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,14 +609,15 @@ function list_gs_arguments {
|
|||||||
|
|
||||||
# Output Version
|
# Output Version
|
||||||
function show_version {
|
function show_version {
|
||||||
echo -e "${INFO} ${PROGRAM} ${VERSION}"
|
MESSAGE="${PROGRAM} ${VERSION}"
|
||||||
|
echo_info
|
||||||
}
|
}
|
||||||
|
|
||||||
# Task Stack
|
# Task Stack
|
||||||
## Automate Task
|
## Automate Task
|
||||||
function task_automate {
|
function task_automate {
|
||||||
TASKTYPE='AUTOMATE'
|
TASKTYPE='AUTOMATE'
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
echo_good
|
||||||
|
|
||||||
import_gs
|
import_gs
|
||||||
|
|
||||||
@ -628,8 +645,8 @@ function task_automate {
|
|||||||
MESSAGE="12 = Every 05 Minutes"
|
MESSAGE="12 = Every 05 Minutes"
|
||||||
echo -e "++++++ ${MESSAGE}"
|
echo -e "++++++ ${MESSAGE}"
|
||||||
|
|
||||||
MESSAGE="Input Automation Frequency: "
|
MESSAGE="Input Automation Frequency"
|
||||||
echo -en "${NEED} ${MESSAGE}"
|
echo_need
|
||||||
read INPUT_AUTO_FREQ
|
read INPUT_AUTO_FREQ
|
||||||
|
|
||||||
if [ $INPUT_AUTO_FREQ == 1 ]
|
if [ $INPUT_AUTO_FREQ == 1 ]
|
||||||
@ -654,7 +671,7 @@ function task_automate {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
MESSAGE="Saving to Crontab"
|
MESSAGE="Saving to Crontab"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
(crontab -l 2>/dev/null; echo "*/${AUTO_FREQ} * * * * ${BASH_PATH} $HOME/${LOCAL_FOLDR}/${GS_FILENAME} pull > ${LOG_PATH}/${CRONJOB_LOG}") | crontab -
|
(crontab -l 2>/dev/null; echo "*/${AUTO_FREQ} * * * * ${BASH_PATH} $HOME/${LOCAL_FOLDR}/${GS_FILENAME} pull > ${LOG_PATH}/${CRONJOB_LOG}") | crontab -
|
||||||
error_validate
|
error_validate
|
||||||
|
|
||||||
@ -698,19 +715,23 @@ function echo_need {
|
|||||||
SCRIPT_START=$SECONDS
|
SCRIPT_START=$SECONDS
|
||||||
|
|
||||||
MESSAGE="Evaluating Script Arguments"
|
MESSAGE="Evaluating Script Arguments"
|
||||||
echo -en "${STAT} ${MESSAGE}"
|
echo_stat
|
||||||
|
|
||||||
case $# in
|
case $# in
|
||||||
|
|
||||||
0)
|
0)
|
||||||
echo -e "\r${FAIL} ${MESSAGE}"
|
echo_fail
|
||||||
list_gs_arguments
|
list_gs_arguments
|
||||||
;;
|
;;
|
||||||
|
|
||||||
1)
|
1)
|
||||||
case $1 in
|
case $1 in
|
||||||
pull)
|
pull)
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
TASKTYPE='PULL'
|
||||||
|
echo_good
|
||||||
|
|
||||||
|
MESSAGE="${TASKTYPE} Requested"
|
||||||
|
echo_info
|
||||||
|
|
||||||
import_gs
|
import_gs
|
||||||
|
|
||||||
@ -725,11 +746,16 @@ case $# in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
push)
|
push)
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
TASKTYPE='PUSH'
|
||||||
|
echo_good
|
||||||
|
|
||||||
|
MESSAGE="${TASKTYPE} Requested"
|
||||||
|
echo_info
|
||||||
|
|
||||||
import_gs
|
import_gs
|
||||||
|
|
||||||
echo -e "${INFO} Validating Folder Configuration"
|
MESSAGE="Validating Folder Configuration"
|
||||||
|
echo_info
|
||||||
validate_gs_folders
|
validate_gs_folders
|
||||||
validate_ph_folders
|
validate_ph_folders
|
||||||
validate_os_sshpass
|
validate_os_sshpass
|
||||||
@ -740,47 +766,59 @@ case $# in
|
|||||||
|
|
||||||
version)
|
version)
|
||||||
TASKTYPE='VERSION'
|
TASKTYPE='VERSION'
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
echo_good
|
||||||
|
|
||||||
|
MESSAGE="${TASKTYPE} Requested"
|
||||||
|
echo_info
|
||||||
|
|
||||||
show_version
|
show_version
|
||||||
exit_nochange
|
exit_nochange
|
||||||
;;
|
;;
|
||||||
|
|
||||||
update)
|
update)
|
||||||
# TASKTYPE='UPDATE'
|
TASKTYPE='UPDATE'
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
echo_good
|
||||||
|
|
||||||
|
MESSAGE="${TASKTYPE} Requested"
|
||||||
|
echo_info
|
||||||
|
|
||||||
echo -e "${INFO} Update Requested"
|
|
||||||
update_gs
|
update_gs
|
||||||
exit_nochange
|
exit_nochange
|
||||||
;;
|
;;
|
||||||
|
|
||||||
beta)
|
beta)
|
||||||
# TASKTYPE='BETA'
|
TASKTYPE='BETA'
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
echo_good
|
||||||
|
|
||||||
|
MESSAGE="${TASKTYPE} Requested"
|
||||||
|
echo_info
|
||||||
|
|
||||||
echo -e "${INFO} Beta Update Requested"
|
|
||||||
beta_gs
|
beta_gs
|
||||||
exit_nochange
|
exit_nochange
|
||||||
;;
|
;;
|
||||||
|
|
||||||
logs)
|
logs)
|
||||||
TASKTYPE='LOGS'
|
TASKTYPE='LOGS'
|
||||||
|
echo_good
|
||||||
|
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
MESSAGE="${TASKTYPE} Requested"
|
||||||
|
|
||||||
MESSAGE="Logs Requested"
|
|
||||||
echo_info
|
echo_info
|
||||||
|
|
||||||
logs_gs
|
logs_gs
|
||||||
;;
|
;;
|
||||||
|
|
||||||
compare)
|
compare)
|
||||||
TASKTYPE='COMPARE'
|
TASKTYPE='COMPARE'
|
||||||
|
echo_good
|
||||||
|
|
||||||
|
MESSAGE="${TASKTYPE} Requested"
|
||||||
|
echo_info
|
||||||
|
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
|
||||||
import_gs
|
import_gs
|
||||||
|
|
||||||
echo -e "${INFO} Validating Folder Configuration"
|
MESSAGE="Validating OS Configuration"
|
||||||
|
echo_info
|
||||||
|
|
||||||
validate_gs_folders
|
validate_gs_folders
|
||||||
validate_ph_folders
|
validate_ph_folders
|
||||||
validate_os_sshpass
|
validate_os_sshpass
|
||||||
@ -790,15 +828,20 @@ case $# in
|
|||||||
|
|
||||||
cron)
|
cron)
|
||||||
TASKTYPE='CRON'
|
TASKTYPE='CRON'
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
echo_good
|
||||||
|
|
||||||
|
MESSAGE="${TASKTYPE} Requested"
|
||||||
|
echo_info
|
||||||
|
|
||||||
show_crontab
|
show_crontab
|
||||||
;;
|
;;
|
||||||
|
|
||||||
config)
|
config)
|
||||||
TASKTYPE='CONFIGURE'
|
TASKTYPE='CONFIGURE'
|
||||||
echo -e "\r${GOOD} ${MESSAGE}"
|
echo_good
|
||||||
echo -e "${INFO} Entering ${TASKTYPE} Mode"
|
|
||||||
|
MESSAGE="${TASKTYPE} Requested"
|
||||||
|
echo_info
|
||||||
|
|
||||||
if [ -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} ]
|
if [ -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} ]
|
||||||
then
|
then
|
||||||
@ -821,14 +864,14 @@ case $# in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
echo -e "\r${FAIL} ${MESSAGE}"
|
echo_fail
|
||||||
list_gs_arguments
|
list_gs_arguments
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
echo -e "\r${FAIL} ${MESSAGE}"
|
echo_fail
|
||||||
list_gs_arguments
|
list_gs_arguments
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
Loading…
Reference in New Issue
Block a user