#!/bin/sh set -eu umask 077 mkdir -p /data /secrets secret=/secrets/nixmsg-admin-password if [ ! -s "$secret" ]; then set +e out=$(/usr/local/bin/nixmsg admin init 2>&1) code=$? set -e if [ "$code" -ne 0 ]; then printf '%s\n' "$out" >&2 if printf '%s\n' "$out" | grep -q "already initialized"; then echo "nixmsg admin already initialized but the password file is missing" >&2 exit 1 fi exit "$code" fi pw=$(printf '%s\n' "$out" | sed -n 's/^admin password: //p' | head -n 1) if [ -z "$pw" ]; then echo "admin init did not print a password" >&2 exit 1 fi printf '%s' "$pw" > "$secret" echo "nixmsg admin initialized" else echo "nixmsg admin password file present" fi chown -R 65532:65532 /data /secrets chmod 700 /secrets chmod 600 "$secret"