This commit is contained in:
Alexandre
2025-07-16 08:26:36 +02:00
committed by GitHub
parent 7e4ae308d9
commit 4704c11f94
12 changed files with 228 additions and 74 deletions

View File

@@ -0,0 +1,65 @@
#!/usr/bin/with-contenv bashio
# Generate museum.yaml (first boot) from add-on options
set -euo pipefail
CFG=/config/museum.yaml
if bashio::fs.file_exists "$CFG"; then
bashio::log.info "Using existing $CFG"
exit 0
fi
bashio::log.info "Generating $CFG"
# --- options ---
USE_EXTERNAL_DB=$(bashio::config.true 'USE_EXTERNAL_DB' && echo true || echo false)
DB_HOST="localhost"
DB_PORT=5432
DB_USER="$(bashio::config 'DB_USERNAME')"
DB_PASS="$(bashio::config 'DB_PASSWORD')"
DB_NAME="$(bashio::config 'DB_DATABASE_NAME')"
if ${USE_EXTERNAL_DB}; then
# override host/port for external DB (fall back if missing)
DB_HOST="$(bashio::config 'DB_HOSTNAME')"
DB_PORT="$(bashio::config 'DB_PORT')"
bashio::log.info "museum.yaml will point to external Postgres at ${DB_HOST}:${DB_PORT}"
else
bashio::log.info "museum.yaml will use internal Postgres."
fi
MINIO_USER="$(bashio::config 'MINIO_ROOT_USER')"
MINIO_PASS="$(bashio::config 'MINIO_ROOT_PASSWORD')"
S3_BUCKET="$(bashio::config 'S3_BUCKET')"
# helpers
_random_b64() { head -c "$1" /dev/urandom | base64 | tr -d '\n'; }
_random_b64_url() { head -c "$1" /dev/urandom | base64 | tr '+/' '-_' | tr -d '\n'; }
cat >"$CFG" <<EOF
key:
encryption: $(_random_b64 32)
hash: $(_random_b64 64)
jwt:
secret: $(_random_b64_url 32)
db:
host: ${DB_HOST}
port: ${DB_PORT}
name: ${DB_NAME}
user: ${DB_USER}
password: ${DB_PASS}
s3:
are_local_buckets: true
b2-eu-cen:
key: ${MINIO_USER}
secret: ${MINIO_PASS}
endpoint: localhost:3200
region: eu-central-2
bucket: ${S3_BUCKET}
EOF
bashio::log.info "Generated $CFG"

View File

@@ -0,0 +1,35 @@
#!/usr/bin/with-contenv bashio
set -euo pipefail
if bashio::config.true 'USE_EXTERNAL_DB'; then
bashio::log.info "External DB in use; skipping internal Postgres bootstrap."
exit 0
fi
bashio::log.info "Bootstrapping internal Postgres cluster…"
DB_USER="$(bashio::config 'DB_USERNAME')"
DB_PASS="$(bashio::config 'DB_PASSWORD')"
DB_NAME="$(bashio::config 'DB_DATABASE_NAME')"
# Wait for postgres service (localhost)
until pg_isready -q -h localhost -p 5432 -U postgres; do
bashio::log.info "Waiting for Postgres to accept connections…"
sleep 1
done
bashio::log.info "Creating role + database if needed…"
su - postgres -c psql <<SQL
DO \$\$
BEGIN
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '${DB_USER}') THEN
CREATE ROLE ${DB_USER} LOGIN PASSWORD '${DB_PASS}';
END IF;
IF NOT EXISTS (SELECT FROM pg_database WHERE datname = '${DB_NAME}') THEN
CREATE DATABASE ${DB_NAME} OWNER ${DB_USER};
END IF;
END
\$\$;
SQL
bashio::log.info "Internal Postgres ready."

View File

