Files
kamidso-back/docker/kamidso/init-app-user.sh
T
javadandCursor b93ecf1691 Initial commit of the Kamidso API.
Keep source, config, and deploy files. Leave runtime data, uploads, and logs out of git.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-10 13:43:09 +03:30

31 lines
1008 B
Bash

#!/bin/bash
# Runs once, on the first boot of an empty data directory, as a Mongo init script.
set -euo pipefail
: "${MONGO_INITDB_ROOT_USERNAME:?MONGO_INITDB_ROOT_USERNAME is required}"
: "${MONGO_INITDB_ROOT_PASSWORD:?MONGO_INITDB_ROOT_PASSWORD is required}"
: "${MONGO_APP_USERNAME:?MONGO_APP_USERNAME is required}"
: "${MONGO_APP_PASSWORD:?MONGO_APP_PASSWORD is required}"
: "${MONGO_APP_DATABASE:?MONGO_APP_DATABASE is required}"
js_string() {
local s=$1
s=${s//\\/\\\\}
s=${s//\"/\\\"}
s=${s//$'\n'/\\n}
printf '"%s"' "$s"
}
mongosh --quiet \
--host 127.0.0.1 \
--username "$MONGO_INITDB_ROOT_USERNAME" \
--password "$MONGO_INITDB_ROOT_PASSWORD" \
--authenticationDatabase admin \
--eval "
const name = $(js_string "$MONGO_APP_DATABASE");
const user = $(js_string "$MONGO_APP_USERNAME");
const pwd = $(js_string "$MONGO_APP_PASSWORD");
const app = db.getSiblingDB(name);
app.createUser({ user: user, pwd: pwd, roles: [{ role: 'readWrite', db: name }] });
"