mirror of
https://github.com/vmstan/gravity-sync.git
synced 2024-08-30 18:22:11 +00:00
9dae851a9c
* first! * folders * break out colors * home * seperate update * breakout pull * move file * breakout push * breakout smart * restore breakout * include restore * breakout logs validate ssh * breakout config exit intent * source exit * breakout backup automation and purge * breakout root * file headers * create push pull restore smart functions * consolidate options * include root check * includes * includes 2 * automate * rearrange imports * header * ssh rsync * new install steps * ticks * yellow * host check * check for git * ticks * check for pihole * check sudo powers * create sudo file * write output * pihole directory * install sudo file * purge error message * comment cleanup * installer * header * instructions * l * read p * header * skip prompts * sudo no longer in config * compare exit code * exit with change * 3.0 Co-authored-by: Michael Stanclift <vmstan@Sovereign.vmstan.net> Co-authored-by: Michael Stanclift <vmstan@Sovereign.local>
185 lines
3.9 KiB
Bash
185 lines
3.9 KiB
Bash
# GRAVITY SYNC BY VMSTAN #####################
|
|
# gs-ssh.sh ##################################
|
|
|
|
# For documentation or downloading updates visit https://github.com/vmstan/gravity-sync
|
|
# This code is called from the main gravity-sync.sh file and should not execute directly!
|
|
|
|
## Determine SSH Pathways
|
|
function create_sshcmd {
|
|
if hash ssh 2>/dev/null
|
|
then
|
|
if [ -z "$SSHPASSWORD" ]
|
|
then
|
|
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
|
|
else
|
|
timeout --preserve-status ${CMD_TIMEOUT} ${SSHPASSWORD} ${SSH_CMD} -p ${SSH_PORT} -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} "${CMD_REQUESTED}"
|
|
error_validate
|
|
fi
|
|
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
|
|
fi
|
|
}
|
|
|
|
## Detect SSH-KEYGEN
|
|
function detect_sshkeygen {
|
|
MESSAGE="Validating SSH-KEYGEN install on $HOSTNAME"
|
|
echo_stat
|
|
|
|
if hash ssh-keygen >/dev/null 2>&1
|
|
then
|
|
echo_good
|
|
else
|
|
echo_fail
|
|
MESSAGE="SSH-KEYGEN is Required"
|
|
echo_info
|
|
|
|
exit_nochange
|
|
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
|
|
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
|
|
|
|
ssh-copy-id -f -p ${SSH_PORT} -i $HOME/${SSH_PKIF}.pub ${REMOTE_USER}@${REMOTE_HOST}
|
|
else
|
|
MESSAGE="Error Registering Key-Pair"
|
|
echo_warn
|
|
fi
|
|
fi
|
|
}
|
|
|
|
## Detect SSH & RSYNC
|
|
function detect_ssh {
|
|
MESSAGE="Validating SSH Client on $HOSTNAME"
|
|
echo_stat
|
|
|
|
if hash ssh 2>/dev/null
|
|
then
|
|
MESSAGE="${MESSAGE} (OpenSSH)"
|
|
echo_good
|
|
SSH_CMD='ssh'
|
|
elif hash dbclient 2>/dev/null
|
|
then
|
|
MESSAGE="${MESSAGE} (Dropbear)"
|
|
echo_fail
|
|
|
|
MESSAGE="Dropbear not supported in GS ${VERSION}"
|
|
echo_info
|
|
exit_nochange
|
|
else
|
|
echo_fail
|
|
|
|
MESSAGE="Attempting to Compensate"
|
|
echo_warn
|
|
MESSAGE="Installing SSH Client with ${PKG_MANAGER}"
|
|
echo_stat
|
|
|
|
${PKG_INSTALL} ssh-client >/dev/null 2>&1
|
|
error_validate
|
|
fi
|
|
|
|
MESSAGE="Validating RSYNC Installed on $HOSTNAME"
|
|
echo_stat
|
|
|
|
if hash rsync 2>/dev/null
|
|
then
|
|
echo_good
|
|
else
|
|
echo_fail
|
|
MESSAGE="RSYNC is Required"
|
|
echo_warn
|
|
|
|
distro_check
|
|
|
|
MESSAGE="Attempting to Compensate"
|
|
echo_warn
|
|
|
|
MESSAGE="Installing RSYNC with ${PKG_MANAGER}"
|
|
echo_stat
|
|
${PKG_INSTALL} rsync >/dev/null 2>&1
|
|
error_validate
|
|
fi
|
|
}
|
|
|
|
function detect_remotersync {
|
|
MESSAGE="Creating Test File on ${REMOTE_HOST}"
|
|
echo_stat
|
|
|
|
CMD_TIMEOUT='15'
|
|
CMD_REQUESTED="touch ~/gs.test"
|
|
create_sshcmd
|
|
|
|
MESSAGE="If pull test fails ensure RSYNC is installed on ${REMOTE_HOST}"
|
|
echo_warn
|
|
|
|
MESSAGE="Pulling Test File to $HOSTNAME"
|
|
echo_stat
|
|
|
|
RSYNC_REPATH="rsync"
|
|
RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:~/gs.test"
|
|
RSYNC_TARGET="$HOME/${LOCAL_FOLDR}/gs.test"
|
|
create_rsynccmd
|
|
|
|
MESSAGE="Cleaning Up Local Test File"
|
|
echo_stat
|
|
|
|
rm $HOME/${LOCAL_FOLDR}/gs.test
|
|
error_validate
|
|
|
|
MESSAGE="Cleaning Up Remote Test File"
|
|
echo_stat
|
|
|
|
CMD_TIMEOUT='15'
|
|
CMD_REQUESTED="rm ~/gs.test"
|
|
create_sshcmd
|
|
}
|
|
|
|
function show_target {
|
|
MESSAGE="Targeting ${REMOTE_USER}@${REMOTE_HOST}"
|
|
echo_info
|
|
|
|
detect_ssh
|
|
} |