error message for cert renewal
This commit is contained in:
@@ -33,7 +33,7 @@ title_msg() {
|
||||
prompt_user() {
|
||||
full_prompt_msg="$(title_msg "${1}" "${2}")"
|
||||
echo -n -e "$MAGENTA_QUESTION $full_prompt_msg"
|
||||
read -p " (y/n) " -n 1 -r
|
||||
read -p " (y/n) " -r
|
||||
}
|
||||
|
||||
update_prompt() {
|
||||
@@ -50,40 +50,72 @@ update_prompt() {
|
||||
}
|
||||
|
||||
reupdate_prompt() {
|
||||
# echo -en "$UP_ONE_LINE"
|
||||
echo -en "$UP_ONE_LINE"
|
||||
update_prompt "$@"
|
||||
}
|
||||
|
||||
icon_msg() {
|
||||
local icon="$1"
|
||||
echo -en "$icon "
|
||||
title_msg "${@:2}"
|
||||
}
|
||||
|
||||
success_msg() {
|
||||
icon_msg "${GREEN_CHECK}" "$@"
|
||||
}
|
||||
|
||||
warn_msg() {
|
||||
icon_msg "${YELLOW_BANG}" "$@"
|
||||
}
|
||||
|
||||
check_user_private_key() {
|
||||
if [[ -e "$SSH_USER_KEY" ]]; then
|
||||
success_msg "SSH User" "Private key: $SSH_USER_KEY"
|
||||
else
|
||||
prompt_user "SSH User" "Private key missing: ${SSH_USER_KEY}. Create?"
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
reupdate_prompt $YELLOW_BANG "SSH User" "Creating private key"
|
||||
ERROR_MSG=$(ssh-keygen -t ed25519 -f "$SSH_USER_KEY" -N "" 2>&1)
|
||||
if [[ $? -eq 0 ]]; then
|
||||
reupdate_prompt $GREEN_CHECK "SSH User" "Created private key: ${SSH_USER_KEY}"
|
||||
else
|
||||
reupdate_prompt $RED_X "SSH User" "Failed to create key: ${SSH_USER_KEY}"
|
||||
echo -e "Error: $ERROR_MSG"
|
||||
fi
|
||||
elif [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||
reupdate_prompt $YELLOW_BANG "SSH User" "Continuing without private key"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
check_user_cert() {
|
||||
if [[ -e "$SSH_USER_CERT" ]]; then
|
||||
success_msg "SSH User" "Certificate: $SSH_USER_CERT"
|
||||
else
|
||||
prompt_user "SSH User" "Cert missing. Renew cert?"
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
if renew_user_cert; then
|
||||
update_prompt $GREEN_CHECK "SSH User" "Renewed cert"
|
||||
else
|
||||
update_prompt $RED_X "SSH User" "Failed to renew cert"
|
||||
fi
|
||||
elif [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||
reupdate_prompt $RED_X "SSH User" "Declined to renew cert"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
renew_user_cert() {
|
||||
step ssh certificate --sign \
|
||||
--principal root --principal john \
|
||||
--provisioner admin \
|
||||
john@john-pc-ubuntu ~/.ssh/id_ed25519.pub
|
||||
john@john-pc-ubuntu ~/.ssh/id_ed25519.pub < /dev/tty
|
||||
}
|
||||
|
||||
#
|
||||
# Run Process
|
||||
#
|
||||
|
||||
if [[ ! -e "$SSH_USER_KEY" ]]; then
|
||||
prompt_user "SSH User" "Private key missing: ${SSH_USER_KEY}. Create?"
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
update_prompt $YELLOW_BANG "SSH User" "Creating private key"
|
||||
sleep 0.5
|
||||
reupdate_prompt $GREEN_CHECK "SSH User" "Created private key: ${SSH_USER_KEY}"
|
||||
fi
|
||||
fi
|
||||
|
||||
prompt_user "SSH User" "Cert missing. Renew cert?"
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
# update_prompt $YELLOW_BANG "SSH User" "Renewing cert"
|
||||
# sleep 0.25
|
||||
renew_user_cert
|
||||
if [[ $? -eq 0 ]]; then
|
||||
update_prompt $GREEN_CHECK "SSH User" "Renewed cert"
|
||||
else
|
||||
update_prompt $RED_X "SSH User" "Failed to renew cert"
|
||||
fi
|
||||
echo
|
||||
fi
|
||||
check_user_private_key
|
||||
check_user_cert
|
||||
|
||||
Reference in New Issue
Block a user