28 lines
935 B
Bash
28 lines
935 B
Bash
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
# Required env-vars
|
|
: "${PB_ADMIN_EMAIL:?need PB_ADMIN_EMAIL}"
|
|
: "${PB_ADMIN_PASSWORD:?need PB_ADMIN_PASSWORD}"
|
|
: "${PB_DATA_DIR:?need PB_DATA_DIR}"
|
|
|
|
# ensure data dir exists (for embedded SQLite + migrations + files)
|
|
mkdir -p "${PB_DATA_DIR}"
|
|
export POCKETBASE_DATA_DIR="${PB_DATA_DIR}"
|
|
|
|
# if there are no users yet, create the superuser
|
|
# we check the sqlite file for any existing record in the users table
|
|
if [ ! -f "${PB_DATA_DIR}/pb_data.db" ] || ! \
|
|
sqlite3 "${PB_DATA_DIR}/pb_data.db" \
|
|
"SELECT id FROM users WHERE email='${PB_ADMIN_EMAIL}' LIMIT 1;" \
|
|
| grep -q .; then
|
|
|
|
echo ">>> Creating PocketBase superuser: ${PB_ADMIN_EMAIL}"
|
|
/pb/pocketbase superuser create "${PB_ADMIN_EMAIL}" "${PB_ADMIN_PASSWORD}"
|
|
else
|
|
echo ">>> Superuser ${PB_ADMIN_EMAIL} already exists, skipping creation."
|
|
fi
|
|
|
|
# exec the real pocketbase binary with any passed arguments
|
|
exec /pb/pocketbase "$@"
|