secrets-init: store a piped secret without a final newline

`pbpaste | ssh petrolyst /root/secrets-init.sh keycloak-secret` sends the
secret without a trailing newline. read then sets the value but returns
non-zero, and set -e ended the script silently before storing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Nasim SadatandClaude Opus 5.5 committed 2026-10-24 00:37:38 +02:00
1 parent d3800ac9dd
commit d074092abd
1 file changed
+3 -1
+3 -1
View File
@@ -44,7 +44,9 @@ case ${1:-all} in
IFS= read -rs value IFS= read -rs value
echo >&2 echo >&2
else else
IFS= read -r value # `pbpaste | ...` sends no final newline: read then still sets value but
# fails, which set -e would turn into a silent exit.
IFS= read -r value || true
fi fi
value=$(printf '%s' "$value" | tr -d '[:space:]') value=$(printf '%s' "$value" | tr -d '[:space:]')
[ -n "$value" ] || die "empty secret" [ -n "$value" ] || die "empty secret"