@@ -0,0 +1,19 @@
#!/usr/bin/with-contenv bashio
set -euo pipefail
if bashio::config.true 'USE_EXTERNAL_DB'; then
bashio::log.info "External DB requested; not starting internal Postgres service."
exit 0
fi
export PGDATA=/data/postgres
mkdir -p "$PGDATA"
chown -R postgres:postgres /data
if [[ ! -s "$PGDATA/PG_VERSION" ]]; then
bashio::log.info "Initializing Postgres 17 data directory."
su - postgres -c "/usr/lib/postgresql/17/bin/initdb -D $PGDATA"
fi
bashio::log.info "Starting Postgres 17 (listening on 127.0.0.1:5432)."
exec su - postgres -c "/usr/lib/postgresql/17/bin/postgres -D $PGDATA -c listen_addresses='127.0.0.1'"

View File

@@ -0,0 +1,4 @@
#!/usr/bin/with-contenv bashio
set -euo pipefail
bashio::log.info "Starting MinIO."
exec /usr/local/bin/minio server /data --address ":3200"

View File

@@ -1,13 +0,0 @@
#!/usr/bin/with-contenv bash
set -e
CONFIG_FILE="/config/museum.yaml"
# Safety: refuse to start if the config file is missing
if [[ ! -f "$CONFIG_FILE" ]]; then
echo "[museum] ERROR: $CONFIG_FILE not found" >&2
exit 1
fi
# Exec so that S6 can reap the PID
exec /usr/bin/museum --config "$CONFIG_FILE"

View File

@@ -0,0 +1,16 @@
#!/usr/bin/with-contenv bashio
set -euo pipefail
MINIO_USER="$(bashio::config 'MINIO_ROOT_USER')"
MINIO_PASS="$(bashio::config 'MINIO_ROOT_PASSWORD')"
S3_BUCKET="$(bashio::config 'S3_BUCKET')"
bashio::log.info "Waiting for MinIO API…"
until /usr/local/bin/mc alias set h0 http://localhost:3200 "${MINIO_USER}" "${MINIO_PASS}" 2>/dev/null; do
sleep 1
done
bashio::log.info "Ensuring bucket ${S3_BUCKET} exists…"
/usr/local/bin/mc mb -p "h0/${S3_BUCKET}" || true
bashio::log.info "MinIO bucket ready."
exit 0

View File

@@ -1,3 +0,0 @@
#!/usr/bin/with-contenv bash
set -e
exec /usr/local/bin/minio server /data --address ":3200"

View File

@@ -0,0 +1,27 @@
#!/usr/bin/with-contenv bashio
set -euo pipefail
CFG=/config/museum.yaml
if ! bashio::fs.file_exists "$CFG"; then
bashio::log.error "$CFG not found; aborting museum start."
exit 1
fi
if bashio::config.true 'USE_EXTERNAL_DB'; then
DB_HOST="$(bashio::config 'DB_HOSTNAME')"
DB_PORT="$(bashio::config 'DB_PORT')"
DB_USER="$(bashio::config 'DB_USERNAME')"
bashio::log.info "Waiting for external Postgres at ${DB_HOST}:${DB_PORT}…"
until pg_isready -q -h "${DB_HOST}" -p "${DB_PORT}" -U "${DB_USER}"; do
sleep 2
done
else
DB_USER="postgres"
bashio::log.info "Waiting for internal Postgres…"
until pg_isready -q -h localhost -p 5432 -U "${DB_USER}"; do
sleep 2
done
fi
bashio::log.info "Starting museum."
exec /usr/bin/museum --config "$CFG"

View File

@@ -1,4 +0,0 @@
#!/usr/bin/with-contenv bash
set -e
[[ "${DISABLE_WEB_UI,,}" == "true" ]] && exit 0
exec /usr/bin/ente-web

View File

@@ -0,0 +1,8 @@
#!/usr/bin/with-contenv bashio
set -euo pipefail
if bashio::config.true 'DISABLE_WEB_UI'; then
bashio::log.info "Web UI disabled by option."
exit 0
fi
bashio::log.info "Starting Ente web."
exec /usr/bin/ente-web