From 334ed3aedce6cc8c22c598da2f8b8498255619b1 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Sat, 25 Oct 2025 19:08:48 +0000 Subject: [PATCH] Improve setup script auth usability --- internal/api/config_handlers.go | 48 +++++++++++++++++---------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/internal/api/config_handlers.go b/internal/api/config_handlers.go index 14598d3..d6bb7e5 100644 --- a/internal/api/config_handlers.go +++ b/internal/api/config_handlers.go @@ -3593,15 +3593,14 @@ else IFS= read -r AUTH_TOKEN if command -v stty >/dev/null 2>&1; then stty echo; fi printf "\n" - elif { exec 3/dev/null; then - printf "Pulse setup token: " >&3 - if command -v stty >/dev/null 2>&1; then stty -echo <&3 2>/dev/null || true; fi - IFS= read -r AUTH_TOKEN <&3 || true - if command -v stty >/dev/null 2>&1; then stty echo <&3 2>/dev/null || true; fi - printf "\n" >&3 - exec 3<&- - fi - fi + elif [ -c /dev/tty ] && [ -r /dev/tty ] && [ -w /dev/tty ]; then + printf "Pulse setup token: " >/dev/tty + if command -v stty >/dev/null 2>&1; then stty -echo /dev/null || true; fi + IFS= read -r AUTH_TOKEN /dev/null 2>&1; then stty echo /dev/null || true; fi + printf "\n" >/dev/tty + fi + fi # Only proceed with auto-registration if we have an auth token if [ -n "$AUTH_TOKEN" ]; then @@ -4653,15 +4652,14 @@ else IFS= read -r AUTH_TOKEN if command -v stty >/dev/null 2>&1; then stty echo; fi printf "\n" - elif { exec 3/dev/null; then - printf "Pulse setup token: " >&3 - if command -v stty >/dev/null 2>&1; then stty -echo <&3 2>/dev/null || true; fi - IFS= read -r AUTH_TOKEN <&3 || true - if command -v stty >/dev/null 2>&1; then stty echo <&3 2>/dev/null || true; fi - printf "\n" >&3 - exec 3<&- - fi - fi + elif [ -c /dev/tty ] && [ -r /dev/tty ] && [ -w /dev/tty ]; then + printf "Pulse setup token: " >/dev/tty + if command -v stty >/dev/null 2>&1; then stty -echo /dev/null || true; fi + IFS= read -r AUTH_TOKEN /dev/null 2>&1; then stty echo /dev/null || true; fi + printf "\n" >/dev/tty + fi + fi # Only proceed with auto-registration if we have an auth token if [ -n "$AUTH_TOKEN" ]; then @@ -4871,12 +4869,16 @@ func (h *ConfigHandlers) HandleSetupScriptURL(w http.ResponseWriter, r *http.Req tokenHint = fmt.Sprintf("%s…%s", token[:3], token[len(token)-3:]) } + command := fmt.Sprintf(`curl -sSL "%s" | PULSE_SETUP_TOKEN=%s bash`, scriptURL, token) + response := map[string]interface{}{ - "url": scriptURL, - "command": fmt.Sprintf(`curl -sSL "%s" | bash`, scriptURL), - "expires": expiry.Unix(), - "setupToken": token, - "tokenHint": tokenHint, + "url": scriptURL, + "command": command, + "expires": expiry.Unix(), + "setupToken": token, + "tokenHint": tokenHint, + "commandWithEnv": command, + "commandWithoutEnv": fmt.Sprintf(`curl -sSL "%s" | bash`, scriptURL), } w.Header().Set("Content-Type", "application/json")