From a158a2d0426f69941575178887ae07d22fd4ec19 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 11 Jul 2020 18:34:22 -0500 Subject: [PATCH 01/28] betamode --- gravity-sync.sh | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/gravity-sync.sh b/gravity-sync.sh index e4fb55d..04d6ad9 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1634,6 +1634,17 @@ function task_devmode { echo_stat rm -f $HOME/${LOCAL_FOLDR}/dev error_validate + 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 else MESSAGE="Enabling ${TASKTYPE}" echo_stat @@ -1647,6 +1658,42 @@ function task_devmode { exit_withchange } +## 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 +} + ## Update Task function task_update { TASKTYPE='UPDATE' @@ -1936,6 +1983,9 @@ case $# in task_devmode ;; + beta) + task_betamode + devmode) task_devmode ;; From 668475c103bf5854ac1722690543fbc0bfea280e Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 11 Jul 2020 18:42:22 -0500 Subject: [PATCH 02/28] beta mode in changelog --- CHANGELOG.md | 3 +++ gravity-sync.sh | 1 + 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a813c6..7a505a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,9 @@ The `./gravity-sync.sh update` and `version` functions will look for the `dbclie #### 2.1.5 Skipping a few digits because what does it really matter? +- Implements a new beta branch, and with it a new `./gravity-sync.sh beta` function to enable it. This will hopefully allow new features and such to be added for test users who can adopt them and provide feedback before rolling out to the main update branch. +- Uses new SQLITE3 backup methodology introduced in 2.1, for all push/pull sync operations. + ## 2.0 ### The Smart Release diff --git a/gravity-sync.sh b/gravity-sync.sh index 04d6ad9..b4e3737 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1985,6 +1985,7 @@ case $# in beta) task_betamode + ;; devmode) task_devmode From 0617525e64ad7e07b77c0f2c441c646643f60007 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 11 Jul 2020 18:46:29 -0500 Subject: [PATCH 03/28] extra quotes --- gravity-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index b4e3737..bbc57ed 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1810,7 +1810,7 @@ function backup_remote_custom { echo_stat CMD_TIMEOUT='15' - CMD_REQUESTED="sudo cp ${PIHOLE_DIR}/${CUSTOM_DNS} ${PIHOLE_DIR}/${CUSTOM_DNS}.backup'\"" + CMD_REQUESTED="sudo cp ${PIHOLE_DIR}/${CUSTOM_DNS} ${PIHOLE_DIR}/${CUSTOM_DNS}.backup" create_sshcmd fi fi From ac8e6389983aec64643b5051efb085eb4c7489f3 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 11 Jul 2020 20:48:51 -0500 Subject: [PATCH 04/28] adjust md5 hash checking --- gravity-sync.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index bbc57ed..2a76be5 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -299,12 +299,14 @@ function pull_gs_reload { ## Pull Function function pull_gs { + previous_md5 md5_compare backup_settime pull_gs_grav pull_gs_cust pull_gs_reload + md5_recheck logs_export exit_withchange @@ -401,6 +403,7 @@ function push_gs_reload { ## Push Function function push_gs { + previous_md5 md5_compare intent_validate @@ -413,11 +416,7 @@ function push_gs { exit_withchange } -## Smart Sync Function -function smart_gs { - md5_compare - backup_settime - +function previous_md5 { if [ -f "${LOG_PATH}/${HISTORY_MD5}" ] then last_primaryDBMD5=$(sed "1q;d" ${LOG_PATH}/${HISTORY_MD5}) @@ -430,6 +429,13 @@ function smart_gs { last_primaryCLMD5="0" last_secondCLMD5="0" fi +} + +## Smart Sync Function +function smart_gs { + previous_md5 + md5_compare + backup_settime PRIDBCHANGE="0" SECDBCHANGE="0" @@ -1115,6 +1121,11 @@ function error_validate { ## Validate Sync Required function md5_compare { + # last_primaryDBMD5="0" + # last_secondDBMD5="0" + # last_primaryCLMD5="0" + # last_secondCLMD5="0" + HASHMARK='0' MESSAGE="Analyzing ${GRAVITY_FI} on ${REMOTE_HOST}" @@ -1127,7 +1138,7 @@ function md5_compare { secondDBMD5=$(md5sum ${PIHOLE_DIR}/${GRAVITY_FI} | sed 's/\s.*$//') error_validate - if [ "$primaryDBMD5" == "$secondDBMD5" ] + if [ "$primaryDBMD5" == "$last_primaryDBMD5" ] && [ "$secondDBMD5" == "$last_secondDBMD5" ] then HASHMARK=$((HASHMARK+0)) else @@ -1154,7 +1165,7 @@ function md5_compare { secondCLMD5=$(md5sum ${PIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//') error_validate - if [ "$primaryCLMD5" == "$secondCLMD5" ] + if [ "$primaryCLMD5" == "$last_primaryCLMD5" ] && [ "$secondCLMD5" == "$last_secondCLMD5" ] then # MESSAGE="${CUSTOM_DNS} Identical" # echo_info From 985ce623557bfcd76eaeb80fdbaeb3eb0cb70270 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 11 Jul 2020 20:50:59 -0500 Subject: [PATCH 05/28] settime --- gravity-sync.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gravity-sync.sh b/gravity-sync.sh index 2a76be5..0279805 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -405,6 +405,7 @@ function push_gs_reload { function push_gs { previous_md5 md5_compare + backup_settime intent_validate @@ -412,6 +413,7 @@ function push_gs { push_gs_cust push_gs_reload + md5_recheck logs_export exit_withchange } From 90ea491d9ec0f7d221632818ec0af5ef5af5bfed Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 11 Jul 2020 21:01:21 -0500 Subject: [PATCH 06/28] comment out warning on recheck --- gravity-sync.sh | 50 ++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 0279805..59e4dab 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1222,14 +1222,14 @@ function md5_recheck { secondDBMD5=$(md5sum ${PIHOLE_DIR}/${GRAVITY_FI} | sed 's/\s.*$//') error_validate - if [ "$primaryDBMD5" == "$secondDBMD5" ] - then - HASHMARK=$((HASHMARK+0)) - else - MESSAGE="Differenced ${GRAVITY_FI} Detected" - echo_warn - HASHMARK=$((HASHMARK+1)) - fi + # if [ "$primaryDBMD5" == "$secondDBMD5" ] + # then + # HASHMARK=$((HASHMARK+0)) + # else + # MESSAGE="Differenced ${GRAVITY_FI} Detected" + # echo_warn + # HASHMARK=$((HASHMARK+1)) + # fi if [ "$SKIP_CUSTOM" != '1' ] then @@ -1249,16 +1249,16 @@ function md5_recheck { secondCLMD5=$(md5sum ${PIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//') error_validate - if [ "$primaryCLMD5" == "$secondCLMD5" ] - then + # if [ "$primaryCLMD5" == "$secondCLMD5" ] + # then # MESSAGE="${CUSTOM_DNS} Identical" # echo_info - HASHMARK=$((HASHMARK+0)) - else - MESSAGE="Differenced ${CUSTOM_DNS} Detected" - echo_warn - HASHMARK=$((HASHMARK+1)) - fi + # HASHMARK=$((HASHMARK+0)) + # else + # MESSAGE="Differenced ${CUSTOM_DNS} Detected" + # echo_warn + # HASHMARK=$((HASHMARK+1)) + # fi else MESSAGE="No ${CUSTOM_DNS} Detected on ${REMOTE_HOST}" echo_info @@ -1268,7 +1268,7 @@ function md5_recheck { then REMOTE_CUSTOM_DNS="1" MESSAGE="${REMOTE_HOST} has ${CUSTOM_DNS}" - HASHMARK=$((HASHMARK+1)) + # HASHMARK=$((HASHMARK+1)) echo_info fi MESSAGE="No ${CUSTOM_DNS} Detected on $HOSTNAME" @@ -1276,14 +1276,14 @@ function md5_recheck { fi fi - if [ "$HASHMARK" != "0" ] - then - MESSAGE="Replication Checks Failed" - echo_warn - else - MESSAGE="Replication Was Successful" - echo_info - fi + # if [ "$HASHMARK" != "0" ] + # then + # MESSAGE="Replication Checks Failed" + # echo_warn + # else + # MESSAGE="Replication Was Successful" + # echo_info + # fi } ## Validate Intent From bc756641295f54a145423dcb876de8c64c6fabb0 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 11 Jul 2020 21:06:06 -0500 Subject: [PATCH 07/28] load previous md5 for compare --- gravity-sync.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 59e4dab..be52d0b 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1747,7 +1747,8 @@ function task_compare { validate_gs_folders validate_ph_folders validate_os_sshpass - + + previous_md5 md5_compare } From 8e78bca575299674791b64419ac80a69868ab01d Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 11 Jul 2020 21:12:21 -0500 Subject: [PATCH 08/28] beta updater --- gravity-sync.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index be52d0b..7e702f7 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -108,6 +108,9 @@ function update_gs { if [ -f "$HOME/${LOCAL_FOLDR}/dev" ] then BRANCH='development' + elif if [ -f "$HOME/${LOCAL_FOLDR}/beta" ] + then + BRANCH='beta' else BRANCH='master' fi @@ -1492,6 +1495,9 @@ function show_version { if [ -f $HOME/${LOCAL_FOLDR}/dev ] then DEVVERSION="dev" + elif [ -f $HOME/${LOCAL_FOLDR}/beta ] + then + DEVVERSION="beta" else DEVVERSION="" fi @@ -1513,8 +1519,6 @@ function show_version { fi echo_info echo -e "========================================================" - - dbclient_warning } function dbclient_warning { From ad1f758384af59e4c48bc42e8b27856c4afccb41 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 11 Jul 2020 21:15:01 -0500 Subject: [PATCH 09/28] if --- gravity-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 7e702f7..fd22e34 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -108,7 +108,7 @@ function update_gs { if [ -f "$HOME/${LOCAL_FOLDR}/dev" ] then BRANCH='development' - elif if [ -f "$HOME/${LOCAL_FOLDR}/beta" ] + elif [ -f "$HOME/${LOCAL_FOLDR}/beta" ] then BRANCH='beta' else From d4276042b5a8f31e97b98a0916eb2a59007e21e1 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sun, 12 Jul 2020 09:20:58 -0500 Subject: [PATCH 10/28] select different files for restore --- CHANGELOG.md | 1 + gravity-sync.sh | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a505a3..46e5ffb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ Skipping a few digits because what does it really matter? - Implements a new beta branch, and with it a new `./gravity-sync.sh beta` function to enable it. This will hopefully allow new features and such to be added for test users who can adopt them and provide feedback before rolling out to the main update branch. - Uses new SQLITE3 backup methodology introduced in 2.1, for all push/pull sync operations. +- `./gravity-sync.sh restore` lets you select a different `gravity.db` and `custom.list` for restoration. ## 2.0 ### The Smart Release diff --git a/gravity-sync.sh b/gravity-sync.sh index fd22e34..14c3609 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -565,18 +565,46 @@ function restore_gs { echo_info ls $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${GRAVITY_FI} | colrm 18 - MESSAGE="Enter the date you want to restore from" + MESSAGE="Enter the backup you want to restore ${GRAVITY_FI} from" echo_need read INPUT_BACKUP_DATE if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${GRAVITY_FI}.backup ] then - MESSAGE="Backup File Located" + MESSAGE="Backup File Selected" echo_info else - MESSAGE="Invalid Requested" + MESSAGE="Invalid Request" + echo_info fi + 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 + + MESSAGE="Enter the backup you want to restore ${CUSTOM_DNS} from" + echo_need + read INPUT_DNSBACKUP_DATE + + if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_DNSBACKUP_DATE}-${CUSTOM_DNS}.backup ] + then + MESSAGE="Backup File Selected" + echo_info + else + MESSAGE="Invalid Request" + echo_info + fi + fi + fi + + MESSAGE="${GRAVITY_FI} from ${INPUT_BACKUP_DATE} Selected" + echo_info + MESSAGE="${CUSTOM_DNS} from ${INPUT_DNSBACKUP_DATE} Selected" + echo_info + intent_validate MESSAGE="Stopping Pi-hole Services" @@ -630,11 +658,11 @@ function restore_gs { if [ "$SKIP_CUSTOM" != '1' ] then - if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${CUSTOM_DNS}.backup ] + if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_DNSBACKUP_DATE}-${CUSTOM_DNS}.backup ] then MESSAGE="Restoring ${CUSTOM_DNS} on $HOSTNAME" echo_stat - sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${CUSTOM_DNS}.backup ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1 + sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_DNSBACKUP_DATE}-${CUSTOM_DNS}.backup ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1 error_validate MESSAGE="Validating Ownership on ${CUSTOM_DNS}" From dd5e7a63b5db105169b34b767abb5948d7d0292a Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sun, 12 Jul 2020 09:24:45 -0500 Subject: [PATCH 11/28] star trek reference --- CHANGELOG.md | 1 + gravity-sync.sh | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46e5ffb..56abe28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ Skipping a few digits because what does it really matter? - Implements a new beta branch, and with it a new `./gravity-sync.sh beta` function to enable it. This will hopefully allow new features and such to be added for test users who can adopt them and provide feedback before rolling out to the main update branch. - Uses new SQLITE3 backup methodology introduced in 2.1, for all push/pull sync operations. - `./gravity-sync.sh restore` lets you select a different `gravity.db` and `custom.list` for restoration. +- One new Star Trek reference. ## 2.0 ### The Smart Release diff --git a/gravity-sync.sh b/gravity-sync.sh index 14c3609..bc7e85f 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -561,21 +561,22 @@ function restore_gs { MESSAGE="This will restore your settings on $HOSTNAME with a previous version!" echo_warn - MESSAGE="PREVIOUS BACKUPS" + MESSAGE="PREVIOUS BACKUPS AVAILABLE FOR RESTORATION" echo_info ls $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${GRAVITY_FI} | colrm 18 - MESSAGE="Enter the backup you want to restore ${GRAVITY_FI} from" + MESSAGE="Select backup date to restore ${GRAVITY_FI} from" echo_need read INPUT_BACKUP_DATE if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${GRAVITY_FI}.backup ] then MESSAGE="Backup File Selected" - echo_info else MESSAGE="Invalid Request" echo_info + + exit_nochange fi if [ "$SKIP_CUSTOM" != '1' ] @@ -585,17 +586,18 @@ function restore_gs { then ls $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${CUSTOM_DNS} | colrm 18 - MESSAGE="Enter the backup you want to restore ${CUSTOM_DNS} from" + MESSAGE="Select backup date to restore ${CUSTOM_DNS} from" echo_need read INPUT_DNSBACKUP_DATE if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_DNSBACKUP_DATE}-${CUSTOM_DNS}.backup ] then MESSAGE="Backup File Selected" - echo_info else MESSAGE="Invalid Request" echo_info + + exit_nochange fi fi fi @@ -607,6 +609,9 @@ function restore_gs { intent_validate + MESSAGE="Making Time Warp Calculations" + echo_info + MESSAGE="Stopping Pi-hole Services" echo_stat From e2acade06300165258c6a65f964ee8a490e21ff9 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sun, 12 Jul 2020 10:26:07 -0500 Subject: [PATCH 12/28] Log backup jobs --- CHANGELOG.md | 1 + gravity-sync.sh | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56abe28..94996e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ Skipping a few digits because what does it really matter? - Uses new SQLITE3 backup methodology introduced in 2.1, for all push/pull sync operations. - `./gravity-sync.sh restore` lets you select a different `gravity.db` and `custom.list` for restoration. - One new Star Trek reference. +- `./gravity-sync.sh restore` now shows recent complete Backup executions. ## 2.0 ### The Smart Release diff --git a/gravity-sync.sh b/gravity-sync.sh index bc7e85f..4632284 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -749,6 +749,9 @@ function restore_gs { ## Core Logging ### Write Logs Out function logs_export { + + if [ "${TASKTYPE}" != "BACKUP" ] + then MESSAGE="Saving File Hashes" echo_stat rm -f ${LOG_PATH}/${HISTORY_MD5} @@ -757,6 +760,7 @@ function logs_export { echo -e ${primaryCLMD5} >> ${LOG_PATH}/${HISTORY_MD5} echo -e ${secondCLMD5} >> ${LOG_PATH}/${HISTORY_MD5} error_validate + fi MESSAGE="Logging Successful ${TASKTYPE}" echo_stat @@ -778,6 +782,8 @@ function logs_gs { tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PULL echo -e "Recent Complete ${YELLOW}PUSH${NC} Executions" tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PUSH + echo -e "Recent Complete ${YELLOW}BACKUP${NC} Executions" + tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep BACKUP echo -e "Recent Complete ${YELLOW}RESTORE${NC} Executions" tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep RESTORE echo -e "========================================================" @@ -1814,6 +1820,7 @@ function task_backup { backup_local_custom backup_cleanup + logs_export exit_withchange } From fb23d48296e2973b36e144f67a567f41f47fab83 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sun, 12 Jul 2020 10:27:15 -0500 Subject: [PATCH 13/28] color restore --- gravity-sync.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 4632284..fbb4a63 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -602,9 +602,9 @@ function restore_gs { fi fi - MESSAGE="${GRAVITY_FI} from ${INPUT_BACKUP_DATE} Selected" + MESSAGE="${GRAVITY_FI} from ${CYAN}${INPUT_BACKUP_DATE}${NC} Selected" echo_info - MESSAGE="${CUSTOM_DNS} from ${INPUT_DNSBACKUP_DATE} Selected" + MESSAGE="${CUSTOM_DNS} from ${CYAN}${INPUT_DNSBACKUP_DATE}${NC} Selected" echo_info intent_validate From a994652b2bb4319d1c89bb89a01f3b6340eeeba1 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 11:37:06 -0500 Subject: [PATCH 14/28] ping avoid and custom ssh prompts --- ADVANCED.md | 4 ++-- CHANGELOG.md | 3 +++ VERSION | 2 +- gravity-sync.sh | 39 ++++++++++++++++++++++++++++++++++++--- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/ADVANCED.md b/ADVANCED.md index 3c63b5a..2f6d3ae 100644 --- a/ADVANCED.md +++ b/ADVANCED.md @@ -14,8 +14,8 @@ Download the latest release from [GitHub](https://github.com/vmstan/gravity-sync ```bash cd ~ -wget https://github.com/vmstan/gravity-sync/archive/v2.1.5.zip -unzip v2.1.5.zip -d gravity-sync +wget https://github.com/vmstan/gravity-sync/archive/v2.1.6.zip +unzip v2.1.6.zip -d gravity-sync cd gravity-sync ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index 94996e4..2c1ec65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,9 @@ Skipping a few digits because what does it really matter? - One new Star Trek reference. - `./gravity-sync.sh restore` now shows recent complete Backup executions. +#### 2.1.6 +- Adds prompts during `./gravity-sync.sh configure` to allow custom SSH port and enable PING avoidance. + ## 2.0 ### The Smart Release diff --git a/VERSION b/VERSION index c5864dc..b6da512 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.5 \ No newline at end of file +2.1.6 \ No newline at end of file diff --git a/gravity-sync.sh b/gravity-sync.sh index fbb4a63..8c8afed 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -3,7 +3,7 @@ SCRIPT_START=$SECONDS # GRAVITY SYNC BY VMSTAN ##################### PROGRAM='Gravity Sync' -VERSION='2.1.5' +VERSION='2.1.6' # 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 @@ -602,9 +602,9 @@ function restore_gs { fi fi - MESSAGE="${GRAVITY_FI} from ${CYAN}${INPUT_BACKUP_DATE}${NC} Selected" + MESSAGE="${GRAVITY_FI} from ${INPUT_BACKUP_DATE} Selected" echo_info - MESSAGE="${CUSTOM_DNS} from ${CYAN}${INPUT_DNSBACKUP_DATE}${NC} Selected" + MESSAGE="${CUSTOM_DNS} from ${INPUT_DNSBACKUP_DATE} Selected" echo_info intent_validate @@ -1373,13 +1373,46 @@ function config_generate { echo_stat cp $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}.example $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} error_validate + + MESSAGE="Environment Customization" + echo_info + + MESSAGE="Are you using a custom SSH Port? (Leave blank for default '22')" + echo_need + read INPUT_SSH_PORT + + if [ "${INPUT_SSH_PORT}" != "" ] || [ "${INPUT_SSH_PORT}" != "22" ] + 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 + + if [ "${INPUT_PING_AVOID}" != "" ] || [ "${INPUT_PING_AVOID}" != "Yes" ] || [ "${INPUT_PING_AVOID}" != "yes" ] || [ "${INPUT_PING_AVOID}" != "Y" ] || [ "${INPUT_PING_AVOID}" != "y" ] + 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 + MESSAGE="Standard Settings" + echo_info + MESSAGE="IP or DNS of Primary Pi-hole" echo_need read INPUT_REMOTE_HOST if [ "${PING_AVOID}" != "1" ] then + + MESSAGE="Testing Network Connection (PING)" echo_stat ping -c 3 ${INPUT_REMOTE_HOST} >/dev/null 2>&1 From 1092db143e1765a45742a623dd261c04f0d457af Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 11:44:20 -0500 Subject: [PATCH 15/28] z variable --- gravity-sync.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 8c8afed..438ddc0 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1377,11 +1377,11 @@ function config_generate { MESSAGE="Environment Customization" echo_info - MESSAGE="Are you using a custom SSH Port? (Leave blank for default '22')" + MESSAGE="Enter a custom SSH port if required (Leave blank for default '22')" echo_need read INPUT_SSH_PORT - if [ "${INPUT_SSH_PORT}" != "" ] || [ "${INPUT_SSH_PORT}" != "22" ] + if [ -z "${INPUT_SSH_PORT}" ] || [ "${INPUT_SSH_PORT}" != "22" ] then MESSAGE="Saving Custom SSH Port to ${CONFIG_FILE}" echo_stat @@ -1393,7 +1393,7 @@ function config_generate { echo_need read INPUT_PING_AVOID - if [ "${INPUT_PING_AVOID}" != "" ] || [ "${INPUT_PING_AVOID}" != "Yes" ] || [ "${INPUT_PING_AVOID}" != "yes" ] || [ "${INPUT_PING_AVOID}" != "Y" ] || [ "${INPUT_PING_AVOID}" != "y" ] + if [ -z "${INPUT_PING_AVOID}" ] || [ "${INPUT_PING_AVOID}" != "Yes" ] || [ "${INPUT_PING_AVOID}" != "yes" ] || [ "${INPUT_PING_AVOID}" != "Y" ] || [ "${INPUT_PING_AVOID}" != "y" ] then MESSAGE="Saving Ping Avoidance to ${CONFIG_FILE}" echo_stat From 719d2bf0777c1dba3b0f6f4f87cb38f455e4afee Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 11:49:12 -0500 Subject: [PATCH 16/28] or --- gravity-sync.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 438ddc0..7368896 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1381,7 +1381,7 @@ function config_generate { echo_need read INPUT_SSH_PORT - if [ -z "${INPUT_SSH_PORT}" ] || [ "${INPUT_SSH_PORT}" != "22" ] + if [[ -z "${INPUT_SSH_PORT}" || "${INPUT_SSH_PORT}" != "22" ]] then MESSAGE="Saving Custom SSH Port to ${CONFIG_FILE}" echo_stat @@ -1393,7 +1393,7 @@ function config_generate { echo_need read INPUT_PING_AVOID - if [ -z "${INPUT_PING_AVOID}" ] || [ "${INPUT_PING_AVOID}" != "Yes" ] || [ "${INPUT_PING_AVOID}" != "yes" ] || [ "${INPUT_PING_AVOID}" != "Y" ] || [ "${INPUT_PING_AVOID}" != "y" ] + if [[ -z "${INPUT_PING_AVOID}" || [ "${INPUT_PING_AVOID}" != "Yes" || "${INPUT_PING_AVOID}" != "yes" || "${INPUT_PING_AVOID}" != "Y" || [ "${INPUT_PING_AVOID}" != "y" ]] then MESSAGE="Saving Ping Avoidance to ${CONFIG_FILE}" echo_stat From 86805ab02dd4f658a0b3593e5c3b090c8939d8c5 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 11:50:45 -0500 Subject: [PATCH 17/28] [] --- gravity-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 7368896..3c4b746 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1393,7 +1393,7 @@ function config_generate { echo_need read INPUT_PING_AVOID - if [[ -z "${INPUT_PING_AVOID}" || [ "${INPUT_PING_AVOID}" != "Yes" || "${INPUT_PING_AVOID}" != "yes" || "${INPUT_PING_AVOID}" != "Y" || [ "${INPUT_PING_AVOID}" != "y" ]] + if [[ -z "${INPUT_PING_AVOID}" || "${INPUT_PING_AVOID}" != "Yes" || "${INPUT_PING_AVOID}" != "yes" || "${INPUT_PING_AVOID}" != "Y" || "${INPUT_PING_AVOID}" != "y" ]] then MESSAGE="Saving Ping Avoidance to ${CONFIG_FILE}" echo_stat From c73b3c9dfc0aafc26f06952a1e712aba12716d4f Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 11:57:02 -0500 Subject: [PATCH 18/28] new method for defaults --- gravity-sync.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 3c4b746..5a5add2 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1380,8 +1380,9 @@ function config_generate { MESSAGE="Enter a custom SSH port if required (Leave blank for default '22')" echo_need read INPUT_SSH_PORT + INPUT_SSH_PORT="${INPUT_SSH_PORT:-22}" - if [[ -z "${INPUT_SSH_PORT}" || "${INPUT_SSH_PORT}" != "22" ]] + if [ "${INPUT_SSH_PORT}" != "22" ] then MESSAGE="Saving Custom SSH Port to ${CONFIG_FILE}" echo_stat @@ -1392,8 +1393,9 @@ function config_generate { MESSAGE="Perform PING tests between Pi-holes? (Leave blank for default 'Yes')" echo_need read INPUT_PING_AVOID + INPUT_SSH_PORT="${INPUT_SSH_PORT:-Y}" - if [[ -z "${INPUT_PING_AVOID}" || "${INPUT_PING_AVOID}" != "Yes" || "${INPUT_PING_AVOID}" != "yes" || "${INPUT_PING_AVOID}" != "Y" || "${INPUT_PING_AVOID}" != "y" ]] + if [[ "${INPUT_PING_AVOID}" != "Yes" || "${INPUT_PING_AVOID}" != "yes" || "${INPUT_PING_AVOID}" != "Y" || "${INPUT_PING_AVOID}" != "y" ]] then MESSAGE="Saving Ping Avoidance to ${CONFIG_FILE}" echo_stat From 8c5dadb5601aca0aa2ccda1eb031e97407a66506 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 11:59:02 -0500 Subject: [PATCH 19/28] variables matter --- gravity-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 5a5add2..e22d4b8 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1393,7 +1393,7 @@ function config_generate { MESSAGE="Perform PING tests between Pi-holes? (Leave blank for default 'Yes')" echo_need read INPUT_PING_AVOID - INPUT_SSH_PORT="${INPUT_SSH_PORT:-Y}" + INPUT_PING_AVOID="${INPUT_PING_AVOID:-Y}" if [[ "${INPUT_PING_AVOID}" != "Yes" || "${INPUT_PING_AVOID}" != "yes" || "${INPUT_PING_AVOID}" != "Y" || "${INPUT_PING_AVOID}" != "y" ]] then From 2d7fa277ad6c6cc3c266c878ee23f87766ad5753 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 12:02:48 -0500 Subject: [PATCH 20/28] or this? --- gravity-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index e22d4b8..47ec631 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1395,7 +1395,7 @@ function config_generate { read INPUT_PING_AVOID INPUT_PING_AVOID="${INPUT_PING_AVOID:-Y}" - if [[ "${INPUT_PING_AVOID}" != "Yes" || "${INPUT_PING_AVOID}" != "yes" || "${INPUT_PING_AVOID}" != "Y" || "${INPUT_PING_AVOID}" != "y" ]] + if [ "${INPUT_PING_AVOID}" != "Yes" ] || [ "${INPUT_PING_AVOID}" != "yes" ] || [ "${INPUT_PING_AVOID}" != "Y" ] || [ "${INPUT_PING_AVOID}" != "y" ] then MESSAGE="Saving Ping Avoidance to ${CONFIG_FILE}" echo_stat From 70da7aad1470d8d0375fb33d215eebbf2e3d198c Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 12:04:34 -0500 Subject: [PATCH 21/28] making it specific --- gravity-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 47ec631..06bf34a 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1395,7 +1395,7 @@ function config_generate { read INPUT_PING_AVOID INPUT_PING_AVOID="${INPUT_PING_AVOID:-Y}" - if [ "${INPUT_PING_AVOID}" != "Yes" ] || [ "${INPUT_PING_AVOID}" != "yes" ] || [ "${INPUT_PING_AVOID}" != "Y" ] || [ "${INPUT_PING_AVOID}" != "y" ] + if [ "${INPUT_PING_AVOID}" != "Y" ] then MESSAGE="Saving Ping Avoidance to ${CONFIG_FILE}" echo_stat From 6cb842a12bd11f6ce037f47ac637b6f68f75dddf Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 12:25:07 -0500 Subject: [PATCH 22/28] 2.1.6 beta 1 (#65) * select different files for restore * star trek reference * Log backup jobs * color restore * ping avoid and custom ssh prompts * z variable * or * [] * new method for defaults * variables matter * or this? * making it specific Co-authored-by: Michael Stanclift --- ADVANCED.md | 4 +-- CHANGELOG.md | 6 ++++ VERSION | 2 +- gravity-sync.sh | 91 ++++++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 92 insertions(+), 11 deletions(-) diff --git a/ADVANCED.md b/ADVANCED.md index 3c63b5a..2f6d3ae 100644 --- a/ADVANCED.md +++ b/ADVANCED.md @@ -14,8 +14,8 @@ Download the latest release from [GitHub](https://github.com/vmstan/gravity-sync ```bash cd ~ -wget https://github.com/vmstan/gravity-sync/archive/v2.1.5.zip -unzip v2.1.5.zip -d gravity-sync +wget https://github.com/vmstan/gravity-sync/archive/v2.1.6.zip +unzip v2.1.6.zip -d gravity-sync cd gravity-sync ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a505a3..2c1ec65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,12 @@ Skipping a few digits because what does it really matter? - Implements a new beta branch, and with it a new `./gravity-sync.sh beta` function to enable it. This will hopefully allow new features and such to be added for test users who can adopt them and provide feedback before rolling out to the main update branch. - Uses new SQLITE3 backup methodology introduced in 2.1, for all push/pull sync operations. +- `./gravity-sync.sh restore` lets you select a different `gravity.db` and `custom.list` for restoration. +- One new Star Trek reference. +- `./gravity-sync.sh restore` now shows recent complete Backup executions. + +#### 2.1.6 +- Adds prompts during `./gravity-sync.sh configure` to allow custom SSH port and enable PING avoidance. ## 2.0 ### The Smart Release diff --git a/VERSION b/VERSION index c5864dc..b6da512 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.5 \ No newline at end of file +2.1.6 \ No newline at end of file diff --git a/gravity-sync.sh b/gravity-sync.sh index fd22e34..06bf34a 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -3,7 +3,7 @@ SCRIPT_START=$SECONDS # GRAVITY SYNC BY VMSTAN ##################### PROGRAM='Gravity Sync' -VERSION='2.1.5' +VERSION='2.1.6' # 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 @@ -561,24 +561,57 @@ function restore_gs { MESSAGE="This will restore your settings on $HOSTNAME with a previous version!" echo_warn - MESSAGE="PREVIOUS BACKUPS" + MESSAGE="PREVIOUS BACKUPS AVAILABLE FOR RESTORATION" echo_info ls $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD} | grep $(date +%Y) | grep ${GRAVITY_FI} | colrm 18 - MESSAGE="Enter the date you want to restore from" + MESSAGE="Select backup date to restore ${GRAVITY_FI} from" echo_need read INPUT_BACKUP_DATE if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${GRAVITY_FI}.backup ] then - MESSAGE="Backup File Located" - echo_info + MESSAGE="Backup File Selected" else - MESSAGE="Invalid Requested" + MESSAGE="Invalid Request" + echo_info + + exit_nochange fi + 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 + + MESSAGE="Select backup date to restore ${CUSTOM_DNS} from" + 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 + + exit_nochange + fi + fi + fi + + MESSAGE="${GRAVITY_FI} from ${INPUT_BACKUP_DATE} Selected" + echo_info + MESSAGE="${CUSTOM_DNS} from ${INPUT_DNSBACKUP_DATE} Selected" + echo_info + intent_validate + MESSAGE="Making Time Warp Calculations" + echo_info + MESSAGE="Stopping Pi-hole Services" echo_stat @@ -630,11 +663,11 @@ function restore_gs { if [ "$SKIP_CUSTOM" != '1' ] then - if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${CUSTOM_DNS}.backup ] + if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_DNSBACKUP_DATE}-${CUSTOM_DNS}.backup ] then MESSAGE="Restoring ${CUSTOM_DNS} on $HOSTNAME" echo_stat - sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_BACKUP_DATE}-${CUSTOM_DNS}.backup ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1 + sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${INPUT_DNSBACKUP_DATE}-${CUSTOM_DNS}.backup ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1 error_validate MESSAGE="Validating Ownership on ${CUSTOM_DNS}" @@ -716,6 +749,9 @@ function restore_gs { ## Core Logging ### Write Logs Out function logs_export { + + if [ "${TASKTYPE}" != "BACKUP" ] + then MESSAGE="Saving File Hashes" echo_stat rm -f ${LOG_PATH}/${HISTORY_MD5} @@ -724,6 +760,7 @@ function logs_export { echo -e ${primaryCLMD5} >> ${LOG_PATH}/${HISTORY_MD5} echo -e ${secondCLMD5} >> ${LOG_PATH}/${HISTORY_MD5} error_validate + fi MESSAGE="Logging Successful ${TASKTYPE}" echo_stat @@ -745,6 +782,8 @@ function logs_gs { tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PULL echo -e "Recent Complete ${YELLOW}PUSH${NC} Executions" tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep PUSH + echo -e "Recent Complete ${YELLOW}BACKUP${NC} Executions" + tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep BACKUP echo -e "Recent Complete ${YELLOW}RESTORE${NC} Executions" tail -n 7 "${LOG_PATH}/${SYNCING_LOG}" | grep RESTORE echo -e "========================================================" @@ -1334,13 +1373,48 @@ function config_generate { echo_stat cp $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}.example $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} error_validate + + MESSAGE="Environment Customization" + echo_info + + MESSAGE="Enter a custom SSH port if required (Leave blank for default '22')" + echo_need + read INPUT_SSH_PORT + INPUT_SSH_PORT="${INPUT_SSH_PORT:-22}" + + if [ "${INPUT_SSH_PORT}" != "22" ] + 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 + INPUT_PING_AVOID="${INPUT_PING_AVOID:-Y}" + + if [ "${INPUT_PING_AVOID}" != "Y" ] + 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 + MESSAGE="Standard Settings" + echo_info + MESSAGE="IP or DNS of Primary Pi-hole" echo_need read INPUT_REMOTE_HOST if [ "${PING_AVOID}" != "1" ] then + + MESSAGE="Testing Network Connection (PING)" echo_stat ping -c 3 ${INPUT_REMOTE_HOST} >/dev/null 2>&1 @@ -1781,6 +1855,7 @@ function task_backup { backup_local_custom backup_cleanup + logs_export exit_withchange } From f6cdbc40ec9d60c3352cf5af74847a05597877c3 Mon Sep 17 00:00:00 2001 From: fbourqui Date: Thu, 16 Jul 2020 20:09:44 +0200 Subject: [PATCH 23/28] adv conf: add ROOT_CHECK_AVOID for container. (#64) * adv conf: add ROOT_CHECK_AVOID for container. import_gs only once at start * allow parameters for automation option Co-authored-by: Michael Stanclift --- ADVANCED.md | 18 ++++++++++- gravity-sync.conf.example | 1 + gravity-sync.sh | 65 ++++++++++++++++++++++++++------------- 3 files changed, 61 insertions(+), 23 deletions(-) diff --git a/ADVANCED.md b/ADVANCED.md index 2f6d3ae..e6d9374 100644 --- a/ADVANCED.md +++ b/ADVANCED.md @@ -169,6 +169,11 @@ The `./gravity-sync.sh config` function will attempt to ping the remote host to Default setting in Gravity Sync is 0, change to 1 to skip this network test. +#### `ROOT_CHECK_AVOID=''` +The `./gravity-sync.sh` check that it's deployed with it's own user, but for container deployment it's a nuisance, to install a user and gave it passwordless sudo power, witch result with the same security risk as running as root. + +Default setting in Gravity Sync is 0, change to 1 to skip this root user test. + #### `BACKUP_RETAIN=''` The `./gravity-sync.sh backup` function will retain a defined number of days worth of `gravity.db` and `custom.list` backups. @@ -212,11 +217,22 @@ If your code is still not updating after this, reinstallation is suggested rathe ## Automation There are many automation methods available to run scripts on a regular basis of a Linux system. The one built into all of them is cron, but if you'd like to utilize something different then the principles are still the same. +To automate the deployment of automation option, you can call it with 2 parameters: +first interval in minutes to run sync [0-30], +then the hour to run backup [0-24] +Note: 0 will disable the cron entry. + +for example: +gravity-sync.sh automate 15 23 + +will sync every 15 minutes and backup at 23:00. + If you prefer to still use cron but modify your settings by hand, using the entry below will cause the entry to run at the top and bottom of every hour (1:00 PM, 1:30 PM, 2:00 PM, etc) but you are free to dial this back or be more agressive if you feel the need. ```bash crontab -e -*/30 * * * * /bin/bash /home/USER/gravity-sync/gravity-sync.sh > /home/USER/gravity-sync/gravity-sync.cron +*/15 * * * * /bin/bash /home/USER/gravity-sync/gravity-sync.sh > /home/USER/gravity-sync/gravity-sync.cron +0 23 * * * /bin/bash /home/USER//gravity-sync/gravity-sync.sh backup >/dev/null 2>&1 ``` ## Reference Architectures diff --git a/gravity-sync.conf.example b/gravity-sync.conf.example index 1e55653..c340201 100644 --- a/gravity-sync.conf.example +++ b/gravity-sync.conf.example @@ -33,5 +33,6 @@ REMOTE_PASS='' # SKIP_CUSTOM='' # DATE_OUTPUT='' # PING_AVOID='' +# ROOT_CHECK_AVOID='' # BACKUP_RETAIN='' \ No newline at end of file diff --git a/gravity-sync.sh b/gravity-sync.sh index 06bf34a..18d1c4c 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -31,6 +31,7 @@ VERIFY_PASS='0' # replace in gravity-sync.conf to overwrite SKIP_CUSTOM='0' # replace in gravity-sync.conf to overwrite DATE_OUTPUT='0' # replace in gravity-sync.conf to overwrite PING_AVOID='0' # replace in gravity-sync.conf to overwrite +ROOT_CHECK_AVOID='0' # replace in gravity-sync.conf to overwrite # Backup Customization BACKUP_RETAIN='7' # replace in gravity-sync.conf to overwrite @@ -770,7 +771,6 @@ function logs_export { ### Output Sync Logs function logs_gs { - import_gs MESSAGE="Tailing ${LOG_PATH}/${SYNCING_LOG}" echo_info @@ -794,7 +794,6 @@ function logs_gs { ## Crontab Logs ### Core Crontab Logs function show_crontab { - import_gs MESSAGE="Replaying Last Cronjob" echo_stat @@ -1610,8 +1609,6 @@ function task_automate { MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good - import_gs - CRON_EXIST='0' CRON_CHECK=$(crontab -l | grep -q "${GS_FILENAME}" && echo '1' || echo '0') if [ ${CRON_CHECK} == 1 ] @@ -1624,9 +1621,14 @@ function task_automate { MESSAGE="Configuring Hourly Smart Sync" echo_info - MESSAGE="Sync Frequency in Minutes (1-30) or 0 to Disable" - echo_need - read INPUT_AUTO_FREQ + 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 if [ $INPUT_AUTO_FREQ -gt 30 ] then @@ -1660,9 +1662,14 @@ function task_automate { MESSAGE="Configuring Daily Backup Frequency" echo_info - MESSAGE="Hour of Day to Backup (1-24) or 0 to Disable" - echo_need - read INPUT_AUTO_BACKUP + 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 if [ $INPUT_AUTO_BACKUP -gt 24 ] then @@ -1820,8 +1827,7 @@ function task_compare { TASKTYPE='COMPARE' MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good - - import_gs + validate_gs_folders validate_ph_folders validate_os_sshpass @@ -1970,8 +1976,11 @@ function root_check { MESSAGE="Evaluating Arguments" echo_stat - - root_check + import_gs + if [ "${ROOT_CHECK_AVOID}" != "1" ] + then + root_check + fi case $# in @@ -1980,7 +1989,6 @@ case $# in MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good - import_gs validate_gs_folders validate_ph_folders validate_os_sshpass @@ -1996,7 +2004,6 @@ case $# in MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good - import_gs validate_gs_folders validate_ph_folders validate_os_sshpass @@ -2010,7 +2017,6 @@ case $# in MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good - import_gs validate_gs_folders validate_ph_folders validate_os_sshpass @@ -2023,8 +2029,7 @@ case $# in TASKTYPE='PULL' MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good - - import_gs + validate_gs_folders validate_ph_folders validate_os_sshpass @@ -2037,8 +2042,7 @@ case $# in TASKTYPE='PUSH' MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good - - import_gs + validate_gs_folders validate_ph_folders validate_os_sshpass @@ -2052,7 +2056,6 @@ case $# in MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good - import_gs validate_gs_folders validate_ph_folders @@ -2125,6 +2128,24 @@ case $# in ;; esac ;; + + 2) + case $1 in + automate) + task_automate + ;; + + esac + ;; + + 3) + case $1 in + automate) + task_automate $2 $3 + ;; + + esac + ;; *) task_invalid From 9a8e49f07c8d644d4fd6efa28a53627104fb6e0a Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 13:15:38 -0500 Subject: [PATCH 24/28] Post PR cleanup --- ADVANCED.md | 25 ++++++++++++++----------- CHANGELOG.md | 2 ++ gravity-sync.sh | 2 ++ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/ADVANCED.md b/ADVANCED.md index e6d9374..ca4a138 100644 --- a/ADVANCED.md +++ b/ADVANCED.md @@ -170,7 +170,7 @@ The `./gravity-sync.sh config` function will attempt to ping the remote host to Default setting in Gravity Sync is 0, change to 1 to skip this network test. #### `ROOT_CHECK_AVOID=''` -The `./gravity-sync.sh` check that it's deployed with it's own user, but for container deployment it's a nuisance, to install a user and gave it passwordless sudo power, witch result with the same security risk as running as root. +At execution, Gravity Sync will check that it's deployed with it's own user (not running as root), but for a container deployment this is not necessary. Default setting in Gravity Sync is 0, change to 1 to skip this root user test. @@ -217,16 +217,6 @@ If your code is still not updating after this, reinstallation is suggested rathe ## Automation There are many automation methods available to run scripts on a regular basis of a Linux system. The one built into all of them is cron, but if you'd like to utilize something different then the principles are still the same. -To automate the deployment of automation option, you can call it with 2 parameters: -first interval in minutes to run sync [0-30], -then the hour to run backup [0-24] -Note: 0 will disable the cron entry. - -for example: -gravity-sync.sh automate 15 23 - -will sync every 15 minutes and backup at 23:00. - If you prefer to still use cron but modify your settings by hand, using the entry below will cause the entry to run at the top and bottom of every hour (1:00 PM, 1:30 PM, 2:00 PM, etc) but you are free to dial this back or be more agressive if you feel the need. ```bash @@ -235,6 +225,19 @@ crontab -e 0 23 * * * /bin/bash /home/USER//gravity-sync/gravity-sync.sh backup >/dev/null 2>&1 ``` +### Automating Automation + +To automate the deployment of automation option you can call it with 2 parameters: +- First interval in minutes to run sync [0-30], +- Second the hour to run backup [0-24] + +(0 will disable the cron entry) + +For example: +`./gravity-sync.sh automate 15 23` + +Will configure automation of the sync function every 15 minutes and of a backup at 23:00. + ## Reference Architectures The designation of primary and secondary is purely at your discretion. The doesn't matter if you're using an HA process like keepalived to present a single DNS IP address to clients, or handing out two DNS resolvers via DHCP. Generally it is expected that the two (or more) Pi-hole(s) will be at the same phyiscal location, or at least on the same internal networks. It should also be possible to to replicate to a secondary Pi-hole across networks, either over a VPN or open-Internet, with the approprate firewall/NAT configuration. diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c1ec65..26ab0b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,8 @@ Skipping a few digits because what does it really matter? #### 2.1.6 - Adds prompts during `./gravity-sync.sh configure` to allow custom SSH port and enable PING avoidance. +- Adds `ROOT_CHECK_AVOID` variable to advanced configuration options, to help facilitate running Gravity Sync with container installations of Pi-hole. (PR [#64](https://github.com/vmstan/gravity-sync/pull/64)) +- Adds ## 2.0 ### The Smart Release diff --git a/gravity-sync.sh b/gravity-sync.sh index 18d1c4c..1d5f0e1 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1976,7 +1976,9 @@ function root_check { MESSAGE="Evaluating Arguments" echo_stat + import_gs + if [ "${ROOT_CHECK_AVOID}" != "1" ] then root_check From 5fc12be73b83419fdce5c5d714706556d6ee9643 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 13:18:51 -0500 Subject: [PATCH 25/28] Thanks for fbourqui --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26ab0b3..405ebe8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,9 @@ Skipping a few digits because what does it really matter? #### 2.1.6 - Adds prompts during `./gravity-sync.sh configure` to allow custom SSH port and enable PING avoidance. - Adds `ROOT_CHECK_AVOID` variable to advanced configuration options, to help facilitate running Gravity Sync with container installations of Pi-hole. (PR [#64](https://github.com/vmstan/gravity-sync/pull/64)) -- Adds +- Adds the ability to automate automation. :mind_blown_emoji: Please see the ADVANCED.md document for more information. (PR [#64](https://github.com/vmstan/gravity-sync/pull/64)) + +(Thanks to [@fbourqui](https://github.com/fbourqui) for this contributions to this release.) ## 2.0 ### The Smart Release From 606336377394b3143799f3de4878a8dfbf4aaf9b Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 13:37:27 -0500 Subject: [PATCH 26/28] readjusts import_gs --- gravity-sync.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 1d5f0e1..9b5f4e5 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -771,6 +771,7 @@ function logs_export { ### Output Sync Logs function logs_gs { + import_gs MESSAGE="Tailing ${LOG_PATH}/${SYNCING_LOG}" echo_info @@ -794,6 +795,7 @@ function logs_gs { ## Crontab Logs ### Core Crontab Logs function show_crontab { + import_gs MESSAGE="Replaying Last Cronjob" echo_stat @@ -1609,6 +1611,8 @@ function task_automate { MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good + import_gs + CRON_EXIST='0' CRON_CHECK=$(crontab -l | grep -q "${GS_FILENAME}" && echo '1' || echo '0') if [ ${CRON_CHECK} == 1 ] @@ -1828,6 +1832,8 @@ function task_compare { MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good + import_gs + validate_gs_folders validate_ph_folders validate_os_sshpass @@ -1976,8 +1982,6 @@ function root_check { MESSAGE="Evaluating Arguments" echo_stat - - import_gs if [ "${ROOT_CHECK_AVOID}" != "1" ] then @@ -1991,6 +1995,7 @@ case $# in MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good + import_gs validate_gs_folders validate_ph_folders validate_os_sshpass @@ -2006,6 +2011,7 @@ case $# in MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good + import_gs validate_gs_folders validate_ph_folders validate_os_sshpass @@ -2019,6 +2025,7 @@ case $# in MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good + import_gs validate_gs_folders validate_ph_folders validate_os_sshpass @@ -2032,6 +2039,7 @@ case $# in MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good + import_gs validate_gs_folders validate_ph_folders validate_os_sshpass @@ -2045,6 +2053,7 @@ case $# in MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good + import_gs validate_gs_folders validate_ph_folders validate_os_sshpass @@ -2058,6 +2067,7 @@ case $# in MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" echo_good + import_gs validate_gs_folders validate_ph_folders From b0f1c6d4c77c2d9d7a6ab5cc928c393843360b05 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 13:55:22 -0500 Subject: [PATCH 27/28] advanced md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 405ebe8..0211e67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,7 @@ Skipping a few digits because what does it really matter? #### 2.1.6 - Adds prompts during `./gravity-sync.sh configure` to allow custom SSH port and enable PING avoidance. - Adds `ROOT_CHECK_AVOID` variable to advanced configuration options, to help facilitate running Gravity Sync with container installations of Pi-hole. (PR [#64](https://github.com/vmstan/gravity-sync/pull/64)) -- Adds the ability to automate automation. :mind_blown_emoji: Please see the ADVANCED.md document for more information. (PR [#64](https://github.com/vmstan/gravity-sync/pull/64)) +- Adds the ability to automate automation. :mind_blown_emoji: Please see the [ADVANCED.md](https://github.com/vmstan/gravity-sync/blob/master/ADVANCED.md) document for more information. (PR [#64](https://github.com/vmstan/gravity-sync/pull/64)) (Thanks to [@fbourqui](https://github.com/fbourqui) for this contributions to this release.) From 1afc7cd521a41b20c247cffa79cd4ed47c085c25 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Thu, 16 Jul 2020 22:02:46 -0500 Subject: [PATCH 28/28] rebase --- ADVANCED.md | 4 ++-- CHANGELOG.md | 3 +++ VERSION | 2 +- gravity-sync.sh | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ADVANCED.md b/ADVANCED.md index ca4a138..2cc369c 100644 --- a/ADVANCED.md +++ b/ADVANCED.md @@ -14,8 +14,8 @@ Download the latest release from [GitHub](https://github.com/vmstan/gravity-sync ```bash cd ~ -wget https://github.com/vmstan/gravity-sync/archive/v2.1.6.zip -unzip v2.1.6.zip -d gravity-sync +wget https://github.com/vmstan/gravity-sync/archive/v2.1.7.zip +unzip v2.1.7.zip -d gravity-sync cd gravity-sync ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index 0211e67..cc456ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,9 @@ Skipping a few digits because what does it really matter? (Thanks to [@fbourqui](https://github.com/fbourqui) for this contributions to this release.) +#### 2.1.7 +- Git Rebase + ## 2.0 ### The Smart Release diff --git a/VERSION b/VERSION index b6da512..9671f9a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.6 \ No newline at end of file +2.1.7 \ No newline at end of file diff --git a/gravity-sync.sh b/gravity-sync.sh index 9b5f4e5..bace2f8 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -3,7 +3,7 @@ SCRIPT_START=$SECONDS # GRAVITY SYNC BY VMSTAN ##################### PROGRAM='Gravity Sync' -VERSION='2.1.6' +VERSION='2.1.7' # 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