diff --git a/README.md b/README.md index 81a317c..fb6185b 100644 --- a/README.md +++ b/README.md @@ -126,13 +126,13 @@ Gravity Sync will validate that the `sshpass` utility is installed on your syste Save. Keep calm, carry on. ## Execution -Now test the script. You can run a comparison between the two which will be non-distruptive and see if everything has been configured correctly. +Now, test Gravity Sync. You can run a comparison between primary and secondary databases, which will be non-distruptive, and see if everything has been configured correctly. ```bash ./gravity-sync.sh compare ``` -Assuming Gravity Sync runs successfully, it'll indicate if there are changes pending between the two databases. If not, I suggest making a subtle change to a whitelist/blacklist on your primary PH, such as changing a description field or disabling a whitelist item, and then running `./gravity-sync.sh compare` again to validate your installation is working correctly. +Assuming Gravity Sync runs successfully, it will indicate if there are changes pending between the two databases. If not, make a subtle change to a whitelist/blacklist on your primary PH, such as changing a description field or disabling a whitelist item, and then running `./gravity-sync.sh compare` again to validate your installation is working correctly. ### The Pull Function @@ -142,7 +142,7 @@ The Gravity Sync Pull, is the standard method of sync operation, and will not pr ./gravity-sync.sh pull ``` -If the execution completes, you will now have overwritten your running gravity.db on the secondary PH after creating a copy of the running database (`gravity.db.backup`) in the `backup` subfolder located with your script. Gravity Sync will also keep a copy of the last sync'd gravity.db from the master, in the `backup` folder identified as `gravity.db.pull` for future use. +If the execution completes, you will now have overwritten your running gravity.db on the secondary PH after creating a copy of the running database (`gravity.db.backup`) in the `backup` subfolder located with your script. Gravity Sync will also keep a copy of the last sync'd gravity.db from the primary (in the `backup` folder identified as `gravity.db.pull`) for future use. Finally, a file called `gravity-sync.log` will be created in the `gravity-sync` folder along side the script with the date the script was last executed appended to the bottom. @@ -224,4 +224,6 @@ chmod +x gravity-sync.sh - 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` - If the update script fails, make sure you did your original deployment via `git clone` and not a manual install. -- If it doesn't kick off, you can manually execute a `git pull` while in the `gravity-sync` directory. \ No newline at end of file +- If it doesn't kick off, you can manually execute a `git pull` while in the `gravity-sync` directory. + +If all else fails, delete the entire `gravity-sync` folder from your system and re-deploy. This will have no impact on your replicated databases. \ No newline at end of file diff --git a/gravity-sync.sh b/gravity-sync.sh index 8747eb6..c9dbe42 100755 --- a/gravity-sync.sh +++ b/gravity-sync.sh @@ -73,12 +73,12 @@ function import_gs { error_validate MESSAGE="Using ${REMOTE_USER}@${REMOTE_HOST}" - echo -e "${INFO} ${MESSAGE}" + echo_info else echo -e "\r${FAIL} ${MESSAGE}" MESSAGE="${CONFIG_FILE} Missing" - echo -e "${INFO} ${MESSAGE}" + echo_info TASKTYPE='CONFIG' config_generate @@ -93,7 +93,7 @@ function update_gs { # logs_export # dumps log prior to execution because script stops after successful pull MESSAGE="Requires GitHub Installation" - echo -e "${INFO} ${MESSAGE}" + echo_info git reset --hard git pull exit @@ -105,7 +105,7 @@ function beta_gs { # logs_export # dumps log prior to execution because script stops after successful pull MESSAGE="Requires GitHub Installation" - echo -e "${INFO} ${MESSAGE}" + echo_info git reset --hard git fetch origin git pull origin development @@ -117,10 +117,13 @@ function beta_gs { function pull_gs { TASKTYPE='PULL' - echo -e "${INFO} ${TASKTYPE} Requested" + MESSAGE="${TASKTYPE} Requested" + echo_info + md5_compare - echo -e "${INFO} ${TASKTYPE} Commencing" + MESSAGE="${TASKTYPE} Starting" + echo_info MESSAGE="Backing Up ${GRAVITY_FI} on $HOSTNAME" echo -en "${STAT} ${MESSAGE}" @@ -176,7 +179,7 @@ function pull_gs { fi MESSAGE="Inverting Tachyon Pulse" - echo -e "${INFO} ${MESSAGE}" + echo_info sleep 1 MESSAGE="Updating FTLDNS Configuration" @@ -226,7 +229,7 @@ function push_gs { error_validate MESSAGE="Contacting Borg Collective" - echo -e "${INFO} ${MESSAGE}" + echo_info sleep 1 MESSAGE="Updating FTLDNS Configuration" @@ -343,7 +346,7 @@ function validate_ph_folders { ## Validate SSHPASS function validate_os_sshpass { MESSAGE="Checking SSH Configuration" - echo -e "${INFO} ${MESSAGE}" + echo_info if hash sshpass 2>/dev/null then @@ -367,7 +370,7 @@ function validate_os_sshpass { MESSAGE="Using SSH Key-Pair Authentication" fi - echo -e "${INFO} ${MESSAGE}" + echo_info MESSAGE="Testing SSH Connection" echo -en "${STAT} ${MESSAGE}" @@ -437,7 +440,7 @@ function config_generate { if hash sshpass 2>/dev/null then MESSAGE="SSHPASS Utility Detected" - echo -e "${INFO} ${MESSAGE}" + echo_info MESSAGE="Do you want to configure password based SSH authentication?" echo -e "${WARN} ${MESSAGE}" @@ -455,10 +458,10 @@ function config_generate { else MESSAGE="SSHPASS Not Installed" - echo -e "${INFO} ${MESSAGE}" + echo_info MESSAGE="Defaulting to SSH Key-Pair Authentication" - echo -e "${INFO} ${MESSAGE}" + echo_info fi if [ -z $INPUT_REMOTE_PASS ] @@ -466,10 +469,10 @@ function config_generate { if [ -f $HOME/${SSH_PKIF} ] then MESSAGE="Using Existing ~/${SSH_PKIF}" - echo -e "${INFO} ${MESSAGE}" + echo_info else MESSAGE="Generating ~/${SSH_PKIF}" - echo -e "${INFO} ${MESSAGE}" + echo_info MESSAGE="Accept All Defaults" echo -e "${WARN} ${MESSAGE}" @@ -495,7 +498,7 @@ function config_generate { if [ -f $HOME/${SSH_PKIF} ] then MESSAGE="Registering Key-Pair on ${REMOTE_HOST}" - echo -e "${INFO} ${MESSAGE}" + echo_info MESSAGE="Enter ${REMOTE_USER}@${REMOTE_HOST} Password Below" echo -e "${NEED} ${MESSAGE}" @@ -558,7 +561,7 @@ function exit_nochange { function exit_withchange { SCRIPT_END=$SECONDS MESSAGE="${PROGRAM} ${TASKTYPE} Completed in $((SCRIPT_END-SCRIPT_START)) seconds" - echo -e "${INFO} ${MESSAGE}" + echo_info exit 0 } @@ -605,14 +608,14 @@ function task_automate { if [ ${CRON_CHECK} == 1 ] then MESSAGE="Automation Task Already Exists" - echo -e "${INFO} ${MESSAGE}" + echo_info MESSAGE="Use 'crontab -e' to manually remove/edit" - echo -e "${INFO} ${MESSAGE}" + echo_info exit_nochange fi MESSAGE="Set Automation Frequency Per Hour" - echo -e "${INFO} ${MESSAGE}" + echo_info MESSAGE="1 = Every 60 Minutes" echo -e "++++++ ${MESSAGE}" @@ -658,6 +661,39 @@ function task_automate { exit_withchange } +# Echo Stack +## Informative +function echo_info { + echo -e "${INFO} ${MESSAGE}" +} + +## Warning +function echo_warn { + echo -e "${WARN} ${MESSAGE}" +} + +## Executing +function echo_stat { + echo -en "${STAT} ${MESSAGE}" +} + +## Success +function echo_good { + echo -e "\r${GOOD} ${MESSAGE}" +} + +## Failure +function echo_fail { + echo -e "\r${FAIL} ${MESSAGE}" +} + +## Request +function echo_need { + echo -en "${NEED} ${MESSAGE}: " +} + + + # SCRIPT EXECUTION ########################### SCRIPT_START=$SECONDS @@ -679,7 +715,7 @@ case $# in import_gs MESSAGE="Validating Folder Configuration" - echo -e "${INFO} ${MESSAGE}" + echo_info validate_gs_folders validate_ph_folders validate_os_sshpass @@ -734,7 +770,7 @@ case $# in echo -e "\r${GOOD} ${MESSAGE}" MESSAGE="Logs Requested" - echo -e "${INFO} ${MESSAGE}" + echo_info logs_gs ;; @@ -770,7 +806,7 @@ case $# in else MESSAGE="${CONFIG_FILE} Missing" - echo -e "${INFO} ${MESSAGE}" + echo_info config_generate fi