askrobots / dbbasic-object-server
Public
Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
danq9
signup: the person chooses the password and name on the confirm page
83c7aa6
2 weeks, 5 days ago
History
docker-entrypoint.sh · 1.7 KB · 44 lines
| 1 | #!/bin/sh |
| 2 | # |
| 3 | # DBBASIC Object Server — container entrypoint. |
| 4 | # |
| 5 | # Mirrors scripts/install.sh's first-boot admin-token behavior for the |
| 6 | # container path: if DBBASIC_ADMIN_TOKEN is not set in the environment, |
| 7 | # generate one once, persist it under the mounted data directory so it |
| 8 | # survives restarts and image rebuilds, and print it clearly to stdout on |
| 9 | # that first boot only. An existing persisted token is never overwritten, |
| 10 | # and no token is ever baked into the image — only into the runtime-only |
| 11 | # data volume. |
| 12 | # |
| 13 | # On later boots, if DBBASIC_ADMIN_TOKEN still is not set explicitly, the |
| 14 | # persisted token file is read instead of generating a new one. |
| 15 | set -eu |
| 16 | |
| 17 | DATA_DIR="${DBBASIC_DATA_DIR:-/data/state}" |
| 18 | TOKEN_FILE="${DATA_DIR}/admin_token" |
| 19 | |
| 20 | mkdir -p "${DATA_DIR}" |
| 21 | |
| 22 | if [ -z "${DBBASIC_ADMIN_TOKEN:-}" ]; then |
| 23 | if [ -f "${TOKEN_FILE}" ]; then |
| 24 | DBBASIC_ADMIN_TOKEN="$(cat "${TOKEN_FILE}")" |
| 25 | else |
| 26 | DBBASIC_ADMIN_TOKEN="$(python -c 'import secrets; print(secrets.token_urlsafe(32))')" |
| 27 | umask 077 |
| 28 | printf '%s' "${DBBASIC_ADMIN_TOKEN}" >"${TOKEN_FILE}" |
| 29 | printf '\n' |
| 30 | printf '============================================================\n' |
| 31 | printf ' DBBASIC: generated a new admin token on first boot.\n' |
| 32 | printf ' Save it now -- it is only printed here, once:\n' |
| 33 | printf '\n %s\n\n' "${DBBASIC_ADMIN_TOKEN}" |
| 34 | printf ' Persisted at (inside the container): %s\n' "${TOKEN_FILE}" |
| 35 | printf ' To pin it explicitly (recommended once you have a real\n' |
| 36 | printf ' deployment, e.g. Coolify-managed environment variables),\n' |
| 37 | printf ' set DBBASIC_ADMIN_TOKEN yourself and it will be used instead.\n' |
| 38 | printf '============================================================\n\n' |
| 39 | fi |
| 40 | fi |
| 41 | |
| 42 | export DBBASIC_ADMIN_TOKEN |
| 43 | |
| 44 | exec "$@" |