From 7f634bf0ba04af25a54398d44e0c5d2bccfc9f32 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sun, 4 Jan 2026 11:48:01 -0600 Subject: [PATCH] more prompts --- scripts/ssh-server-check.sh | 56 +++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/scripts/ssh-server-check.sh b/scripts/ssh-server-check.sh index ed621fa..c4ecbbe 100755 --- a/scripts/ssh-server-check.sh +++ b/scripts/ssh-server-check.sh @@ -43,9 +43,19 @@ prompt_user() { } update_prompt() { - local msg="${1:-$full_prompt_msg}" + local icon="$1" + local msg="${2:-$full_prompt_msg}" + + # \e[1A: Move up one line + # \r: Move to start of line + # \e[K: Clear to end of line echo -en "\e[1A\r\e[K" - echo -e "$1 $msg $REPLY" + + if [[ "$msg" != "$full_prompt_msg" ]]; then + echo -e "$icon $msg" + else + echo -e "$icon $msg $REPLY" + fi } auto_update_prompt() { @@ -69,7 +79,7 @@ sign_host_cert() { } -check_ssh_files() { +check_ssh_config_files() { row_success() { local key="$1" local path="$2" @@ -171,38 +181,36 @@ EOF prompt_user "sshd config" "Do you want to configure sshd?" if [[ $REPLY =~ ^[Yy]$ ]]; then install_cert_config - restart_sshd + update_prompt $GREEN_CHECK "Configured sshd" fi fi + restart_sshd } restart_sshd() { - if systemctl is-active --quiet sshd; then - local sshd_pid=$(systemctl show --property MainPID --value sshd) - echo "Restarting sshd service..." - systemctl restart sshd - echo -e "$GREEN_CHECK Restarted sshd service on PID: $sshd_pid" - else - echo -e "$YELLOW_BANG Not running sshd service" - read -p "Do you want to start sshd? (y/n) " -n 1 -r - echo + if ! systemctl is-active --quiet sshd; then + prompt_user "sshd.service" "sshd.service is not active. Restart?" if [[ $REPLY =~ ^[Yy]$ ]]; then - systemctl start sshd - echo -e "$GREEN_CHECK Started sshd" + systemctl restart sshd + local sshd_pid=$(systemctl show --property MainPID --value sshd) + update_prompt $GREEN_CHECK "Restarted sshd.service on PID: $sshd_pid" fi + else + local sshd_pid=$(systemctl show --property MainPID --value sshd) + echo -e "$GREEN_CHECK sshd.service is active on PID: $sshd_pid" fi } -# + # Run Process -# -# check_cert_config "certs.conf" -# check_ssh_files +check_cert_config "certs.conf" +echo +check_ssh_config_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 +# prompt_user +# auto_update_prompt