From 20ca89d4529ad04c394ce8e1079530d9918ebf44 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sun, 4 Jan 2026 11:21:22 -0600 Subject: [PATCH] updating prompt --- scripts/ssh-server-check.sh | 56 +++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/scripts/ssh-server-check.sh b/scripts/ssh-server-check.sh index ff6ae13..ac24c80 100755 --- a/scripts/ssh-server-check.sh +++ b/scripts/ssh-server-check.sh @@ -1,20 +1,24 @@ #!/usr/bin/env bash -GREEN_CHECK="\e[32m✔\e[0m" -RED_X="\e[31m✗\e[0m" -YELLOW_BANG="\e[33m!\e[0m" +# +# Env vars +# +# SSH config paths SSH_CFG_DIR="/etc/ssh" SSH_USER_CA="$SSH_CFG_DIR/ssh_user_ca.pub" SSH_HOST_KEY="$SSH_CFG_DIR/ssh_host_ed25519_key" SSH_HOST_PUBLIC_KEY="$SSH_HOST_KEY.pub" SSH_HOST_CERT="$SSH_HOST_KEY-cert.pub" +GREEN_CHECK="\e[32m✔\e[0m" +RED_X="\e[31m✗\e[0m" +YELLOW_BANG="\e[33m!\e[0m" + # # Function Definition # - # This test loads the sshd config to see what values actually get parsed. ssh_config_val() { local field="$1" @@ -28,6 +32,27 @@ ssh_config_val() { echo $(sshd -T 2>/dev/null | grep -i "^$field " | head -1 | awk '{print $2}') } +prompt_user() { + local title="\e[1m${1:-Title}\e[0m" + local prompt="${2:-Prompt for the user}" + local msg="$title: $prompt" + + echo -n -e "$YELLOW_BANG $msg" + read -p " (y/n) " -n 1 -r + echo + + update_prompt() { + echo -en "\e[1A\r\e[K" + echo -e "$1 $msg $REPLY" + } + + if [[ $REPLY =~ ^[Yy]$ ]]; then + update_prompt $GREEN_CHECK + elif [[ $REPLY =~ ^[Nn]$ ]]; then + update_prompt $RED_X + fi +} + sign_host_cert() { local if="eth0" @@ -92,8 +117,10 @@ check_ssh_files() { success) return ;; missing) # Do something if trustedusercakeys is missing - read -p "Create the trusted keys file? (y/n) " -n 1 -r - echo + prompt_user "User CA" "Created the trusted keys file?" + + # read -p "Create the trusted keys file? (y/n) " -n 1 -r + # echo if [[ $REPLY =~ ^[Yy]$ ]]; then (step ssh config --roots > "$path") echo -e "$GREEN_CHECK Created public key file for SSH user CA" @@ -144,9 +171,7 @@ EOF } if [[ ! -e $cfg_path ]]; then - echo -e "$YELLOW_BANG sshd not configured to use SSH certs" - read -p "Do you want to configure sshd? (y/n) " -n 1 -r - echo + prompt_user "sshd config" "Do you want to configure sshd?" if [[ $REPLY =~ ^[Yy]$ ]]; then install_cert_config restart_sshd @@ -175,9 +200,12 @@ restart_sshd() { # Run Process # -check_cert_config "certs.conf" -check_ssh_files +# check_cert_config "certs.conf" +# check_ssh_files -echo "" -echo "Host key fingerprint" -ssh_fingerprint hostkey +# echo "" +# echo "Host key fingerprint" +# ssh_fingerprint hostkey + + +prompt_user \ No newline at end of file