2020-05-21 18:00:42 +00:00
|
|
|
#!/bin/bash
|
2020-06-02 15:44:16 +00:00
|
|
|
SCRIPT_START=$SECONDS
|
2020-05-21 18:00:42 +00:00
|
|
|
|
2020-05-22 17:18:16 +00:00
|
|
|
# GRAVITY SYNC BY VMSTAN #####################
|
2020-05-23 23:37:08 +00:00
|
|
|
PROGRAM='Gravity Sync'
|
2020-10-02 19:01:17 +00:00
|
|
|
VERSION='2.2.3'
|
2020-05-21 18:00:42 +00:00
|
|
|
|
2020-05-28 01:51:21 +00:00
|
|
|
# Execute from the home folder of the user who owns it (ex: 'cd ~/gravity-sync')
|
|
|
|
# For documentation or downloading updates visit https://github.com/vmstan/gravity-sync
|
2020-05-21 18:00:42 +00:00
|
|
|
|
2020-05-22 17:18:16 +00:00
|
|
|
# REQUIRED SETTINGS ##########################
|
2020-05-21 18:00:42 +00:00
|
|
|
|
2020-05-27 03:20:36 +00:00
|
|
|
# Run './gravity-sync.sh config' to get started
|
2020-05-22 17:18:16 +00:00
|
|
|
|
2020-05-22 17:25:30 +00:00
|
|
|
# STANDARD VARIABLES #########################
|
2020-05-21 18:00:42 +00:00
|
|
|
|
2020-05-22 15:44:38 +00:00
|
|
|
# GS Folder/File Locations
|
2020-05-27 03:20:36 +00:00
|
|
|
LOCAL_FOLDR='gravity-sync' # must exist in running user home folder
|
2020-05-27 15:00:30 +00:00
|
|
|
CONFIG_FILE='gravity-sync.conf' # must exist with primary host/user configured
|
2020-05-28 18:05:22 +00:00
|
|
|
GS_FILENAME='gravity-sync.sh' # must exist because it's this script
|
2020-05-27 03:20:36 +00:00
|
|
|
BACKUP_FOLD='backup' # must exist as subdirectory in LOCAL_FOLDR
|
2020-05-21 18:00:42 +00:00
|
|
|
|
2020-05-27 15:00:30 +00:00
|
|
|
# Logging Folder/File Locations
|
|
|
|
LOG_PATH="$HOME/${LOCAL_FOLDR}" # replace in gravity-sync.conf to overwrite
|
|
|
|
SYNCING_LOG='gravity-sync.log' # replace in gravity-sync.conf to overwrite
|
|
|
|
CRONJOB_LOG='gravity-sync.cron' # replace in gravity-sync.conf to overwrite
|
2020-06-29 19:03:47 +00:00
|
|
|
HISTORY_MD5='gravity-sync.md5' # replace in gravity-sync.conf to overwrite
|
2020-05-27 15:00:30 +00:00
|
|
|
|
2020-05-29 02:43:58 +00:00
|
|
|
# Interaction Customization
|
|
|
|
VERIFY_PASS='0' # replace in gravity-sync.conf to overwrite
|
2020-05-29 19:43:36 +00:00
|
|
|
SKIP_CUSTOM='0' # replace in gravity-sync.conf to overwrite
|
|
|
|
DATE_OUTPUT='0' # replace in gravity-sync.conf to overwrite
|
2020-06-02 14:43:58 +00:00
|
|
|
PING_AVOID='0' # replace in gravity-sync.conf to overwrite
|
2020-07-16 18:09:44 +00:00
|
|
|
ROOT_CHECK_AVOID='0' # replace in gravity-sync.conf to overwrite
|
2020-05-29 02:43:58 +00:00
|
|
|
|
2020-07-11 03:13:49 +00:00
|
|
|
# Backup Customization
|
|
|
|
BACKUP_RETAIN='7' # replace in gravity-sync.conf to overwrite
|
|
|
|
|
2020-05-29 03:01:08 +00:00
|
|
|
# Pi-hole Folder/File Locations
|
|
|
|
PIHOLE_DIR='/etc/pihole' # default Pi-hole data directory
|
|
|
|
GRAVITY_FI='gravity.db' # default Pi-hole database file
|
2020-05-29 15:58:06 +00:00
|
|
|
CUSTOM_DNS='custom.list' # default Pi-hole local DNS lookups
|
2020-08-18 15:09:13 +00:00
|
|
|
PIHOLE_BIN='/usr/local/bin/pihole' # default Pi-hole binary directory (local)
|
|
|
|
RIHOLE_BIN='/usr/local/bin/pihole' # default Pi-hole binary directory (remote)
|
2020-10-02 19:01:17 +00:00
|
|
|
FILE_OWNER='pihole:pihole' # default Pi-hole file owner and group (local)
|
|
|
|
REMOTE_FILE_OWNER='pihole:pihole' # default Pi-hole file owner and group (remote)
|
2020-05-21 18:00:42 +00:00
|
|
|
|
2020-05-28 15:54:32 +00:00
|
|
|
# OS Settings
|
|
|
|
BASH_PATH='/bin/bash' # default OS bash path
|
|
|
|
|
2020-05-27 03:20:36 +00:00
|
|
|
# SSH CONFIGURATION ##########################
|
|
|
|
|
|
|
|
# Suggested not to replace these values here
|
|
|
|
# Add replacement variables to gravity-sync.conf
|
|
|
|
|
|
|
|
SSH_PORT='22' # default SSH port
|
2020-05-27 21:09:41 +00:00
|
|
|
SSH_PKIF='.ssh/id_rsa' # default local SSH key
|
2020-05-26 21:51:31 +00:00
|
|
|
|
2020-05-24 18:39:21 +00:00
|
|
|
##############################################
|
|
|
|
### DO NOT CHANGE ANYTHING BELOW THIS LINE ###
|
|
|
|
##############################################
|
|
|
|
|
2020-05-22 15:44:38 +00:00
|
|
|
# Script Colors
|
2020-05-21 19:09:55 +00:00
|
|
|
RED='\033[0;91m'
|
|
|
|
GREEN='\033[0;92m'
|
|
|
|
CYAN='\033[0;96m'
|
2020-05-21 19:10:49 +00:00
|
|
|
YELLOW='\033[0;93m'
|
|
|
|
PURPLE='\033[0;95m'
|
2020-05-26 19:39:55 +00:00
|
|
|
BLUE='\033[0;94m'
|
2020-05-30 02:09:37 +00:00
|
|
|
BOLD='\033[1m'
|
2020-05-21 18:00:42 +00:00
|
|
|
NC='\033[0m'
|
|
|
|
|
2020-05-23 22:58:06 +00:00
|
|
|
# Message Codes
|
2020-05-31 02:58:25 +00:00
|
|
|
FAIL="[ ${RED}FAIL${NC} ]"
|
|
|
|
WARN="[ ${PURPLE}WARN${NC} ]"
|
|
|
|
GOOD="[ ${GREEN} OK ${NC} ]"
|
|
|
|
STAT="[ ${CYAN}EXEC${NC} ]"
|
|
|
|
INFO="[ ${YELLOW}INFO${NC} ]"
|
|
|
|
NEED="[ ${BLUE}NEED${NC} ]"
|
2020-05-23 22:58:06 +00:00
|
|
|
|
2020-05-22 15:46:24 +00:00
|
|
|
# FUNCTION DEFINITIONS #######################
|
2020-05-22 15:44:38 +00:00
|
|
|
|
2020-05-22 15:46:24 +00:00
|
|
|
# Import Settings
|
|
|
|
function import_gs {
|
2020-05-31 02:23:02 +00:00
|
|
|
MESSAGE="Importing ${CONFIG_FILE} Settings"
|
2020-05-26 02:16:31 +00:00
|
|
|
echo -en "${STAT} $MESSAGE"
|
2020-05-23 03:35:46 +00:00
|
|
|
if [ -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} ]
|
2020-05-22 15:46:24 +00:00
|
|
|
then
|
2020-05-23 04:00:59 +00:00
|
|
|
source $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
2020-05-25 00:40:09 +00:00
|
|
|
error_validate
|
2020-05-25 00:38:43 +00:00
|
|
|
|
2020-07-17 14:45:08 +00:00
|
|
|
# MESSAGE="Targeting ${REMOTE_USER}@${REMOTE_HOST}"
|
|
|
|
# echo_info
|
2020-05-31 01:40:33 +00:00
|
|
|
|
2020-07-17 14:45:08 +00:00
|
|
|
# detect_ssh
|
2020-05-22 15:46:24 +00:00
|
|
|
else
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_fail
|
2020-05-25 00:56:55 +00:00
|
|
|
|
|
|
|
MESSAGE="${CONFIG_FILE} Missing"
|
2020-05-28 21:21:10 +00:00
|
|
|
echo_info
|
2020-05-27 17:00:23 +00:00
|
|
|
|
2020-05-27 17:06:39 +00:00
|
|
|
TASKTYPE='CONFIG'
|
2020-05-27 17:00:23 +00:00
|
|
|
config_generate
|
2020-05-22 15:46:24 +00:00
|
|
|
fi
|
|
|
|
}
|
2020-05-22 15:28:02 +00:00
|
|
|
|
2020-07-17 14:45:08 +00:00
|
|
|
function show_target {
|
|
|
|
MESSAGE="Targeting ${REMOTE_USER}@${REMOTE_HOST}"
|
|
|
|
echo_info
|
|
|
|
|
|
|
|
detect_ssh
|
|
|
|
}
|
|
|
|
|
2020-05-27 03:20:36 +00:00
|
|
|
# GS Update Functions
|
|
|
|
## Master Branch
|
2020-05-22 15:28:02 +00:00
|
|
|
function update_gs {
|
2020-05-31 01:20:06 +00:00
|
|
|
if [ -f "$HOME/${LOCAL_FOLDR}/dev" ]
|
2020-05-30 02:28:22 +00:00
|
|
|
then
|
2020-10-02 19:01:17 +00:00
|
|
|
source $HOME/${LOCAL_FOLDR}/dev
|
2020-05-30 02:28:22 +00:00
|
|
|
else
|
2020-10-02 19:01:17 +00:00
|
|
|
BRANCH='origin/master'
|
2020-06-02 16:32:38 +00:00
|
|
|
fi
|
|
|
|
|
2020-10-02 19:01:17 +00:00
|
|
|
if [ "$BRANCH" != "origin/master" ]
|
2020-06-02 16:32:38 +00:00
|
|
|
then
|
2020-10-02 19:01:17 +00:00
|
|
|
MESSAGE="Pulling from ${BRANCH}"
|
2020-06-02 16:32:38 +00:00
|
|
|
echo_info
|
2020-05-30 02:28:22 +00:00
|
|
|
fi
|
|
|
|
|
2020-06-03 20:12:39 +00:00
|
|
|
GIT_CHECK=$(git status | awk '{print $1}')
|
2020-05-31 03:43:59 +00:00
|
|
|
if [ "$GIT_CHECK" == "fatal:" ]
|
2020-05-31 03:37:06 +00:00
|
|
|
then
|
|
|
|
MESSAGE="Requires GitHub Installation"
|
|
|
|
echo_warn
|
|
|
|
exit_nochange
|
|
|
|
else
|
2020-05-31 03:42:37 +00:00
|
|
|
MESSAGE="Updating Cache"
|
|
|
|
echo_stat
|
|
|
|
git fetch --all >/dev/null 2>&1
|
|
|
|
error_validate
|
2020-06-02 16:32:38 +00:00
|
|
|
MESSAGE="Applying Update"
|
2020-05-31 03:42:57 +00:00
|
|
|
echo_stat
|
2020-10-02 19:01:17 +00:00
|
|
|
git reset --hard ${BRANCH} >/dev/null 2>&1
|
2020-05-31 03:42:37 +00:00
|
|
|
error_validate
|
2020-07-21 05:14:20 +00:00
|
|
|
fi
|
2020-05-22 15:28:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 03:20:36 +00:00
|
|
|
# Gravity Core Functions
|
2020-06-29 18:41:54 +00:00
|
|
|
## Pull Gravity
|
|
|
|
function pull_gs_grav {
|
2020-07-11 19:42:52 +00:00
|
|
|
|
|
|
|
backup_local_gravity
|
2020-07-11 20:33:35 +00:00
|
|
|
backup_remote_gravity
|
2020-05-23 23:26:12 +00:00
|
|
|
|
2020-05-26 17:14:32 +00:00
|
|
|
MESSAGE="Pulling ${GRAVITY_FI} from ${REMOTE_HOST}"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_stat
|
2020-06-03 14:45:06 +00:00
|
|
|
RSYNC_REPATH="rsync"
|
2020-07-11 20:33:35 +00:00
|
|
|
RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI}.backup"
|
2020-06-03 04:09:46 +00:00
|
|
|
RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull"
|
|
|
|
create_rsynccmd
|
2020-05-26 17:26:21 +00:00
|
|
|
|
|
|
|
MESSAGE="Replacing ${GRAVITY_FI} on $HOSTNAME"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_stat
|
2020-05-26 17:30:00 +00:00
|
|
|
sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
|
2020-05-23 23:26:12 +00:00
|
|
|
error_validate
|
2020-05-26 17:14:32 +00:00
|
|
|
|
2020-06-02 16:52:07 +00:00
|
|
|
MESSAGE="Validating Settings of ${GRAVITY_FI}"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_stat
|
2020-06-29 18:48:54 +00:00
|
|
|
|
2020-10-02 19:01:17 +00:00
|
|
|
GRAVDB_OWN=$(ls -ld ${PIHOLE_DIR}/${GRAVITY_FI} | awk 'OFS=":" {print $3,$4}')
|
|
|
|
if [ "$GRAVDB_OWN" != "$FILE_OWNER" ]
|
2020-06-29 18:48:54 +00:00
|
|
|
then
|
|
|
|
MESSAGE="Validating Ownership on ${GRAVITY_FI}"
|
|
|
|
echo_fail
|
|
|
|
|
|
|
|
MESSAGE="Attempting to Compensate"
|
|
|
|
echo_warn
|
|
|
|
|
|
|
|
MESSAGE="Setting Ownership on ${GRAVITY_FI}"
|
|
|
|
echo_stat
|
2020-10-02 19:01:17 +00:00
|
|
|
sudo chown ${FILE_OWNER} ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
|
2020-06-29 18:48:54 +00:00
|
|
|
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
|
2020-06-29 18:41:54 +00:00
|
|
|
}
|
2020-06-02 16:52:07 +00:00
|
|
|
|
2020-06-29 18:41:54 +00:00
|
|
|
## Pull Custom
|
|
|
|
function pull_gs_cust {
|
2020-05-29 18:46:23 +00:00
|
|
|
if [ "$SKIP_CUSTOM" != '1' ]
|
|
|
|
then
|
2020-05-29 19:20:24 +00:00
|
|
|
if [ "$REMOTE_CUSTOM_DNS" == "1" ]
|
2020-10-01 20:05:23 +00:00
|
|
|
then
|
|
|
|
backup_local_custom
|
|
|
|
backup_remote_custom
|
|
|
|
|
2020-05-29 18:46:23 +00:00
|
|
|
MESSAGE="Pulling ${CUSTOM_DNS} from ${REMOTE_HOST}"
|
|
|
|
echo_stat
|
2020-06-03 14:45:06 +00:00
|
|
|
RSYNC_REPATH="rsync"
|
2020-07-11 20:33:35 +00:00
|
|
|
RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${CUSTOM_DNS}.backup"
|
2020-06-03 14:45:06 +00:00
|
|
|
RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.pull"
|
|
|
|
create_rsynccmd
|
2020-05-29 18:37:35 +00:00
|
|
|
|
2020-05-29 18:46:23 +00:00
|
|
|
MESSAGE="Replacing ${CUSTOM_DNS} on $HOSTNAME"
|
|
|
|
echo_stat
|
|
|
|
sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.pull ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1
|
|
|
|
error_validate
|
2020-05-29 18:37:35 +00:00
|
|
|
|
2020-06-02 16:52:07 +00:00
|
|
|
MESSAGE="Validating Settings on ${CUSTOM_DNS}"
|
2020-05-29 18:46:23 +00:00
|
|
|
echo_stat
|
|
|
|
|
|
|
|
CUSTOMLS_OWN=$(ls -ld ${PIHOLE_DIR}/${CUSTOM_DNS} | awk '{print $3 $4}')
|
2020-06-03 20:09:26 +00:00
|
|
|
if [ "$CUSTOMLS_OWN" != "rootroot" ]
|
2020-05-29 18:46:23 +00:00
|
|
|
then
|
2020-06-02 16:52:07 +00:00
|
|
|
MESSAGE="Validating Ownership on ${CUSTOM_DNS}"
|
2020-05-29 18:46:23 +00:00
|
|
|
echo_fail
|
2020-05-29 18:37:35 +00:00
|
|
|
|
2020-05-29 18:46:23 +00:00
|
|
|
MESSAGE="Attempting to Compensate"
|
2020-06-02 16:52:07 +00:00
|
|
|
echo_warn
|
2020-05-29 18:46:23 +00:00
|
|
|
|
|
|
|
MESSAGE="Setting Ownership on ${CUSTOM_DNS}"
|
|
|
|
echo_stat
|
|
|
|
sudo chown root:root ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1
|
|
|
|
error_validate
|
2020-06-02 16:52:07 +00:00
|
|
|
|
|
|
|
MESSAGE="Continuing Validation of ${GRAVITY_FI}"
|
|
|
|
echo_stat
|
2020-05-29 18:46:23 +00:00
|
|
|
fi
|
2020-05-29 18:37:35 +00:00
|
|
|
|
2020-06-03 20:12:39 +00:00
|
|
|
CUSTOMLS_RWE=$(namei -m ${PIHOLE_DIR}/${CUSTOM_DNS} | grep -v f: | grep ${CUSTOM_DNS} | awk '{print $1}')
|
2020-06-03 20:09:26 +00:00
|
|
|
if [ "$CUSTOMLS_RWE" != "-rw-r--r--" ]
|
2020-05-29 18:46:23 +00:00
|
|
|
then
|
2020-06-02 16:52:07 +00:00
|
|
|
MESSAGE="Validating Permissions on ${CUSTOM_DNS}"
|
2020-05-29 18:46:23 +00:00
|
|
|
echo_fail
|
|
|
|
|
|
|
|
MESSAGE="Attempting to Compensate"
|
2020-06-02 16:52:07 +00:00
|
|
|
echo_warn
|
2020-05-29 18:46:23 +00:00
|
|
|
|
|
|
|
MESSAGE="Setting Ownership on ${CUSTOM_DNS}"
|
|
|
|
echo_stat
|
|
|
|
sudo chmod 644 ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1
|
|
|
|
error_validate
|
2020-06-02 16:52:07 +00:00
|
|
|
|
|
|
|
MESSAGE="Continuing Validation of ${GRAVITY_FI}"
|
|
|
|
echo_stat
|
2020-05-29 18:46:23 +00:00
|
|
|
fi
|
2020-06-02 16:52:07 +00:00
|
|
|
|
|
|
|
echo_good
|
2020-05-29 18:46:23 +00:00
|
|
|
fi
|
2020-05-29 18:37:35 +00:00
|
|
|
fi
|
2020-06-29 18:41:54 +00:00
|
|
|
}
|
2020-05-29 18:37:35 +00:00
|
|
|
|
2020-06-29 18:41:54 +00:00
|
|
|
## Pull Reload
|
|
|
|
function pull_gs_reload {
|
2020-06-01 20:52:35 +00:00
|
|
|
MESSAGE="Isolating Regeneration Pathways"
|
2020-05-28 21:21:10 +00:00
|
|
|
echo_info
|
2020-05-26 17:32:11 +00:00
|
|
|
sleep 1
|
2020-05-23 23:26:12 +00:00
|
|
|
|
2020-05-25 00:59:03 +00:00
|
|
|
MESSAGE="Updating FTLDNS Configuration"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_stat
|
2020-05-26 05:09:45 +00:00
|
|
|
${PIHOLE_BIN} restartdns reloadlists >/dev/null 2>&1
|
2020-05-25 00:59:03 +00:00
|
|
|
error_validate
|
|
|
|
|
|
|
|
MESSAGE="Reloading FTLDNS Services"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_stat
|
2020-05-26 05:09:45 +00:00
|
|
|
${PIHOLE_BIN} restartdns >/dev/null 2>&1
|
2020-05-23 23:26:12 +00:00
|
|
|
error_validate
|
2020-05-22 15:32:02 +00:00
|
|
|
}
|
2020-05-22 15:28:02 +00:00
|
|
|
|
2020-06-29 18:41:54 +00:00
|
|
|
## Pull Function
|
|
|
|
function pull_gs {
|
2020-07-12 01:48:51 +00:00
|
|
|
previous_md5
|
2020-05-25 01:54:02 +00:00
|
|
|
md5_compare
|
|
|
|
|
2020-07-11 19:42:52 +00:00
|
|
|
backup_settime
|
2020-06-29 18:41:54 +00:00
|
|
|
pull_gs_grav
|
|
|
|
pull_gs_cust
|
|
|
|
pull_gs_reload
|
2020-07-12 01:48:51 +00:00
|
|
|
md5_recheck
|
2020-06-29 18:41:54 +00:00
|
|
|
|
|
|
|
logs_export
|
|
|
|
exit_withchange
|
|
|
|
}
|
2020-05-28 22:24:31 +00:00
|
|
|
|
2020-06-29 18:41:54 +00:00
|
|
|
## Push Gravity
|
|
|
|
function push_gs_grav {
|
2020-07-11 20:17:27 +00:00
|
|
|
backup_remote_gravity
|
2020-07-11 20:33:35 +00:00
|
|
|
backup_local_gravity
|
2020-07-11 20:17:27 +00:00
|
|
|
|
2020-07-11 20:33:35 +00:00
|
|
|
MESSAGE="Copying ${GRAVITY_FI} from ${REMOTE_HOST}"
|
2020-05-28 22:24:31 +00:00
|
|
|
echo_stat
|
2020-06-03 14:45:06 +00:00
|
|
|
RSYNC_REPATH="rsync"
|
2020-07-11 20:33:35 +00:00
|
|
|
RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI}.backup"
|
2020-06-03 14:45:06 +00:00
|
|
|
RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.push"
|
|
|
|
create_rsynccmd
|
|
|
|
|
2020-05-28 22:24:31 +00:00
|
|
|
MESSAGE="Pushing ${GRAVITY_FI} to ${REMOTE_HOST}"
|
|
|
|
echo_stat
|
2020-06-03 14:45:06 +00:00
|
|
|
RSYNC_REPATH="sudo rsync"
|
2020-07-11 20:33:35 +00:00
|
|
|
RSYNC_SOURCE="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${GRAVITY_FI}.backup"
|
2020-06-03 14:45:06 +00:00
|
|
|
RSYNC_TARGET="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI}"
|
|
|
|
create_rsynccmd
|
2020-05-28 22:24:31 +00:00
|
|
|
|
|
|
|
MESSAGE="Setting Permissions on ${GRAVITY_FI}"
|
2020-06-03 14:45:06 +00:00
|
|
|
echo_stat
|
|
|
|
CMD_TIMEOUT='15'
|
|
|
|
CMD_REQUESTED="sudo chmod 664 ${PIHOLE_DIR}/${GRAVITY_FI}"
|
|
|
|
create_sshcmd
|
2020-05-28 22:24:31 +00:00
|
|
|
|
|
|
|
MESSAGE="Setting Ownership on ${GRAVITY_FI}"
|
2020-06-03 14:45:06 +00:00
|
|
|
echo_stat
|
|
|
|
CMD_TIMEOUT='15'
|
2020-10-02 19:01:17 +00:00
|
|
|
CMD_REQUESTED="sudo chown ${RFILE_OWNER} ${PIHOLE_DIR}/${GRAVITY_FI}"
|
2020-06-03 14:45:06 +00:00
|
|
|
create_sshcmd
|
2020-06-29 18:41:54 +00:00
|
|
|
}
|
2020-06-03 14:45:06 +00:00
|
|
|
|
2020-06-29 18:41:54 +00:00
|
|
|
## Push Custom
|
|
|
|
function push_gs_cust {
|
2020-05-29 19:03:18 +00:00
|
|
|
if [ "$SKIP_CUSTOM" != '1' ]
|
|
|
|
then
|
2020-05-29 19:20:24 +00:00
|
|
|
if [ "$REMOTE_CUSTOM_DNS" == "1" ]
|
2020-05-29 19:03:18 +00:00
|
|
|
then
|
2020-10-01 20:05:23 +00:00
|
|
|
backup_remote_custom
|
|
|
|
backup_local_custom
|
|
|
|
|
2020-07-11 20:33:35 +00:00
|
|
|
MESSAGE="Copying ${CUSTOM_DNS} from ${REMOTE_HOST}"
|
2020-05-29 19:03:18 +00:00
|
|
|
echo_stat
|
2020-06-03 14:45:06 +00:00
|
|
|
RSYNC_REPATH="rsync"
|
2020-07-11 20:33:35 +00:00
|
|
|
RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${CUSTOM_DNS}.backup"
|
2020-06-03 14:45:06 +00:00
|
|
|
RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.push"
|
|
|
|
create_rsynccmd
|
2020-05-29 19:03:18 +00:00
|
|
|
|
|
|
|
MESSAGE="Pushing ${CUSTOM_DNS} to ${REMOTE_HOST}"
|
|
|
|
echo_stat
|
2020-06-03 14:45:06 +00:00
|
|
|
RSYNC_REPATH="sudo rsync"
|
2020-07-11 20:33:35 +00:00
|
|
|
RSYNC_SOURCE="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${CUSTOM_DNS}.backup"
|
2020-06-03 14:45:06 +00:00
|
|
|
RSYNC_TARGET="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${CUSTOM_DNS}"
|
|
|
|
create_rsynccmd
|
|
|
|
|
2020-05-29 19:03:18 +00:00
|
|
|
MESSAGE="Setting Permissions on ${CUSTOM_DNS}"
|
2020-06-03 14:45:06 +00:00
|
|
|
echo_stat
|
|
|
|
CMD_TIMEOUT='15'
|
|
|
|
CMD_REQUESTED="sudo chmod 644 ${PIHOLE_DIR}/${CUSTOM_DNS}"
|
|
|
|
create_sshcmd
|
|
|
|
|
2020-05-29 19:03:18 +00:00
|
|
|
MESSAGE="Setting Ownership on ${CUSTOM_DNS}"
|
2020-06-03 14:45:06 +00:00
|
|
|
echo_stat
|
|
|
|
CMD_TIMEOUT='15'
|
|
|
|
CMD_REQUESTED="sudo chown root:root ${PIHOLE_DIR}/${CUSTOM_DNS}"
|
|
|
|
create_sshcmd
|
2020-05-29 19:19:07 +00:00
|
|
|
fi
|
2020-05-29 19:03:18 +00:00
|
|
|
fi
|
2020-06-29 18:41:54 +00:00
|
|
|
}
|
2020-05-29 19:03:18 +00:00
|
|
|
|
2020-06-29 18:41:54 +00:00
|
|
|
## Push Reload
|
|
|
|
function push_gs_reload {
|
2020-06-02 02:04:09 +00:00
|
|
|
MESSAGE="Inverting Tachyon Pulses"
|
2020-05-28 22:24:31 +00:00
|
|
|
echo_info
|
|
|
|
sleep 1
|
|
|
|
|
2020-06-29 18:41:54 +00:00
|
|
|
MESSAGE="Updating Remote FTLDNS Configuration"
|
2020-05-28 22:24:31 +00:00
|
|
|
echo_stat
|
2020-06-03 14:45:06 +00:00
|
|
|
CMD_TIMEOUT='15'
|
2020-08-18 15:09:13 +00:00
|
|
|
CMD_REQUESTED="${RIHOLE_BIN} restartdns reloadlists"
|
2020-06-03 14:45:06 +00:00
|
|
|
create_sshcmd
|
2020-05-23 23:50:29 +00:00
|
|
|
|
2020-06-29 18:41:54 +00:00
|
|
|
MESSAGE="Reloading Remote FTLDNS Services"
|
2020-06-03 14:45:06 +00:00
|
|
|
echo_stat
|
|
|
|
CMD_TIMEOUT='15'
|
2020-08-18 15:09:13 +00:00
|
|
|
CMD_REQUESTED="${RIHOLE_BIN} restartdns"
|
2020-06-03 14:45:06 +00:00
|
|
|
create_sshcmd
|
2020-06-29 18:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
## Push Function
|
|
|
|
function push_gs {
|
2020-07-12 01:48:51 +00:00
|
|
|
previous_md5
|
2020-06-29 18:41:54 +00:00
|
|
|
md5_compare
|
2020-07-12 01:50:59 +00:00
|
|
|
backup_settime
|
2020-06-29 18:41:54 +00:00
|
|
|
|
|
|
|
intent_validate
|
|
|
|
|
|
|
|
push_gs_grav
|
|
|
|
push_gs_cust
|
|
|
|
push_gs_reload
|
2020-06-03 14:45:06 +00:00
|
|
|
|
2020-07-12 01:50:59 +00:00
|
|
|
md5_recheck
|
2020-05-28 22:24:31 +00:00
|
|
|
logs_export
|
|
|
|
exit_withchange
|
2020-05-22 15:32:02 +00:00
|
|
|
}
|
2020-05-22 15:28:02 +00:00
|
|
|
|
2020-07-12 01:48:51 +00:00
|
|
|
function previous_md5 {
|
2020-07-07 20:15:42 +00:00
|
|
|
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})
|
2020-07-07 20:21:58 +00:00
|
|
|
last_secondCLMD5=$(sed "4q;d" ${LOG_PATH}/${HISTORY_MD5})
|
2020-07-07 20:15:42 +00:00
|
|
|
else
|
|
|
|
last_primaryDBMD5="0"
|
|
|
|
last_secondDBMD5="0"
|
|
|
|
last_primaryCLMD5="0"
|
|
|
|
last_secondCLMD5="0"
|
|
|
|
fi
|
2020-07-12 01:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
## Smart Sync Function
|
|
|
|
function smart_gs {
|
|
|
|
previous_md5
|
|
|
|
md5_compare
|
|
|
|
backup_settime
|
2020-06-29 17:57:13 +00:00
|
|
|
|
2020-07-07 19:26:45 +00:00
|
|
|
PRIDBCHANGE="0"
|
|
|
|
SECDBCHANGE="0"
|
|
|
|
PRICLCHANGE="0"
|
2020-07-07 20:00:08 +00:00
|
|
|
SECCLCHANGE="0"
|
2020-07-07 19:26:45 +00:00
|
|
|
|
2020-06-29 17:57:13 +00:00
|
|
|
if [ "${primaryDBMD5}" != "${last_primaryDBMD5}" ]
|
|
|
|
then
|
2020-07-07 19:26:45 +00:00
|
|
|
PRIDBCHANGE="1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${secondDBMD5}" != "${last_secondDBMD5}" ]
|
2020-06-29 17:57:13 +00:00
|
|
|
then
|
2020-07-07 19:26:45 +00:00
|
|
|
SECDBCHANGE="1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${PRIDBCHANGE}" == "${SECDBCHANGE}" ]
|
|
|
|
then
|
|
|
|
if [ "${PRIDBCHANGE}" != "0" ]
|
|
|
|
then
|
2020-07-07 20:37:20 +00:00
|
|
|
MESSAGE="Both ${GRAVITY_FI} Changed"
|
2020-07-07 19:55:52 +00:00
|
|
|
echo_warn
|
|
|
|
|
|
|
|
PRIDBDATE=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "stat -c %Y ${PIHOLE_DIR}/${GRAVITY_FI}")
|
|
|
|
SECDBDATE=$(stat -c %Y ${PIHOLE_DIR}/${GRAVITY_FI})
|
|
|
|
|
|
|
|
if [ "${PRIDBDATE}" -gt "$SECDBDATE" ]
|
|
|
|
then
|
2020-07-07 20:37:20 +00:00
|
|
|
MESSAGE="Primary ${GRAVITY_FI} Last Changed"
|
2020-07-07 19:55:52 +00:00
|
|
|
echo_info
|
|
|
|
|
|
|
|
pull_gs_grav
|
|
|
|
PULLRESTART="1"
|
|
|
|
else
|
2020-07-07 20:37:20 +00:00
|
|
|
MESSAGE="Secondary ${GRAVITY_FI} Last Changed"
|
2020-07-07 19:55:52 +00:00
|
|
|
echo_info
|
|
|
|
|
|
|
|
push_gs_grav
|
|
|
|
PUSHRESTART="1"
|
|
|
|
fi
|
2020-07-07 19:26:45 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ "${PRIDBCHANGE}" != "0" ]
|
|
|
|
then
|
2020-07-07 19:29:38 +00:00
|
|
|
pull_gs_grav
|
|
|
|
PULLRESTART="1"
|
2020-07-07 19:26:45 +00:00
|
|
|
elif [ "${SECDBCHANGE}" != "0" ]
|
|
|
|
then
|
2020-07-07 19:29:38 +00:00
|
|
|
push_gs_grav
|
|
|
|
PUSHRESTART="1"
|
2020-07-07 19:26:45 +00:00
|
|
|
fi
|
2020-06-29 17:57:13 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${primaryCLMD5}" != "${last_primaryCLMD5}" ]
|
|
|
|
then
|
2020-07-07 19:55:52 +00:00
|
|
|
PRICLCHANGE="1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${secondCLMD5}" != "${last_secondCLMD5}" ]
|
2020-06-29 17:57:13 +00:00
|
|
|
then
|
2020-07-07 19:55:52 +00:00
|
|
|
SECCLCHANGE="1"
|
|
|
|
fi
|
|
|
|
|
2020-08-18 14:51:38 +00:00
|
|
|
if [ "$SKIP_CUSTOM" != '1' ]
|
2020-07-07 19:55:52 +00:00
|
|
|
then
|
|
|
|
|
2020-08-18 14:51:38 +00:00
|
|
|
if [ -f "${PIHOLE_DIR}/${CUSTOM_DNS}" ]
|
|
|
|
then
|
2020-07-07 19:55:52 +00:00
|
|
|
|
2020-08-18 14:51:38 +00:00
|
|
|
if [ "${PRICLCHANGE}" == "${SECCLCHANGE}" ]
|
|
|
|
then
|
|
|
|
if [ "${PRICLCHANGE}" != "0" ]
|
2020-07-07 19:55:52 +00:00
|
|
|
then
|
2020-08-18 14:51:38 +00:00
|
|
|
MESSAGE="Both ${CUSTOM_DNS} Changed"
|
|
|
|
echo_warn
|
|
|
|
|
|
|
|
PRICLDATE=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "stat -c %Y ${PIHOLE_DIR}/${CUSTOM_DNS}")
|
|
|
|
SECCLDATE=$(stat -c %Y ${PIHOLE_DIR}/${CUSTOM_DNS})
|
2020-07-07 19:55:52 +00:00
|
|
|
|
2020-08-18 14:51:38 +00:00
|
|
|
if [ "${PRICLDATE}" -gt "${SECCLDATE}" ]
|
|
|
|
then
|
|
|
|
MESSAGE="Primary ${CUSTOM_DNS} Last Changed"
|
|
|
|
echo_info
|
|
|
|
|
|
|
|
pull_gs_cust
|
|
|
|
PULLRESTART="1"
|
|
|
|
else
|
|
|
|
MESSAGE="Secondary ${CUSTOM_DNS} Last Changed"
|
|
|
|
echo_info
|
|
|
|
|
|
|
|
push_gs_cust
|
|
|
|
PUSHRESTART="1"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ "${PRICLCHANGE}" != "0" ]
|
|
|
|
then
|
2020-07-07 19:55:52 +00:00
|
|
|
pull_gs_cust
|
|
|
|
PULLRESTART="1"
|
2020-08-18 14:51:38 +00:00
|
|
|
elif [ "${SECCLCHANGE}" != "0" ]
|
|
|
|
then
|
2020-07-07 19:55:52 +00:00
|
|
|
push_gs_cust
|
|
|
|
PUSHRESTART="1"
|
|
|
|
fi
|
2020-08-18 14:51:38 +00:00
|
|
|
fi
|
2020-08-18 14:54:26 +00:00
|
|
|
else
|
|
|
|
pull_gs_cust
|
|
|
|
PULLRESTART="1"
|
2020-07-07 19:55:52 +00:00
|
|
|
fi
|
2020-06-29 17:57:13 +00:00
|
|
|
fi
|
2020-06-29 18:41:54 +00:00
|
|
|
|
2020-06-29 20:49:16 +00:00
|
|
|
if [ "$PULLRESTART" == "1" ]
|
|
|
|
then
|
|
|
|
pull_gs_reload
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$PUSHRESTART" == "1" ]
|
|
|
|
then
|
|
|
|
push_gs_reload
|
|
|
|
fi
|
2020-06-29 18:41:54 +00:00
|
|
|
|
2020-06-29 21:08:27 +00:00
|
|
|
md5_recheck
|
2020-06-29 20:50:58 +00:00
|
|
|
|
2020-06-29 20:49:16 +00:00
|
|
|
logs_export
|
|
|
|
exit_withchange
|
2020-06-29 03:23:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 22:29:41 +00:00
|
|
|
function restore_gs {
|
2020-07-11 03:58:43 +00:00
|
|
|
MESSAGE="This will restore your settings on $HOSTNAME with a previous version!"
|
2020-05-28 22:09:58 +00:00
|
|
|
echo_warn
|
|
|
|
|
2020-07-12 14:24:45 +00:00
|
|
|
MESSAGE="PREVIOUS BACKUPS AVAILABLE FOR RESTORATION"
|
2020-07-11 03:58:43 +00:00
|
|
|
echo_info
|
|
|
|
ls $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${GRAVITY_FI} | colrm 18
|
|
|
|
|
2020-07-12 14:24:45 +00:00
|
|
|
MESSAGE="Select backup date to restore ${GRAVITY_FI} from"
|
2020-07-11 03:58:43 +00:00
|
|
|
echo_need
|
|
|
|
read INPUT_BACKUP_DATE
|
|
|
|
|
|
|
|
if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${GRAVITY_FI}.backup ]
|
|
|
|
then
|
2020-07-12 14:20:58 +00:00
|
|
|
MESSAGE="Backup File Selected"
|
2020-07-11 03:58:43 +00:00
|
|
|
else
|
2020-07-12 14:20:58 +00:00
|
|
|
MESSAGE="Invalid Request"
|
|
|
|
echo_info
|
2020-07-12 14:24:45 +00:00
|
|
|
|
|
|
|
exit_nochange
|
2020-07-11 03:58:43 +00:00
|
|
|
fi
|
|
|
|
|
2020-07-12 14:20:58 +00:00
|
|
|
if [ "$SKIP_CUSTOM" != '1' ]
|
|
|
|
then
|
|
|
|
|
|
|
|
if [ -f ${PIHOLE_DIR}/${CUSTOM_DNS} ]
|
|
|
|
then
|
|
|
|
ls $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${CUSTOM_DNS} | colrm 18
|
|
|
|
|
2020-07-12 14:24:45 +00:00
|
|
|
MESSAGE="Select backup date to restore ${CUSTOM_DNS} from"
|
2020-07-12 14:20:58 +00:00
|
|
|
echo_need
|
|
|
|
read INPUT_DNSBACKUP_DATE
|
|
|
|
|
|
|
|
if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_DNSBACKUP_DATE}-${CUSTOM_DNS}.backup ]
|
|
|
|
then
|
|
|
|
MESSAGE="Backup File Selected"
|
|
|
|
else
|
|
|
|
MESSAGE="Invalid Request"
|
|
|
|
echo_info
|
2020-07-12 14:24:45 +00:00
|
|
|
|
|
|
|
exit_nochange
|
2020-07-12 14:20:58 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-07-16 16:37:06 +00:00
|
|
|
MESSAGE="${GRAVITY_FI} from ${INPUT_BACKUP_DATE} Selected"
|
2020-07-12 14:20:58 +00:00
|
|
|
echo_info
|
2020-07-16 16:37:06 +00:00
|
|
|
MESSAGE="${CUSTOM_DNS} from ${INPUT_DNSBACKUP_DATE} Selected"
|
2020-07-12 14:20:58 +00:00
|
|
|
echo_info
|
|
|
|
|
2020-05-29 02:28:14 +00:00
|
|
|
intent_validate
|
2020-05-28 22:24:31 +00:00
|
|
|
|
2020-07-12 14:24:45 +00:00
|
|
|
MESSAGE="Making Time Warp Calculations"
|
|
|
|
echo_info
|
|
|
|
|
2020-07-11 03:58:43 +00:00
|
|
|
MESSAGE="Stopping Pi-hole Services"
|
|
|
|
echo_stat
|
|
|
|
|
|
|
|
sudo service pihole-FTL stop >/dev/null 2>&1
|
|
|
|
error_validate
|
|
|
|
|
2020-05-28 22:09:58 +00:00
|
|
|
MESSAGE="Restoring ${GRAVITY_FI} on $HOSTNAME"
|
|
|
|
echo_stat
|
2020-07-11 03:58:43 +00:00
|
|
|
sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${GRAVITY_FI}.backup ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
|
2020-05-28 22:09:58 +00:00
|
|
|
error_validate
|
|
|
|
|
|
|
|
MESSAGE="Validating Ownership on ${GRAVITY_FI}"
|
|
|
|
echo_stat
|
|
|
|
|
2020-10-02 19:01:17 +00:00
|
|
|
GRAVDB_OWN=$(ls -ld ${PIHOLE_DIR}/${GRAVITY_FI} | awk 'OFS=":" {print $3,$4}')
|
|
|
|
if [ "$GRAVDB_OWN" == "$FILE_OWNER" ]
|
2020-05-28 22:09:58 +00:00
|
|
|
then
|
|
|
|
echo_good
|
|
|
|
else
|
|
|
|
echo_fail
|
|
|
|
|
|
|
|
MESSAGE="Attempting to Compensate"
|
2020-06-02 16:52:07 +00:00
|
|
|
echo_warn
|
2020-05-28 22:09:58 +00:00
|
|
|
|
|
|
|
MESSAGE="Setting Ownership on ${GRAVITY_FI}"
|
|
|
|
echo_stat
|
2020-10-02 19:01:17 +00:00
|
|
|
sudo chown ${FILE_OWNER} ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
|
2020-05-28 22:09:58 +00:00
|
|
|
error_validate
|
|
|
|
fi
|
|
|
|
|
|
|
|
MESSAGE="Validating Permissions on ${GRAVITY_FI}"
|
|
|
|
echo_stat
|
|
|
|
|
2020-06-03 20:12:39 +00:00
|
|
|
GRAVDB_RWE=$(namei -m ${PIHOLE_DIR}/${GRAVITY_FI} | grep -v f: | grep ${GRAVITY_FI} | awk '{print $1}')
|
2020-06-03 20:09:26 +00:00
|
|
|
if [ "$GRAVDB_RWE" = "-rw-rw-r--" ]
|
2020-05-28 22:09:58 +00:00
|
|
|
then
|
|
|
|
echo_good
|
|
|
|
else
|
|
|
|
echo_fail
|
|
|
|
|
|
|
|
MESSAGE="Attempting to Compensate"
|
2020-06-02 16:52:07 +00:00
|
|
|
echo_warn
|
2020-05-28 22:09:58 +00:00
|
|
|
|
|
|
|
MESSAGE="Setting Ownership on ${GRAVITY_FI}"
|
|
|
|
echo_stat
|
|
|
|
sudo chmod 664 ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
|
|
|
|
error_validate
|
|
|
|
fi
|
2020-05-29 19:08:56 +00:00
|
|
|
|
|
|
|
if [ "$SKIP_CUSTOM" != '1' ]
|
|
|
|
then
|
2020-07-12 14:20:58 +00:00
|
|
|
if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_DNSBACKUP_DATE}-${CUSTOM_DNS}.backup ]
|
2020-05-29 19:08:56 +00:00
|
|
|
then
|
|
|
|
MESSAGE="Restoring ${CUSTOM_DNS} on $HOSTNAME"
|
|
|
|
echo_stat
|
2020-07-12 14:20:58 +00:00
|
|
|
sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_DNSBACKUP_DATE}-${CUSTOM_DNS}.backup ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1
|
2020-05-29 19:08:56 +00:00
|
|
|
error_validate
|
|
|
|
|
|
|
|
MESSAGE="Validating Ownership on ${CUSTOM_DNS}"
|
|
|
|
echo_stat
|
|
|
|
|
|
|
|
CUSTOMLS_OWN=$(ls -ld ${PIHOLE_DIR}/${CUSTOM_DNS} | awk '{print $3 $4}')
|
2020-06-03 20:09:26 +00:00
|
|
|
if [ "$CUSTOMLS_OWN" == "rootroot" ]
|
2020-05-29 19:08:56 +00:00
|
|
|
then
|
|
|
|
echo_good
|
|
|
|
else
|
|
|
|
echo_fail
|
|
|
|
|
|
|
|
MESSAGE="Attempting to Compensate"
|
2020-06-02 16:52:07 +00:00
|
|
|
echo_warn
|
2020-05-29 19:08:56 +00:00
|
|
|
|
|
|
|
MESSAGE="Setting Ownership on ${CUSTOM_DNS}"
|
|
|
|
echo_stat
|
|
|
|
sudo chown root:root ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1
|
|
|
|
error_validate
|
|
|
|
fi
|
|
|
|
|
|
|
|
MESSAGE="Validating Permissions on ${CUSTOM_DNS}"
|
|
|
|
echo_stat
|
|
|
|
|
2020-06-03 20:12:39 +00:00
|
|
|
CUSTOMLS_RWE=$(namei -m ${PIHOLE_DIR}/${CUSTOM_DNS} | grep -v f: | grep ${CUSTOM_DNS} | awk '{print $1}')
|
2020-06-03 20:09:26 +00:00
|
|
|
if [ "$CUSTOMLS_RWE" == "-rw-r--r--" ]
|
2020-05-29 19:08:56 +00:00
|
|
|
then
|
|
|
|
echo_good
|
|
|
|
else
|
|
|
|
echo_fail
|
|
|
|
|
|
|
|
MESSAGE="Attempting to Compensate"
|
2020-06-02 16:52:07 +00:00
|
|
|
echo_warn
|
2020-05-29 19:08:56 +00:00
|
|
|
|
|
|
|
MESSAGE="Setting Ownership on ${CUSTOM_DNS}"
|
|
|
|
echo_stat
|
|
|
|
sudo chmod 644 ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1
|
|
|
|
error_validate
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-05-29 02:50:29 +00:00
|
|
|
MESSAGE="Evacuating Saucer Section"
|
2020-05-28 22:09:58 +00:00
|
|
|
echo_info
|
|
|
|
sleep 1
|
2020-07-11 03:58:43 +00:00
|
|
|
|
|
|
|
MESSAGE="Restarting FTLDNS Services"
|
2020-05-28 22:09:58 +00:00
|
|
|
echo_stat
|
2020-07-11 03:58:43 +00:00
|
|
|
sudo service pihole-FTL start >/dev/null 2>&1
|
2020-05-28 22:09:58 +00:00
|
|
|
error_validate
|
|
|
|
|
2020-07-11 03:58:43 +00:00
|
|
|
MESSAGE="Updating FTLDNS Configuration"
|
2020-05-28 22:09:58 +00:00
|
|
|
echo_stat
|
2020-07-11 03:58:43 +00:00
|
|
|
${PIHOLE_BIN} restartdns reloadlists >/dev/null 2>&1
|
2020-05-28 22:09:58 +00:00
|
|
|
error_validate
|
|
|
|
|
2020-07-11 04:15:28 +00:00
|
|
|
|
|
|
|
MESSAGE="Do you want to push the restored configuration to the primary Pi-hole? (yes/no)"
|
|
|
|
echo_need
|
|
|
|
read PUSH_TO_PRIMARY
|
|
|
|
|
|
|
|
if [ "${PUSH_TO_PRIMARY}" == "Yes" ] || [ "${PUSH_TO_PRIMARY}" == "yes" ] || [ "${PUSH_TO_PRIMARY}" == "Y" ] || [ "${PUSH_TO_PRIMARY}" == "y" ]
|
|
|
|
then
|
|
|
|
push_gs
|
|
|
|
elif [ "${PUSH_TO_PRIMARY}" == "No" ] || [ "${PUSH_TO_PRIMARY}" == "no" ] || [ "${PUSH_TO_PRIMARY}" == "N" ] || [ "${PUSH_TO_PRIMARY}" == "n" ]
|
2020-07-11 04:15:51 +00:00
|
|
|
then
|
2020-07-11 04:15:28 +00:00
|
|
|
logs_export
|
|
|
|
exit_withchange
|
|
|
|
else
|
|
|
|
MESSAGE="Invalid Selection - Defaulting No"
|
|
|
|
echo_warn
|
|
|
|
|
|
|
|
logs_export
|
|
|
|
exit_withchange
|
|
|
|
fi
|
2020-05-28 22:09:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-22 16:39:31 +00:00
|
|
|
# Logging Functions
|
2020-05-27 03:20:36 +00:00
|
|
|
## Core Logging
|
|
|
|
### Write Logs Out
|
|
|
|
function logs_export {
|
2020-07-12 15:26:07 +00:00
|
|
|
|
|
|
|
if [ "${TASKTYPE}" != "BACKUP" ]
|
|
|
|
then
|
2020-06-29 14:21:50 +00:00
|
|
|
MESSAGE="Saving File Hashes"
|
|
|
|
echo_stat
|
2020-07-07 20:15:42 +00:00
|
|
|
rm -f ${LOG_PATH}/${HISTORY_MD5}
|
|
|
|
echo -e ${primaryDBMD5} >> ${LOG_PATH}/${HISTORY_MD5}
|
|
|
|
echo -e ${secondDBMD5} >> ${LOG_PATH}/${HISTORY_MD5}
|
|
|
|
echo -e ${primaryCLMD5} >> ${LOG_PATH}/${HISTORY_MD5}
|
|
|
|
echo -e ${secondCLMD5} >> ${LOG_PATH}/${HISTORY_MD5}
|
2020-06-29 14:21:50 +00:00
|
|
|
error_validate
|
2020-07-12 15:26:07 +00:00
|
|
|
fi
|
2020-06-29 14:21:50 +00:00
|
|
|
|
2020-06-02 16:55:35 +00:00
|
|
|
MESSAGE="Logging Successful ${TASKTYPE}"
|
|
|
|
echo_stat
|
|
|
|
echo -e $(date) "[${TASKTYPE}]" >> ${LOG_PATH}/${SYNCING_LOG}
|
|
|
|
error_validate
|
2020-05-27 03:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
### Output Sync Logs
|
2020-05-22 15:47:39 +00:00
|
|
|
function logs_gs {
|
2020-07-17 14:45:08 +00:00
|
|
|
# import_gs
|
2020-05-27 16:13:04 +00:00
|
|
|
|
2020-05-28 21:50:25 +00:00
|
|
|
MESSAGE="Tailing ${LOG_PATH}/${SYNCING_LOG}"
|
|
|
|
echo_info
|
|
|
|
|
2020-05-25 02:15:08 +00:00
|
|
|
echo -e "========================================================"
|
2020-07-07 20:37:20 +00:00
|
|
|
echo -e "Recent Complete ${YELLOW}SMART${NC} Executions"
|
|
|
|
tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep SMART
|
2020-05-25 02:15:08 +00:00
|
|
|
echo -e "Recent Complete ${YELLOW}PULL${NC} Executions"
|
2020-05-27 16:06:35 +00:00
|
|
|
tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PULL
|
2020-05-25 02:15:08 +00:00
|
|
|
echo -e "Recent Complete ${YELLOW}PUSH${NC} Executions"
|
2020-05-27 16:06:35 +00:00
|
|
|
tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PUSH
|
2020-07-12 15:26:07 +00:00
|
|
|
echo -e "Recent Complete ${YELLOW}BACKUP${NC} Executions"
|
|
|
|
tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep BACKUP
|
2020-05-29 19:08:56 +00:00
|
|
|
echo -e "Recent Complete ${YELLOW}RESTORE${NC} Executions"
|
|
|
|
tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep RESTORE
|
2020-05-25 02:15:08 +00:00
|
|
|
echo -e "========================================================"
|
2020-05-28 21:50:25 +00:00
|
|
|
|
2020-05-22 18:59:09 +00:00
|
|
|
exit_nochange
|
2020-05-22 15:44:38 +00:00
|
|
|
}
|
2020-05-22 01:25:06 +00:00
|
|
|
|
2020-05-27 03:20:36 +00:00
|
|
|
## Crontab Logs
|
|
|
|
### Core Crontab Logs
|
2020-05-26 02:16:31 +00:00
|
|
|
function show_crontab {
|
2020-07-17 14:45:08 +00:00
|
|
|
# import_gs
|
2020-05-26 02:16:31 +00:00
|
|
|
|
|
|
|
MESSAGE="Replaying Last Cronjob"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_stat
|
2020-05-26 02:16:31 +00:00
|
|
|
|
2020-05-27 15:00:30 +00:00
|
|
|
if [ -f ${LOG_PATH}/${CRONJOB_LOG} ]
|
2020-05-26 02:16:31 +00:00
|
|
|
then
|
2020-05-27 15:00:30 +00:00
|
|
|
if [ -s ${LOG_PATH}/${CRONJOB_LOG} ]
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_good
|
2020-05-27 15:18:58 +00:00
|
|
|
|
2020-05-28 21:50:25 +00:00
|
|
|
MESSAGE="Tailing ${LOG_PATH}/${CRONJOB_LOG}"
|
|
|
|
echo_info
|
|
|
|
|
2020-05-27 15:18:58 +00:00
|
|
|
echo -e "========================================================"
|
2020-05-27 15:20:14 +00:00
|
|
|
date -r ${LOG_PATH}/${CRONJOB_LOG}
|
2020-05-27 15:18:58 +00:00
|
|
|
cat ${LOG_PATH}/${CRONJOB_LOG}
|
|
|
|
echo -e "========================================================"
|
2020-05-28 21:50:25 +00:00
|
|
|
|
|
|
|
exit_nochange
|
2020-05-26 02:16:31 +00:00
|
|
|
then
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_fail
|
|
|
|
|
|
|
|
MESSAGE="${LOG_PATH}/${CRONJOB_LOG} is Empty"
|
|
|
|
echo_info
|
|
|
|
|
|
|
|
exit_nochange
|
2020-05-26 02:16:31 +00:00
|
|
|
fi
|
|
|
|
else
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_fail
|
|
|
|
|
|
|
|
MESSAGE="${LOG_PATH}/${CRONJOB_LOG} is Missing"
|
|
|
|
echo_info
|
|
|
|
|
|
|
|
exit_nochange
|
2020-05-26 02:16:31 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-22 16:39:31 +00:00
|
|
|
# Validate Functions
|
2020-05-22 15:44:38 +00:00
|
|
|
## Validate GS Folders
|
|
|
|
function validate_gs_folders {
|
2020-06-02 16:03:57 +00:00
|
|
|
MESSAGE="Validating ${PROGRAM} Folders on $HOSTNAME"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_stat
|
2020-06-02 16:07:51 +00:00
|
|
|
if [ ! -d $HOME/${LOCAL_FOLDR} ]
|
2020-05-25 00:38:43 +00:00
|
|
|
then
|
2020-06-02 16:03:57 +00:00
|
|
|
MESSAGE="Unable to Find $HOME/${LOCAL_FOLDR}"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_fail
|
2020-05-25 00:38:43 +00:00
|
|
|
exit_nochange
|
|
|
|
fi
|
2020-05-22 20:44:15 +00:00
|
|
|
|
2020-06-02 16:07:51 +00:00
|
|
|
if [ ! -d $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD} ]
|
2020-05-25 00:38:43 +00:00
|
|
|
then
|
2020-06-02 16:03:57 +00:00
|
|
|
MESSAGE="Unable to Find $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_fail
|
2020-05-25 00:38:43 +00:00
|
|
|
exit_nochange
|
|
|
|
fi
|
2020-06-02 16:03:57 +00:00
|
|
|
echo_good
|
2020-05-22 15:44:38 +00:00
|
|
|
}
|
2020-05-21 18:44:01 +00:00
|
|
|
|
2020-05-29 03:01:08 +00:00
|
|
|
## Validate Pi-hole Folders
|
2020-05-22 15:44:38 +00:00
|
|
|
function validate_ph_folders {
|
2020-06-02 16:03:57 +00:00
|
|
|
MESSAGE="Validating Pi-hole Configuration on $HOSTNAME"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_stat
|
2020-06-02 16:07:51 +00:00
|
|
|
if [ ! -f ${PIHOLE_BIN} ]
|
2020-06-02 16:03:57 +00:00
|
|
|
then
|
|
|
|
MESSAGE="Unable to Validate Pi-Hole is Installed"
|
|
|
|
echo_fail
|
|
|
|
exit_nochange
|
|
|
|
fi
|
|
|
|
|
2020-06-02 16:07:51 +00:00
|
|
|
if [ ! -d ${PIHOLE_DIR} ]
|
2020-05-25 00:38:43 +00:00
|
|
|
then
|
2020-06-02 16:03:57 +00:00
|
|
|
MESSAGE="Unable to Validate Pi-Hole Configuration Directory"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_fail
|
2020-05-25 00:38:43 +00:00
|
|
|
exit_nochange
|
|
|
|
fi
|
2020-06-02 16:03:57 +00:00
|
|
|
echo_good
|
2020-05-22 15:44:38 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 19:01:17 +00:00
|
|
|
## Validate SQLite3
|
|
|
|
function validate_sqlite3 {
|
|
|
|
MESSAGE="Validating SQLITE Installed on $HOSTNAME"
|
|
|
|
echo_stat
|
|
|
|
if hash sqlite3 2>/dev/null
|
|
|
|
then
|
|
|
|
MESSAGE="SQLITE3 Utility Detected"
|
|
|
|
echo_good
|
|
|
|
else
|
|
|
|
MESSAGE="SQLITE3 Utility Missing"
|
|
|
|
echo_warn
|
|
|
|
|
|
|
|
MESSAGE="Installing SQLLITE3 with ${PKG_MANAGER}"
|
|
|
|
echo_stat
|
|
|
|
|
|
|
|
${PKG_INSTALL} sqllite3 >/dev/null 2>&1
|
|
|
|
error_validate
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-25 02:15:08 +00:00
|
|
|
## Validate SSHPASS
|
|
|
|
function validate_os_sshpass {
|
2020-06-02 20:45:44 +00:00
|
|
|
SSHPASSWORD=''
|
|
|
|
|
2020-05-25 19:31:46 +00:00
|
|
|
if hash sshpass 2>/dev/null
|
2020-05-25 02:15:08 +00:00
|
|
|
then
|
2020-06-02 20:45:44 +00:00
|
|
|
MESSAGE="SSHPASS Utility Detected"
|
|
|
|
echo_warn
|
|
|
|
if [ -z "$REMOTE_PASS" ]
|
2020-06-02 16:23:21 +00:00
|
|
|
then
|
2020-05-25 17:06:37 +00:00
|
|
|
MESSAGE="Using SSH Key-Pair Authentication"
|
2020-06-02 16:23:21 +00:00
|
|
|
echo_info
|
2020-06-02 20:45:44 +00:00
|
|
|
else
|
|
|
|
MESSAGE="Testing Authentication Options"
|
2020-06-03 04:09:46 +00:00
|
|
|
echo_stat
|
2020-06-02 20:45:44 +00:00
|
|
|
|
|
|
|
timeout 5 ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} 'exit' >/dev/null 2>&1
|
|
|
|
if [ "$?" != "0" ]
|
|
|
|
then
|
|
|
|
SSHPASSWORD="sshpass -p ${REMOTE_PASS}"
|
|
|
|
MESSAGE="Using SSH Password Authentication"
|
|
|
|
echo_warn
|
|
|
|
else
|
2020-06-02 22:27:49 +00:00
|
|
|
MESSAGE="Valid Key-Pair Detected ${NC}(${RED}Password Ignored${NC})"
|
2020-06-02 20:45:44 +00:00
|
|
|
echo_info
|
|
|
|
fi
|
2020-05-25 17:06:37 +00:00
|
|
|
fi
|
2020-05-25 02:15:08 +00:00
|
|
|
else
|
2020-05-25 19:07:38 +00:00
|
|
|
SSHPASSWORD=''
|
2020-05-25 02:29:23 +00:00
|
|
|
MESSAGE="Using SSH Key-Pair Authentication"
|
2020-06-02 16:23:21 +00:00
|
|
|
echo_info
|
2020-05-25 02:15:08 +00:00
|
|
|
fi
|
2020-05-25 02:29:23 +00:00
|
|
|
|
2020-06-02 16:27:46 +00:00
|
|
|
MESSAGE="Validating Connection to ${REMOTE_HOST}"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_stat
|
2020-06-03 01:45:25 +00:00
|
|
|
|
2020-06-03 01:44:46 +00:00
|
|
|
CMD_TIMEOUT='5'
|
|
|
|
CMD_REQUESTED="exit"
|
2020-06-03 04:09:46 +00:00
|
|
|
create_sshcmd
|
2020-06-03 14:20:35 +00:00
|
|
|
|
2020-05-25 02:15:08 +00:00
|
|
|
}
|
|
|
|
|
2020-06-03 01:44:46 +00:00
|
|
|
## Determine SSH Pathways
|
2020-06-03 04:09:46 +00:00
|
|
|
function create_sshcmd {
|
2020-06-03 01:44:46 +00:00
|
|
|
if hash ssh 2>/dev/null
|
|
|
|
then
|
|
|
|
if [ -z "$SSHPASSWORD" ]
|
|
|
|
then
|
2020-06-03 14:20:35 +00:00
|
|
|
timeout --preserve-status ${CMD_TIMEOUT} ${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF} -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} "${CMD_REQUESTED}"
|
|
|
|
error_validate
|
2020-06-03 01:44:46 +00:00
|
|
|
else
|
2020-06-03 14:20:35 +00:00
|
|
|
timeout --preserve-status ${CMD_TIMEOUT} ${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} "${CMD_REQUESTED}"
|
|
|
|
error_validate
|
2020-06-03 01:44:46 +00:00
|
|
|
fi
|
2020-07-21 05:14:20 +00:00
|
|
|
# elif hash dbclient 2>/dev/null
|
|
|
|
# then
|
|
|
|
# timeout --preserve-status ${CMD_TIMEOUT} ${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF} ${REMOTE_USER}@${REMOTE_HOST} "${CMD_REQUESTED}"
|
|
|
|
# error_validate
|
2020-06-03 04:09:46 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## Determine SSH Pathways
|
|
|
|
function create_rsynccmd {
|
|
|
|
if hash ssh 2>/dev/null
|
|
|
|
then
|
|
|
|
if [ -z "$SSHPASSWORD" ]
|
|
|
|
then
|
2020-06-03 14:45:06 +00:00
|
|
|
rsync --rsync-path="${RSYNC_REPATH}" -e "${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${RSYNC_SOURCE} ${RSYNC_TARGET} >/dev/null 2>&1
|
2020-06-03 05:11:02 +00:00
|
|
|
error_validate
|
2020-06-03 04:09:46 +00:00
|
|
|
else
|
2020-06-03 14:45:06 +00:00
|
|
|
rsync --rsync-path="${RSYNC_REPATH}" -e "${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${RSYNC_SOURCE} ${RSYNC_TARGET} >/dev/null 2>&1
|
2020-06-03 05:11:02 +00:00
|
|
|
error_validate
|
2020-06-03 04:09:46 +00:00
|
|
|
fi
|
2020-07-21 05:14:20 +00:00
|
|
|
# elif hash dbclient 2>/dev/null
|
|
|
|
# then
|
|
|
|
# rsync --rsync-path="${RSYNC_REPATH}" -e "${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${RSYNC_SOURCE} ${RSYNC_TARGET} >/dev/null 2>&1
|
|
|
|
# error_validate
|
2020-06-03 01:44:46 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-31 02:01:24 +00:00
|
|
|
## Detect SSH-KEYGEN
|
|
|
|
function detect_sshkeygen {
|
2020-05-31 03:28:57 +00:00
|
|
|
MESSAGE="Validating SSH-KEYGEN install on $HOSTNAME"
|
2020-05-31 02:01:24 +00:00
|
|
|
echo_stat
|
|
|
|
|
2020-05-31 02:29:01 +00:00
|
|
|
if hash ssh-keygen >/dev/null 2>&1
|
2020-05-31 02:01:24 +00:00
|
|
|
then
|
|
|
|
echo_good
|
|
|
|
else
|
|
|
|
echo_fail
|
|
|
|
MESSAGE="SSH-KEYGEN is Required"
|
|
|
|
echo_info
|
2020-07-21 05:14:20 +00:00
|
|
|
|
|
|
|
exit_nochange
|
|
|
|
# MESSAGE="Attempting to Compensate"
|
|
|
|
# echo_warn
|
|
|
|
|
|
|
|
# if hash dropbearkey >/dev/null 2>&1
|
|
|
|
# then
|
|
|
|
# MESSAGE="Using DROPBEARKEY Instead"
|
|
|
|
# echo_info
|
|
|
|
# if [ ! -d $HOME/.ssh ]
|
|
|
|
# then
|
|
|
|
# mkdir $HOME/.ssh >/dev/null 2>&1
|
|
|
|
# fi
|
|
|
|
# KEYGEN_COMMAND="dropbearkey -t rsa -f"
|
|
|
|
# else
|
|
|
|
# MESSAGE="No Alternatives Located"
|
|
|
|
# echo_info
|
|
|
|
# exit_nochange
|
|
|
|
# fi
|
2020-05-31 02:01:24 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-06-03 19:30:33 +00:00
|
|
|
function generate_sshkey {
|
|
|
|
if [ -z $INPUT_REMOTE_PASS ]
|
|
|
|
then
|
|
|
|
if [ -f $HOME/${SSH_PKIF} ]
|
|
|
|
then
|
|
|
|
MESSAGE="Using Existing ~/${SSH_PKIF}"
|
|
|
|
echo_info
|
|
|
|
else
|
|
|
|
if hash ssh-keygen >/dev/null 2>&1
|
|
|
|
then
|
|
|
|
MESSAGE="Generating ~/${SSH_PKIF} (SSH-KEYGEN)"
|
|
|
|
echo_stat
|
|
|
|
|
2020-06-03 19:38:50 +00:00
|
|
|
ssh-keygen -q -P "" -t rsa -f $HOME/${SSH_PKIF} >/dev/null 2>&1
|
2020-06-03 19:30:33 +00:00
|
|
|
error_validate
|
|
|
|
|
2020-07-21 05:14:20 +00:00
|
|
|
# elif hash dropbearkey >/dev/null 2>&1
|
|
|
|
# then
|
|
|
|
# MESSAGE="Generating ~/${SSH_PKIF} (DROPBEARKEY)"
|
|
|
|
# echo_stat
|
|
|
|
# if [ ! -d $HOME/.ssh ]
|
|
|
|
# then
|
|
|
|
# mkdir $HOME/.ssh >/dev/null 2>&1
|
|
|
|
# fi
|
|
|
|
#
|
|
|
|
# dropbearkey -t rsa -f $HOME/${SSH_PKIF} >/dev/null 2>&1
|
|
|
|
# error_validate
|
2020-06-03 19:30:33 +00:00
|
|
|
else
|
|
|
|
MESSAGE="No SSH Key Generator Located"
|
|
|
|
echo_warn
|
|
|
|
exit_nochange
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function export_sshkey {
|
|
|
|
if [ -z $REMOTE_PASS ]
|
|
|
|
then
|
|
|
|
if [ -f $HOME/${SSH_PKIF} ]
|
|
|
|
then
|
|
|
|
MESSAGE="Registering Key-Pair on ${REMOTE_HOST}"
|
|
|
|
echo_info
|
|
|
|
|
2020-06-03 19:38:50 +00:00
|
|
|
#MESSAGE="Enter ${REMOTE_USER}@${REMOTE_HOST} Password Below"
|
|
|
|
#echo -e "${NEED} ${MESSAGE}"
|
|
|
|
|
2020-07-21 05:14:20 +00:00
|
|
|
# if hash ssh-copy-id 2>/dev/null
|
|
|
|
# then
|
2020-06-03 19:30:33 +00:00
|
|
|
ssh-copy-id -f -p ${SSH_PORT} -i $HOME/${SSH_PKIF}.pub ${REMOTE_USER}@${REMOTE_HOST}
|
2020-07-21 05:14:20 +00:00
|
|
|
# elif hash dbclient 2>/dev/null
|
|
|
|
# then
|
|
|
|
# dropbearkey -y -f $HOME/${SSH_PKIF} | grep "^ssh-rsa " > $HOME/${SSH_PKIF}.pub
|
|
|
|
# cat $HOME/${SSH_PKIF}.pub | dbclient -p ${SSH_PORT} ${REMOTE_USER}@${REMOTE_HOST} 'cat - >> .ssh/authorized_keys'
|
|
|
|
# fi
|
2020-06-03 19:30:33 +00:00
|
|
|
else
|
2020-06-03 19:38:50 +00:00
|
|
|
MESSAGE="Error Registering Key-Pair"
|
|
|
|
echo_warn
|
2020-06-03 19:30:33 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-31 02:01:24 +00:00
|
|
|
## Detect Package Manager
|
|
|
|
function distro_check {
|
2020-05-31 02:35:23 +00:00
|
|
|
if hash apt-get 2>/dev/null
|
2020-05-31 02:01:24 +00:00
|
|
|
then
|
2020-06-01 19:20:50 +00:00
|
|
|
PKG_MANAGER="apt-get"
|
2020-05-31 02:29:01 +00:00
|
|
|
PKG_INSTALL="sudo apt-get --yes --no-install-recommends --quiet install"
|
2020-05-31 02:35:23 +00:00
|
|
|
elif hash rpm 2>/dev/null
|
2020-05-31 02:01:24 +00:00
|
|
|
then
|
2020-05-31 02:35:23 +00:00
|
|
|
if hash dnf 2>/dev/null
|
2020-05-31 02:01:24 +00:00
|
|
|
then
|
|
|
|
PKG_MANAGER="dnf"
|
2020-05-31 02:35:23 +00:00
|
|
|
elif hash yum 2>/dev/null
|
2020-05-31 02:01:24 +00:00
|
|
|
then
|
|
|
|
PKG_MANAGER="yum"
|
|
|
|
else
|
|
|
|
MESSAGE="Unable to find OS Package Manager"
|
|
|
|
echo_info
|
|
|
|
exit_nochange
|
|
|
|
fi
|
|
|
|
PKG_INSTALL="sudo ${PKG_MANAGER} install -y"
|
|
|
|
else
|
|
|
|
MESSAGE="Unable to find OS Package Manager"
|
|
|
|
echo_info
|
|
|
|
exit_nochange
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## Detect SSH & RSYNC
|
|
|
|
function detect_ssh {
|
2020-06-02 16:23:21 +00:00
|
|
|
MESSAGE="Validating SSH Client on $HOSTNAME"
|
2020-05-31 02:01:24 +00:00
|
|
|
echo_stat
|
|
|
|
|
2020-05-31 02:35:23 +00:00
|
|
|
if hash ssh 2>/dev/null
|
2020-05-31 02:01:24 +00:00
|
|
|
then
|
2020-06-02 16:23:21 +00:00
|
|
|
MESSAGE="${MESSAGE} (OpenSSH)"
|
2020-05-31 02:01:24 +00:00
|
|
|
echo_good
|
2020-06-01 15:00:01 +00:00
|
|
|
SSH_CMD='ssh'
|
2020-06-01 18:45:16 +00:00
|
|
|
elif hash dbclient 2>/dev/null
|
|
|
|
then
|
2020-06-02 16:23:21 +00:00
|
|
|
MESSAGE="${MESSAGE} (Dropbear)"
|
2020-07-21 05:14:20 +00:00
|
|
|
echo_fail
|
|
|
|
|
|
|
|
MESSAGE="Dropbear not supported in GS ${VERSION}"
|
|
|
|
echo_info
|
|
|
|
exit_nochange
|
2020-05-31 02:01:24 +00:00
|
|
|
else
|
|
|
|
echo_fail
|
2020-06-01 18:45:16 +00:00
|
|
|
|
2020-05-31 03:16:42 +00:00
|
|
|
MESSAGE="Attempting to Compensate"
|
2020-06-02 16:52:07 +00:00
|
|
|
echo_warn
|
2020-06-01 18:45:16 +00:00
|
|
|
MESSAGE="Installing SSH Client with ${PKG_MANAGER}"
|
|
|
|
echo_stat
|
|
|
|
|
|
|
|
${PKG_INSTALL} ssh-client >/dev/null 2>&1
|
|
|
|
error_validate
|
2020-05-31 02:01:24 +00:00
|
|
|
fi
|
|
|
|
|
2020-06-02 16:23:21 +00:00
|
|
|
MESSAGE="Validating RSYNC Installed on $HOSTNAME"
|
2020-05-31 02:01:24 +00:00
|
|
|
echo_stat
|
|
|
|
|
2020-05-31 02:35:23 +00:00
|
|
|
if hash rsync 2>/dev/null
|
2020-05-31 02:01:24 +00:00
|
|
|
then
|
|
|
|
echo_good
|
|
|
|
else
|
|
|
|
echo_fail
|
2020-05-31 03:16:42 +00:00
|
|
|
MESSAGE="RSYNC is Required"
|
2020-06-02 14:43:58 +00:00
|
|
|
echo_warn
|
2020-05-31 02:01:24 +00:00
|
|
|
|
2020-05-31 02:33:54 +00:00
|
|
|
distro_check
|
|
|
|
|
2020-05-31 03:16:42 +00:00
|
|
|
MESSAGE="Attempting to Compensate"
|
2020-06-02 16:52:07 +00:00
|
|
|
echo_warn
|
2020-06-01 15:13:01 +00:00
|
|
|
|
|
|
|
MESSAGE="Installing RSYNC with ${PKG_MANAGER}"
|
2020-05-31 02:01:24 +00:00
|
|
|
echo_stat
|
2020-05-31 02:29:01 +00:00
|
|
|
${PKG_INSTALL} rsync >/dev/null 2>&1
|
2020-05-31 02:01:24 +00:00
|
|
|
error_validate
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-07-09 01:48:53 +00:00
|
|
|
function detect_remotersync {
|
2020-07-09 15:06:55 +00:00
|
|
|
MESSAGE="Creating Test File on ${REMOTE_HOST}"
|
2020-07-09 01:48:53 +00:00
|
|
|
echo_stat
|
|
|
|
|
2020-07-09 15:02:51 +00:00
|
|
|
CMD_TIMEOUT='15'
|
|
|
|
CMD_REQUESTED="touch ~/gs.test"
|
|
|
|
create_sshcmd
|
2020-07-09 01:48:53 +00:00
|
|
|
|
2020-09-04 20:50:50 +00:00
|
|
|
MESSAGE="If pull test fails ensure RSYNC is installed on ${REMOTE_HOST}"
|
2020-07-09 15:10:25 +00:00
|
|
|
echo_warn
|
|
|
|
|
2020-07-09 15:06:55 +00:00
|
|
|
MESSAGE="Pulling Test File to $HOSTNAME"
|
|
|
|
echo_stat
|
|
|
|
|
2020-07-09 15:02:51 +00:00
|
|
|
RSYNC_REPATH="rsync"
|
|
|
|
RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:~/gs.test"
|
|
|
|
RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/gs.test"
|
|
|
|
create_rsynccmd
|
|
|
|
|
2020-07-21 05:14:20 +00:00
|
|
|
MESSAGE="Cleaning Up Local Test File"
|
2020-07-09 15:06:55 +00:00
|
|
|
echo_stat
|
|
|
|
|
2020-07-21 05:14:20 +00:00
|
|
|
rm $HOME/${LOCAL_FOLDR}/gs.test
|
|
|
|
error_validate
|
2020-07-09 15:02:51 +00:00
|
|
|
|
2020-07-21 05:14:20 +00:00
|
|
|
MESSAGE="Cleaning Up Remote Test File"
|
|
|
|
echo_stat
|
|
|
|
|
|
|
|
CMD_TIMEOUT='15'
|
|
|
|
CMD_REQUESTED="rm ~/gs.test"
|
|
|
|
create_sshcmd
|
2020-07-09 01:48:53 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 03:20:36 +00:00
|
|
|
## Error Validation
|
2020-05-23 23:26:12 +00:00
|
|
|
function error_validate {
|
2020-06-12 02:08:13 +00:00
|
|
|
if [ "$?" != "0" ]
|
|
|
|
then
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_fail
|
2020-05-23 22:39:02 +00:00
|
|
|
exit 1
|
2020-05-23 23:10:18 +00:00
|
|
|
else
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_good
|
2020-05-23 22:39:02 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-27 03:20:36 +00:00
|
|
|
## Validate Sync Required
|
2020-05-25 01:19:40 +00:00
|
|
|
function md5_compare {
|
2020-07-12 01:48:51 +00:00
|
|
|
# last_primaryDBMD5="0"
|
|
|
|
# last_secondDBMD5="0"
|
|
|
|
# last_primaryCLMD5="0"
|
|
|
|
# last_secondCLMD5="0"
|
|
|
|
|
2020-05-29 15:58:06 +00:00
|
|
|
HASHMARK='0'
|
|
|
|
|
2020-06-02 16:27:46 +00:00
|
|
|
MESSAGE="Analyzing ${GRAVITY_FI} on ${REMOTE_HOST}"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_stat
|
2020-06-01 20:17:01 +00:00
|
|
|
primaryDBMD5=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${PIHOLE_DIR}/${GRAVITY_FI}" | sed 's/\s.*$//')
|
2020-05-25 01:48:18 +00:00
|
|
|
error_validate
|
|
|
|
|
2020-06-02 16:27:46 +00:00
|
|
|
MESSAGE="Analyzing ${GRAVITY_FI} on $HOSTNAME"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_stat
|
2020-06-01 20:17:01 +00:00
|
|
|
secondDBMD5=$(md5sum ${PIHOLE_DIR}/${GRAVITY_FI} | sed 's/\s.*$//')
|
2020-05-25 01:48:18 +00:00
|
|
|
error_validate
|
2020-05-25 01:19:40 +00:00
|
|
|
|
2020-07-12 01:48:51 +00:00
|
|
|
if [ "$primaryDBMD5" == "$last_primaryDBMD5" ] && [ "$secondDBMD5" == "$last_secondDBMD5" ]
|
2020-05-25 01:19:40 +00:00
|
|
|
then
|
2020-05-29 15:58:06 +00:00
|
|
|
HASHMARK=$((HASHMARK+0))
|
2020-05-25 01:19:40 +00:00
|
|
|
else
|
2020-06-02 16:23:21 +00:00
|
|
|
MESSAGE="Differenced ${GRAVITY_FI} Detected"
|
2020-06-01 20:27:36 +00:00
|
|
|
echo_warn
|
2020-05-29 15:58:06 +00:00
|
|
|
HASHMARK=$((HASHMARK+1))
|
|
|
|
fi
|
|
|
|
|
2020-05-29 18:46:23 +00:00
|
|
|
if [ "$SKIP_CUSTOM" != '1' ]
|
2020-05-29 15:58:06 +00:00
|
|
|
then
|
2020-05-29 18:46:23 +00:00
|
|
|
if [ -f ${PIHOLE_DIR}/${CUSTOM_DNS} ]
|
2020-05-29 16:03:20 +00:00
|
|
|
then
|
2020-06-01 15:00:01 +00:00
|
|
|
if ${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${PIHOLE_DIR}/${CUSTOM_DNS}
|
2020-05-29 16:31:38 +00:00
|
|
|
then
|
2020-05-29 18:46:23 +00:00
|
|
|
REMOTE_CUSTOM_DNS="1"
|
2020-06-02 16:27:46 +00:00
|
|
|
MESSAGE="Analyzing ${CUSTOM_DNS} on ${REMOTE_HOST}"
|
2020-05-29 18:46:23 +00:00
|
|
|
echo_stat
|
|
|
|
|
2020-06-01 20:17:01 +00:00
|
|
|
primaryCLMD5=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${PIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//'")
|
2020-05-29 18:46:23 +00:00
|
|
|
error_validate
|
|
|
|
|
2020-06-02 16:27:46 +00:00
|
|
|
MESSAGE="Analyzing ${CUSTOM_DNS} on $HOSTNAME"
|
2020-05-29 18:46:23 +00:00
|
|
|
echo_stat
|
2020-06-01 20:17:01 +00:00
|
|
|
secondCLMD5=$(md5sum ${PIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//')
|
2020-05-29 18:46:23 +00:00
|
|
|
error_validate
|
|
|
|
|
2020-07-12 01:48:51 +00:00
|
|
|
if [ "$primaryCLMD5" == "$last_primaryCLMD5" ] && [ "$secondCLMD5" == "$last_secondCLMD5" ]
|
2020-05-29 18:46:23 +00:00
|
|
|
then
|
2020-06-02 16:23:21 +00:00
|
|
|
# MESSAGE="${CUSTOM_DNS} Identical"
|
|
|
|
# echo_info
|
2020-05-29 18:46:23 +00:00
|
|
|
HASHMARK=$((HASHMARK+0))
|
|
|
|
else
|
2020-06-02 16:23:21 +00:00
|
|
|
MESSAGE="Differenced ${CUSTOM_DNS} Detected"
|
2020-06-01 20:27:36 +00:00
|
|
|
echo_warn
|
2020-05-29 18:46:23 +00:00
|
|
|
HASHMARK=$((HASHMARK+1))
|
|
|
|
fi
|
2020-05-29 16:31:38 +00:00
|
|
|
else
|
2020-05-31 03:28:57 +00:00
|
|
|
MESSAGE="No ${CUSTOM_DNS} Detected on ${REMOTE_HOST}"
|
2020-05-29 16:31:38 +00:00
|
|
|
echo_info
|
|
|
|
fi
|
2020-05-29 16:03:20 +00:00
|
|
|
else
|
2020-06-01 20:38:07 +00:00
|
|
|
if ${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${PIHOLE_DIR}/${CUSTOM_DNS}
|
|
|
|
then
|
|
|
|
REMOTE_CUSTOM_DNS="1"
|
|
|
|
MESSAGE="${REMOTE_HOST} has ${CUSTOM_DNS}"
|
2020-06-12 02:24:12 +00:00
|
|
|
HASHMARK=$((HASHMARK+1))
|
2020-06-01 20:38:07 +00:00
|
|
|
echo_info
|
|
|
|
fi
|
2020-05-31 03:28:57 +00:00
|
|
|
MESSAGE="No ${CUSTOM_DNS} Detected on $HOSTNAME"
|
2020-05-29 16:03:20 +00:00
|
|
|
echo_info
|
|
|
|
fi
|
2020-05-29 15:58:06 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$HASHMARK" != "0" ]
|
|
|
|
then
|
2020-06-01 20:27:36 +00:00
|
|
|
MESSAGE="Replication Required"
|
|
|
|
echo_warn
|
2020-05-29 15:58:06 +00:00
|
|
|
HASHMARK=$((HASHMARK+0))
|
|
|
|
else
|
2020-06-02 16:23:21 +00:00
|
|
|
MESSAGE="No Replication Required"
|
2020-05-29 15:58:06 +00:00
|
|
|
echo_info
|
|
|
|
exit_nochange
|
2020-05-25 01:19:40 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-06-29 21:06:28 +00:00
|
|
|
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 ${PIHOLE_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
|
|
|
|
|
2020-07-12 02:01:21 +00:00
|
|
|
# if [ "$primaryDBMD5" == "$secondDBMD5" ]
|
|
|
|
# then
|
|
|
|
# HASHMARK=$((HASHMARK+0))
|
|
|
|
# else
|
|
|
|
# MESSAGE="Differenced ${GRAVITY_FI} Detected"
|
|
|
|
# echo_warn
|
|
|
|
# HASHMARK=$((HASHMARK+1))
|
|
|
|
# fi
|
2020-06-29 21:06:28 +00:00
|
|
|
|
|
|
|
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 ${PIHOLE_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 ${PIHOLE_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
|
|
|
|
|
2020-07-12 02:01:21 +00:00
|
|
|
# if [ "$primaryCLMD5" == "$secondCLMD5" ]
|
|
|
|
# then
|
2020-06-29 21:06:28 +00:00
|
|
|
# MESSAGE="${CUSTOM_DNS} Identical"
|
|
|
|
# echo_info
|
2020-07-12 02:01:21 +00:00
|
|
|
# HASHMARK=$((HASHMARK+0))
|
|
|
|
# else
|
|
|
|
# MESSAGE="Differenced ${CUSTOM_DNS} Detected"
|
|
|
|
# echo_warn
|
|
|
|
# HASHMARK=$((HASHMARK+1))
|
|
|
|
# fi
|
2020-06-29 21:06:28 +00:00
|
|
|
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 ${PIHOLE_DIR}/${CUSTOM_DNS}
|
|
|
|
then
|
|
|
|
REMOTE_CUSTOM_DNS="1"
|
|
|
|
MESSAGE="${REMOTE_HOST} has ${CUSTOM_DNS}"
|
2020-07-12 02:01:21 +00:00
|
|
|
# HASHMARK=$((HASHMARK+1))
|
2020-06-29 21:06:28 +00:00
|
|
|
echo_info
|
|
|
|
fi
|
|
|
|
MESSAGE="No ${CUSTOM_DNS} Detected on $HOSTNAME"
|
|
|
|
echo_info
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-07-12 02:01:21 +00:00
|
|
|
# if [ "$HASHMARK" != "0" ]
|
|
|
|
# then
|
|
|
|
# MESSAGE="Replication Checks Failed"
|
|
|
|
# echo_warn
|
|
|
|
# else
|
|
|
|
# MESSAGE="Replication Was Successful"
|
|
|
|
# echo_info
|
|
|
|
# fi
|
2020-06-29 21:06:28 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 02:28:14 +00:00
|
|
|
## Validate Intent
|
|
|
|
function intent_validate {
|
2020-05-29 02:43:58 +00:00
|
|
|
if [ "$VERIFY_PASS" == "0" ]
|
2020-05-29 02:28:14 +00:00
|
|
|
then
|
2020-05-29 02:43:58 +00:00
|
|
|
PHASER=$((( RANDOM % 4 ) + 1 ))
|
|
|
|
if [ "$PHASER" = "1" ]
|
|
|
|
then
|
|
|
|
INTENT="FIRE PHOTON TORPEDOS"
|
|
|
|
elif [ "$PHASER" = "2" ]
|
|
|
|
then
|
|
|
|
INTENT="FIRE ALL PHASERS"
|
|
|
|
elif [ "$PHASER" = "3" ]
|
|
|
|
then
|
|
|
|
INTENT="EJECT THE WARPCORE"
|
|
|
|
elif [ "$PHASER" = "4" ]
|
|
|
|
then
|
|
|
|
INTENT="ENGAGE TRACTOR BEAM"
|
|
|
|
fi
|
|
|
|
|
2020-06-02 19:54:09 +00:00
|
|
|
MESSAGE="Type ${INTENT} to Confirm"
|
2020-05-29 02:43:58 +00:00
|
|
|
echo_need
|
2020-05-29 02:28:14 +00:00
|
|
|
|
2020-05-29 02:43:58 +00:00
|
|
|
read INPUT_INTENT
|
2020-05-29 02:28:14 +00:00
|
|
|
|
2020-05-29 02:43:58 +00:00
|
|
|
if [ "${INPUT_INTENT}" != "${INTENT}" ]
|
|
|
|
then
|
|
|
|
MESSAGE="${TASKTYPE} Aborted"
|
|
|
|
echo_info
|
|
|
|
exit_nochange
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
MESSAGE="Verification Bypassed"
|
|
|
|
echo_warn
|
2020-05-29 02:28:14 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-27 03:20:36 +00:00
|
|
|
# Configuration Management
|
|
|
|
## Generate New Configuration
|
2020-05-27 02:21:02 +00:00
|
|
|
function config_generate {
|
2020-10-02 19:01:17 +00:00
|
|
|
task_sudo
|
|
|
|
|
2020-05-31 01:37:59 +00:00
|
|
|
detect_ssh
|
|
|
|
|
2020-05-27 02:21:02 +00:00
|
|
|
MESSAGE="Creating ${CONFIG_FILE} from Template"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_stat
|
2020-05-27 02:21:02 +00:00
|
|
|
cp $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}.example $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
|
|
|
error_validate
|
2020-07-16 16:37:06 +00:00
|
|
|
|
|
|
|
MESSAGE="Environment Customization"
|
|
|
|
echo_info
|
|
|
|
|
2020-07-16 16:44:20 +00:00
|
|
|
MESSAGE="Enter a custom SSH port if required (Leave blank for default '22')"
|
2020-07-16 16:37:06 +00:00
|
|
|
echo_need
|
|
|
|
read INPUT_SSH_PORT
|
2020-07-16 16:57:02 +00:00
|
|
|
INPUT_SSH_PORT="${INPUT_SSH_PORT:-22}"
|
2020-07-16 16:37:06 +00:00
|
|
|
|
2020-07-16 16:57:02 +00:00
|
|
|
if [ "${INPUT_SSH_PORT}" != "22" ]
|
2020-07-16 16:37:06 +00:00
|
|
|
then
|
|
|
|
MESSAGE="Saving Custom SSH Port to ${CONFIG_FILE}"
|
|
|
|
echo_stat
|
|
|
|
sed -i "/# SSH_PORT=''/c\SSH_PORT='${INPUT_SSH_PORT}'" $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
|
|
|
error_validate
|
|
|
|
fi
|
|
|
|
|
|
|
|
MESSAGE="Perform PING tests between Pi-holes? (Leave blank for default 'Yes')"
|
|
|
|
echo_need
|
|
|
|
read INPUT_PING_AVOID
|
2020-07-16 16:59:02 +00:00
|
|
|
INPUT_PING_AVOID="${INPUT_PING_AVOID:-Y}"
|
2020-07-16 16:37:06 +00:00
|
|
|
|
2020-07-16 17:04:34 +00:00
|
|
|
if [ "${INPUT_PING_AVOID}" != "Y" ]
|
2020-07-16 16:37:06 +00:00
|
|
|
then
|
|
|
|
MESSAGE="Saving Ping Avoidance to ${CONFIG_FILE}"
|
|
|
|
echo_stat
|
|
|
|
sed -i "/# PING_AVOID=''/c\PING_AVOID='1'" $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
|
|
|
error_validate
|
|
|
|
PING_AVOID=1
|
|
|
|
fi
|
2020-05-27 02:21:02 +00:00
|
|
|
|
2020-07-16 16:37:06 +00:00
|
|
|
MESSAGE="Standard Settings"
|
|
|
|
echo_info
|
|
|
|
|
2020-06-02 19:54:09 +00:00
|
|
|
MESSAGE="IP or DNS of Primary Pi-hole"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_need
|
2020-05-27 02:21:02 +00:00
|
|
|
read INPUT_REMOTE_HOST
|
2020-06-02 14:43:58 +00:00
|
|
|
|
|
|
|
if [ "${PING_AVOID}" != "1" ]
|
2020-06-02 14:47:48 +00:00
|
|
|
then
|
2020-07-16 16:37:06 +00:00
|
|
|
|
|
|
|
|
2020-06-02 14:43:58 +00:00
|
|
|
MESSAGE="Testing Network Connection (PING)"
|
|
|
|
echo_stat
|
2020-06-02 15:05:43 +00:00
|
|
|
ping -c 3 ${INPUT_REMOTE_HOST} >/dev/null 2>&1
|
2020-06-02 15:02:03 +00:00
|
|
|
error_validate
|
2020-06-02 14:47:48 +00:00
|
|
|
else
|
|
|
|
MESSAGE="Bypassing Network Testing (PING)"
|
2020-06-02 15:02:03 +00:00
|
|
|
echo_warn
|
2020-06-02 14:43:58 +00:00
|
|
|
fi
|
2020-05-27 02:21:02 +00:00
|
|
|
|
2020-06-02 19:51:11 +00:00
|
|
|
MESSAGE="SSH User with SUDO rights"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_need
|
2020-05-27 02:21:02 +00:00
|
|
|
read INPUT_REMOTE_USER
|
|
|
|
|
|
|
|
MESSAGE="Saving Host to ${CONFIG_FILE}"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_stat
|
2020-05-27 02:21:02 +00:00
|
|
|
sed -i "/REMOTE_HOST='192.168.1.10'/c\REMOTE_HOST='${INPUT_REMOTE_HOST}'" $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
|
|
|
error_validate
|
|
|
|
|
|
|
|
MESSAGE="Saving User to ${CONFIG_FILE}"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_stat
|
2020-05-27 02:21:02 +00:00
|
|
|
sed -i "/REMOTE_USER='pi'/c\REMOTE_USER='${INPUT_REMOTE_USER}'" $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
|
|
|
error_validate
|
|
|
|
|
|
|
|
if hash sshpass 2>/dev/null
|
|
|
|
then
|
|
|
|
MESSAGE="SSHPASS Utility Detected"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_warn
|
2020-06-02 19:51:11 +00:00
|
|
|
if hash ssh 2>/dev/null
|
2020-06-02 19:55:05 +00:00
|
|
|
then
|
2020-06-02 20:26:25 +00:00
|
|
|
MESSAGE="Please Reference Documentation"
|
|
|
|
echo_info
|
|
|
|
|
|
|
|
MESSAGE="${BLUE}https://github.com/vmstan/gravity-sync/blob/master/ADVANCED.md#ssh-configuration${NC}"
|
2020-06-02 19:51:11 +00:00
|
|
|
echo_info
|
2020-05-28 16:27:14 +00:00
|
|
|
|
2020-06-02 19:54:09 +00:00
|
|
|
MESSAGE="Leave password blank to use key-pair! (reccomended)"
|
2020-06-02 19:51:11 +00:00
|
|
|
echo_warn
|
2020-05-27 02:21:02 +00:00
|
|
|
|
2020-06-02 19:51:11 +00:00
|
|
|
MESSAGE="SSH User Password"
|
|
|
|
echo_need
|
|
|
|
read INPUT_REMOTE_PASS
|
|
|
|
|
|
|
|
MESSAGE="Saving Password to ${CONFIG_FILE}"
|
|
|
|
echo_stat
|
|
|
|
sed -i "/REMOTE_PASS=''/c\REMOTE_PASS='${INPUT_REMOTE_PASS}'" $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
|
|
|
error_validate
|
|
|
|
elif hash dbclient 2>/dev/null
|
2020-06-02 19:55:05 +00:00
|
|
|
then
|
2020-06-02 19:51:11 +00:00
|
|
|
MESSAGE="Dropbear SSH Detected"
|
|
|
|
echo_warn
|
|
|
|
MESSAGE="Skipping Password Setup"
|
|
|
|
echo_info
|
|
|
|
fi
|
2020-05-27 02:21:02 +00:00
|
|
|
fi
|
2020-05-31 01:20:06 +00:00
|
|
|
|
2020-06-03 19:30:33 +00:00
|
|
|
generate_sshkey
|
2020-05-27 02:21:02 +00:00
|
|
|
|
|
|
|
MESSAGE="Importing New ${CONFIG_FILE}"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_stat
|
2020-05-27 02:21:02 +00:00
|
|
|
source $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
|
|
|
error_validate
|
2020-06-03 19:30:33 +00:00
|
|
|
|
|
|
|
export_sshkey
|
2020-05-27 02:21:02 +00:00
|
|
|
|
2020-06-02 20:45:44 +00:00
|
|
|
MESSAGE="Testing Configuration"
|
|
|
|
echo_info
|
|
|
|
|
2020-05-27 02:21:02 +00:00
|
|
|
validate_os_sshpass
|
2020-10-02 19:01:17 +00:00
|
|
|
validate_sqlite3
|
2020-07-09 01:48:53 +00:00
|
|
|
|
|
|
|
detect_remotersync
|
2020-05-27 02:21:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 03:20:36 +00:00
|
|
|
## Delete Existing Configuration
|
2020-05-27 02:21:02 +00:00
|
|
|
function config_delete {
|
|
|
|
source $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
|
|
|
MESSAGE="Configuration File Exists"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_warn
|
2020-05-27 02:21:02 +00:00
|
|
|
|
|
|
|
echo -e "========================================================"
|
|
|
|
cat $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
|
|
|
echo -e "========================================================"
|
|
|
|
|
|
|
|
MESSAGE="Are you sure you want to erase this configuration?"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_warn
|
2020-05-27 02:21:02 +00:00
|
|
|
|
2020-05-29 02:28:14 +00:00
|
|
|
intent_validate
|
2020-05-28 22:29:41 +00:00
|
|
|
|
2020-05-29 02:28:14 +00:00
|
|
|
MESSAGE="Erasing Existing Configuration"
|
|
|
|
echo_stat
|
|
|
|
rm -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
|
|
|
|
error_validate
|
2020-05-28 22:29:41 +00:00
|
|
|
|
2020-05-29 02:28:14 +00:00
|
|
|
config_generate
|
2020-05-27 02:21:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 03:20:36 +00:00
|
|
|
# Exit Codes
|
|
|
|
## No Changes Made
|
|
|
|
function exit_nochange {
|
2020-06-02 16:03:57 +00:00
|
|
|
SCRIPT_END=$SECONDS
|
|
|
|
MESSAGE="${PROGRAM} ${TASKTYPE} Aborting ($((SCRIPT_END-SCRIPT_START)) seconds)"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_info
|
2020-05-27 03:20:36 +00:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
## Changes Made
|
|
|
|
function exit_withchange {
|
|
|
|
SCRIPT_END=$SECONDS
|
2020-06-02 16:03:57 +00:00
|
|
|
MESSAGE="${PROGRAM} ${TASKTYPE} Completed ($((SCRIPT_END-SCRIPT_START)) seconds)"
|
2020-05-28 21:21:10 +00:00
|
|
|
echo_info
|
2020-05-27 03:20:36 +00:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
## List GS Arguments
|
|
|
|
function list_gs_arguments {
|
|
|
|
echo -e "Usage: $0 [options]"
|
|
|
|
echo -e "Example: '$0 pull'"
|
|
|
|
echo -e ""
|
2020-05-27 04:02:41 +00:00
|
|
|
echo -e "Setup Options:"
|
|
|
|
echo -e " ${YELLOW}config${NC} Create a new ${CONFIG_FILE} file"
|
2020-05-30 05:06:54 +00:00
|
|
|
echo -e " ${YELLOW}automate${NC} Add a scheduled pull task to crontab"
|
|
|
|
echo -e " ${YELLOW}update${NC} Update ${PROGRAM} to the latest version"
|
|
|
|
echo -e " ${YELLOW}version${NC} Display installed version of ${PROGRAM}"
|
2020-05-27 04:02:41 +00:00
|
|
|
echo -e ""
|
2020-05-27 03:20:36 +00:00
|
|
|
echo -e "Replication Options:"
|
2020-07-08 14:48:24 +00:00
|
|
|
echo -e " ${YELLOW}smart${NC} Detect changes on each side and bring them together"
|
2020-06-29 20:49:16 +00:00
|
|
|
echo -e " ${YELLOW}pull${NC} Force remote configuration changes to this server"
|
|
|
|
echo -e " ${YELLOW}push${NC} Force local configuration made on this server back"
|
|
|
|
echo -e " ${YELLOW}restore${NC} Restore the ${GRAVITY_FI} on this server"
|
2020-05-30 05:06:54 +00:00
|
|
|
echo -e " ${YELLOW}compare${NC} Just check for differences"
|
2020-05-27 03:20:36 +00:00
|
|
|
echo -e ""
|
|
|
|
echo -e "Debug Options:"
|
2020-05-27 04:02:41 +00:00
|
|
|
echo -e " ${YELLOW}logs${NC} Show recent successful replication jobs"
|
2020-05-27 03:20:36 +00:00
|
|
|
echo -e " ${YELLOW}cron${NC} Display output of last crontab execution"
|
|
|
|
echo -e ""
|
|
|
|
exit_nochange
|
|
|
|
}
|
|
|
|
|
2020-05-30 02:01:52 +00:00
|
|
|
# Version Control
|
|
|
|
## Show Version
|
2020-05-27 03:20:36 +00:00
|
|
|
function show_version {
|
2020-05-30 02:06:07 +00:00
|
|
|
echo -e "========================================================"
|
2020-05-30 02:09:37 +00:00
|
|
|
MESSAGE="${BOLD}${PROGRAM}${NC} by ${CYAN}@vmstan${NC}"
|
2020-05-30 02:04:11 +00:00
|
|
|
echo_info
|
|
|
|
|
|
|
|
MESSAGE="${BLUE}https://github.com/vmstan/gravity-sync${NC}"
|
2020-05-29 23:09:48 +00:00
|
|
|
echo_info
|
2020-06-22 14:45:35 +00:00
|
|
|
|
|
|
|
if [ -f $HOME/${LOCAL_FOLDR}/dev ]
|
|
|
|
then
|
|
|
|
DEVVERSION="dev"
|
2020-07-12 02:12:21 +00:00
|
|
|
elif [ -f $HOME/${LOCAL_FOLDR}/beta ]
|
|
|
|
then
|
|
|
|
DEVVERSION="beta"
|
2020-06-22 14:45:35 +00:00
|
|
|
else
|
|
|
|
DEVVERSION=""
|
|
|
|
fi
|
2020-05-29 23:09:48 +00:00
|
|
|
|
2020-06-22 14:45:35 +00:00
|
|
|
MESSAGE="Running Version: ${GREEN}${VERSION}${NC} ${DEVVERSION}"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_info
|
2020-05-29 23:07:38 +00:00
|
|
|
|
2020-05-30 02:39:01 +00:00
|
|
|
GITVERSION=$(curl -sf https://raw.githubusercontent.com/vmstan/gravity-sync/master/VERSION)
|
2020-05-30 01:53:28 +00:00
|
|
|
if [ -z "$GITVERSION" ]
|
|
|
|
then
|
2020-05-30 02:01:52 +00:00
|
|
|
MESSAGE="Latest Version: ${RED}Unknown${NC}"
|
2020-05-30 01:53:28 +00:00
|
|
|
else
|
2020-05-30 02:01:52 +00:00
|
|
|
if [ "$GITVERSION" != "$VERSION" ]
|
|
|
|
then
|
2020-07-11 04:34:54 +00:00
|
|
|
MESSAGE="Update Available: ${PURPLE}${GITVERSION}${NC}"
|
2020-05-30 02:01:52 +00:00
|
|
|
else
|
|
|
|
MESSAGE="Latest Version: ${GREEN}${GITVERSION}${NC}"
|
|
|
|
fi
|
2020-05-30 01:53:28 +00:00
|
|
|
fi
|
2020-05-29 23:07:38 +00:00
|
|
|
echo_info
|
2020-05-30 02:06:07 +00:00
|
|
|
echo -e "========================================================"
|
2020-07-11 04:34:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function dbclient_warning {
|
|
|
|
if hash dbclient 2>/dev/null
|
|
|
|
then
|
2020-07-21 05:14:20 +00:00
|
|
|
if hash ssh 2>/dev/null
|
|
|
|
then
|
|
|
|
NOEMPTYBASHIF="1"
|
|
|
|
else
|
|
|
|
MESSAGE="Dropbear support has been deprecated - please convert to OpenSSH"
|
|
|
|
echo_warn
|
|
|
|
fi
|
2020-07-11 04:34:54 +00:00
|
|
|
fi
|
2020-05-27 03:20:36 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 01:51:21 +00:00
|
|
|
# Task Stack
|
|
|
|
## Automate Task
|
|
|
|
function task_automate {
|
|
|
|
TASKTYPE='AUTOMATE'
|
2020-06-02 15:36:59 +00:00
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_good
|
2020-05-28 01:51:21 +00:00
|
|
|
|
2020-07-17 14:45:08 +00:00
|
|
|
# import_gs
|
2020-07-16 18:37:27 +00:00
|
|
|
|
2020-06-22 15:30:49 +00:00
|
|
|
CRON_EXIST='0'
|
2020-05-28 18:05:22 +00:00
|
|
|
CRON_CHECK=$(crontab -l | grep -q "${GS_FILENAME}" && echo '1' || echo '0')
|
2020-05-28 16:27:14 +00:00
|
|
|
if [ ${CRON_CHECK} == 1 ]
|
|
|
|
then
|
|
|
|
MESSAGE="Automation Task Already Exists"
|
2020-05-28 21:21:10 +00:00
|
|
|
echo_info
|
2020-06-22 15:30:49 +00:00
|
|
|
CRON_EXIST='1'
|
2020-05-28 16:27:14 +00:00
|
|
|
fi
|
2020-05-28 15:54:32 +00:00
|
|
|
|
2020-07-11 03:32:32 +00:00
|
|
|
MESSAGE="Configuring Hourly Smart Sync"
|
|
|
|
echo_info
|
|
|
|
|
2020-07-16 18:09:44 +00:00
|
|
|
if [[ $1 =~ ^[0-9][0-9]?$ ]]
|
|
|
|
then
|
|
|
|
INPUT_AUTO_FREQ=$1
|
|
|
|
else
|
|
|
|
MESSAGE="Sync Frequency in Minutes (1-30) or 0 to Disable"
|
|
|
|
echo_need
|
|
|
|
read INPUT_AUTO_FREQ
|
|
|
|
fi
|
2020-05-28 15:54:32 +00:00
|
|
|
|
2020-06-22 15:10:24 +00:00
|
|
|
if [ $INPUT_AUTO_FREQ -gt 30 ]
|
2020-05-28 15:59:04 +00:00
|
|
|
then
|
2020-06-22 15:34:20 +00:00
|
|
|
MESSAGE="Invalid Frequency Range"
|
2020-06-22 15:10:24 +00:00
|
|
|
echo_fail
|
|
|
|
exit_nochange
|
|
|
|
elif [ $INPUT_AUTO_FREQ -lt 1 ]
|
2020-06-22 15:14:49 +00:00
|
|
|
then
|
2020-06-22 15:33:24 +00:00
|
|
|
if [ $CRON_EXIST == 1 ]
|
|
|
|
then
|
2020-06-22 15:27:30 +00:00
|
|
|
clear_cron
|
|
|
|
|
2020-07-11 03:32:32 +00:00
|
|
|
MESSAGE="Sync Automation Disabled"
|
|
|
|
echo_warn
|
2020-06-22 15:33:24 +00:00
|
|
|
else
|
2020-07-11 03:32:32 +00:00
|
|
|
MESSAGE="No Sync Automation Scheduled"
|
|
|
|
echo_warn
|
2020-06-22 15:33:24 +00:00
|
|
|
fi
|
2020-06-22 15:27:30 +00:00
|
|
|
else
|
|
|
|
if [ $CRON_EXIST == 1 ]
|
|
|
|
then
|
|
|
|
clear_cron
|
2020-06-22 15:04:48 +00:00
|
|
|
fi
|
|
|
|
|
2020-07-11 03:32:32 +00:00
|
|
|
MESSAGE="Saving New Sync Automation"
|
2020-06-22 14:52:03 +00:00
|
|
|
echo_stat
|
2020-07-11 03:32:32 +00:00
|
|
|
(crontab -l 2>/dev/null; echo "*/${INPUT_AUTO_FREQ} * * * * ${BASH_PATH} $HOME/${LOCAL_FOLDR}/${GS_FILENAME} smart > ${LOG_PATH}/${CRONJOB_LOG}") | crontab -
|
2020-05-28 15:54:32 +00:00
|
|
|
error_validate
|
2020-06-22 14:52:03 +00:00
|
|
|
fi
|
2020-07-11 03:32:32 +00:00
|
|
|
|
|
|
|
MESSAGE="Configuring Daily Backup Frequency"
|
|
|
|
echo_info
|
|
|
|
|
2020-07-16 18:09:44 +00:00
|
|
|
if [[ $2 =~ ^[0-9][0-9]?$ ]]
|
|
|
|
then
|
|
|
|
INPUT_AUTO_BACKUP=$2
|
|
|
|
else
|
|
|
|
MESSAGE="Hour of Day to Backup (1-24) or 0 to Disable"
|
|
|
|
echo_need
|
|
|
|
read INPUT_AUTO_BACKUP
|
|
|
|
fi
|
2020-07-11 03:32:32 +00:00
|
|
|
|
|
|
|
if [ $INPUT_AUTO_BACKUP -gt 24 ]
|
|
|
|
then
|
|
|
|
MESSAGE="Invalid Frequency Range"
|
|
|
|
echo_fail
|
|
|
|
exit_nochange
|
2020-07-11 03:33:31 +00:00
|
|
|
elif [ $INPUT_AUTO_BACKUP -lt 1 ]
|
2020-07-11 03:32:32 +00:00
|
|
|
then
|
|
|
|
MESSAGE="No Backup Automation Scheduled"
|
|
|
|
echo_warn
|
|
|
|
else
|
|
|
|
MESSAGE="Saving New Backup Automation"
|
|
|
|
echo_stat
|
2020-07-11 15:04:40 +00:00
|
|
|
(crontab -l 2>/dev/null; echo "0 ${INPUT_AUTO_BACKUP} * * * ${BASH_PATH} $HOME/${LOCAL_FOLDR}/${GS_FILENAME} backup >/dev/null 2>&1") | crontab -
|
2020-07-11 03:32:32 +00:00
|
|
|
error_validate
|
|
|
|
fi
|
|
|
|
|
2020-06-22 15:27:30 +00:00
|
|
|
exit_withchange
|
2020-05-28 01:51:21 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 15:27:30 +00:00
|
|
|
## Clear Existing Automation Settings
|
|
|
|
function clear_cron {
|
|
|
|
MESSAGE="Removing Existing Automation"
|
|
|
|
echo_stat
|
|
|
|
|
|
|
|
crontab -l > cronjob-old.tmp
|
2020-07-08 14:32:20 +00:00
|
|
|
sed "/${GS_FILENAME}/d" cronjob-old.tmp > cronjob-new.tmp
|
2020-06-22 15:27:30 +00:00
|
|
|
crontab cronjob-new.tmp 2>/dev/null
|
|
|
|
error_validate
|
|
|
|
rm cronjob-old.tmp
|
|
|
|
rm cronjob-new.tmp
|
|
|
|
}
|
|
|
|
|
2020-06-02 15:36:59 +00:00
|
|
|
## Configure Task
|
|
|
|
function task_configure {
|
|
|
|
TASKTYPE='CONFIGURE'
|
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
|
|
|
|
|
|
|
if [ -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} ]
|
|
|
|
then
|
|
|
|
config_delete
|
|
|
|
else
|
|
|
|
MESSAGE="No Active ${CONFIG_FILE}"
|
|
|
|
echo_warn
|
|
|
|
|
|
|
|
config_generate
|
|
|
|
fi
|
2020-07-21 05:14:20 +00:00
|
|
|
|
|
|
|
backup_settime
|
|
|
|
backup_local_gravity
|
|
|
|
backup_local_custom
|
|
|
|
backup_cleanup
|
|
|
|
|
|
|
|
exit_withchange
|
2020-06-02 15:36:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 15:42:19 +00:00
|
|
|
## Devmode Task
|
2020-06-02 15:36:59 +00:00
|
|
|
function task_devmode {
|
|
|
|
TASKTYPE='DEV'
|
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
|
|
|
|
|
|
|
if [ -f $HOME/${LOCAL_FOLDR}/dev ]
|
|
|
|
then
|
|
|
|
MESSAGE="Disabling ${TASKTYPE}"
|
|
|
|
echo_stat
|
|
|
|
rm -f $HOME/${LOCAL_FOLDR}/dev
|
|
|
|
error_validate
|
2020-07-11 23:34:22 +00:00
|
|
|
elif [ -f $HOME/${LOCAL_FOLDR}/beta ]
|
|
|
|
then
|
|
|
|
MESSAGE="Disabling BETA"
|
|
|
|
echo_stat
|
|
|
|
rm -f $HOME/${LOCAL_FOLDR}/beta
|
|
|
|
error_validate
|
|
|
|
|
|
|
|
MESSAGE="Enabling ${TASKTYPE}"
|
|
|
|
echo_stat
|
|
|
|
touch $HOME/${LOCAL_FOLDR}/dev
|
|
|
|
error_validate
|
2020-06-02 15:36:59 +00:00
|
|
|
else
|
|
|
|
MESSAGE="Enabling ${TASKTYPE}"
|
|
|
|
echo_stat
|
|
|
|
touch $HOME/${LOCAL_FOLDR}/dev
|
|
|
|
error_validate
|
2020-10-02 19:01:17 +00:00
|
|
|
|
|
|
|
git branch -r
|
|
|
|
|
|
|
|
MESSAGE="Select Branch to Update Against"
|
|
|
|
echo_need
|
|
|
|
read INPUT_BRANCH
|
|
|
|
|
|
|
|
echo -e "BRANCH='${INPUT_BRANCH}'" >> $HOME/${LOCAL_FOLDR}/dev
|
2020-06-02 15:36:59 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
MESSAGE="Run UPDATE to apply changes"
|
|
|
|
echo_info
|
|
|
|
|
|
|
|
exit_withchange
|
|
|
|
}
|
|
|
|
|
2020-07-11 23:34:22 +00:00
|
|
|
## Devmode Task
|
|
|
|
function task_betamode {
|
|
|
|
TASKTYPE='BETA'
|
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
|
|
|
|
|
|
|
if [ -f $HOME/${LOCAL_FOLDR}/beta ]
|
|
|
|
then
|
|
|
|
MESSAGE="Disabling ${TASKTYPE}"
|
|
|
|
echo_stat
|
|
|
|
rm -f $HOME/${LOCAL_FOLDR}/beta
|
|
|
|
error_validate
|
|
|
|
elif [ -f $HOME/${LOCAL_FOLDR}/dev ]
|
|
|
|
then
|
|
|
|
MESSAGE="Disabling DEV"
|
|
|
|
echo_stat
|
|
|
|
rm -f $HOME/${LOCAL_FOLDR}/dev
|
|
|
|
error_validate
|
|
|
|
|
|
|
|
MESSAGE="Enabling ${TASKTYPE}"
|
|
|
|
echo_stat
|
|
|
|
touch $HOME/${LOCAL_FOLDR}/beta
|
|
|
|
error_validate
|
|
|
|
else
|
|
|
|
MESSAGE="Enabling ${TASKTYPE}"
|
|
|
|
echo_stat
|
|
|
|
touch $HOME/${LOCAL_FOLDR}/beta
|
|
|
|
error_validate
|
|
|
|
fi
|
|
|
|
|
|
|
|
MESSAGE="Run UPDATE to apply changes"
|
|
|
|
echo_info
|
|
|
|
|
|
|
|
exit_withchange
|
|
|
|
}
|
|
|
|
|
2020-06-02 15:42:19 +00:00
|
|
|
## Update Task
|
|
|
|
function task_update {
|
|
|
|
TASKTYPE='UPDATE'
|
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
2020-07-11 04:34:54 +00:00
|
|
|
|
|
|
|
dbclient_warning
|
2020-06-02 15:42:19 +00:00
|
|
|
|
|
|
|
update_gs
|
2020-07-21 05:14:20 +00:00
|
|
|
|
|
|
|
exit_withchange
|
2020-06-02 15:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
## Version Task
|
|
|
|
function task_version {
|
|
|
|
TASKTYPE='VERSION'
|
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
|
|
|
|
|
|
|
show_version
|
|
|
|
exit_nochange
|
|
|
|
}
|
|
|
|
|
|
|
|
## Logs Task
|
|
|
|
function task_logs {
|
|
|
|
TASKTYPE='LOGS'
|
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
|
|
|
|
|
|
|
logs_gs
|
|
|
|
}
|
|
|
|
|
|
|
|
## Compare Task
|
|
|
|
function task_compare {
|
|
|
|
TASKTYPE='COMPARE'
|
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
2020-07-16 18:09:44 +00:00
|
|
|
|
2020-07-17 14:45:08 +00:00
|
|
|
# import_gs
|
|
|
|
show_target
|
2020-06-03 18:26:00 +00:00
|
|
|
validate_gs_folders
|
|
|
|
validate_ph_folders
|
|
|
|
validate_os_sshpass
|
2020-07-12 02:06:06 +00:00
|
|
|
|
|
|
|
previous_md5
|
2020-06-02 15:42:19 +00:00
|
|
|
md5_compare
|
|
|
|
}
|
|
|
|
|
|
|
|
## Cron Task
|
|
|
|
function task_cron {
|
|
|
|
TASKTYPE='CRON'
|
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
|
|
|
|
|
|
|
show_crontab
|
|
|
|
}
|
|
|
|
|
2020-06-02 15:46:02 +00:00
|
|
|
function task_invalid {
|
|
|
|
echo_fail
|
|
|
|
list_gs_arguments
|
|
|
|
}
|
|
|
|
|
2020-07-21 05:14:20 +00:00
|
|
|
## Purge Task
|
|
|
|
function task_purge {
|
|
|
|
TASKTYPE="THE-PURGE"
|
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
|
|
|
|
|
|
|
MESSAGE="THIS WILL RESET YOUR ENTIRE GRAVITY SYNC INSTALLATION"
|
|
|
|
echo_warn
|
|
|
|
MESSAGE="This will remove:"
|
|
|
|
echo_warn
|
|
|
|
MESSAGE="- All backups files."
|
|
|
|
echo_warn
|
|
|
|
MESSAGE="- Your ${CONFIG_FILE} file."
|
|
|
|
echo_warn
|
|
|
|
|
|
|
|
if [ -f "$HOME/${LOCAL_FOLDR}/dev" ]
|
|
|
|
then
|
|
|
|
MESSAGE="- Your development branch updater."
|
|
|
|
elif [ -f "$HOME/${LOCAL_FOLDR}/beta" ]
|
|
|
|
then
|
|
|
|
MESSAGE="- Your beta branch updater."
|
|
|
|
fi
|
|
|
|
echo_warn
|
|
|
|
|
|
|
|
MESSAGE="- All cronjob/automation tasks."
|
|
|
|
echo_warn
|
|
|
|
MESSAGE="- All job history/logs."
|
|
|
|
echo_warn
|
|
|
|
MESSAGE="- Associated SSH id_rsa keys."
|
|
|
|
echo_warn
|
|
|
|
MESSAGE="This function cannot be undone!"
|
|
|
|
echo_warn
|
|
|
|
|
|
|
|
MESSAGE="YOU WILL NEED TO REBUILD GRAVITY SYNC AFTER EXECUTION"
|
|
|
|
echo_warn
|
|
|
|
|
|
|
|
MESSAGE="Pi-hole binaries, configuration and services ARE NOT impacted!"
|
|
|
|
echo_info
|
|
|
|
MESSAGE="Your device will continue to resolve and block DNS requests,"
|
|
|
|
echo_info
|
|
|
|
MESSAGE="but your ${GRAVITY_FI} and ${CUSTOM_DNS} WILL NOT sync anymore,"
|
|
|
|
echo_info
|
|
|
|
MESSAGE="until you reconfigure Gravity Sync on this device."
|
|
|
|
echo_info
|
|
|
|
|
|
|
|
intent_validate
|
|
|
|
|
|
|
|
MESSAGE="Cleaning Gravity Sync Directory"
|
|
|
|
echo_stat
|
|
|
|
|
|
|
|
git clean -f -X -d >/dev/null 2>&1
|
|
|
|
error_validate
|
|
|
|
|
|
|
|
clear_cron
|
|
|
|
|
|
|
|
MESSAGE="Deleting SSH Key-files"
|
|
|
|
echo_stat
|
|
|
|
|
|
|
|
rm -f $HOME/${SSH_PKIF} >/dev/null 2>&1
|
|
|
|
rm -f $HOME/${SSH_PKIF}.pub >/dev/null 2>&1
|
|
|
|
error_validate
|
|
|
|
|
|
|
|
MESSAGE="Realigning Dilithium Matrix"
|
|
|
|
echo_fail
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
update_gs
|
|
|
|
}
|
|
|
|
|
2020-10-02 19:01:17 +00:00
|
|
|
## Sudo Creation Task
|
|
|
|
function task_sudo {
|
|
|
|
TASKTYPE='SUDO'
|
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
|
|
|
|
|
|
|
MESSAGE="Creating Sudoer.d Template"
|
|
|
|
echo_stat
|
|
|
|
|
|
|
|
NEW_SUDO_USER=$(whoami)
|
|
|
|
echo -e "${NEW_SUDO_USER} ALL=(ALL) NOPASSWD: ${PIHOLE_DIR}" > gs-nopasswd.sudo
|
|
|
|
error_validate
|
|
|
|
|
|
|
|
MESSAGE="Installing Sudoer.d File"
|
|
|
|
echo_stat
|
|
|
|
|
|
|
|
sudo install -m 0440 gs-nopasswd.sudo /etc/sudoers.d/gs-nopasswd
|
|
|
|
error_validate
|
|
|
|
}
|
|
|
|
|
2020-07-11 02:43:05 +00:00
|
|
|
## Backup Task
|
|
|
|
function task_backup {
|
|
|
|
TASKTYPE='BACKUP'
|
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
|
|
|
|
2020-07-11 19:42:52 +00:00
|
|
|
backup_settime
|
|
|
|
backup_local_gravity
|
|
|
|
backup_local_custom
|
|
|
|
backup_cleanup
|
|
|
|
|
2020-07-12 15:26:07 +00:00
|
|
|
logs_export
|
2020-07-11 19:42:52 +00:00
|
|
|
exit_withchange
|
|
|
|
}
|
|
|
|
|
|
|
|
function backup_settime {
|
2020-07-11 03:13:49 +00:00
|
|
|
BACKUPTIMESTAMP=$(date +%F-%H%M%S)
|
2020-07-11 19:42:52 +00:00
|
|
|
}
|
2020-07-11 03:13:49 +00:00
|
|
|
|
2020-07-11 19:42:52 +00:00
|
|
|
function backup_local_gravity {
|
2020-07-11 20:33:35 +00:00
|
|
|
MESSAGE="Performing Backup of Local ${GRAVITY_FI}"
|
2020-07-11 02:57:04 +00:00
|
|
|
echo_stat
|
|
|
|
|
2020-07-11 03:13:49 +00:00
|
|
|
sqlite3 ${PIHOLE_DIR}/${GRAVITY_FI} ".backup '$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${GRAVITY_FI}.backup'"
|
2020-07-11 02:57:04 +00:00
|
|
|
error_validate
|
2020-07-11 19:42:52 +00:00
|
|
|
}
|
2020-07-11 02:57:04 +00:00
|
|
|
|
2020-07-11 19:42:52 +00:00
|
|
|
function backup_local_custom {
|
2020-07-11 13:50:32 +00:00
|
|
|
if [ "$SKIP_CUSTOM" != '1' ]
|
|
|
|
then
|
|
|
|
if [ -f ${PIHOLE_DIR}/${CUSTOM_DNS} ]
|
|
|
|
then
|
2020-07-11 20:33:35 +00:00
|
|
|
MESSAGE="Performing Backup Up Local ${CUSTOM_DNS}"
|
2020-07-11 13:50:32 +00:00
|
|
|
echo_stat
|
2020-07-11 02:57:04 +00:00
|
|
|
|
2020-07-11 13:50:32 +00:00
|
|
|
cp ${PIHOLE_DIR}/${CUSTOM_DNS} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${BACKUPTIMESTAMP}-${CUSTOM_DNS}.backup
|
|
|
|
error_validate
|
|
|
|
fi
|
|
|
|
fi
|
2020-07-11 19:42:52 +00:00
|
|
|
}
|
2020-07-11 03:19:28 +00:00
|
|
|
|
2020-07-11 20:17:27 +00:00
|
|
|
function backup_remote_gravity {
|
2020-07-11 20:33:35 +00:00
|
|
|
MESSAGE="Performing Backup of Remote ${GRAVITY_FI}"
|
|
|
|
echo_stat
|
|
|
|
|
2020-07-21 05:14:20 +00:00
|
|
|
CMD_TIMEOUT='60'
|
2020-07-11 20:33:35 +00:00
|
|
|
CMD_REQUESTED="sudo sqlite3 ${PIHOLE_DIR}/${GRAVITY_FI} \".backup '${PIHOLE_DIR}/${GRAVITY_FI}.backup'\""
|
2020-07-11 20:17:27 +00:00
|
|
|
create_sshcmd
|
|
|
|
}
|
|
|
|
|
|
|
|
function backup_remote_custom {
|
2020-07-11 20:33:35 +00:00
|
|
|
if [ "$SKIP_CUSTOM" != '1' ]
|
|
|
|
then
|
|
|
|
MESSAGE="Performing Backup of Remote ${CUSTOM_DNS}"
|
|
|
|
echo_stat
|
|
|
|
|
|
|
|
CMD_TIMEOUT='15'
|
2020-07-11 23:46:29 +00:00
|
|
|
CMD_REQUESTED="sudo cp ${PIHOLE_DIR}/${CUSTOM_DNS} ${PIHOLE_DIR}/${CUSTOM_DNS}.backup"
|
2020-07-11 20:33:35 +00:00
|
|
|
create_sshcmd
|
|
|
|
fi
|
2020-07-11 20:17:27 +00:00
|
|
|
}
|
|
|
|
|
2020-07-11 19:42:52 +00:00
|
|
|
function backup_cleanup {
|
2020-07-11 03:19:28 +00:00
|
|
|
MESSAGE="Cleaning Up Old Backups"
|
|
|
|
echo_stat
|
|
|
|
|
|
|
|
find $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/$(date +%Y)*.backup -mtime +${BACKUP_RETAIN} -type f -delete
|
|
|
|
error_validate
|
2020-07-11 02:43:05 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 21:21:10 +00:00
|
|
|
# Echo Stack
|
|
|
|
## Informative
|
|
|
|
function echo_info {
|
2020-05-31 04:17:36 +00:00
|
|
|
echo -e "${INFO} ${YELLOW}${MESSAGE}${NC}"
|
2020-05-28 21:21:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
## Warning
|
|
|
|
function echo_warn {
|
2020-06-01 20:27:36 +00:00
|
|
|
echo -e "${WARN} ${PURPLE}${MESSAGE}${NC}"
|
2020-05-28 21:21:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
## Executing
|
|
|
|
function echo_stat {
|
|
|
|
echo -en "${STAT} ${MESSAGE}"
|
|
|
|
}
|
|
|
|
|
|
|
|
## Success
|
|
|
|
function echo_good {
|
|
|
|
echo -e "\r${GOOD} ${MESSAGE}"
|
|
|
|
}
|
|
|
|
|
|
|
|
## Failure
|
|
|
|
function echo_fail {
|
|
|
|
echo -e "\r${FAIL} ${MESSAGE}"
|
|
|
|
}
|
|
|
|
|
|
|
|
## Request
|
|
|
|
function echo_need {
|
|
|
|
echo -en "${NEED} ${MESSAGE}: "
|
|
|
|
}
|
|
|
|
|
2020-06-03 20:47:20 +00:00
|
|
|
# Root Check
|
|
|
|
function root_check {
|
2020-06-03 20:43:36 +00:00
|
|
|
if [ ! "$EUID" -ne 0 ]
|
|
|
|
then
|
2020-06-03 20:47:20 +00:00
|
|
|
TASKTYPE='ROOT'
|
|
|
|
MESSAGE="${MESSAGE} ${TASKTYPE}"
|
2020-06-03 20:43:36 +00:00
|
|
|
echo_fail
|
|
|
|
|
2020-06-03 20:45:41 +00:00
|
|
|
MESSAGE="${PROGRAM} Must Not Run as Root"
|
2020-06-03 20:43:36 +00:00
|
|
|
echo_warn
|
|
|
|
|
|
|
|
exit_nochange
|
|
|
|
fi
|
2020-06-03 20:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# SCRIPT EXECUTION ###########################
|
|
|
|
|
|
|
|
MESSAGE="${PROGRAM} ${VERSION} Executing"
|
|
|
|
echo_info
|
|
|
|
|
2020-07-17 14:45:08 +00:00
|
|
|
import_gs
|
|
|
|
|
2020-06-03 20:47:20 +00:00
|
|
|
MESSAGE="Evaluating Arguments"
|
|
|
|
echo_stat
|
2020-07-16 18:15:38 +00:00
|
|
|
|
2020-07-16 18:09:44 +00:00
|
|
|
if [ "${ROOT_CHECK_AVOID}" != "1" ]
|
|
|
|
then
|
|
|
|
root_check
|
|
|
|
fi
|
2020-06-03 20:43:36 +00:00
|
|
|
|
2020-05-21 18:00:42 +00:00
|
|
|
case $# in
|
2020-05-22 01:30:20 +00:00
|
|
|
|
2020-05-22 02:42:37 +00:00
|
|
|
0)
|
2020-07-07 20:15:42 +00:00
|
|
|
TASKTYPE='SMART'
|
2020-06-29 03:23:43 +00:00
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
|
|
|
|
2020-07-17 14:45:08 +00:00
|
|
|
# import_gs
|
|
|
|
show_target
|
2020-06-29 03:23:43 +00:00
|
|
|
validate_gs_folders
|
|
|
|
validate_ph_folders
|
2020-10-02 19:01:17 +00:00
|
|
|
validate_sqlite3
|
2020-06-29 03:23:43 +00:00
|
|
|
validate_os_sshpass
|
|
|
|
|
|
|
|
smart_gs
|
|
|
|
exit
|
2020-05-22 01:30:20 +00:00
|
|
|
;;
|
2020-05-22 01:39:14 +00:00
|
|
|
|
2020-05-22 02:42:37 +00:00
|
|
|
1)
|
|
|
|
case $1 in
|
2020-06-29 20:49:16 +00:00
|
|
|
sync)
|
2020-07-07 20:15:42 +00:00
|
|
|
TASKTYPE='SMART'
|
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
|
|
|
|
2020-07-17 14:45:08 +00:00
|
|
|
# import_gs
|
|
|
|
show_target
|
2020-07-07 20:15:42 +00:00
|
|
|
validate_gs_folders
|
|
|
|
validate_ph_folders
|
2020-10-02 19:01:17 +00:00
|
|
|
validate_sqlite3
|
2020-07-07 20:15:42 +00:00
|
|
|
validate_os_sshpass
|
|
|
|
|
|
|
|
smart_gs
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
|
|
|
|
smart)
|
|
|
|
TASKTYPE='SMART'
|
2020-06-29 20:49:16 +00:00
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
|
|
|
echo_good
|
|
|
|
|
2020-07-17 14:45:08 +00:00
|
|
|
# import_gs
|
|
|
|
show_target
|
2020-06-29 20:49:16 +00:00
|
|
|
validate_gs_folders
|
|
|
|
validate_ph_folders
|
2020-10-02 19:01:17 +00:00
|
|
|
validate_sqlite3
|
2020-06-29 20:49:16 +00:00
|
|
|
validate_os_sshpass
|
|
|
|
|
|
|
|
smart_gs
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
|
2020-05-22 02:42:37 +00:00
|
|
|
pull)
|
2020-05-28 21:50:25 +00:00
|
|
|
TASKTYPE='PULL'
|
2020-06-02 15:18:51 +00:00
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_good
|
2020-07-16 18:09:44 +00:00
|
|
|
|
2020-07-17 14:45:08 +00:00
|
|
|
# import_gs
|
|
|
|
show_target
|
2020-06-03 18:07:15 +00:00
|
|
|
validate_gs_folders
|
|
|
|
validate_ph_folders
|
2020-10-02 19:01:17 +00:00
|
|
|
validate_sqlite3
|
2020-06-03 18:07:15 +00:00
|
|
|
validate_os_sshpass
|
2020-05-22 15:55:23 +00:00
|
|
|
|
|
|
|
pull_gs
|
2020-05-22 02:42:37 +00:00
|
|
|
exit
|
|
|
|
;;
|
|
|
|
|
|
|
|
push)
|
2020-05-28 21:50:25 +00:00
|
|
|
TASKTYPE='PUSH'
|
2020-06-02 15:36:59 +00:00
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
2020-05-28 21:50:25 +00:00
|
|
|
echo_good
|
2020-07-16 18:09:44 +00:00
|
|
|
|
2020-07-17 14:45:08 +00:00
|
|
|
# import_gs
|
|
|
|
show_target
|
2020-06-03 18:07:15 +00:00
|
|
|
validate_gs_folders
|
|
|
|
validate_ph_folders
|
2020-10-02 19:01:17 +00:00
|
|
|
validate_sqlite3
|
2020-06-03 18:07:15 +00:00
|
|
|
validate_os_sshpass
|
2020-05-22 15:55:23 +00:00
|
|
|
|
|
|
|
push_gs
|
2020-05-22 02:42:37 +00:00
|
|
|
exit
|
|
|
|
;;
|
2020-05-28 22:09:58 +00:00
|
|
|
|
2020-05-28 22:29:41 +00:00
|
|
|
restore)
|
|
|
|
TASKTYPE='RESTORE'
|
2020-06-02 15:36:59 +00:00
|
|
|
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
|
2020-05-28 22:09:58 +00:00
|
|
|
echo_good
|
|
|
|
|
2020-07-17 14:45:08 +00:00
|
|
|
# import_gs
|
|
|
|
show_target
|
2020-06-03 18:07:15 +00:00
|
|
|
validate_gs_folders
|
|
|
|
validate_ph_folders
|
2020-10-02 19:01:17 +00:00
|
|
|
validate_sqlite3
|
2020-05-28 22:09:58 +00:00
|
|
|
|
2020-05-28 22:29:41 +00:00
|
|
|
restore_gs
|
2020-05-28 22:09:58 +00:00
|
|
|
exit
|
|
|
|
;;
|
2020-05-22 02:42:37 +00:00
|
|
|
|
|
|
|
version)
|
2020-06-02 15:42:19 +00:00
|
|
|
task_version
|
2020-05-22 02:42:37 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
update)
|
2020-06-02 15:42:19 +00:00
|
|
|
task_update
|
|
|
|
;;
|
|
|
|
|
|
|
|
upgrade)
|
|
|
|
task_update
|
2020-05-22 02:42:37 +00:00
|
|
|
;;
|
2020-05-25 01:23:19 +00:00
|
|
|
|
2020-05-30 21:23:02 +00:00
|
|
|
dev)
|
2020-06-02 15:36:59 +00:00
|
|
|
task_devmode
|
|
|
|
;;
|
|
|
|
|
2020-10-02 19:01:17 +00:00
|
|
|
# beta)
|
|
|
|
# task_betamode
|
|
|
|
# ;;
|
2020-07-11 23:34:22 +00:00
|
|
|
|
2020-06-02 15:36:59 +00:00
|
|
|
devmode)
|
|
|
|
task_devmode
|
|
|
|
;;
|
|
|
|
|
|
|
|
development)
|
|
|
|
task_devmode
|
2020-05-30 21:23:02 +00:00
|
|
|
;;
|
2020-05-22 02:07:01 +00:00
|
|
|
|
2020-05-22 02:42:37 +00:00
|
|
|
logs)
|
2020-06-02 15:42:19 +00:00
|
|
|
task_logs
|
2020-05-22 02:42:37 +00:00
|
|
|
;;
|
2020-05-24 18:39:21 +00:00
|
|
|
|
2020-05-25 01:19:40 +00:00
|
|
|
compare)
|
2020-06-02 15:42:19 +00:00
|
|
|
task_compare
|
2020-05-25 01:20:52 +00:00
|
|
|
;;
|
2020-05-25 01:19:40 +00:00
|
|
|
|
2020-05-24 18:39:21 +00:00
|
|
|
cron)
|
2020-06-02 15:42:19 +00:00
|
|
|
task_cron
|
2020-05-24 18:39:21 +00:00
|
|
|
;;
|
2020-05-26 19:01:01 +00:00
|
|
|
|
|
|
|
config)
|
2020-06-02 15:36:59 +00:00
|
|
|
task_configure
|
|
|
|
;;
|
2020-05-28 21:50:25 +00:00
|
|
|
|
2020-06-02 15:36:59 +00:00
|
|
|
configure)
|
|
|
|
task_configure
|
2020-05-26 19:01:01 +00:00
|
|
|
;;
|
2020-05-28 01:51:21 +00:00
|
|
|
|
|
|
|
auto)
|
|
|
|
task_automate
|
|
|
|
;;
|
|
|
|
|
|
|
|
automate)
|
|
|
|
task_automate
|
|
|
|
;;
|
2020-05-22 02:42:37 +00:00
|
|
|
|
2020-07-11 02:43:05 +00:00
|
|
|
backup)
|
|
|
|
task_backup
|
|
|
|
;;
|
|
|
|
|
2020-07-21 05:14:20 +00:00
|
|
|
purge)
|
|
|
|
task_purge
|
|
|
|
;;
|
|
|
|
|
2020-10-02 19:01:17 +00:00
|
|
|
sudo)
|
|
|
|
task_sudo
|
|
|
|
exit_withchange
|
|
|
|
;;
|
|
|
|
|
2020-05-22 02:42:37 +00:00
|
|
|
*)
|
2020-06-02 15:46:02 +00:00
|
|
|
task_invalid
|
2020-05-22 02:42:37 +00:00
|
|
|
;;
|
|
|
|
esac
|
2020-05-22 02:08:31 +00:00
|
|
|
;;
|
2020-07-16 18:09:44 +00:00
|
|
|
|
|
|
|
2)
|
|
|
|
case $1 in
|
|
|
|
automate)
|
|
|
|
task_automate
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
|
|
|
3)
|
|
|
|
case $1 in
|
|
|
|
automate)
|
|
|
|
task_automate $2 $3
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
;;
|
2020-05-22 16:39:31 +00:00
|
|
|
|
2020-05-21 18:00:42 +00:00
|
|
|
*)
|
2020-06-02 15:46:02 +00:00
|
|
|
task_invalid
|
2020-05-22 16:39:31 +00:00
|
|
|
;;
|
2020-07-21 05:14:20 +00:00
|
|
|
esac
|