From d591f38acf6f948b1642c4acb2cd829c99d388c8 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 8 Jun 2026 01:12:43 +0000 Subject: [PATCH] fix manage_users.sh: show API errors on user creation, fix symlink listing - User creation was silently failing: api_post used curl -sf (fail on HTTP error) with output piped to /dev/null, so set -Eeuo pipefail would exit the script with no message. Now captures HTTP status code and response body, printing the server's error message on failure. - Symlink folder listing (? prompt) only searched -type d, missing symlinked directories in /srv. Changed to -type d -o -type l so all browsable entries appear. Also switched xargs echo to tr for a cleaner one-line display. - mkdir -p and ln -s in docker exec were not checked for errors; failures would silently kill the script under set -e. Both now show a useful error message and continue/return instead of crashing. https://claude.ai/code/session_014CCYqVwW6d6f5dw1qRokYt --- tools/manage_users.sh | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/tools/manage_users.sh b/tools/manage_users.sh index f014f79..e0d3186 100644 --- a/tools/manage_users.sh +++ b/tools/manage_users.sh @@ -192,7 +192,10 @@ prompt_add_links() { check_container "$_c" || return 1 local _scope_dir="/srv$_scope" - docker exec "$_c" mkdir -p "$_scope_dir" >/dev/null 2>&1 || true + if ! docker exec "$_c" mkdir -p "$_scope_dir" 2>/dev/null; then + errmsg "Could not create scope directory '$_scope_dir' in container (permission denied?)." + return 1 + fi echo echo " Type a folder name to add — ? to list available folders, blank when done." @@ -205,9 +208,10 @@ prompt_add_links() { if [[ "$_src" == "?" ]]; then local _avail - _avail=$(docker exec "$_c" find /srv -maxdepth 1 -mindepth 1 -type d \ - -not -name ".*" 2>/dev/null | sed 's|^/srv/||' | sort | xargs echo) || true - echo " Available: ${_avail:-(none found)}" + _avail=$(docker exec "$_c" find /srv -maxdepth 1 -mindepth 1 \ + \( -type d -o -type l \) \ + -not -name ".*" 2>/dev/null | sed 's|^/srv/||' | sort | tr '\n' ' ') || true + echo " Available: ${_avail:-(none — no subdirectories in /srv)}" echo continue fi @@ -232,7 +236,10 @@ prompt_add_links() { continue fi - docker exec "$_c" ln -s "$_target" "$_link_path" + if ! docker exec "$_c" ln -s "$_target" "$_link_path" 2>/dev/null; then + errmsg "Failed to create symlink inside container (check container logs)." + continue + fi if [[ "$_src" == "$_link_name" ]]; then ok "User can now see '$_link_name'" else @@ -355,7 +362,24 @@ cmd_add() { '{username:$u, password:$p, scope:$s, locale:"en", viewMode:"list", singleClick:false, sorting:{by:"name",asc:true}, perm:$perms, commands:[], lockPassword:false, hideDotfiles:false, dateFormat:false}') - api_post "/api/users" "$_body" >/dev/null + + local _resp _http_code + _resp=$(curl -s -w '\n%{http_code}' -X POST "$FB_URL/api/users" \ + -H "X-Auth: $TOKEN" \ + -H "Content-Type: application/json" \ + -d "$_body" 2>&1) || true + _http_code=$(printf '%s' "$_resp" | tail -1) + _resp=$(printf '%s' "$_resp" | head -n -1) + + if [[ "$_http_code" != "200" && "$_http_code" != "201" ]]; then + local _msg + _msg=$(printf '%s' "$_resp" | jq -r '.message // .error // empty' 2>/dev/null) || true + [[ -z "$_msg" ]] && _msg="$_resp" + [[ -z "$_msg" ]] && _msg="HTTP $_http_code" + errmsg "Failed to create user '$_username': $_msg" + return 1 + fi + echo ok "User '$_username' created | scope: $_scope | admin: $_is_admin"