Compare commits

...

2 Commits

Author SHA1 Message Date
John Lancaster
7f634bf0ba more prompts 2026-01-04 11:48:01 -06:00
John Lancaster
fce8a539d4 prompts wip 2026-01-04 11:33:36 -06:00

View File

@@ -35,17 +35,30 @@ ssh_config_val() {
prompt_user() { prompt_user() {
local title="\e[1m${1:-Title}\e[0m" local title="\e[1m${1:-Title}\e[0m"
local prompt="${2:-Prompt for the user}" local prompt="${2:-Prompt for the user}"
local msg="$title: $prompt" full_prompt_msg="$title: $prompt"
echo -n -e "$YELLOW_BANG $msg" echo -n -e "$YELLOW_BANG $full_prompt_msg"
read -p " (y/n) " -n 1 -r read -p " (y/n) " -n 1 -r
echo echo
update_prompt() {
echo -en "\e[1A\r\e[K"
echo -e "$1 $msg $REPLY"
} }
update_prompt() {
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"
if [[ "$msg" != "$full_prompt_msg" ]]; then
echo -e "$icon $msg"
else
echo -e "$icon $msg $REPLY"
fi
}
auto_update_prompt() {
if [[ $REPLY =~ ^[Yy]$ ]]; then if [[ $REPLY =~ ^[Yy]$ ]]; then
update_prompt $GREEN_CHECK update_prompt $GREEN_CHECK
elif [[ $REPLY =~ ^[Nn]$ ]]; then elif [[ $REPLY =~ ^[Nn]$ ]]; then
@@ -53,7 +66,6 @@ prompt_user() {
fi fi
} }
sign_host_cert() { sign_host_cert() {
local if="eth0" local if="eth0"
local IP_ADDRESS=$(ip -4 addr show dev $if | awk '/inet /{print $2}' | cut -d/ -f1) && \ local IP_ADDRESS=$(ip -4 addr show dev $if | awk '/inet /{print $2}' | cut -d/ -f1) && \
@@ -67,7 +79,7 @@ sign_host_cert() {
} }
check_ssh_files() { check_ssh_config_files() {
row_success() { row_success() {
local key="$1" local key="$1"
local path="$2" local path="$2"
@@ -118,12 +130,11 @@ check_ssh_files() {
missing) missing)
# Do something if trustedusercakeys is missing # Do something if trustedusercakeys is missing
prompt_user "User CA" "Created the trusted keys file?" 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 if [[ $REPLY =~ ^[Yy]$ ]]; then
(step ssh config --roots > "$path") (step ssh config --roots > "$path")
echo -e "$GREEN_CHECK Created public key file for SSH user CA" update_prompt $GREEN_CHECK "Created public key file for SSH user CA"
else
update_prompt $RED_X
fi fi
;; ;;
unconfigured) return;; unconfigured) return;;
@@ -159,52 +170,47 @@ check_cert_config() {
install_cert_config() { install_cert_config() {
mkdir -p $(dirname $cfg_path) mkdir -p $(dirname $cfg_path)
cat <<EOF > $cfg_path cat <<EOF > $cfg_path
TrustedUserCAKeys $SSH_USER_CA TrustedUserCAKeys $SSH_USER_CA
HostKey $SSH_HOST_KEY HostKey $SSH_HOST_KEY
HostCertificate $SSH_HOST_CERT HostCertificate $SSH_HOST_CERT
EOF EOF
echo -e "$GREEN_CHECK Configured sshd to use and accept SSH certs."
} }
if [[ ! -e $cfg_path ]]; then if [[ ! -e $cfg_path ]]; then
prompt_user "sshd config" "Do you want to configure sshd?" prompt_user "sshd config" "Do you want to configure sshd?"
if [[ $REPLY =~ ^[Yy]$ ]]; then if [[ $REPLY =~ ^[Yy]$ ]]; then
install_cert_config install_cert_config
update_prompt $GREEN_CHECK "Configured sshd"
fi
fi
restart_sshd restart_sshd
fi
fi
} }
restart_sshd() { restart_sshd() {
if systemctl is-active --quiet sshd; then if ! systemctl is-active --quiet sshd; then
local sshd_pid=$(systemctl show --property MainPID --value sshd) prompt_user "sshd.service" "sshd.service is not active. Restart?"
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 [[ $REPLY =~ ^[Yy]$ ]]; then if [[ $REPLY =~ ^[Yy]$ ]]; then
systemctl start sshd systemctl restart sshd
echo -e "$GREEN_CHECK Started sshd" local sshd_pid=$(systemctl show --property MainPID --value sshd)
update_prompt $GREEN_CHECK "Restarted sshd.service on PID: $sshd_pid"
fi fi
else
local sshd_pid=$(systemctl show --property MainPID --value sshd)
echo -e "$GREEN_CHECK sshd.service is active on PID: $sshd_pid"
fi fi
} }
#
# Run Process # Run Process
#
# check_cert_config "certs.conf" check_cert_config "certs.conf"
# check_ssh_files echo
check_ssh_config_files
# echo "" echo
# echo "Host key fingerprint" echo "Host key fingerprint"
# ssh_fingerprint hostkey ssh_fingerprint hostkey
# prompt_user
prompt_user # auto_update_prompt