From 75252a83f42dcd0ab77fe5bf8b64008246425c43 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 11:39:12 -0500 Subject: [PATCH 01/41] Polarity reversed. --- CHANGELOG.md | 78 +++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e488354..b043d76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,11 @@ **Known Issues** - No new Star Trek references. -#### 1.7.1 -- There is a changelog file now. I'm mentioning it in the changelog file. So meta. -- `./gravity-sync.sh version` will check for and alert you for new versions. +#### 1.7.4 +- Changelog polarity reversed. + +#### 1.7.3 +- Cleaning up output of argument listing #### 1.7.2 This update changes the way that beta/development updates are applied. To continue receving the development branch, create an empty file in the `gravity-sync` folder called `dev` and afterwards the standard `./gravity-sync.sh update` function will apply the correct updates. @@ -27,8 +29,9 @@ Delete the `dev` file and update again to revert back to the stable/master branc **Deprecation** - Removes `beta` function for applying development branch updates. -#### 1.7.3 -- Cleaning up output of argument listing +#### 1.7.1 +- There is a changelog file now. I'm mentioning it in the changelog file. So meta. +- `./gravity-sync.sh version` will check for and alert you for new versions. ## 1.6 ### The Restorative Release @@ -64,14 +67,14 @@ Delete the `dev` file and update again to revert back to the stable/master branc - All new and exciting code comments. - No new Star Trek references. -#### 1.4.1 -- Adds variables for custom log locations to `gravity-sync.conf`, see `.example` file for listing. +#### 1.4.3 +- Bug fixes around not properly utilizing custom SSH keyfile. #### 1.4.2 - Will prompt to create new `gravity-sync.conf` file when run without an existing configuration. -#### 1.4.3 -- Bug fixes around not properly utilizing custom SSH keyfile. +#### 1.4.1 +- Adds variables for custom log locations to `gravity-sync.conf`, see `.example` file for listing. ## 1.3 ### The Comparison Release @@ -83,21 +86,22 @@ Delete the `dev` file and update again to revert back to the stable/master branc - Additional debugging options such as checking last cronjob output via `./gravity-sync.sh cron` if configured. - Much more consistency in how running commands are processed in interactive mode. +#### 1.3.4 +- Moves backup of local database before initiating remote pull. +- Validates file ownership and permissions before attempting to rewrite. +- Added two Star Trek references. + +#### 1.3.3 +- Corrected Pihole bin path issue that cause automated sync not to reload services. + +#### 1.3.2 +- MUCH cleaner output, same great features. + #### 1.3.1 - Changes [GOOD] to [DONE] in execution output. - Better validation of initial SSH connection. - Support for password based authentication using SSHPASS. -#### 1.3.2 -- MUCH cleaner output, same great features. - -#### 1.3.3 -- Corrected Pihole bin path issue that cause automated sync not to reload services. - -#### 1.3.4 -- Moves backup of local database before initiating remote pull. -- Validates file ownership and permissions before attempting to rewrite. -- Added two Star Trek references. ## 1.2 ### The Functional Release @@ -105,23 +109,23 @@ Delete the `dev` file and update again to revert back to the stable/master branc - Does not look for permission to update when run. - Cleanup and expand comments. -#### 1.2.1 -- Improved logging functions. +#### 1.2.5 +- Push function now does a backup, on the secondary PH, of the primary database, before pushing. -#### 1.2.2 -- Different style for status updates. +#### 1.2.4 +- Changes `~` to `$HOME`. +- Fixes bug that prevented sync from working when run via crontab. #### 1.2.3 - Uses a dedicated backup folder for `.backup` and `.last` files. - Copies db instead of moving to rename and then replacing to be more reliable. - Even cleaner label status. -#### 1.2.4 -- Changes `~` to `$HOME`. -- Fixes bug that prevented sync from working when run via crontab. +#### 1.2.2 +- Different style for status updates. -#### 1.2.5 -- Push function now does a backup, on the secondary PH, of the primary database, before pushing. +#### 1.2.1 +- Improved logging functions. ## 1.1 ### The Pushy Release @@ -129,22 +133,22 @@ Delete the `dev` file and update again to revert back to the stable/master branc - Seperated main purpose of script into `pull` argument. - Allow process to reverse back using `push` argument. -#### 1.1.2 -- First release since move from being just a Gist. -- Just relearning how to use GitHub, minor bug fixes. +#### 1.1.6 +- Code easier to read with proper tabs. -#### 1.1.3 -- Now includes example an configuration file. +#### 1.1.5 +- Added ability to view logs with `./gravity-sync.sh logs`. #### 1.1.4 - Added update script. - Added version check. -#### 1.1.5 -- Added ability to view logs with `./gravity-sync.sh logs`. +#### 1.1.3 +- Now includes example an configuration file. -#### 1.1.6 -- Code easier to read with proper tabs. +#### 1.1.2 +- First release since move from being just a Gist. +- Just relearning how to use GitHub, minor bug fixes. ## 1.0 ### The Initial Release From 99cc5428ebe2d24a226aff72ddb50501e3665706 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 16:23:02 -0500 Subject: [PATCH 02/41] Add dev mode --- gravity-sync.sh | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index bdb7887..63a2b16 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1113,16 +1113,28 @@ case $# in exit_nochange ;; - # beta) - # TASKTYPE='BETA' - # echo_good - - # MESSAGE="${TASKTYPE} Requested" - # echo_info + dev) + TASKTYPE='DEV' + echo_good - # beta_gs - # exit_nochange - # ;; + if [ -f $HOME/${LOCAL_FOLDR}/dev ] + then + MESSAGE="Enabling ${TASKTYPE}" + echo_stat + touch $HOME/${LOCAL_FOLDR}/dev + error_validate + else + MESSAGE="Disabling ${TASKTYPE}" + echo_stat + rm -f $HOME/${LOCAL_FOLDR}/dev + error_validate + fi + + MESSAGE="Please run ${YELLOW}update${NC}" + echo_info + + exit_withchange + ;; logs) TASKTYPE='LOGS' From 0ee951503a714deb2da3ee7a2ad246ac199a0496 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 16:28:22 -0500 Subject: [PATCH 03/41] flip it --- gravity-sync.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 63a2b16..0d7f08a 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1119,15 +1119,15 @@ case $# in if [ -f $HOME/${LOCAL_FOLDR}/dev ] then - MESSAGE="Enabling ${TASKTYPE}" - echo_stat - touch $HOME/${LOCAL_FOLDR}/dev - error_validate - else MESSAGE="Disabling ${TASKTYPE}" echo_stat rm -f $HOME/${LOCAL_FOLDR}/dev error_validate + else + MESSAGE="Enabling ${TASKTYPE}" + echo_stat + touch $HOME/${LOCAL_FOLDR}/dev + error_validate fi MESSAGE="Please run ${YELLOW}update${NC}" From e54a01ecb68c821dc305f870212698e523b25188 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 16:39:19 -0500 Subject: [PATCH 04/41] 1.7.4 --- CHANGELOG.md | 4 +++- README.md | 4 ++-- VERSION | 2 +- gravity-sync.sh | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b043d76..199fa57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,9 @@ - No new Star Trek references. #### 1.7.4 -- Changelog polarity reversed. +- Changelog polarity reversed after heated discussions with marketing team. +- Improved method to activate development branch updates, as added in 1.7.2. +- `./gravity-sync.sh dev` will now toggle dev flag on/off. No `touch` required, although it still works that way under the covers. #### 1.7.3 - Cleaning up output of argument listing diff --git a/README.md b/README.md index 8b5bf60..f1012e4 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,8 @@ Download the latest release from [GitHub](https://github.com/vmstan/gravity-sync ```bash cd ~ -wget https://github.com/vmstan/gravity-sync/archive/v1.7.3.zip -unzip v1.7.3.zip -d gravity-sync +wget https://github.com/vmstan/gravity-sync/archive/v1.7.4.zip +unzip v1.7.4.zip -d gravity-sync cd gravity-sync ``` diff --git a/VERSION b/VERSION index bbf649f..3511591 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.7.3 \ No newline at end of file +1.7.4 \ No newline at end of file diff --git a/gravity-sync.sh b/gravity-sync.sh index 0d7f08a..0520741 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -2,7 +2,7 @@ # GRAVITY SYNC BY VMSTAN ##################### PROGRAM='Gravity Sync' -VERSION='1.7.3' +VERSION='1.7.4' # 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 @@ -1130,7 +1130,7 @@ case $# in error_validate fi - MESSAGE="Please run ${YELLOW}update${NC}" + MESSAGE="Please run ${YELLOW}update${NC} to apply changes" echo_info exit_withchange From 7e64129e49f276f9ba2314113d60ce36acdb9c89 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 20:20:06 -0500 Subject: [PATCH 05/41] Detect SSH-Keygen method --- CHANGELOG.md | 1 + gravity-sync.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 199fa57..7f81f89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Changelog polarity reversed after heated discussions with marketing team. - Improved method to activate development branch updates, as added in 1.7.2. - `./gravity-sync.sh dev` will now toggle dev flag on/off. No `touch` required, although it still works that way under the covers. +- Detects absence of ssh-keygen on host OS and prompts to install (DietPi) #### 1.7.3 - Cleaning up output of argument listing diff --git a/gravity-sync.sh b/gravity-sync.sh index 0520741..9bfc703 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -99,7 +99,7 @@ function update_gs { TASKTYPE='UPDATE' # logs_export # dumps log prior to execution because script stops after successful pull - if [ -f "dev" ] + if [ -f "$HOME/${LOCAL_FOLDR}/dev" ] then BRANCH='development' else @@ -769,7 +769,7 @@ function config_generate { MESSAGE="Defaulting to SSH Key-Pair Authentication" echo_info fi - + if [ -z $INPUT_REMOTE_PASS ] then if [ -f $HOME/${SSH_PKIF} ] @@ -777,6 +777,9 @@ function config_generate { MESSAGE="Using Existing ~/${SSH_PKIF}" echo_info else + KEYGEN_COMMAND="ssh-keygen -t rsa -f" + detect_sshkeygen + MESSAGE="Generating ~/${SSH_PKIF}" echo_info @@ -788,7 +791,7 @@ function config_generate { echo -e "========================================================" echo -e "========================================================" - ssh-keygen -t rsa + ${KEYGEN_COMMAND} $HOME/${SSH_PKIF} echo -e "========================================================" echo -e "========================================================" fi @@ -825,6 +828,69 @@ function config_generate { exit_withchange } +## Detect SSH-KEYGEN +function detect_sshkeygen { + MESSAGE="Checking for SSH-KEYGEN" + echo_stat + + if hash ssh-keygen 2>/dev/null + then + echo_good + else + echo_fail + MESSAGE="SSH-KEYGEN is Required" + echo_info + MESSAGE="Attempting to Compensate" + echo_info + + if is_command dropbearkey + then + MESSAGE="Using DROPBEARKEY Instead" + echo_info + KEYGEN_COMMAND="dropbearkey -t rsa -f" + + MESSAGE="Installing SSH" + echo_stat + distro_check + + ${PKG_INSTALL} ssh + error_validate + else + MESSAGE="Installing SSH-KEYGEN" + echo_stat + distro_check + + ${PKG_INSTALL} ssh-keygen + error_validate + fi + fi +} + +## Detect Package Manager +function distro_check { + if is_command apt-get + then + PKG_MANAGER="apt-get" + PKG_INSTALL="${PKG_MANAGER} --yes --no-install-recommends install" + elif is_command rpm + if is_command dnf + then + PKG_MANAGER="dnf" + elif is_command yum + PKG_MANAGER="yum" + else + MESSAGE="Unable to find OS Package Manager" + echo_info + exit_nochange + fi + PKG_INSTALL="${PKG_MANAGER} install -y" + else + MESSAGE="Unable to find OS Package Manager" + echo_info + exit_nochange + fi +} + ## Delete Existing Configuration function config_delete { source $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} From d767b4bd811ab7acffde0dc47d1227ac3b7b8390 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 20:21:24 -0500 Subject: [PATCH 06/41] and THEN --- gravity-sync.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/gravity-sync.sh b/gravity-sync.sh index 9bfc703..c7c9ad5 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -877,6 +877,7 @@ function distro_check { then PKG_MANAGER="dnf" elif is_command yum + then PKG_MANAGER="yum" else MESSAGE="Unable to find OS Package Manager" From b52423cba739e3ea052a0d41c7181373bab5b5d1 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 20:22:59 -0500 Subject: [PATCH 07/41] AND THEN --- gravity-sync.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/gravity-sync.sh b/gravity-sync.sh index c7c9ad5..8429006 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -873,6 +873,7 @@ function distro_check { PKG_MANAGER="apt-get" PKG_INSTALL="${PKG_MANAGER} --yes --no-install-recommends install" elif is_command rpm + then if is_command dnf then PKG_MANAGER="dnf" From d7817aa3e4d8affbc83f8ce8bff202e75325b030 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 20:25:02 -0500 Subject: [PATCH 08/41] hashycorp --- gravity-sync.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 8429006..15dc3d3 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -843,7 +843,7 @@ function detect_sshkeygen { MESSAGE="Attempting to Compensate" echo_info - if is_command dropbearkey + if hash dropbearkey 2>/dev/null then MESSAGE="Using DROPBEARKEY Instead" echo_info @@ -868,16 +868,16 @@ function detect_sshkeygen { ## Detect Package Manager function distro_check { - if is_command apt-get + if hash apt-get 2>/dev/null then PKG_MANAGER="apt-get" PKG_INSTALL="${PKG_MANAGER} --yes --no-install-recommends install" - elif is_command rpm + elif hash rpm 2>/dev/null then - if is_command dnf + if hash dnf 2>/dev/null then PKG_MANAGER="dnf" - elif is_command yum + elif hash yum 2>/dev/null then PKG_MANAGER="yum" else From d71b901e58a78404335d7af2c07f6ca7e8e846ab Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 20:26:43 -0500 Subject: [PATCH 09/41] sudo --- gravity-sync.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 15dc3d3..5377421 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -871,7 +871,7 @@ function distro_check { if hash apt-get 2>/dev/null then PKG_MANAGER="apt-get" - PKG_INSTALL="${PKG_MANAGER} --yes --no-install-recommends install" + PKG_INSTALL="sudo ${PKG_MANAGER} --yes --no-install-recommends install" elif hash rpm 2>/dev/null then if hash dnf 2>/dev/null @@ -885,7 +885,7 @@ function distro_check { echo_info exit_nochange fi - PKG_INSTALL="${PKG_MANAGER} install -y" + PKG_INSTALL="sudo ${PKG_MANAGER} install -y" else MESSAGE="Unable to find OS Package Manager" echo_info From 67df5dd266d0d05c573c6c5e0d6ab3a10055a2ed Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 20:37:59 -0500 Subject: [PATCH 10/41] Look for SSH --- CHANGELOG.md | 3 ++- gravity-sync.sh | 34 ++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f81f89..79eb3fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,8 @@ - Changelog polarity reversed after heated discussions with marketing team. - Improved method to activate development branch updates, as added in 1.7.2. - `./gravity-sync.sh dev` will now toggle dev flag on/off. No `touch` required, although it still works that way under the covers. -- Detects absence of ssh-keygen on host OS and prompts to install (DietPi) +- Detects absence of ssh client command on host OS (DietPi) +- Detects absence of ssh-keygen on host OS and will use dropbearkey as an alternative (DietPi) #### 1.7.3 - Cleaning up output of argument listing diff --git a/gravity-sync.sh b/gravity-sync.sh index 5377421..8a73333 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -720,6 +720,8 @@ function intent_validate { # Configuration Management ## Generate New Configuration function config_generate { + detect_ssh + MESSAGE="Creating ${CONFIG_FILE} from Template" echo_stat cp $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}.example $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} @@ -849,19 +851,11 @@ function detect_sshkeygen { echo_info KEYGEN_COMMAND="dropbearkey -t rsa -f" - MESSAGE="Installing SSH" - echo_stat - distro_check - - ${PKG_INSTALL} ssh - error_validate + MESSAGE="No Alternatives Located" + echo_info + exit_nochange else - MESSAGE="Installing SSH-KEYGEN" - echo_stat - distro_check - - ${PKG_INSTALL} ssh-keygen - error_validate + fi fi } @@ -893,6 +887,22 @@ function distro_check { fi } +function detect_ssh { + MESSAGE="Checking for SSH Client on $hostname" + echo_stat + + if hash ssh 2>/dev/null + then + echo_good + else + echo_fail + MESSAGE="${PROGRAM} requires SSH be installed" + echo_info + + exit_nochange + fi +} + ## Delete Existing Configuration function config_delete { source $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} From 21f25e00a24cb8c285b74a20736c1d196e09a660 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 20:39:28 -0500 Subject: [PATCH 11/41] Adds SSH detection --- gravity-sync.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 8a73333..4751f97 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -72,7 +72,7 @@ NEED="[${BLUE}NEED${NC}]" # Import Settings function import_gs { - MESSAGE="Importing ${CONFIG_FILE} Settings" + MESSAGE="Importing ${CONFIG_FILE} Settings" echo -en "${STAT} $MESSAGE" if [ -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} ] then @@ -81,6 +81,8 @@ function import_gs { MESSAGE="Using ${REMOTE_USER}@${REMOTE_HOST}" echo_info + + detect_ssh else echo_fail From cf80241c9e4911b773a041a64837d08e4e5dc140 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 20:40:33 -0500 Subject: [PATCH 12/41] Else in wrong place --- gravity-sync.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 4751f97..9579b53 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -81,7 +81,7 @@ function import_gs { MESSAGE="Using ${REMOTE_USER}@${REMOTE_HOST}" echo_info - + detect_ssh else echo_fail @@ -853,11 +853,10 @@ function detect_sshkeygen { echo_info KEYGEN_COMMAND="dropbearkey -t rsa -f" + else MESSAGE="No Alternatives Located" echo_info exit_nochange - else - fi fi } From 028fee30ddacfb745b438b3ba54b01c82e36e34d Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 20:42:55 -0500 Subject: [PATCH 13/41] Check for rsync too --- gravity-sync.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gravity-sync.sh b/gravity-sync.sh index 9579b53..51248f7 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -902,6 +902,20 @@ function detect_ssh { exit_nochange fi + + MESSAGE="Checking for RSYNC Client on $hostname" + echo_stat + + if hash rsync 2>/dev/null + then + echo_good + else + echo_fail + MESSAGE="${PROGRAM} requires RSYNC be installed" + echo_info + + exit_nochange + fi } ## Delete Existing Configuration From c63507c6c39751ecb4f7c5a561923b6ebe1c0c42 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 20:52:01 -0500 Subject: [PATCH 14/41] HOSTNAME --- CHANGELOG.md | 1 + README.md | 6 ++++++ gravity-sync.sh | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79eb3fa..d33f5a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Improved method to activate development branch updates, as added in 1.7.2. - `./gravity-sync.sh dev` will now toggle dev flag on/off. No `touch` required, although it still works that way under the covers. - Detects absence of ssh client command on host OS (DietPi) +- Detects absence of rsync client command on host OS (DietPi) - Detects absence of ssh-keygen on host OS and will use dropbearkey as an alternative (DietPi) #### 1.7.3 diff --git a/README.md b/README.md index f1012e4..50514c1 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,12 @@ If you are just straight up unable to run the `gravity-sync.sh` file, make sure chmod +x gravity-sync.sh ``` +If you are getting errors about missing SSH or RSYNC when you run your first `compare` or `pull` operation, and you're using an ultra-lightweight distro like DietPi, make sure they are installed on the base operating system. + +```bash +sudo apt-get install rsync +``` + - If your script prompts for a password on the remote system, make sure that your user account is setup not to require passwords in the sudoers file. - If you use a non-standard SSH port to connect to your primary Pi-hole, you can add `SSH_PORT='123'` to the bottom of your `gravity-sync.conf` file. (Subsitute 123 for your non-standard port.) This will overwrite the `SSH_PORT=22` at the top of the script as it is imported later in the execution. - If you'd like to know what version of the script you have running by running `./gravity-sync.sh version` diff --git a/gravity-sync.sh b/gravity-sync.sh index 51248f7..0657766 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -889,7 +889,7 @@ function distro_check { } function detect_ssh { - MESSAGE="Checking for SSH Client on $hostname" + MESSAGE="Checking for SSH Client on $HOSTNAME" echo_stat if hash ssh 2>/dev/null @@ -903,7 +903,7 @@ function detect_ssh { exit_nochange fi - MESSAGE="Checking for RSYNC Client on $hostname" + MESSAGE="Checking for RSYNC Client on $HOSTNAME" echo_stat if hash rsync 2>/dev/null From 385ef3812c24f0860e9f7a6b54de3e47c588c978 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 21:01:24 -0500 Subject: [PATCH 15/41] Attempt to install ssh and rsync --- gravity-sync.sh | 182 +++++++++++++++++++++++++----------------------- 1 file changed, 95 insertions(+), 87 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 0657766..cf740a6 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -79,7 +79,7 @@ function import_gs { source $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} error_validate - MESSAGE="Using ${REMOTE_USER}@${REMOTE_HOST}" + MESSAGE="Targeting ${REMOTE_USER}@${REMOTE_HOST}" echo_info detect_ssh @@ -592,6 +592,100 @@ function validate_os_sshpass { error_validate } + +## Detect SSH-KEYGEN +function detect_sshkeygen { + MESSAGE="Checking for SSH-KEYGEN" + echo_stat + + if hash ssh-keygen 2>/dev/null + then + echo_good + else + echo_fail + MESSAGE="SSH-KEYGEN is Required" + echo_info + MESSAGE="Attempting to Compensate" + echo_info + + if hash dropbearkey 2>/dev/null + then + MESSAGE="Using DROPBEARKEY Instead" + echo_info + KEYGEN_COMMAND="dropbearkey -t rsa -f" + + else + MESSAGE="No Alternatives Located" + echo_info + exit_nochange + fi + fi +} + +## Detect Package Manager +function distro_check { + if hash apt-get 2>/dev/null + then + PKG_MANAGER="apt-get" + PKG_INSTALL="sudo ${PKG_MANAGER} --yes --no-install-recommends install" + elif hash rpm 2>/dev/null + then + if hash dnf 2>/dev/null + then + PKG_MANAGER="dnf" + elif hash yum 2>/dev/null + 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 { + MESSAGE="Checking for SSH Client on $HOSTNAME" + echo_stat + + if hash ssh 2>/dev/null + then + echo_good + else + echo_fail + MESSAGE="${PROGRAM} requires SSH be installed" + echo_info + + MESSAGE="Installing SSH" + echo_stat + ${PKG_INSTALL} ssh 2>/dev/null + error_validate + fi + + MESSAGE="Checking for RSYNC Client on $HOSTNAME" + echo_stat + + if hash rsync 2>/dev/null + then + echo_good + else + echo_fail + MESSAGE="${PROGRAM} requires RSYNC be installed" + echo_info + + MESSAGE="Installing RSYNC" + echo_stat + ${PKG_INSTALL} rsync 2>/dev/null + error_validate + fi +} + ## Error Validation function error_validate { if [ "$?" != "0" ]; then @@ -832,92 +926,6 @@ function config_generate { exit_withchange } -## Detect SSH-KEYGEN -function detect_sshkeygen { - MESSAGE="Checking for SSH-KEYGEN" - echo_stat - - if hash ssh-keygen 2>/dev/null - then - echo_good - else - echo_fail - MESSAGE="SSH-KEYGEN is Required" - echo_info - MESSAGE="Attempting to Compensate" - echo_info - - if hash dropbearkey 2>/dev/null - then - MESSAGE="Using DROPBEARKEY Instead" - echo_info - KEYGEN_COMMAND="dropbearkey -t rsa -f" - - else - MESSAGE="No Alternatives Located" - echo_info - exit_nochange - fi - fi -} - -## Detect Package Manager -function distro_check { - if hash apt-get 2>/dev/null - then - PKG_MANAGER="apt-get" - PKG_INSTALL="sudo ${PKG_MANAGER} --yes --no-install-recommends install" - elif hash rpm 2>/dev/null - then - if hash dnf 2>/dev/null - then - PKG_MANAGER="dnf" - elif hash yum 2>/dev/null - 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 -} - -function detect_ssh { - MESSAGE="Checking for SSH Client on $HOSTNAME" - echo_stat - - if hash ssh 2>/dev/null - then - echo_good - else - echo_fail - MESSAGE="${PROGRAM} requires SSH be installed" - echo_info - - exit_nochange - fi - - MESSAGE="Checking for RSYNC Client on $HOSTNAME" - echo_stat - - if hash rsync 2>/dev/null - then - echo_good - else - echo_fail - MESSAGE="${PROGRAM} requires RSYNC be installed" - echo_info - - exit_nochange - fi -} - ## Delete Existing Configuration function config_delete { source $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} From b8359ae505037dbe6065402eb9e9b8428f3061b9 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 21:23:02 -0500 Subject: [PATCH 16/41] apt install quieter --- CHANGELOG.md | 5 ++--- gravity-sync.sh | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d33f5a2..17b6267 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,12 +12,11 @@ - No new Star Trek references. #### 1.7.4 -- Changelog polarity reversed after heated discussions with marketing team. -- Improved method to activate development branch updates, as added in 1.7.2. -- `./gravity-sync.sh dev` will now toggle dev flag on/off. No `touch` required, although it still works that way under the covers. +- (**Featureish**) `./gravity-sync.sh dev` will now toggle dev flag on/off. No `touch` required, although it still works that way under the covers. Improvement of methods added in 1.7.2. - Detects absence of ssh client command on host OS (DietPi) - Detects absence of rsync client command on host OS (DietPi) - Detects absence of ssh-keygen on host OS and will use dropbearkey as an alternative (DietPi) +- Changelog polarity reversed after heated discussions with marketing team. #### 1.7.3 - Cleaning up output of argument listing diff --git a/gravity-sync.sh b/gravity-sync.sh index cf740a6..82455c8 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -72,7 +72,7 @@ NEED="[${BLUE}NEED${NC}]" # Import Settings function import_gs { - MESSAGE="Importing ${CONFIG_FILE} Settings" + MESSAGE="Importing ${CONFIG_FILE} Settings" echo -en "${STAT} $MESSAGE" if [ -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} ] then @@ -627,7 +627,7 @@ function distro_check { if hash apt-get 2>/dev/null then PKG_MANAGER="apt-get" - PKG_INSTALL="sudo ${PKG_MANAGER} --yes --no-install-recommends install" + PKG_INSTALL="sudo ${PKG_MANAGER} --yes --no-install-recommends --quiet install" elif hash rpm 2>/dev/null then if hash dnf 2>/dev/null From 210cd53a1cbb551ca5a1ea61279532014d503e0f Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 21:29:01 -0500 Subject: [PATCH 17/41] Another try --- gravity-sync.sh | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 82455c8..b7de1d7 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -598,7 +598,7 @@ function detect_sshkeygen { MESSAGE="Checking for SSH-KEYGEN" echo_stat - if hash ssh-keygen 2>/dev/null + if hash ssh-keygen >/dev/null 2>&1 then echo_good else @@ -608,7 +608,7 @@ function detect_sshkeygen { MESSAGE="Attempting to Compensate" echo_info - if hash dropbearkey 2>/dev/null + if hash dropbearkey >/dev/null 2>&1 then MESSAGE="Using DROPBEARKEY Instead" echo_info @@ -624,16 +624,15 @@ function detect_sshkeygen { ## Detect Package Manager function distro_check { - if hash apt-get 2>/dev/null + if hash apt-get then - PKG_MANAGER="apt-get" - PKG_INSTALL="sudo ${PKG_MANAGER} --yes --no-install-recommends --quiet install" - elif hash rpm 2>/dev/null + PKG_INSTALL="sudo apt-get --yes --no-install-recommends --quiet install" + elif hash rpm then - if hash dnf 2>/dev/null + if hash dnf then PKG_MANAGER="dnf" - elif hash yum 2>/dev/null + elif hash yum then PKG_MANAGER="yum" else @@ -654,7 +653,7 @@ function detect_ssh { MESSAGE="Checking for SSH Client on $HOSTNAME" echo_stat - if hash ssh 2>/dev/null + if hash ssh then echo_good else @@ -664,14 +663,14 @@ function detect_ssh { MESSAGE="Installing SSH" echo_stat - ${PKG_INSTALL} ssh 2>/dev/null + ${PKG_INSTALL} ssh >/dev/null 2>&1 error_validate fi MESSAGE="Checking for RSYNC Client on $HOSTNAME" echo_stat - if hash rsync 2>/dev/null + if hash rsync then echo_good else @@ -681,7 +680,7 @@ function detect_ssh { MESSAGE="Installing RSYNC" echo_stat - ${PKG_INSTALL} rsync 2>/dev/null + ${PKG_INSTALL} rsync >/dev/null 2>&1 error_validate fi } From 7ac49933b42c226e5f3e72c62902091765085cc4 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 21:33:54 -0500 Subject: [PATCH 18/41] distrocheck --- gravity-sync.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gravity-sync.sh b/gravity-sync.sh index b7de1d7..73bc4bd 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -661,6 +661,8 @@ function detect_ssh { MESSAGE="${PROGRAM} requires SSH be installed" echo_info + distro_check + MESSAGE="Installing SSH" echo_stat ${PKG_INSTALL} ssh >/dev/null 2>&1 @@ -678,6 +680,8 @@ function detect_ssh { MESSAGE="${PROGRAM} requires RSYNC be installed" echo_info + distro_check + MESSAGE="Installing RSYNC" echo_stat ${PKG_INSTALL} rsync >/dev/null 2>&1 From 4aaeda32f4bcfa3ab428733c79633b1a97ff7c25 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 21:35:23 -0500 Subject: [PATCH 19/41] 2>/dev/null --- gravity-sync.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 73bc4bd..2af5a83 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -624,15 +624,15 @@ function detect_sshkeygen { ## Detect Package Manager function distro_check { - if hash apt-get + if hash apt-get 2>/dev/null then PKG_INSTALL="sudo apt-get --yes --no-install-recommends --quiet install" - elif hash rpm + elif hash rpm 2>/dev/null then - if hash dnf + if hash dnf 2>/dev/null then PKG_MANAGER="dnf" - elif hash yum + elif hash yum 2>/dev/null then PKG_MANAGER="yum" else @@ -653,7 +653,7 @@ function detect_ssh { MESSAGE="Checking for SSH Client on $HOSTNAME" echo_stat - if hash ssh + if hash ssh 2>/dev/null then echo_good else @@ -672,7 +672,7 @@ function detect_ssh { MESSAGE="Checking for RSYNC Client on $HOSTNAME" echo_stat - if hash rsync + if hash rsync 2>/dev/null then echo_good else From b70aa3ad3d6c6d7eae58eba1ca9d11a7c399d1da Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 21:58:25 -0500 Subject: [PATCH 20/41] OK instead of GOOD --- gravity-sync.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 2af5a83..33c0167 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -61,12 +61,12 @@ BOLD='\033[1m' NC='\033[0m' # Message Codes -FAIL="[${RED}FAIL${NC}]" -WARN="[${PURPLE}WARN${NC}]" -GOOD="[${GREEN}DONE${NC}]" -STAT="[${CYAN}EXEC${NC}]" -INFO="[${YELLOW}INFO${NC}]" -NEED="[${BLUE}NEED${NC}]" +FAIL="[ ${RED}FAIL${NC} ]" +WARN="[ ${PURPLE}WARN${NC} ]" +GOOD="[ ${GREEN} OK ${NC} ]" +STAT="[ ${CYAN}EXEC${NC} ]" +INFO="[ ${YELLOW}INFO${NC} ]" +NEED="[ ${BLUE}NEED${NC} ]" # FUNCTION DEFINITIONS ####################### From a9975d0630f46a17b902c6cab479e8905fdc494b Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 22:06:31 -0500 Subject: [PATCH 21/41] Slightly less verbose --- gravity-sync.sh | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 33c0167..ddeb497 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -559,8 +559,8 @@ function validate_ph_folders { ## Validate SSHPASS function validate_os_sshpass { - MESSAGE="Checking SSH Configuration" - echo_info + # MESSAGE="Checking SSH Configuration" + # echo_info if hash sshpass 2>/dev/null then @@ -701,8 +701,8 @@ function error_validate { ## Validate Sync Required function md5_compare { - MESSAGE="Comparing ${GRAVITY_FI} Changes" - echo_info + # MESSAGE="Comparing ${GRAVITY_FI} Changes" + # echo_info HASHMARK='0' @@ -731,8 +731,8 @@ function md5_compare { then if [ -f ${PIHOLE_DIR}/${CUSTOM_DNS} ] then - MESSAGE="Comparing ${CUSTOM_DNS} Changes" - echo_info + # MESSAGE="Comparing ${CUSTOM_DNS} Changes" + # echo_info if ${SSHPASSWORD} ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${PIHOLE_DIR}/${CUSTOM_DNS} then @@ -770,7 +770,7 @@ function md5_compare { if [ "$HASHMARK" != "0" ] then - MESSAGE="Replication Suggested" + MESSAGE="${YELLOW}Replication Required${NC}" echo_info HASHMARK=$((HASHMARK+0)) else @@ -1125,8 +1125,11 @@ function echo_need { # SCRIPT EXECUTION ########################### SCRIPT_START=$SECONDS + + MESSAGE="${PROGRAM} Starting" + echo_info - MESSAGE="Evaluating Script Arguments" + MESSAGE="Evaluating Arguments" echo_stat case $# in @@ -1147,8 +1150,8 @@ case $# in import_gs - MESSAGE="Validating Folder Configuration" - echo_info + # MESSAGE="Validating Folder Configuration" + # echo_info validate_gs_folders validate_ph_folders validate_os_sshpass @@ -1166,8 +1169,8 @@ case $# in import_gs - MESSAGE="Validating Folder Configuration" - echo_info + # MESSAGE="Validating Folder Configuration" + # echo_info validate_gs_folders validate_ph_folders validate_os_sshpass From 01ff343fba7357203d1a0bf3ac60f9b63afc6b92 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 22:08:47 -0500 Subject: [PATCH 22/41] Bold! --- gravity-sync.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index ddeb497..7d61c4c 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1121,12 +1121,10 @@ function echo_need { echo -en "${NEED} ${MESSAGE}: " } - - # SCRIPT EXECUTION ########################### SCRIPT_START=$SECONDS - MESSAGE="${PROGRAM} Starting" + MESSAGE="${BOLD}${PROGRAM}${NC} Executing" echo_info MESSAGE="Evaluating Arguments" From e1a7b9329c7dccf6fbfb75e54e29892f62c4a402 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 22:16:42 -0500 Subject: [PATCH 23/41] Tighten up verbage --- CHANGELOG.md | 3 +++ gravity-sync.sh | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17b6267..9e14dfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ #### 1.7.4 - (**Featureish**) `./gravity-sync.sh dev` will now toggle dev flag on/off. No `touch` required, although it still works that way under the covers. Improvement of methods added in 1.7.2. +- Slightly less verbose in some places to make up for being more verbose in others. +- [DONE] has become [ OK ] in output. +- Tighten up verbage of some status messages. - Detects absence of ssh client command on host OS (DietPi) - Detects absence of rsync client command on host OS (DietPi) - Detects absence of ssh-keygen on host OS and will use dropbearkey as an alternative (DietPi) diff --git a/gravity-sync.sh b/gravity-sync.sh index 7d61c4c..19a4c4e 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -658,12 +658,12 @@ function detect_ssh { echo_good else echo_fail - MESSAGE="${PROGRAM} requires SSH be installed" + MESSAGE="Attempting to Compensate" echo_info distro_check - MESSAGE="Installing SSH" + MESSAGE="Installing SSH on $HOSTNAME" echo_stat ${PKG_INSTALL} ssh >/dev/null 2>&1 error_validate @@ -677,12 +677,12 @@ function detect_ssh { echo_good else echo_fail - MESSAGE="${PROGRAM} requires RSYNC be installed" + MESSAGE="RSYNC is Required" echo_info distro_check - MESSAGE="Installing RSYNC" + MESSAGE="Attempting to Compensate" echo_stat ${PKG_INSTALL} rsync >/dev/null 2>&1 error_validate @@ -955,7 +955,7 @@ function config_delete { # Exit Codes ## No Changes Made function exit_nochange { - MESSAGE="${PROGRAM} ${TASKTYPE} Aborting" + MESSAGE="${BOLD}${PROGRAM}${NC} ${TASKTYPE} Aborting" echo_info exit 0 } @@ -963,7 +963,7 @@ function exit_nochange { ## Changes Made function exit_withchange { SCRIPT_END=$SECONDS - MESSAGE="${PROGRAM} ${TASKTYPE} Completed in $((SCRIPT_END-SCRIPT_START)) seconds" + MESSAGE="${BOLD}${PROGRAM}${NC} ${TASKTYPE} Completed in $((SCRIPT_END-SCRIPT_START)) seconds" echo_info exit 0 } From cfd49f75665ddd9213b48c61d573053951a1fb9b Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 22:28:57 -0500 Subject: [PATCH 24/41] Clean up, clean up, everybody cleanup --- gravity-sync.sh | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 19a4c4e..4b36a7a 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -523,7 +523,7 @@ function show_crontab { # Validate Functions ## Validate GS Folders function validate_gs_folders { - MESSAGE="Locating $HOME/${LOCAL_FOLDR}" + MESSAGE="Validating $HOSTNAME:$HOME/${LOCAL_FOLDR}" echo_stat if [ -d $HOME/${LOCAL_FOLDR} ] then @@ -533,7 +533,7 @@ function validate_gs_folders { exit_nochange fi - MESSAGE="Locating $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}" + MESSAGE="Validating $HOSTNAME:$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}" echo_stat if [ -d $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD} ] then @@ -546,7 +546,7 @@ function validate_gs_folders { ## Validate Pi-hole Folders function validate_ph_folders { - MESSAGE="Locating ${PIHOLE_DIR}" + MESSAGE="Validating $HOSTNAME:${PIHOLE_DIR}" echo_stat if [ -d ${PIHOLE_DIR} ] then @@ -586,7 +586,7 @@ function validate_os_sshpass { echo_info - MESSAGE="Testing SSH Connection" + MESSAGE="Validating SSH Connection to ${REMOTE_HOST}" echo_stat timeout 5 ${SSHPASSWORD} ssh -p ${SSH_PORT} -i '$HOME/${SSH_PKIF}' -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} 'exit' >/dev/null 2>&1 error_validate @@ -595,7 +595,7 @@ function validate_os_sshpass { ## Detect SSH-KEYGEN function detect_sshkeygen { - MESSAGE="Checking for SSH-KEYGEN" + MESSAGE="Validating SSH-KEYGEN install on $HOSTNAME" echo_stat if hash ssh-keygen >/dev/null 2>&1 @@ -650,7 +650,7 @@ function distro_check { ## Detect SSH & RSYNC function detect_ssh { - MESSAGE="Checking for SSH Client on $HOSTNAME" + MESSAGE="Validating SSH Client on $HOSTNAME" echo_stat if hash ssh 2>/dev/null @@ -669,7 +669,7 @@ function detect_ssh { error_validate fi - MESSAGE="Checking for RSYNC Client on $HOSTNAME" + MESSAGE="Validating RSYNC Client on $HOSTNAME" echo_stat if hash rsync 2>/dev/null @@ -706,23 +706,23 @@ function md5_compare { HASHMARK='0' - MESSAGE="Analyzing Remote ${GRAVITY_FI}" + MESSAGE="Analyzing ${REMOTE_HOST} ${GRAVITY_FI}" echo_stat primaryDBMD5=$(${SSHPASSWORD} ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${PIHOLE_DIR}/${GRAVITY_FI}") error_validate - MESSAGE="Analyzing Local ${GRAVITY_FI}" + MESSAGE="Analyzing $HOSTNAME ${GRAVITY_FI}" echo_stat secondDBMD5=$(md5sum ${PIHOLE_DIR}/${GRAVITY_FI}) error_validate if [ "$primaryDBMD5" == "$secondDBMD5" ] then - MESSAGE="No Differences in ${GRAVITY_FI}" + MESSAGE="${GRAVITY_FI} Up-to-Date" echo_info HASHMARK=$((HASHMARK+0)) else - MESSAGE="Changes Detected in ${GRAVITY_FI}" + MESSAGE="${GRAVITY_FI} Ready to Replicate" echo_info HASHMARK=$((HASHMARK+1)) fi @@ -737,33 +737,33 @@ function md5_compare { if ${SSHPASSWORD} ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${PIHOLE_DIR}/${CUSTOM_DNS} then REMOTE_CUSTOM_DNS="1" - MESSAGE="Analyzing Remote ${CUSTOM_DNS}" + MESSAGE="Analyzing ${REMOTE_HOST} ${CUSTOM_DNS}" echo_stat primaryCLMD5=$(${SSHPASSWORD} ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${PIHOLE_DIR}/${CUSTOM_DNS}") error_validate - MESSAGE="Analyzing Local ${CUSTOM_DNS}" + MESSAGE="Analyzing $HOSTNAME ${CUSTOM_DNS}" echo_stat secondCLMD5=$(md5sum ${PIHOLE_DIR}/${CUSTOM_DNS}) error_validate if [ "$primaryCLMD5" == "$secondCLMD5" ] then - MESSAGE="No Differences in ${CUSTOM_DNS}" + MESSAGE="${CUSTOM_DNS} Up-to-Date" echo_info HASHMARK=$((HASHMARK+0)) else - MESSAGE="Changes Detected in ${CUSTOM_DNS}" + MESSAGE="${CUSTOM_DNS} Ready to Replicate" echo_info HASHMARK=$((HASHMARK+1)) fi else - MESSAGE="No Remote ${CUSTOM_DNS} Detected" + MESSAGE="No ${CUSTOM_DNS} Detected on ${REMOTE_HOST}" echo_info fi else - MESSAGE="No Local ${CUSTOM_DNS} Detected" + MESSAGE="No ${CUSTOM_DNS} Detected on $HOSTNAME" echo_info fi fi @@ -1186,8 +1186,8 @@ case $# in import_gs - MESSAGE="Validating Folder Configuration" - echo_info + # MESSAGE="Validating Folder Configuration" + # echo_info validate_gs_folders validate_ph_folders # validate_os_sshpass @@ -1260,8 +1260,8 @@ case $# in import_gs - MESSAGE="Validating OS Configuration" - echo_info + # MESSAGE="Validating OS Configuration" + # echo_info validate_gs_folders validate_ph_folders From df42d91c8b5f8e1e31417aee3324719fa23322f9 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 22:37:06 -0500 Subject: [PATCH 25/41] Check git status before update --- gravity-sync.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 4b36a7a..4d3ca65 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -108,10 +108,22 @@ function update_gs { BRANCH='master' fi - MESSAGE="Requires GitHub Installation" - echo_info + GIT_CHECK=$(git status | awk '{print $1}') + if [ $GIT_CHECK == "fatal:" ] + then + MESSAGE="Requires GitHub Installation" + echo_warn + exit_nochange + elif [ $GIT_CHECK == "HEAD" ] git fetch --all git reset --hard origin/${BRANCH} + else + MESSAGE="This might break..." + echo_warn + git fetch --all + git reset --hard origin/${BRANCH} + fi + exit } From 5055366bc25e5f8f063bb74358017fb99e82498d Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 22:37:36 -0500 Subject: [PATCH 26/41] AND THEN --- gravity-sync.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/gravity-sync.sh b/gravity-sync.sh index 4d3ca65..2e8c44e 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -115,6 +115,7 @@ function update_gs { echo_warn exit_nochange elif [ $GIT_CHECK == "HEAD" ] + then git fetch --all git reset --hard origin/${BRANCH} else From ad72568e353e4a6bacdd1dd96737401833800f5a Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 22:42:37 -0500 Subject: [PATCH 27/41] Validate Git completion --- CHANGELOG.md | 3 ++- gravity-sync.sh | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e14dfb..c2dd2f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,8 @@ - No new Star Trek references. #### 1.7.4 -- (**Featureish**) `./gravity-sync.sh dev` will now toggle dev flag on/off. No `touch` required, although it still works that way under the covers. Improvement of methods added in 1.7.2. +- `./gravity-sync.sh dev` will now toggle dev flag on/off. No `touch` required, although it still works that way under the covers. Improvement of methods added in 1.7.2. +- `./gravity-sync.sh dev` performs better error handling. - Slightly less verbose in some places to make up for being more verbose in others. - [DONE] has become [ OK ] in output. - Tighten up verbage of some status messages. diff --git a/gravity-sync.sh b/gravity-sync.sh index 2e8c44e..7866537 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -114,15 +114,15 @@ function update_gs { MESSAGE="Requires GitHub Installation" echo_warn exit_nochange - elif [ $GIT_CHECK == "HEAD" ] - then - git fetch --all - git reset --hard origin/${BRANCH} else MESSAGE="This might break..." echo_warn - git fetch --all - git reset --hard origin/${BRANCH} + MESSAGE="Updating Cache" + echo_stat + git fetch --all >/dev/null 2>&1 + error_validate + git reset --hard origin/${BRANCH} >/dev/null 2>&1 + error_validate fi exit From b29a53b238e230d466f4bdc601cdc4f8bbb74a82 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 22:42:57 -0500 Subject: [PATCH 28/41] Applying update --- gravity-sync.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gravity-sync.sh b/gravity-sync.sh index 7866537..41d820a 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -121,6 +121,8 @@ function update_gs { echo_stat git fetch --all >/dev/null 2>&1 error_validate + MESSAGE="Applying Update" + echo_stat git reset --hard origin/${BRANCH} >/dev/null 2>&1 error_validate fi From 00ee682b0b5b73c9183e5b9e2fe17c163126c8c0 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 22:43:59 -0500 Subject: [PATCH 29/41] Quotes --- gravity-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 41d820a..400ce3b 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -109,7 +109,7 @@ function update_gs { fi GIT_CHECK=$(git status | awk '{print $1}') - if [ $GIT_CHECK == "fatal:" ] + if [ "$GIT_CHECK" == "fatal:" ] then MESSAGE="Requires GitHub Installation" echo_warn From 1e85db3bd03ad3f3c274a88de9d2197038f5826b Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 22:44:30 -0500 Subject: [PATCH 30/41] Comment out might break --- gravity-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 400ce3b..022c911 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -115,7 +115,7 @@ function update_gs { echo_warn exit_nochange else - MESSAGE="This might break..." + # MESSAGE="This might break..." echo_warn MESSAGE="Updating Cache" echo_stat From f8d6c0021b79957c8bd64ab4863efc4100449bd0 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 22:44:57 -0500 Subject: [PATCH 31/41] Remove beta function --- gravity-sync.sh | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 022c911..c1effa5 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -130,20 +130,6 @@ function update_gs { exit } -## Developer Branch -# function beta_gs { -# TASKTYPE='BETA' -# # logs_export # dumps log prior to execution because script stops after successful pull -# -# MESSAGE="Requires GitHub Installation" -# echo_info -# git fetch --all -# git reset --hard origin/development -# # git fetch origin -# # git pull origin development -# exit -# } - # Gravity Core Functions ## Pull Function function pull_gs { From e16a3c4d845ccd739ddda97a98451db8c9a4c385 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 22:46:22 -0500 Subject: [PATCH 32/41] No warning --- gravity-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index c1effa5..2e84952 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -116,7 +116,7 @@ function update_gs { exit_nochange else # MESSAGE="This might break..." - echo_warn + # echo_warn MESSAGE="Updating Cache" echo_stat git fetch --all >/dev/null 2>&1 From 6015bb19729956f09ff774f94ea2a02f2dd975b9 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 22:47:03 -0500 Subject: [PATCH 33/41] Exit with change --- gravity-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 2e84952..1ab615e 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -127,7 +127,7 @@ function update_gs { error_validate fi - exit + exit_withchange } # Gravity Core Functions From 7ea83a607bf85751f21d244b86f66ff508682de6 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 22:59:03 -0500 Subject: [PATCH 34/41] Fix restore of custom.list --- gravity-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 1ab615e..efc5217 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -387,7 +387,7 @@ function restore_gs { if [ "$SKIP_CUSTOM" != '1' ] then - if [ "$REMOTE_CUSTOM_DNS" == "1" ] + if [ -f $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.backup ] then MESSAGE="Restoring ${CUSTOM_DNS} on $HOSTNAME" echo_stat From b549f7d891da160d3733579f79209f781d639a89 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 23:02:21 -0500 Subject: [PATCH 35/41] sudo --- gravity-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index efc5217..215925c 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -391,7 +391,7 @@ function restore_gs { then MESSAGE="Restoring ${CUSTOM_DNS} on $HOSTNAME" echo_stat - cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.backup ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1 + sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.backup ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1 error_validate MESSAGE="Validating Ownership on ${CUSTOM_DNS}" From 3f4c0ee7545853afd3c448fd2acd65307cbb8b99 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 23:09:21 -0500 Subject: [PATCH 36/41] Yellow status --- gravity-sync.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 215925c..7e9ac21 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -719,11 +719,11 @@ function md5_compare { if [ "$primaryDBMD5" == "$secondDBMD5" ] then - MESSAGE="${GRAVITY_FI} Up-to-Date" + MESSAGE="${GRAVITY_FI} Identical" echo_info HASHMARK=$((HASHMARK+0)) else - MESSAGE="${GRAVITY_FI} Ready to Replicate" + MESSAGE="${GRAVITY_FI} ${YELLOW}Ready${NC}" echo_info HASHMARK=$((HASHMARK+1)) fi @@ -751,11 +751,11 @@ function md5_compare { if [ "$primaryCLMD5" == "$secondCLMD5" ] then - MESSAGE="${CUSTOM_DNS} Up-to-Date" + MESSAGE="${CUSTOM_DNS} Identical" echo_info HASHMARK=$((HASHMARK+0)) else - MESSAGE="${CUSTOM_DNS} Ready to Replicate" + MESSAGE="${CUSTOM_DNS} ${YELLOW}Ready${NC}" echo_info HASHMARK=$((HASHMARK+1)) fi @@ -1216,7 +1216,6 @@ case $# in echo_info update_gs - exit_nochange ;; dev) From cd443f13065d9b965d7d4d1a2a1fc4210ee165e6 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 23:14:29 -0500 Subject: [PATCH 37/41] Verbs --- gravity-sync.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 7e9ac21..cdd3e72 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -723,7 +723,7 @@ function md5_compare { echo_info HASHMARK=$((HASHMARK+0)) else - MESSAGE="${GRAVITY_FI} ${YELLOW}Ready${NC}" + MESSAGE="${GRAVITY_FI} ${YELLOW}Differenced${NC}" echo_info HASHMARK=$((HASHMARK+1)) fi @@ -755,7 +755,7 @@ function md5_compare { echo_info HASHMARK=$((HASHMARK+0)) else - MESSAGE="${CUSTOM_DNS} ${YELLOW}Ready${NC}" + MESSAGE="${CUSTOM_DNS} ${YELLOW}Differenced${NC}" echo_info HASHMARK=$((HASHMARK+1)) fi @@ -771,11 +771,11 @@ function md5_compare { if [ "$HASHMARK" != "0" ] then - MESSAGE="${YELLOW}Replication Required${NC}" + MESSAGE="${YELLOW}Replication Necessary${NC}" echo_info HASHMARK=$((HASHMARK+0)) else - MESSAGE="No Replication Required" + MESSAGE="Replication Unncessary" echo_info exit_nochange fi From 9778318e66a0f0068ab7b85d50c8f706830c78af Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 23:17:36 -0500 Subject: [PATCH 38/41] Make the entire info block yellow --- gravity-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index cdd3e72..da00560 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -1094,7 +1094,7 @@ function task_automate { # Echo Stack ## Informative function echo_info { - echo -e "${INFO} ${MESSAGE}" + echo -e "${INFO} ${YELLOW}${MESSAGE}${NC}" } ## Warning From 50e0996f2072e4bac5916630f813895ef37cea97 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 23:20:34 -0500 Subject: [PATCH 39/41] NC --- gravity-sync.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index da00560..4d9ed60 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -723,7 +723,7 @@ function md5_compare { echo_info HASHMARK=$((HASHMARK+0)) else - MESSAGE="${GRAVITY_FI} ${YELLOW}Differenced${NC}" + MESSAGE="${GRAVITY_FI} Differenced" echo_info HASHMARK=$((HASHMARK+1)) fi @@ -755,7 +755,7 @@ function md5_compare { echo_info HASHMARK=$((HASHMARK+0)) else - MESSAGE="${CUSTOM_DNS} ${YELLOW}Differenced${NC}" + MESSAGE="${CUSTOM_DNS} Differenced" echo_info HASHMARK=$((HASHMARK+1)) fi @@ -771,7 +771,7 @@ function md5_compare { if [ "$HASHMARK" != "0" ] then - MESSAGE="${YELLOW}Replication Necessary${NC}" + MESSAGE="Replication Necessary" echo_info HASHMARK=$((HASHMARK+0)) else @@ -1017,7 +1017,7 @@ function show_version { else if [ "$GITVERSION" != "$VERSION" ] then - MESSAGE="Upgrade Available: ${YELLOW}${GITVERSION}${NC}" + MESSAGE="Upgrade Available: ${PURPLE}${GITVERSION}${NC}" else MESSAGE="Latest Version: ${GREEN}${GITVERSION}${NC}" fi @@ -1235,7 +1235,7 @@ case $# in error_validate fi - MESSAGE="Please run ${YELLOW}update${NC} to apply changes" + MESSAGE="Run UPDATE to apply changes" echo_info exit_withchange From 5e3b06e9cf3c0077044111651532defc142f80a2 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 23:22:37 -0500 Subject: [PATCH 40/41] Less bold --- gravity-sync.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gravity-sync.sh b/gravity-sync.sh index 4d9ed60..603e0f6 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -956,7 +956,7 @@ function config_delete { # Exit Codes ## No Changes Made function exit_nochange { - MESSAGE="${BOLD}${PROGRAM}${NC} ${TASKTYPE} Aborting" + MESSAGE="${PROGRAM} ${TASKTYPE} Aborting" echo_info exit 0 } @@ -964,7 +964,7 @@ function exit_nochange { ## Changes Made function exit_withchange { SCRIPT_END=$SECONDS - MESSAGE="${BOLD}${PROGRAM}${NC} ${TASKTYPE} Completed in $((SCRIPT_END-SCRIPT_START)) seconds" + MESSAGE="${PROGRAM} ${TASKTYPE} Completed in $((SCRIPT_END-SCRIPT_START)) seconds" echo_info exit 0 } @@ -1125,7 +1125,7 @@ function echo_need { # SCRIPT EXECUTION ########################### SCRIPT_START=$SECONDS - MESSAGE="${BOLD}${PROGRAM}${NC} Executing" + MESSAGE="${PROGRAM} Executing" echo_info MESSAGE="Evaluating Arguments" From b7c96acf0cf7510e6181fe6a9266911df784194d Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 23:25:51 -0500 Subject: [PATCH 41/41] TIght --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2dd2f2..4906284 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,8 @@ - `./gravity-sync.sh dev` performs better error handling. - Slightly less verbose in some places to make up for being more verbose in others. - [DONE] has become [ OK ] in output. -- Tighten up verbage of some status messages. +- [INFO] header is now yellow all the way across. +- Tightens up verbage of some status messages. - Detects absence of ssh client command on host OS (DietPi) - Detects absence of rsync client command on host OS (DietPi) - Detects absence of ssh-keygen on host OS and will use dropbearkey as an alternative (DietPi)