mirror of
https://github.com/vmstan/gravity-sync.git
synced 2025-06-10 08:44:12 -04:00
Rewrite SSH key generation
This commit is contained in:
parent
bdb770ef60
commit
1ab2a4ffe9
@ -16,7 +16,7 @@
|
|||||||
- Removes INFO that SSHPASS is not installed during config, if it's not needed. Redirects user to documentation.
|
- Removes INFO that SSHPASS is not installed during config, if it's not needed. Redirects user to documentation.
|
||||||
- Better error handling of configuration options.
|
- Better error handling of configuration options.
|
||||||
- Adds custom port specification to ssh-copy-id command during configuration generation.
|
- Adds custom port specification to ssh-copy-id command during configuration generation.
|
||||||
- OpenSSH key generation works fewer user prompts.
|
- OpenSSH key generation works with fewer user prompts.
|
||||||
|
|
||||||
#### 1.7.7
|
#### 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.
|
- `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.
|
||||||
|
123
gravity-sync.sh
123
gravity-sync.sh
@ -705,6 +705,74 @@ 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}
|
||||||
|
error_validate
|
||||||
|
|
||||||
|
elif hash dropbearkey >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
MESSAGE="Generating ~/${SSH_PKIF} (DROPBEARKEY)"
|
||||||
|
echo_info
|
||||||
|
if [ ! -d $HOME/.ssh ]
|
||||||
|
then
|
||||||
|
mkdir $HOME/.ssh >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
echo -e "========================================================"
|
||||||
|
echo -e "========================================================"
|
||||||
|
dropbearkey -t rsa -f $HOME/${SSH_PKIF}
|
||||||
|
echo -e "========================================================"
|
||||||
|
echo -e "========================================================"
|
||||||
|
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}"
|
||||||
|
|
||||||
|
echo -e "========================================================"
|
||||||
|
echo -e "========================================================"
|
||||||
|
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 ${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
|
||||||
|
}
|
||||||
|
|
||||||
## 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
|
||||||
@ -978,65 +1046,14 @@ function config_generate {
|
|||||||
fi
|
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 -N \"""\" -t rsa -f"
|
|
||||||
detect_sshkeygen
|
|
||||||
|
|
||||||
MESSAGE="Generating ~/${SSH_PKIF}"
|
|
||||||
echo_info
|
|
||||||
|
|
||||||
MESSAGE="Accept All Defaults If Prompted"
|
|
||||||
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"
|
|
||||||
echo -e "${NEED} ${MESSAGE}"
|
|
||||||
|
|
||||||
echo -e "========================================================"
|
|
||||||
echo -e "========================================================"
|
|
||||||
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 ${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
|
|
||||||
|
|
||||||
MESSAGE="Testing Configuration"
|
MESSAGE="Testing Configuration"
|
||||||
echo_info
|
echo_info
|
||||||
|
Loading…
x
Reference in New Issue
Block a user