Merge pull request #33 from vmstan:development

1.7.7
This commit is contained in:
Michael Stanclift 2020-06-02 12:00:39 -05:00 committed by GitHub
commit f6c9ae5a0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 292 additions and 178 deletions

View File

@ -7,7 +7,7 @@ assignees: ''
--- ---
**Describe the bug** **Describe the Issue**
A clear and concise description of what the bug is. A clear and concise description of what the bug is.
**Screenshots** **Screenshots**
@ -21,5 +21,5 @@ If applicable, add screenshots to help explain your problem.
- Gravity Sync Version: [e.g. 1.7.6] - Gravity Sync Version: [e.g. 1.7.6]
- Pi-hole Versions: [e.g. v5.0] - Pi-hole Versions: [e.g. v5.0]
**Additional context** **Additional Context**
Add any other context about the problem here. If you have any advanced flags set in your `gravity-sync.conf` please list them here. Add any other context about the problem here. If you have any advanced flags set in your `gravity-sync.conf` please list them here.

View File

@ -2,6 +2,9 @@
## Advanced Configuration ## Advanced Configuration
The purpose of this guide is to break out the manual install instructions, and any advanced configuration flags, into a seperate document to limit confusion from the primary README. It is expected that users have read and are familiar with the process and concepts outlined in the primary README. The purpose of this guide is to break out the manual install instructions, and any advanced configuration flags, into a seperate document to limit confusion from the primary README. It is expected that users have read and are familiar with the process and concepts outlined in the primary README.
## Prerequisites
- If you're installing Gravity Sync on a system running Fedora or CentOS, make sure that you are not just using the built in root account and have a dedicated user in the Administrator group. You'll also need SELinux disabled to install Pi-hole.
## Installation ## Installation
If you don't trust `git` to install your software, or just like doing things by hand, that's fine. If you don't trust `git` to install your software, or just like doing things by hand, that's fine.
@ -11,8 +14,8 @@ Download the latest release from [GitHub](https://github.com/vmstan/gravity-sync
```bash ```bash
cd ~ cd ~
wget https://github.com/vmstan/gravity-sync/archive/v1.7.6.zip wget https://github.com/vmstan/gravity-sync/archive/v1.7.7.zip
unzip v1.7.6.zip -d gravity-sync unzip v1.7.7.zip -d gravity-sync
cd gravity-sync cd gravity-sync
``` ```
@ -86,24 +89,24 @@ Gravity Sync is configured by default to use the `.ssh/id_rsa` keyfile that is g
At this time Gravity Sync does not support passphrases in RSA keyfiles. If you have a passphrase applied to your standard `.ssh/id_rsa` either remove it, or generate a new file and specify that key for use only by Gravity Sync. At this time Gravity Sync does not support passphrases in RSA keyfiles. If you have a passphrase applied to your standard `.ssh/id_rsa` either remove it, or generate a new file and specify that key for use only by Gravity Sync.
Default setting for Gravity Sync is `.ssh/id_rsa` Default setting in Gravity Sync is `.ssh/id_rsa`
#### `LOG_PATH=''` #### `LOG_PATH=''`
Gravity Sync will place logs in the same folder as the script (identified as .cron and .log) but if you'd like to place these in a another location, you can do that by identifying the full path to the directory. (ex: `/full/path/to/logs`) Gravity Sync will place logs in the same folder as the script (identified as .cron and .log) but if you'd like to place these in a another location, you can do that by identifying the full path to the directory. (ex: `/full/path/to/logs`)
Default setting for Gravity Sync is `$HOME/${LOCAL_FOLDR}` Default setting in Gravity Sync is `$HOME/${LOCAL_FOLDR}`
#### `SYNCING_LOG=''` #### `SYNCING_LOG=''`
Gravity Sync will write a timestamp for any completed pull, push or restore job to this file. If you want to change the name of this file, you will also need to adjust the LOG_PATH variable above, otherwise your file will be remove during `update` operations. Gravity Sync will write a timestamp for any completed pull, push or restore job to this file. If you want to change the name of this file, you will also need to adjust the LOG_PATH variable above, otherwise your file will be remove during `update` operations.
Default setting for Gravity Sync is `gravity-sync.log` Default setting in Gravity Sync is `gravity-sync.log`
#### `CRONJOB_LOG=''` #### `CRONJOB_LOG=''`
Gravity Sync will log the execution history of the previous automation task via Cron to this file. If you want to change the name of this file, you will also need to adjust the LOG_PATH variable above, otherwise your file will be remove during `update` operations. Gravity Sync will log the execution history of the previous automation task via Cron to this file. If you want to change the name of this file, you will also need to adjust the LOG_PATH variable above, otherwise your file will be remove during `update` operations.
This will have an impact to both the `./gravity-sync.sh automate` function and the `./gravity-sync.sh cron` functions. If you need to change this after running the automate function, either modify your crontab manually or delete the entry and re-run the automate function. This will have an impact to both the `./gravity-sync.sh automate` function and the `./gravity-sync.sh cron` functions. If you need to change this after running the automate function, either modify your crontab manually or delete the entry and re-run the automate function.
Default setting for Gravity Sync is `gravity-sync.cron` Default setting in Gravity Sync is `gravity-sync.cron`
#### `VERIFY_PASS=''` #### `VERIFY_PASS=''`
Gravity Sync will prompt to verify user interactivity during push, restore, or config operations (that overwrite an existing configuration) with the intention that it prevents someone from accidentally automating in the wrong direction or overwriting data intentionally. If you'd like to automate a push function, or just don't like to be asked twice to do something distructive, then you can opt-out. Gravity Sync will prompt to verify user interactivity during push, restore, or config operations (that overwrite an existing configuration) with the intention that it prevents someone from accidentally automating in the wrong direction or overwriting data intentionally. If you'd like to automate a push function, or just don't like to be asked twice to do something distructive, then you can opt-out.
@ -123,6 +126,11 @@ Default setting in Gravity Sync is 0, change to 1 to print timestamped output.
#### `BASH_PATH=''` #### `BASH_PATH=''`
If you need to adjust the path to bash that is identified for automated execution via Crontab, you can do that here. This will only have an impact if changed before generating the crontab via the `./gravity-sync.sh automate` function. If you need to change this after the fact, either modify your crontab manually or delete the entry and re-run the automate function. If you need to adjust the path to bash that is identified for automated execution via Crontab, you can do that here. This will only have an impact if changed before generating the crontab via the `./gravity-sync.sh automate` function. If you need to change this after the fact, either modify your crontab manually or delete the entry and re-run the automate function.
#### `PING_AVOID=''`
The `./gravity-sync.sh config` function will attempt to ping the remote host to validate it has a valid network connection. If there is a firewall between your hosts preventing ping replies, or you otherwise wish to skip this step, it can by bypassed here.
Default setting in Gravity Sync is 0, change to 1 to skip this network test.
## Execution ## Execution
If you are just straight up unable to run the `gravity-sync.sh` file, make sure it's marked as an executable by Linux. If you are just straight up unable to run the `gravity-sync.sh` file, make sure it's marked as an executable by Linux.

View File

@ -11,6 +11,20 @@
**Known Issues** **Known Issues**
- No new Star Trek references. - No new Star Trek references.
#### 1.7.7
- `config` function will attempt to ping remote host to validate network connection, can by bypassed by adding `PING_AVOID='1'` to your `gravity-sync.conf` file.
- Changes some [INFO] messages to [WARN] where approprate.
- Adds aliases for more Gravity Sync functions.
- Shows current version on each script execution.
- Adds time output to Aborting message (exit without change.)
- Includes parsing of functions in time calculation.
- Checks for existance of Pi-hole binaries during validation.
- Less chatty about each step of configuration validation if it completes.
- Less chatty about replication validation if it's not necessary.
- Less chatty about file validation if no changes are required.
- When applying `update` in DEV mode, the Git branch used will be shown.
- Validates log export operation
#### 1.7.6 #### 1.7.6
- Detects `dbclient` install as alternative to OpenSSH Client. - Detects `dbclient` install as alternative to OpenSSH Client.
- Attempts to install OpenSSH Client if not found, and Dropbear is not alternative. - Attempts to install OpenSSH Client if not found, and Dropbear is not alternative.

View File

@ -62,7 +62,6 @@ Now, test Gravity Sync. You can run a comparison between primary and secondary d
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 Pi-hole, 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 Pi-hole, 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 ### The Pull Function
The Gravity Sync Pull, is the standard method of sync operation, and will not prompt for user input after execution. It will perform some checks to help insure success and then stop before making changes if it detects an issue. It will also perform the same `compare` function outlined above, and if there are no changes pending, it will exit without making an attempt to copy data. The Gravity Sync Pull, is the standard method of sync operation, and will not prompt for user input after execution. It will perform some checks to help insure success and then stop before making changes if it detects an issue. It will also perform the same `compare` function outlined above, and if there are no changes pending, it will exit without making an attempt to copy data.
```bash ```bash

View File

@ -1 +1 @@
1.7.6 1.7.7

View File

@ -1,8 +1,9 @@
#!/bin/bash #!/bin/bash
SCRIPT_START=$SECONDS
# GRAVITY SYNC BY VMSTAN ##################### # GRAVITY SYNC BY VMSTAN #####################
PROGRAM='Gravity Sync' PROGRAM='Gravity Sync'
VERSION='1.7.6' VERSION='1.7.7'
# Execute from the home folder of the user who owns it (ex: 'cd ~/gravity-sync') # 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 # For documentation or downloading updates visit https://github.com/vmstan/gravity-sync
@ -28,6 +29,7 @@ CRONJOB_LOG='gravity-sync.cron' # replace in gravity-sync.conf to overwrite
VERIFY_PASS='0' # replace in gravity-sync.conf to overwrite VERIFY_PASS='0' # replace in gravity-sync.conf to overwrite
SKIP_CUSTOM='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 DATE_OUTPUT='0' # replace in gravity-sync.conf to overwrite
PING_AVOID='0' # replace in gravity-sync.conf to overwrite
# Pi-hole Folder/File Locations # Pi-hole Folder/File Locations
PIHOLE_DIR='/etc/pihole' # default Pi-hole data directory PIHOLE_DIR='/etc/pihole' # default Pi-hole data directory
@ -108,6 +110,12 @@ function update_gs {
BRANCH='master' BRANCH='master'
fi fi
if [ "$BRANCH" = "development" ]
then
MESSAGE="Pulling from origin/${BRANCH}"
echo_info
fi
GIT_CHECK=$(git status | awk '{print $1}') GIT_CHECK=$(git status | awk '{print $1}')
if [ "$GIT_CHECK" == "fatal:" ] if [ "$GIT_CHECK" == "fatal:" ]
then then
@ -150,44 +158,47 @@ function pull_gs {
sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1 sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
error_validate error_validate
MESSAGE="Validating Ownership on ${GRAVITY_FI}" MESSAGE="Validating Settings of ${GRAVITY_FI}"
echo_stat echo_stat
GRAVDB_OWN=$(ls -ld ${PIHOLE_DIR}/${GRAVITY_FI} | awk '{print $3 $4}') GRAVDB_OWN=$(ls -ld ${PIHOLE_DIR}/${GRAVITY_FI} | awk '{print $3 $4}')
if [ $GRAVDB_OWN == "piholepihole" ] if [ $GRAVDB_OWN != "piholepihole" ]
then then
echo_good MESSAGE="Validating Ownership on ${GRAVITY_FI}"
else
echo_fail echo_fail
MESSAGE="Attempting to Compensate" MESSAGE="Attempting to Compensate"
echo_info echo_warn
MESSAGE="Setting Ownership on ${GRAVITY_FI}" MESSAGE="Setting Ownership on ${GRAVITY_FI}"
echo_stat echo_stat
sudo chown pihole:pihole ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1 sudo chown pihole:pihole ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
error_validate error_validate
MESSAGE="Continuing Validation of ${GRAVITY_FI}"
echo_stat
fi fi
MESSAGE="Validating Permissions on ${GRAVITY_FI}"
echo_stat
GRAVDB_RWE=$(namei -m ${PIHOLE_DIR}/${GRAVITY_FI} | grep -v f: | grep ${GRAVITY_FI} | awk '{print $1}') GRAVDB_RWE=$(namei -m ${PIHOLE_DIR}/${GRAVITY_FI} | grep -v f: | grep ${GRAVITY_FI} | awk '{print $1}')
if [ $GRAVDB_RWE = "-rw-rw-r--" ] if [ $GRAVDB_RWE != "-rw-rw-r--" ]
then then
echo_good MESSAGE="Validating Permissions on ${GRAVITY_FI}"
else
echo_fail echo_fail
MESSAGE="Attempting to Compensate" MESSAGE="Attempting to Compensate"
echo_info echo_warn
MESSAGE="Setting Ownership on ${GRAVITY_FI}" MESSAGE="Setting Permissions on ${GRAVITY_FI}"
echo_stat echo_stat
sudo chmod 664 ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1 sudo chmod 664 ${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1
error_validate error_validate
MESSAGE="Continuing Validation of ${GRAVITY_FI}"
echo_stat
fi fi
echo_good
if [ "$SKIP_CUSTOM" != '1' ] if [ "$SKIP_CUSTOM" != '1' ]
then then
if [ "$REMOTE_CUSTOM_DNS" == "1" ] if [ "$REMOTE_CUSTOM_DNS" == "1" ]
@ -210,43 +221,46 @@ function pull_gs {
sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.pull ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1 sudo cp $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.pull ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1
error_validate error_validate
MESSAGE="Validating Ownership on ${CUSTOM_DNS}" MESSAGE="Validating Settings on ${CUSTOM_DNS}"
echo_stat echo_stat
CUSTOMLS_OWN=$(ls -ld ${PIHOLE_DIR}/${CUSTOM_DNS} | awk '{print $3 $4}') CUSTOMLS_OWN=$(ls -ld ${PIHOLE_DIR}/${CUSTOM_DNS} | awk '{print $3 $4}')
if [ $CUSTOMLS_OWN == "rootroot" ] if [ $CUSTOMLS_OWN != "rootroot" ]
then then
echo_good MESSAGE="Validating Ownership on ${CUSTOM_DNS}"
else
echo_fail echo_fail
MESSAGE="Attempting to Compensate" MESSAGE="Attempting to Compensate"
echo_info echo_warn
MESSAGE="Setting Ownership on ${CUSTOM_DNS}" MESSAGE="Setting Ownership on ${CUSTOM_DNS}"
echo_stat echo_stat
sudo chown root:root ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1 sudo chown root:root ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1
error_validate error_validate
MESSAGE="Continuing Validation of ${GRAVITY_FI}"
echo_stat
fi fi
MESSAGE="Validating Permissions on ${CUSTOM_DNS}"
echo_stat
CUSTOMLS_RWE=$(namei -m ${PIHOLE_DIR}/${CUSTOM_DNS} | grep -v f: | grep ${CUSTOM_DNS} | awk '{print $1}') CUSTOMLS_RWE=$(namei -m ${PIHOLE_DIR}/${CUSTOM_DNS} | grep -v f: | grep ${CUSTOM_DNS} | awk '{print $1}')
if [ $CUSTOMLS_RWE == "-rw-r--r--" ] if [ $CUSTOMLS_RWE != "-rw-r--r--" ]
then then
echo_good MESSAGE="Validating Permissions on ${CUSTOM_DNS}"
else
echo_fail echo_fail
MESSAGE="Attempting to Compensate" MESSAGE="Attempting to Compensate"
echo_info echo_warn
MESSAGE="Setting Ownership on ${CUSTOM_DNS}" MESSAGE="Setting Ownership on ${CUSTOM_DNS}"
echo_stat echo_stat
sudo chmod 644 ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1 sudo chmod 644 ${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1
error_validate error_validate
MESSAGE="Continuing Validation of ${GRAVITY_FI}"
echo_stat
fi fi
echo_good
fi fi
fi fi
@ -320,7 +334,7 @@ function push_gs {
fi fi
fi fi
MESSAGE="Inverting Tachyon Pulse" MESSAGE="Inverting Tachyon Pulses"
echo_info echo_info
sleep 1 sleep 1
@ -361,7 +375,7 @@ function restore_gs {
echo_fail echo_fail
MESSAGE="Attempting to Compensate" MESSAGE="Attempting to Compensate"
echo_info echo_warn
MESSAGE="Setting Ownership on ${GRAVITY_FI}" MESSAGE="Setting Ownership on ${GRAVITY_FI}"
echo_stat echo_stat
@ -380,7 +394,7 @@ function restore_gs {
echo_fail echo_fail
MESSAGE="Attempting to Compensate" MESSAGE="Attempting to Compensate"
echo_info echo_warn
MESSAGE="Setting Ownership on ${GRAVITY_FI}" MESSAGE="Setting Ownership on ${GRAVITY_FI}"
echo_stat echo_stat
@ -408,7 +422,7 @@ function restore_gs {
echo_fail echo_fail
MESSAGE="Attempting to Compensate" MESSAGE="Attempting to Compensate"
echo_info echo_warn
MESSAGE="Setting Ownership on ${CUSTOM_DNS}" MESSAGE="Setting Ownership on ${CUSTOM_DNS}"
echo_stat echo_stat
@ -427,7 +441,7 @@ function restore_gs {
echo_fail echo_fail
MESSAGE="Attempting to Compensate" MESSAGE="Attempting to Compensate"
echo_info echo_warn
MESSAGE="Setting Ownership on ${CUSTOM_DNS}" MESSAGE="Setting Ownership on ${CUSTOM_DNS}"
echo_stat echo_stat
@ -459,10 +473,10 @@ function restore_gs {
## Core Logging ## Core Logging
### Write Logs Out ### Write Logs Out
function logs_export { function logs_export {
MESSAGE="Logging Timestamps to ${SYNCING_LOG}" MESSAGE="Logging Successful ${TASKTYPE}"
echo_info echo_stat
echo -e $(date) "[${TASKTYPE}]" >> ${LOG_PATH}/${SYNCING_LOG} echo -e $(date) "[${TASKTYPE}]" >> ${LOG_PATH}/${SYNCING_LOG}
error_validate
} }
### Output Sync Logs ### Output Sync Logs
@ -527,38 +541,42 @@ function show_crontab {
# Validate Functions # Validate Functions
## Validate GS Folders ## Validate GS Folders
function validate_gs_folders { function validate_gs_folders {
MESSAGE="Validating $HOSTNAME:$HOME/${LOCAL_FOLDR}" MESSAGE="Validating ${PROGRAM} Folders on $HOSTNAME"
echo_stat echo_stat
if [ -d $HOME/${LOCAL_FOLDR} ] if [ ! -d $HOME/${LOCAL_FOLDR} ]
then then
echo_good MESSAGE="Unable to Find $HOME/${LOCAL_FOLDR}"
else
echo_fail echo_fail
exit_nochange exit_nochange
fi fi
MESSAGE="Validating $HOSTNAME:$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}" if [ ! -d $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD} ]
echo_stat
if [ -d $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD} ]
then then
echo_good MESSAGE="Unable to Find $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}"
else
echo_fail echo_fail
exit_nochange exit_nochange
fi fi
echo_good
} }
## Validate Pi-hole Folders ## Validate Pi-hole Folders
function validate_ph_folders { function validate_ph_folders {
MESSAGE="Validating $HOSTNAME:${PIHOLE_DIR}" MESSAGE="Validating Pi-hole Configuration on $HOSTNAME"
echo_stat echo_stat
if [ -d ${PIHOLE_DIR} ] if [ ! -f ${PIHOLE_BIN} ]
then then
echo_good MESSAGE="Unable to Validate Pi-Hole is Installed"
else
echo_fail echo_fail
exit_nochange exit_nochange
fi fi
if [ ! -d ${PIHOLE_DIR} ]
then
MESSAGE="Unable to Validate Pi-Hole Configuration Directory"
echo_fail
exit_nochange
fi
echo_good
} }
## Validate SSHPASS ## Validate SSHPASS
@ -574,23 +592,26 @@ function validate_os_sshpass {
MESSAGE="Using SSH Key-Pair Authentication" MESSAGE="Using SSH Key-Pair Authentication"
else else
timeout 5 ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} 'exit' >/dev/null 2>&1 timeout 5 ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} 'exit' >/dev/null 2>&1
if [ "$?" != "0" ]; then if [ "$?" != "0" ]
then
SSHPASSWORD="sshpass -p ${REMOTE_PASS}" SSHPASSWORD="sshpass -p ${REMOTE_PASS}"
MESSAGE="Using SSH Password Authentication" MESSAGE="Using SSH Password Authentication"
echo_warn
else else
SSHPASSWORD='' SSHPASSWORD=''
MESSAGE="Using SSH Key-Pair Authentication" MESSAGE="Using SSH Key-Pair Authentication"
fi
fi
else
SSHPASSWORD=''
MESSAGE="Using SSH Key-Pair Authentication"
fi
echo_info echo_info
fi
MESSAGE="Validating SSH Connection to ${REMOTE_HOST}" fi
else
SSHPASSWORD=''
MESSAGE="Using SSH Key-Pair Authentication"
echo_info
fi
MESSAGE="Validating Connection to ${REMOTE_HOST}"
echo_stat echo_stat
if hash ssh 2>/dev/null if hash ssh 2>/dev/null
then then
@ -598,13 +619,11 @@ function validate_os_sshpass {
error_validate error_validate
elif hash dbclient 2>/dev/null elif hash dbclient 2>/dev/null
then then
# if [ "$SSH_CMD" = "dbclient" ]; then echo ''; fi;
timeout 5 ${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} 'exit' >/dev/null 2>&1 timeout 5 ${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} 'exit' >/dev/null 2>&1
error_validate error_validate
fi fi
} }
## Detect SSH-KEYGEN ## Detect SSH-KEYGEN
function detect_sshkeygen { function detect_sshkeygen {
MESSAGE="Validating SSH-KEYGEN install on $HOSTNAME" MESSAGE="Validating SSH-KEYGEN install on $HOSTNAME"
@ -618,7 +637,7 @@ function detect_sshkeygen {
MESSAGE="SSH-KEYGEN is Required" MESSAGE="SSH-KEYGEN is Required"
echo_info echo_info
MESSAGE="Attempting to Compensate" MESSAGE="Attempting to Compensate"
echo_info echo_warn
if hash dropbearkey >/dev/null 2>&1 if hash dropbearkey >/dev/null 2>&1
then then
@ -668,24 +687,24 @@ function distro_check {
## Detect SSH & RSYNC ## Detect SSH & RSYNC
function detect_ssh { function detect_ssh {
MESSAGE="Validating SSH on $HOSTNAME" MESSAGE="Validating SSH Client on $HOSTNAME"
echo_stat echo_stat
if hash ssh 2>/dev/null if hash ssh 2>/dev/null
then then
MESSAGE="Validating SSH on $HOSTNAME (OpenSSH)" MESSAGE="${MESSAGE} (OpenSSH)"
echo_good echo_good
SSH_CMD='ssh' SSH_CMD='ssh'
elif hash dbclient 2>/dev/null elif hash dbclient 2>/dev/null
then then
MESSAGE="Validating SSH on $HOSTNAME (Dropbear)" MESSAGE="${MESSAGE} (Dropbear)"
echo_good echo_good
SSH_CMD='dbclient' SSH_CMD='dbclient'
else else
echo_fail echo_fail
MESSAGE="Attempting to Compensate" MESSAGE="Attempting to Compensate"
echo_info echo_warn
MESSAGE="Installing SSH Client with ${PKG_MANAGER}" MESSAGE="Installing SSH Client with ${PKG_MANAGER}"
echo_stat echo_stat
@ -693,7 +712,7 @@ function detect_ssh {
error_validate error_validate
fi fi
MESSAGE="Validating RSYNC on $HOSTNAME" MESSAGE="Validating RSYNC Installed on $HOSTNAME"
echo_stat echo_stat
if hash rsync 2>/dev/null if hash rsync 2>/dev/null
@ -702,12 +721,12 @@ function detect_ssh {
else else
echo_fail echo_fail
MESSAGE="RSYNC is Required" MESSAGE="RSYNC is Required"
echo_info echo_warn
distro_check distro_check
MESSAGE="Attempting to Compensate" MESSAGE="Attempting to Compensate"
echo_info echo_warn
MESSAGE="Installing RSYNC with ${PKG_MANAGER}" MESSAGE="Installing RSYNC with ${PKG_MANAGER}"
echo_stat echo_stat
@ -730,23 +749,23 @@ function error_validate {
function md5_compare { function md5_compare {
HASHMARK='0' HASHMARK='0'
MESSAGE="Analyzing ${REMOTE_HOST} ${GRAVITY_FI}" MESSAGE="Analyzing ${GRAVITY_FI} on ${REMOTE_HOST}"
echo_stat echo_stat
primaryDBMD5=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${PIHOLE_DIR}/${GRAVITY_FI}" | sed 's/\s.*$//') primaryDBMD5=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${PIHOLE_DIR}/${GRAVITY_FI}" | sed 's/\s.*$//')
error_validate error_validate
MESSAGE="Analyzing $HOSTNAME ${GRAVITY_FI}" MESSAGE="Analyzing ${GRAVITY_FI} on $HOSTNAME"
echo_stat echo_stat
secondDBMD5=$(md5sum ${PIHOLE_DIR}/${GRAVITY_FI} | sed 's/\s.*$//') secondDBMD5=$(md5sum ${PIHOLE_DIR}/${GRAVITY_FI} | sed 's/\s.*$//')
error_validate error_validate
if [ "$primaryDBMD5" == "$secondDBMD5" ] if [ "$primaryDBMD5" == "$secondDBMD5" ]
then then
MESSAGE="${GRAVITY_FI} Identical" # MESSAGE="Identical ${GRAVITY_FI} Detected"
echo_info # echo_info
HASHMARK=$((HASHMARK+0)) HASHMARK=$((HASHMARK+0))
else else
MESSAGE="${GRAVITY_FI} Differenced" MESSAGE="Differenced ${GRAVITY_FI} Detected"
echo_warn echo_warn
HASHMARK=$((HASHMARK+1)) HASHMARK=$((HASHMARK+1))
fi fi
@ -758,24 +777,24 @@ function md5_compare {
if ${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${PIHOLE_DIR}/${CUSTOM_DNS} if ${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${PIHOLE_DIR}/${CUSTOM_DNS}
then then
REMOTE_CUSTOM_DNS="1" REMOTE_CUSTOM_DNS="1"
MESSAGE="Analyzing ${REMOTE_HOST} ${CUSTOM_DNS}" MESSAGE="Analyzing ${CUSTOM_DNS} on ${REMOTE_HOST}"
echo_stat echo_stat
primaryCLMD5=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${PIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//'") primaryCLMD5=$(${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${PIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//'")
error_validate error_validate
MESSAGE="Analyzing $HOSTNAME ${CUSTOM_DNS}" MESSAGE="Analyzing ${CUSTOM_DNS} on $HOSTNAME"
echo_stat echo_stat
secondCLMD5=$(md5sum ${PIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//') secondCLMD5=$(md5sum ${PIHOLE_DIR}/${CUSTOM_DNS} | sed 's/\s.*$//')
error_validate error_validate
if [ "$primaryCLMD5" == "$secondCLMD5" ] if [ "$primaryCLMD5" == "$secondCLMD5" ]
then then
MESSAGE="${CUSTOM_DNS} Identical" # MESSAGE="${CUSTOM_DNS} Identical"
echo_info # echo_info
HASHMARK=$((HASHMARK+0)) HASHMARK=$((HASHMARK+0))
else else
MESSAGE="${CUSTOM_DNS} Differenced" MESSAGE="Differenced ${CUSTOM_DNS} Detected"
echo_warn echo_warn
HASHMARK=$((HASHMARK+1)) HASHMARK=$((HASHMARK+1))
fi fi
@ -801,7 +820,7 @@ function md5_compare {
echo_warn echo_warn
HASHMARK=$((HASHMARK+0)) HASHMARK=$((HASHMARK+0))
else else
MESSAGE="No Changes to Replicate" MESSAGE="No Replication Required"
echo_info echo_info
exit_nochange exit_nochange
fi fi
@ -857,6 +876,17 @@ function config_generate {
echo_need echo_need
read INPUT_REMOTE_HOST 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
error_validate
else
MESSAGE="Bypassing Network Testing (PING)"
echo_warn
fi
MESSAGE="Enter SSH user with SUDO rights on primary Pi-hole server" MESSAGE="Enter SSH user with SUDO rights on primary Pi-hole server"
echo_need echo_need
read INPUT_REMOTE_USER read INPUT_REMOTE_USER
@ -989,7 +1019,8 @@ function config_delete {
# Exit Codes # Exit Codes
## No Changes Made ## No Changes Made
function exit_nochange { function exit_nochange {
MESSAGE="${PROGRAM} ${TASKTYPE} Aborting" SCRIPT_END=$SECONDS
MESSAGE="${PROGRAM} ${TASKTYPE} Aborting ($((SCRIPT_END-SCRIPT_START)) seconds)"
echo_info echo_info
exit 0 exit 0
} }
@ -997,7 +1028,7 @@ function exit_nochange {
## Changes Made ## Changes Made
function exit_withchange { function exit_withchange {
SCRIPT_END=$SECONDS SCRIPT_END=$SECONDS
MESSAGE="${PROGRAM} ${TASKTYPE} Completed in $((SCRIPT_END-SCRIPT_START)) seconds" MESSAGE="${PROGRAM} ${TASKTYPE} Completed ($((SCRIPT_END-SCRIPT_START)) seconds)"
echo_info echo_info
exit 0 exit 0
} }
@ -1063,6 +1094,7 @@ function show_version {
## Automate Task ## Automate Task
function task_automate { function task_automate {
TASKTYPE='AUTOMATE' TASKTYPE='AUTOMATE'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good echo_good
import_gs import_gs
@ -1124,6 +1156,126 @@ function task_automate {
exit_withchange exit_withchange
} }
## Configure Task
function task_configure {
TASKTYPE='CONFIGURE'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
#MESSAGE="${TASKTYPE} Requested"
#echo_info
if [ -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} ]
then
config_delete
else
MESSAGE="No Active ${CONFIG_FILE}"
echo_warn
config_generate
fi
}
## Devmode Task
function task_devmode {
TASKTYPE='DEV'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
if [ -f $HOME/${LOCAL_FOLDR}/dev ]
then
MESSAGE="Disabling ${TASKTYPE}"
echo_stat
rm -f $HOME/${LOCAL_FOLDR}/dev
error_validate
else
MESSAGE="Enabling ${TASKTYPE}"
echo_stat
touch $HOME/${LOCAL_FOLDR}/dev
error_validate
fi
MESSAGE="Run UPDATE to apply changes"
echo_info
exit_withchange
}
## Update Task
function task_update {
TASKTYPE='UPDATE'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
#MESSAGE="${TASKTYPE} Requested"
#echo_info
update_gs
}
## Version Task
function task_version {
TASKTYPE='VERSION'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
#MESSAGE="${TASKTYPE} Requested"
#echo_info
show_version
exit_nochange
}
## Logs Task
function task_logs {
TASKTYPE='LOGS'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
#MESSAGE="${TASKTYPE} Requested"
#echo_info
logs_gs
}
## Compare Task
function task_compare {
TASKTYPE='COMPARE'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
#MESSAGE="${TASKTYPE} Requested"
#echo_info
import_gs
# MESSAGE="Validating OS Configuration"
# echo_info
validate_gs_folders
validate_ph_folders
validate_os_sshpass
md5_compare
}
## Cron Task
function task_cron {
TASKTYPE='CRON'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
#MESSAGE="${TASKTYPE} Requested"
#echo_info
show_crontab
}
function task_invalid {
echo_fail
list_gs_arguments
}
# Echo Stack # Echo Stack
## Informative ## Informative
function echo_info { function echo_info {
@ -1156,9 +1308,8 @@ function echo_need {
} }
# SCRIPT EXECUTION ########################### # SCRIPT EXECUTION ###########################
SCRIPT_START=$SECONDS
MESSAGE="${PROGRAM} Executing" MESSAGE="${PROGRAM} ${VERSION} Executing"
echo_info echo_info
MESSAGE="Evaluating Arguments" MESSAGE="Evaluating Arguments"
@ -1167,18 +1318,18 @@ SCRIPT_START=$SECONDS
case $# in case $# in
0) 0)
echo_fail task_invalid
list_gs_arguments
;; ;;
1) 1)
case $1 in case $1 in
pull) pull)
TASKTYPE='PULL' TASKTYPE='PULL'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good echo_good
MESSAGE="${TASKTYPE} Requested" #MESSAGE="${TASKTYPE} Requested"
echo_info #echo_info
import_gs import_gs
@ -1194,10 +1345,11 @@ case $# in
push) push)
TASKTYPE='PUSH' TASKTYPE='PUSH'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good echo_good
MESSAGE="${TASKTYPE} Requested" #MESSAGE="${TASKTYPE} Requested"
echo_info #echo_info
import_gs import_gs
@ -1213,10 +1365,11 @@ case $# in
restore) restore)
TASKTYPE='RESTORE' TASKTYPE='RESTORE'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good echo_good
MESSAGE="${TASKTYPE} Requested" #MESSAGE="${TASKTYPE} Requested"
echo_info #echo_info
import_gs import_gs
@ -1231,105 +1384,47 @@ case $# in
;; ;;
version) version)
TASKTYPE='VERSION' task_version
echo_good
MESSAGE="${TASKTYPE} Requested"
echo_info
show_version
exit_nochange
;; ;;
update) update)
TASKTYPE='UPDATE' task_update
echo_good ;;
MESSAGE="${TASKTYPE} Requested" upgrade)
echo_info task_update
update_gs
;; ;;
dev) dev)
TASKTYPE='DEV' task_devmode
echo_good ;;
if [ -f $HOME/${LOCAL_FOLDR}/dev ] devmode)
then task_devmode
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="Run UPDATE to apply changes" development)
echo_info task_devmode
exit_withchange
;; ;;
logs) logs)
TASKTYPE='LOGS' task_logs
echo_good
MESSAGE="${TASKTYPE} Requested"
echo_info
logs_gs
;; ;;
compare) compare)
TASKTYPE='COMPARE' task_compare
echo_good
MESSAGE="${TASKTYPE} Requested"
echo_info
import_gs
# MESSAGE="Validating OS Configuration"
# echo_info
validate_gs_folders
validate_ph_folders
validate_os_sshpass
md5_compare
;; ;;
cron) cron)
TASKTYPE='CRON' task_cron
echo_good
MESSAGE="${TASKTYPE} Requested"
echo_info
show_crontab
;; ;;
config) config)
TASKTYPE='CONFIGURE' task_configure
echo_good ;;
MESSAGE="${TASKTYPE} Requested" configure)
echo_info task_configure
if [ -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} ]
then
config_delete
else
MESSAGE="${CONFIG_FILE} Missing"
echo_info
config_generate
fi
;; ;;
auto) auto)
@ -1341,14 +1436,12 @@ case $# in
;; ;;
*) *)
echo_fail task_invalid
list_gs_arguments
;; ;;
esac esac
;; ;;
*) *)
echo_fail task_invalid
list_gs_arguments
;; ;;
esac esac