From 7e64129e49f276f9ba2314113d60ce36acdb9c89 Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Sat, 30 May 2020 20:20:06 -0500 Subject: [PATCH] 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}