From 7c85f326c8ad18cb0769e63bb35b3120dfbfe1be Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 11 Aug 2026 04:11:56 +0000 Subject: [PATCH] Accept Beszel's own "copy for docker compose" snippet directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Confirmed live: Beszel's Settings -> Tokens & Fingerprints page surfaces a "copy for docker compose" shortcut as the prominent way to grab the key/token — not a bare string — so the previous two-prompt flow (paste plain key, paste plain token) didn't match what people actually have in their clipboard. The user pasted that YAML snippet into .env by hand afterward, using the container's raw KEY/TOKEN names and YAML `NAME: 'value'` syntax instead of what the compose file's own ${AGENT_KEY:-}/${AGENT_TOKEN:-} substitution actually reads — the agent then failed with "no key provided" since AGENT_KEY was never actually set. _beszel_extract_field pulls KEY/TOKEN out of whatever shape the paste arrives in — YAML mapping (`KEY: 'value'`), compose list style (`- KEY=value`), or plain `KEY=value` — regardless of quoting. The agent prompt now accepts a multi-line paste (the whole snippet, or just the two lines) instead of asking for two separately pre-extracted values; if no labeled KEY/TOKEN line is found at all, it falls back to treating the paste as a bare key and asks for the token separately, so a Beszel version that really does just show plain strings still works. Verified all three paths directly: the exact mixed KEY:/TOKEN= paste the user had, the skip path (blank first line leaves .env untouched), and the bare-value fallback with no labels at all. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01H4k6J1qXXyYxhGEgnJaMvn --- services/beszel.sh | 54 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/services/beszel.sh b/services/beszel.sh index 242f4cd..5ec9585 100644 --- a/services/beszel.sh +++ b/services/beszel.sh @@ -134,6 +134,20 @@ fi register_service beszel utilities "Lightweight server + Docker monitoring (Beszel) — CPU/RAM/disk/network, auto-discovers running containers" 8090 +# Pulls a NAME's value out of a pasted blob regardless of which shape it +# arrives in — Beszel's own "copy for docker compose" button (the most +# prominent option next to the key/token fields, confirmed live to be +# what people actually click) hands you YAML (`KEY: 'value'` or +# `- KEY=value`), not a bare string — matches "KEY"/"TOKEN" with either +# `:` or `=`, optional leading `- ` list marker, and strips a single +# layer of surrounding quotes if present. +_beszel_extract_field() { + local field="$1" blob="$2" + echo "$blob" | grep -iE "^[[:space:]]*-?[[:space:]]*${field}[[:space:]]*[:=]" | head -1 \ + | sed -E "s/^[[:space:]]*-?[[:space:]]*${field}[[:space:]]*[:=][[:space:]]*//I" \ + | sed -E "s/^[\"']//; s/[\"'][[:space:]]*\$//" +} + _beszel_configure_agent() { local dir="$1" web_port="$2" @@ -142,19 +156,43 @@ _beszel_configure_agent() { echo " http://localhost:${web_port} (or its Caddy domain, once configured)" echo "" echo " Create the admin account, then go to Settings → Tokens & Fingerprints:" - echo " - Enable the universal token and copy its value" - echo " - Copy the public key shown there too" + echo " - Enable the universal token" + echo " - The key/token fields there usually offer a 'copy for docker" + echo " compose' shortcut — paste whatever that gives you below as-is," + echo " whole snippet or just the two lines, doesn't matter which." echo "" - local AGENT_KEY="" AGENT_TOKEN="" - prompt_text " Paste the public key (blank to skip and do this later):" "" AGENT_KEY - if [ -z "$AGENT_KEY" ]; then + if [ "${UNATTENDED:-false}" = "true" ]; then + log_info "Skipping agent setup (unattended) — re-run this installer to finish it." + return 0 + fi + + echo " Paste it below, then an empty line to finish (blank first line to skip for now):" + local PASTE="" LINE + while IFS= read -r LINE; do + [ -z "$LINE" ] && break + PASTE="${PASTE}${LINE}"$'\n' + done + + if [ -z "$PASTE" ]; then log_info "Skipping agent setup for now — re-run this installer once you have the key and token." return 0 fi - prompt_text " Paste the universal token:" "" AGENT_TOKEN - if [ -z "$AGENT_TOKEN" ]; then - log_info "No token entered — skipping agent setup for now. Re-run this installer to finish." + + local AGENT_KEY AGENT_TOKEN + AGENT_KEY="$(_beszel_extract_field KEY "$PASTE")" + AGENT_TOKEN="$(_beszel_extract_field TOKEN "$PASTE")" + + # Didn't find a labeled KEY/TOKEN line at all — treat the paste as a + # single bare value and ask for the other one directly, so a UI that + # really does just show plain strings (no YAML) still works. + if [ -z "$AGENT_KEY" ] && [ -z "$AGENT_TOKEN" ]; then + AGENT_KEY="$(echo "$PASTE" | head -1)" + prompt_text " Paste the universal token:" "" AGENT_TOKEN + fi + + if [ -z "$AGENT_KEY" ] || [ -z "$AGENT_TOKEN" ]; then + log_warning "Couldn't find both a key and a token in that — skipping agent setup. Re-run this installer to try again." return 0 fi