Merge pull request #36 from vmstan:development

1.8.0
This commit is contained in:
Michael Stanclift 2020-06-03 15:16:28 -05:00 committed by GitHub
commit d1a664ffd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 245 additions and 221 deletions

View File

@ -14,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.7.zip wget https://github.com/vmstan/gravity-sync/archive/v1.8.0.zip
unzip v1.7.7.zip -d gravity-sync unzip v1.8.0.zip -d gravity-sync
cd gravity-sync cd gravity-sync
``` ```
@ -97,12 +97,12 @@ Gravity Sync will place logs in the same folder as the script (identified as .cr
Default setting in 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 an `update` operations.
Default setting in 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 an `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.
@ -138,7 +138,6 @@ If you are just straight up unable to run the `gravity-sync.sh` file, make sure
chmod +x gravity-sync.sh chmod +x gravity-sync.sh
``` ```
## Updates ## Updates
If you manually installed Gravity Sync via .zip or .tar.gz you will need to download and overwrite the `gravity-sync.sh` file with a newer version. If you've chosen this path, I won't lay out exactly what you'll need to do every time, but you should at least review the contents of the script bundle (specifically the example configuration file) to make sure there are no new additional files or required settings. If you manually installed Gravity Sync via .zip or .tar.gz you will need to download and overwrite the `gravity-sync.sh` file with a newer version. If you've chosen this path, I won't lay out exactly what you'll need to do every time, but you should at least review the contents of the script bundle (specifically the example configuration file) to make sure there are no new additional files or required settings.
@ -176,9 +175,3 @@ If you prefer to still use cron but modify your settings by hand, using the entr
crontab -e crontab -e
*/30 * * * * /bin/bash /home/USER/gravity-sync/gravity-sync.sh pull > /home/USER/gravity-sync/gravity-sync.cron */30 * * * * /bin/bash /home/USER/gravity-sync/gravity-sync.sh pull > /home/USER/gravity-sync/gravity-sync.cron
``` ```
## Troubleshooting
- 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.

View File

@ -1,5 +1,16 @@
# The Changelog # The Changelog
## 1.8
### The Logical Release
**Features**
There is nothing really sexy here, but a lot of changes under the covers to improve reliablity between different SSH client types. A lot of the logic and functions are more consistent and cleaner. In some cultures, fewer bugs and more reliablity are considered features. Much of this will continue through the 1.8.x line.
- SSH/RSYNC connection logic rewritten to be specific to client options between OpenSSH, OpenSSH w/ SSHPASS, and Dropbear.
- Key-pair generation functions rewritten to be specific to client options, also now works with no (or at least fewer) user prompts.
- SSHPASS options should be more reliable if used, but removes messages that SSHPASS is not installed during setup, if it's not needed and Redirects user to documentation.
- Adds custom port specification to ssh-copy-id and dropbearkey commands during configuration generation.
- Generally better error handling of configuration options.
## 1.7 ## 1.7
### The Andrew Release ### The Andrew Release
@ -23,7 +34,7 @@
- Less chatty about replication validation if it's not necessary. - Less chatty about replication validation if it's not necessary.
- Less chatty about file validation if no changes are required. - Less chatty about file validation if no changes are required.
- When applying `update` in DEV mode, the Git branch used will be shown. - When applying `update` in DEV mode, the Git branch used will be shown.
- Validates log export operation - 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.

View File

@ -1 +1 @@
1.7.7 1.8.0

View File

@ -31,3 +31,4 @@ REMOTE_PASS=''
# VERIFY_PASS='' # VERIFY_PASS=''
# SKIP_CUSTOM='' # SKIP_CUSTOM=''
# DATE_OUTPUT='' # DATE_OUTPUT=''
# PING_AVOID=''

View File

@ -3,7 +3,7 @@ SCRIPT_START=$SECONDS
# GRAVITY SYNC BY VMSTAN ##################### # GRAVITY SYNC BY VMSTAN #####################
PROGRAM='Gravity Sync' PROGRAM='Gravity Sync'
VERSION='1.7.7' VERSION='1.8.0'
# 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
@ -93,7 +93,6 @@ function import_gs {
TASKTYPE='CONFIG' TASKTYPE='CONFIG'
config_generate config_generate
# echo -e "Please run ${YELLOW}$#${NC} again."
fi fi
} }
@ -101,7 +100,6 @@ function import_gs {
## Master Branch ## Master Branch
function update_gs { function update_gs {
TASKTYPE='UPDATE' TASKTYPE='UPDATE'
# logs_export # dumps log prior to execution because script stops after successful pull
if [ -f "$HOME/${LOCAL_FOLDR}/dev" ] if [ -f "$HOME/${LOCAL_FOLDR}/dev" ]
then then
@ -123,8 +121,6 @@ function update_gs {
echo_warn echo_warn
exit_nochange exit_nochange
else else
# MESSAGE="This might break..."
# echo_warn
MESSAGE="Updating Cache" MESSAGE="Updating Cache"
echo_stat echo_stat
git fetch --all >/dev/null 2>&1 git fetch --all >/dev/null 2>&1
@ -150,8 +146,10 @@ function pull_gs {
MESSAGE="Pulling ${GRAVITY_FI} from ${REMOTE_HOST}" MESSAGE="Pulling ${GRAVITY_FI} from ${REMOTE_HOST}"
echo_stat echo_stat
${SSHPASSWORD} rsync -e "${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull >/dev/null 2>&1 RSYNC_REPATH="rsync"
error_validate RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI}"
RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.pull"
create_rsynccmd
MESSAGE="Replacing ${GRAVITY_FI} on $HOSTNAME" MESSAGE="Replacing ${GRAVITY_FI} on $HOSTNAME"
echo_stat echo_stat
@ -162,7 +160,7 @@ function pull_gs {
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
MESSAGE="Validating Ownership on ${GRAVITY_FI}" MESSAGE="Validating Ownership on ${GRAVITY_FI}"
echo_fail echo_fail
@ -180,7 +178,7 @@ function pull_gs {
fi fi
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
MESSAGE="Validating Permissions on ${GRAVITY_FI}" MESSAGE="Validating Permissions on ${GRAVITY_FI}"
echo_fail echo_fail
@ -213,8 +211,10 @@ function pull_gs {
MESSAGE="Pulling ${CUSTOM_DNS} from ${REMOTE_HOST}" MESSAGE="Pulling ${CUSTOM_DNS} from ${REMOTE_HOST}"
echo_stat echo_stat
${SSHPASSWORD} rsync -e "${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${CUSTOM_DNS} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.pull >/dev/null 2>&1 RSYNC_REPATH="rsync"
error_validate RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${CUSTOM_DNS}"
RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.pull"
create_rsynccmd
MESSAGE="Replacing ${CUSTOM_DNS} on $HOSTNAME" MESSAGE="Replacing ${CUSTOM_DNS} on $HOSTNAME"
echo_stat echo_stat
@ -225,7 +225,7 @@ function pull_gs {
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
MESSAGE="Validating Ownership on ${CUSTOM_DNS}" MESSAGE="Validating Ownership on ${CUSTOM_DNS}"
echo_fail echo_fail
@ -243,7 +243,7 @@ function pull_gs {
fi fi
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
MESSAGE="Validating Permissions on ${CUSTOM_DNS}" MESSAGE="Validating Permissions on ${CUSTOM_DNS}"
echo_fail echo_fail
@ -290,23 +290,29 @@ function push_gs {
MESSAGE="Backing Up ${GRAVITY_FI} from ${REMOTE_HOST}" MESSAGE="Backing Up ${GRAVITY_FI} from ${REMOTE_HOST}"
echo_stat echo_stat
${SSHPASSWORD} rsync -e "${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.push >/dev/null 2>&1 RSYNC_REPATH="rsync"
error_validate RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI}"
RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${GRAVITY_FI}.push"
create_rsynccmd
MESSAGE="Pushing ${GRAVITY_FI} to ${REMOTE_HOST}" MESSAGE="Pushing ${GRAVITY_FI} to ${REMOTE_HOST}"
echo_stat echo_stat
${SSHPASSWORD} rsync --rsync-path="sudo rsync" -e "${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${PIHOLE_DIR}/${GRAVITY_FI} ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI} >/dev/null 2>&1 RSYNC_REPATH="sudo rsync"
error_validate RSYNC_SOURCE="${PIHOLE_DIR}/${GRAVITY_FI}"
RSYNC_TARGET="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${GRAVITY_FI}"
create_rsynccmd
MESSAGE="Setting Permissions on ${GRAVITY_FI}" MESSAGE="Setting Permissions on ${GRAVITY_FI}"
echo_stat echo_stat
${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo chmod 664 ${PIHOLE_DIR}/${GRAVITY_FI}" >/dev/null 2>&1 CMD_TIMEOUT='15'
error_validate CMD_REQUESTED="sudo chmod 664 ${PIHOLE_DIR}/${GRAVITY_FI}"
create_sshcmd
MESSAGE="Setting Ownership on ${GRAVITY_FI}" MESSAGE="Setting Ownership on ${GRAVITY_FI}"
echo_stat echo_stat
${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo chown pihole:pihole ${PIHOLE_DIR}/${GRAVITY_FI}" >/dev/null 2>&1 CMD_TIMEOUT='15'
error_validate CMD_REQUESTED="sudo chown pihole:pihole ${PIHOLE_DIR}/${GRAVITY_FI}"
create_sshcmd
if [ "$SKIP_CUSTOM" != '1' ] if [ "$SKIP_CUSTOM" != '1' ]
then then
@ -314,23 +320,29 @@ function push_gs {
then then
MESSAGE="Backing Up ${CUSTOM_DNS} from ${REMOTE_HOST}" MESSAGE="Backing Up ${CUSTOM_DNS} from ${REMOTE_HOST}"
echo_stat echo_stat
${SSHPASSWORD} rsync -e "${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${CUSTOM_DNS} $HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.push >/dev/null 2>&1 RSYNC_REPATH="rsync"
error_validate RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${CUSTOM_DNS}"
RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/${BACKUP_FOLD}/${CUSTOM_DNS}.push"
create_rsynccmd
MESSAGE="Pushing ${CUSTOM_DNS} to ${REMOTE_HOST}" MESSAGE="Pushing ${CUSTOM_DNS} to ${REMOTE_HOST}"
echo_stat echo_stat
${SSHPASSWORD} rsync --rsync-path="sudo rsync" -e "${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${PIHOLE_DIR}/${CUSTOM_DNS} ${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${CUSTOM_DNS} >/dev/null 2>&1 RSYNC_REPATH="sudo rsync"
error_validate RSYNC_SOURCE="${PIHOLE_DIR}/${CUSTOM_DNS}"
RSYNC_TARGET="${REMOTE_USER}@${REMOTE_HOST}:${PIHOLE_DIR}/${CUSTOM_DNS}"
create_rsynccmd
MESSAGE="Setting Permissions on ${CUSTOM_DNS}" MESSAGE="Setting Permissions on ${CUSTOM_DNS}"
echo_stat echo_stat
${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo chmod 644 ${PIHOLE_DIR}/${CUSTOM_DNS}" >/dev/null 2>&1 CMD_TIMEOUT='15'
error_validate CMD_REQUESTED="sudo chmod 644 ${PIHOLE_DIR}/${CUSTOM_DNS}"
create_sshcmd
MESSAGE="Setting Ownership on ${CUSTOM_DNS}" MESSAGE="Setting Ownership on ${CUSTOM_DNS}"
echo_stat echo_stat
${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo chown root:root ${PIHOLE_DIR}/${CUSTOM_DNS}" >/dev/null 2>&1 CMD_TIMEOUT='15'
error_validate CMD_REQUESTED="sudo chown root:root ${PIHOLE_DIR}/${CUSTOM_DNS}"
create_sshcmd
fi fi
fi fi
@ -340,13 +352,15 @@ function push_gs {
MESSAGE="Updating FTLDNS Configuration" MESSAGE="Updating FTLDNS Configuration"
echo_stat echo_stat
${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "${PIHOLE_BIN} restartdns reloadlists" >/dev/null 2>&1 CMD_TIMEOUT='15'
error_validate CMD_REQUESTED="${PIHOLE_BIN} restartdns reloadlists"
create_sshcmd
MESSAGE="Reloading FTLDNS Services" MESSAGE="Reloading FTLDNS Services"
echo_stat echo_stat
${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "${PIHOLE_BIN} restartdns" >/dev/null 2>&1 CMD_TIMEOUT='15'
error_validate CMD_REQUESTED="${PIHOLE_BIN} restartdns"
create_sshcmd
logs_export logs_export
exit_withchange exit_withchange
@ -368,7 +382,7 @@ function restore_gs {
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 echo_good
else else
@ -387,7 +401,7 @@ function restore_gs {
echo_stat 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 echo_good
else else
@ -415,7 +429,7 @@ function restore_gs {
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 echo_good
else else
@ -434,7 +448,7 @@ function restore_gs {
echo_stat 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 echo_good
else else
@ -581,47 +595,82 @@ function validate_ph_folders {
## Validate SSHPASS ## Validate SSHPASS
function validate_os_sshpass { function validate_os_sshpass {
# MESSAGE="Checking SSH Configuration" SSHPASSWORD=''
# echo_info
if hash sshpass 2>/dev/null if hash sshpass 2>/dev/null
then then
if test -z "$REMOTE_PASS" MESSAGE="SSHPASS Utility Detected"
then echo_warn
SSHPASSWORD='' if [ -z "$REMOTE_PASS" ]
MESSAGE="Using SSH Key-Pair Authentication"
else
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 then
SSHPASSWORD="sshpass -p ${REMOTE_PASS}"
MESSAGE="Using SSH Password Authentication"
echo_warn
else
SSHPASSWORD=''
MESSAGE="Using SSH Key-Pair Authentication" MESSAGE="Using SSH Key-Pair Authentication"
echo_info echo_info
fi else
MESSAGE="Testing Authentication Options"
echo_stat
fi timeout 5 ssh -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} 'exit' >/dev/null 2>&1
if [ "$?" != "0" ]
then
SSHPASSWORD="sshpass -p ${REMOTE_PASS}"
MESSAGE="Using SSH Password Authentication"
echo_warn
else
MESSAGE="Valid Key-Pair Detected ${NC}(${RED}Password Ignored${NC})"
echo_info
fi
fi
else else
SSHPASSWORD='' SSHPASSWORD=''
MESSAGE="Using SSH Key-Pair Authentication" MESSAGE="Using SSH Key-Pair Authentication"
echo_info echo_info
fi fi
MESSAGE="Validating Connection to ${REMOTE_HOST}" MESSAGE="Validating Connection to ${REMOTE_HOST}"
echo_stat echo_stat
if hash ssh 2>/dev/null
CMD_TIMEOUT='5'
CMD_REQUESTED="exit"
create_sshcmd
}
## Determine SSH Pathways
function create_sshcmd {
if hash ssh 2>/dev/null
then
if [ -z "$SSHPASSWORD" ]
then then
timeout 5 ${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i "$HOME/${SSH_PKIF}" -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} 'exit' >/dev/null 2>&1 timeout --preserve-status ${CMD_TIMEOUT} ${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF} -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} "${CMD_REQUESTED}"
error_validate error_validate
elif hash dbclient 2>/dev/null else
then timeout --preserve-status ${CMD_TIMEOUT} ${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} "${CMD_REQUESTED}"
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
elif hash dbclient 2>/dev/null
then
timeout --preserve-status ${CMD_TIMEOUT} ${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF} ${REMOTE_USER}@${REMOTE_HOST} "${CMD_REQUESTED}"
error_validate
fi
}
## Determine SSH Pathways
function create_rsynccmd {
if hash ssh 2>/dev/null
then
if [ -z "$SSHPASSWORD" ]
then
rsync --rsync-path="${RSYNC_REPATH}" -e "${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${RSYNC_SOURCE} ${RSYNC_TARGET} >/dev/null 2>&1
error_validate
else
rsync --rsync-path="${RSYNC_REPATH}" -e "${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${RSYNC_SOURCE} ${RSYNC_TARGET} >/dev/null 2>&1
error_validate
fi
elif hash dbclient 2>/dev/null
then
rsync --rsync-path="${RSYNC_REPATH}" -e "${SSH_CMD} -p ${SSH_PORT} -i $HOME/${SSH_PKIF}" ${RSYNC_SOURCE} ${RSYNC_TARGET} >/dev/null 2>&1
error_validate
fi
} }
## Detect SSH-KEYGEN ## Detect SSH-KEYGEN
@ -643,13 +692,11 @@ function detect_sshkeygen {
then then
MESSAGE="Using DROPBEARKEY Instead" MESSAGE="Using DROPBEARKEY Instead"
echo_info echo_info
if [ -d $HOME/.ssh ] if [ ! -d $HOME/.ssh ]
then then
KEYGEN_COMMAND="dropbearkey -t rsa -f"
else
mkdir $HOME/.ssh >/dev/null 2>&1 mkdir $HOME/.ssh >/dev/null 2>&1
KEYGEN_COMMAND="dropbearkey -t rsa -f $HOME/${SSH_PKIF}"
fi fi
KEYGEN_COMMAND="dropbearkey -t rsa -f"
else else
MESSAGE="No Alternatives Located" MESSAGE="No Alternatives Located"
echo_info echo_info
@ -658,6 +705,68 @@ function detect_sshkeygen {
fi fi
} }
function generate_sshkey {
if [ -z $INPUT_REMOTE_PASS ]
then
if [ -f $HOME/${SSH_PKIF} ]
then
MESSAGE="Using Existing ~/${SSH_PKIF}"
echo_info
else
if hash ssh-keygen >/dev/null 2>&1
then
MESSAGE="Generating ~/${SSH_PKIF} (SSH-KEYGEN)"
echo_stat
ssh-keygen -q -P "" -t rsa -f $HOME/${SSH_PKIF} >/dev/null 2>&1
error_validate
elif hash dropbearkey >/dev/null 2>&1
then
MESSAGE="Generating ~/${SSH_PKIF} (DROPBEARKEY)"
echo_stat
if [ ! -d $HOME/.ssh ]
then
mkdir $HOME/.ssh >/dev/null 2>&1
fi
dropbearkey -t rsa -f $HOME/${SSH_PKIF} >/dev/null 2>&1
error_validate
else
MESSAGE="No SSH Key Generator Located"
echo_warn
exit_nochange
fi
fi
fi
}
function export_sshkey {
if [ -z $REMOTE_PASS ]
then
if [ -f $HOME/${SSH_PKIF} ]
then
MESSAGE="Registering Key-Pair on ${REMOTE_HOST}"
echo_info
#MESSAGE="Enter ${REMOTE_USER}@${REMOTE_HOST} Password Below"
#echo -e "${NEED} ${MESSAGE}"
if hash ssh-copy-id 2>/dev/null
then
ssh-copy-id -f -p ${SSH_PORT} -i $HOME/${SSH_PKIF}.pub ${REMOTE_USER}@${REMOTE_HOST}
elif hash dbclient 2>/dev/null
then
dropbearkey -y -f $HOME/${SSH_PKIF} | grep "^ssh-rsa " > $HOME/${SSH_PKIF}.pub
cat $HOME/${SSH_PKIF}.pub | dbclient -p ${SSH_PORT} ${REMOTE_USER}@${REMOTE_HOST} 'cat - >> .ssh/authorized_keys'
fi
else
MESSAGE="Error Registering Key-Pair"
echo_warn
fi
fi
}
## Detect Package Manager ## Detect Package Manager
function distro_check { function distro_check {
if hash apt-get 2>/dev/null if hash apt-get 2>/dev/null
@ -761,8 +870,6 @@ function md5_compare {
if [ "$primaryDBMD5" == "$secondDBMD5" ] if [ "$primaryDBMD5" == "$secondDBMD5" ]
then then
# MESSAGE="Identical ${GRAVITY_FI} Detected"
# echo_info
HASHMARK=$((HASHMARK+0)) HASHMARK=$((HASHMARK+0))
else else
MESSAGE="Differenced ${GRAVITY_FI} Detected" MESSAGE="Differenced ${GRAVITY_FI} Detected"
@ -845,7 +952,7 @@ function intent_validate {
INTENT="ENGAGE TRACTOR BEAM" INTENT="ENGAGE TRACTOR BEAM"
fi fi
MESSAGE="Enter ${INTENT} at this prompt to confirm" MESSAGE="Type ${INTENT} to Confirm"
echo_need echo_need
read INPUT_INTENT read INPUT_INTENT
@ -872,7 +979,7 @@ function config_generate {
cp $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}.example $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} cp $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}.example $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
error_validate error_validate
MESSAGE="Enter IP or DNS of primary Pi-hole server" MESSAGE="IP or DNS of Primary Pi-hole"
echo_need echo_need
read INPUT_REMOTE_HOST read INPUT_REMOTE_HOST
@ -887,7 +994,7 @@ function config_generate {
echo_warn echo_warn
fi fi
MESSAGE="Enter SSH user with SUDO rights on primary Pi-hole server" MESSAGE="SSH User with SUDO rights"
echo_need echo_need
read INPUT_REMOTE_USER read INPUT_REMOTE_USER
@ -904,89 +1011,46 @@ function config_generate {
if hash sshpass 2>/dev/null if hash sshpass 2>/dev/null
then then
MESSAGE="SSHPASS Utility Detected" MESSAGE="SSHPASS Utility Detected"
echo_info
MESSAGE="Do you want to configure password based SSH authentication?"
echo_warn
MESSAGE="Your password will be stored clear-text in the ${CONFIG_FILE}!"
echo_warn echo_warn
if hash ssh 2>/dev/null
then
MESSAGE="Please Reference Documentation"
echo_info
MESSAGE="Leave blank to use (preferred) SSH Key-Pair Authentication" MESSAGE="${BLUE}https://github.com/vmstan/gravity-sync/blob/master/ADVANCED.md#ssh-configuration${NC}"
echo_need echo_info
read INPUT_REMOTE_PASS
MESSAGE="Saving Password to ${CONFIG_FILE}" MESSAGE="Leave password blank to use key-pair! (reccomended)"
echo_stat echo_warn
sed -i "/REMOTE_PASS=''/c\REMOTE_PASS='${INPUT_REMOTE_PASS}'" $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
error_validate
else MESSAGE="SSH User Password"
MESSAGE="SSHPASS Not Installed" echo_need
echo_info read INPUT_REMOTE_PASS
MESSAGE="Defaulting to SSH Key-Pair Authentication" MESSAGE="Saving Password to ${CONFIG_FILE}"
echo_info echo_stat
sed -i "/REMOTE_PASS=''/c\REMOTE_PASS='${INPUT_REMOTE_PASS}'" $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
error_validate
elif hash dbclient 2>/dev/null
then
MESSAGE="Dropbear SSH Detected"
echo_warn
MESSAGE="Skipping Password Setup"
echo_info
fi
fi fi
if [ -z $INPUT_REMOTE_PASS ] generate_sshkey
then
if [ -f $HOME/${SSH_PKIF} ]
then
MESSAGE="Using Existing ~/${SSH_PKIF}"
echo_info
else
KEYGEN_COMMAND="ssh-keygen -t rsa -f"
detect_sshkeygen
MESSAGE="Generating ~/${SSH_PKIF}"
echo_info
MESSAGE="Accept All Defaults"
echo_warn
MESSAGE="Complete Key-Pair Creation"
echo -e "${NEED} ${MESSAGE}"
echo -e "========================================================"
echo -e "========================================================"
${KEYGEN_COMMAND} $HOME/${SSH_PKIF}
echo -e "========================================================"
echo -e "========================================================"
fi
fi
MESSAGE="Importing New ${CONFIG_FILE}" MESSAGE="Importing New ${CONFIG_FILE}"
echo_stat echo_stat
source $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} source $HOME/${LOCAL_FOLDR}/${CONFIG_FILE}
error_validate error_validate
if [ -z $REMOTE_PASS ] export_sshkey
then
if [ -f $HOME/${SSH_PKIF} ]
then
MESSAGE="Registering Key-Pair on ${REMOTE_HOST}"
echo_info
MESSAGE="Enter ${REMOTE_USER}@${REMOTE_HOST} Password Below" MESSAGE="Testing Configuration"
echo -e "${NEED} ${MESSAGE}" echo_info
echo -e "========================================================"
echo -e "========================================================"
if hash ssh-copy-id 2>/dev/null
then
ssh-copy-id -f -i $HOME/${SSH_PKIF}.pub ${REMOTE_USER}@${REMOTE_HOST}
elif hash dbclient 2>/dev/null
then
dropbearkey -y -f $HOME/${SSH_PKIF} | grep "^ssh-rsa " > $HOME/${SSH_PKIF}.pub
cat $HOME/${SSH_PKIF}.pub | dbclient ${REMOTE_USER}@${REMOTE_HOST} 'cat - >> .ssh/authorized_keys'
fi
echo -e "========================================================"
echo -e "========================================================"
else
MESSAGE="Error Creating Key-Pair"
echo -e "${FAIL} ${MESSAGE}"
fi
fi
validate_os_sshpass validate_os_sshpass
@ -1050,10 +1114,6 @@ function list_gs_arguments {
echo -e " ${YELLOW}restore${NC} Restore ${GRAVITY_FI} on this server" echo -e " ${YELLOW}restore${NC} Restore ${GRAVITY_FI} on this server"
echo -e " ${YELLOW}compare${NC} Just check for differences" echo -e " ${YELLOW}compare${NC} Just check for differences"
echo -e "" echo -e ""
# echo -e "Update Options:"
# echo -e " ${YELLOW}update${NC} Use GitHub to update this script to the latest version"
# echo -e " ${YELLOW}beta${NC} Use GitHub to update this script to the latest beta version"
# echo -e ""
echo -e "Debug Options:" echo -e "Debug Options:"
echo -e " ${YELLOW}logs${NC} Show recent successful replication jobs" echo -e " ${YELLOW}logs${NC} Show recent successful replication jobs"
echo -e " ${YELLOW}cron${NC} Display output of last crontab execution" echo -e " ${YELLOW}cron${NC} Display output of last crontab execution"
@ -1162,9 +1222,6 @@ function task_configure {
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good echo_good
#MESSAGE="${TASKTYPE} Requested"
#echo_info
if [ -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} ] if [ -f $HOME/${LOCAL_FOLDR}/${CONFIG_FILE} ]
then then
config_delete config_delete
@ -1207,9 +1264,6 @@ function task_update {
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good echo_good
#MESSAGE="${TASKTYPE} Requested"
#echo_info
update_gs update_gs
} }
@ -1219,9 +1273,6 @@ function task_version {
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good echo_good
#MESSAGE="${TASKTYPE} Requested"
#echo_info
show_version show_version
exit_nochange exit_nochange
} }
@ -1232,9 +1283,6 @@ function task_logs {
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good echo_good
#MESSAGE="${TASKTYPE} Requested"
#echo_info
logs_gs logs_gs
} }
@ -1244,17 +1292,10 @@ function task_compare {
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good echo_good
#MESSAGE="${TASKTYPE} Requested"
#echo_info
import_gs import_gs
validate_gs_folders
# MESSAGE="Validating OS Configuration" validate_ph_folders
# echo_info validate_os_sshpass
validate_gs_folders
validate_ph_folders
validate_os_sshpass
md5_compare md5_compare
} }
@ -1265,9 +1306,6 @@ function task_cron {
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good echo_good
#MESSAGE="${TASKTYPE} Requested"
#echo_info
show_crontab show_crontab
} }
@ -1328,16 +1366,10 @@ case $# in
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good echo_good
#MESSAGE="${TASKTYPE} Requested"
#echo_info
import_gs import_gs
validate_gs_folders
# MESSAGE="Validating Folder Configuration" validate_ph_folders
# echo_info validate_os_sshpass
validate_gs_folders
validate_ph_folders
validate_os_sshpass
pull_gs pull_gs
exit exit
@ -1348,16 +1380,10 @@ case $# in
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good echo_good
#MESSAGE="${TASKTYPE} Requested"
#echo_info
import_gs import_gs
validate_gs_folders
# MESSAGE="Validating Folder Configuration" validate_ph_folders
# echo_info validate_os_sshpass
validate_gs_folders
validate_ph_folders
validate_os_sshpass
push_gs push_gs
exit exit
@ -1368,16 +1394,9 @@ case $# in
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested" MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good echo_good
#MESSAGE="${TASKTYPE} Requested"
#echo_info
import_gs import_gs
validate_gs_folders
# MESSAGE="Validating Folder Configuration" validate_ph_folders
# echo_info
validate_gs_folders
validate_ph_folders
# validate_os_sshpass
restore_gs restore_gs
exit exit