manage_users.sh: fix login silently bailing on credential entry

Three fixes in ensure_token:
- Use jq to build the login JSON so special chars in passwords
  (quotes, backslashes, etc.) don't break the raw string interpolation
- Add || true to the curl call so set -e doesn't silently exit on
  connection refused before the response check runs
- Show FileBrowser's actual response on failure so the user can see
  whether it's wrong credentials vs unreachable vs something else

https://claude.ai/code/session_01UZus2Q9gNTfUdqSMrhuX29
This commit is contained in:
Claude
2026-06-08 00:06:21 +00:00
parent ea1a9cf3b7
commit 9ab7979833
+17 -6
View File
@@ -101,17 +101,28 @@ ensure_token() {
[[ -n "$TOKEN" ]] && return 0
echo
echo " ${B}FileBrowser login${R} ${DIM}(${FB_URL})${R}"
local _u _p _tok
local _u _p _payload _tok
read -r -p " Admin username [admin]: " _u
_u="${_u:-admin}"
read -r -s -p " Admin password: " _p; echo
# Build JSON with jq so special characters in passwords don't break the payload
_payload=$(jq -n --arg u "$_u" --arg p "$_p" '{username:$u,password:$p}')
# || true prevents set -e from exiting silently on connection refused
_tok=$(curl -s -X POST "$FB_URL/api/login" \
-H "Content-Type: application/json" \
-d "{\"username\":\"$_u\",\"password\":\"$_p\"}")
[[ "$_tok" == *"."*"."* ]] \
|| die "Login failed. Check credentials and that FileBrowser is running at $FB_URL"
TOKEN="$_tok"
ok "Logged in as $_u"
-d "$_payload") || true
if [[ -z "$_tok" ]]; then
die "No response from FileBrowser at $FB_URL — is it running? (docker compose up -d)"
elif [[ "$_tok" == *"."*"."* ]]; then
TOKEN="$_tok"
ok "Logged in as $_u"
else
echo " FileBrowser responded: $_tok" >&2
die "Login failed — wrong credentials, or FileBrowser is not reachable at $FB_URL"
fi
}
# ── REST wrappers ─────────────────────────────────────────────────────────────