mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-10 01:25:58 +02:00
update
This commit is contained in:
65
ente/rootfs/etc/cont-init.d/10-generate-config.sh
Normal file
65
ente/rootfs/etc/cont-init.d/10-generate-config.sh
Normal 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"
|
||||
35
ente/rootfs/etc/cont-init.d/20-internal-db-bootstrap.sh
Normal file
35
ente/rootfs/etc/cont-init.d/20-internal-db-bootstrap.sh
Normal 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."
|
||||
19
ente/rootfs/etc/services.d/00-postgres/run
Normal file
19
ente/rootfs/etc/services.d/00-postgres/run
Normal 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'"
|
||||
4
ente/rootfs/etc/services.d/01-minio/run
Normal file
4
ente/rootfs/etc/services.d/01-minio/run
Normal 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"
|
||||
@@ -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"
|
||||
16
ente/rootfs/etc/services.d/02-minio-init/run
Normal file
16
ente/rootfs/etc/services.d/02-minio-init/run
Normal 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
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/with-contenv bash
|
||||
set -e
|
||||
exec /usr/local/bin/minio server /data --address ":3200"
|
||||
27
ente/rootfs/etc/services.d/03-museum/run
Normal file
27
ente/rootfs/etc/services.d/03-museum/run
Normal 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"
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/usr/bin/with-contenv bash
|
||||
set -e
|
||||
[[ "${DISABLE_WEB_UI,,}" == "true" ]] && exit 0
|
||||
exec /usr/bin/ente-web
|
||||
8
ente/rootfs/etc/services.d/04-web/run
Normal file
8
ente/rootfs/etc/services.d/04-web/run
Normal 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
|
||||
Reference in New Issue
Block a user