mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-11 18:31:02 +01:00
Update 99-run.sh
This commit is contained in:
@@ -24,65 +24,3 @@ for dir in /etc/services.d/*; do
|
||||
bashio::log.fatal "No run file found in $dir"
|
||||
fi
|
||||
done
|
||||
|
||||
#########################
|
||||
# Internal db bootstrap #
|
||||
#########################
|
||||
|
||||
#Default values for internal
|
||||
DB_NAME="ente_db"
|
||||
DB_USER="pguser"
|
||||
DB_PASS="ente"
|
||||
|
||||
if bashio::config.true 'USE_EXTERNAL_DB'; then
|
||||
bashio::log.info "External DB in use; skipping internal Postgres bootstrap."
|
||||
DB_USER="$(bashio::config 'DB_USERNAME')"
|
||||
DB_PASS="$(bashio::config 'DB_PASSWORD')"
|
||||
DB_NAME="$(bashio::config 'DB_DATABASE_NAME')"
|
||||
fi
|
||||
|
||||
bashio::log.info "Postgres-init: waiting for local Postgres..."
|
||||
until pg_isready -q -h 127.0.0.1 -p 5432 -U postgres; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
bashio::log.info "Postgres-init: creating role/database if missing..."
|
||||
# psql search_path safe quoting using dollar-quoted strings for password
|
||||
psql -v ON_ERROR_STOP=1 -h 127.0.0.1 -p 5432 -U postgres <<SQL
|
||||
DO \$\$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '${DB_USER}') THEN
|
||||
EXECUTE 'CREATE ROLE ${DB_USER} LOGIN PASSWORD ''' || replace('${DB_PASS}','''','''''') || '''';
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_database WHERE datname = '${DB_NAME}') THEN
|
||||
EXECUTE 'CREATE DATABASE ${DB_NAME} OWNER ${DB_USER}';
|
||||
END IF;
|
||||
END
|
||||
\$\$;
|
||||
SQL
|
||||
|
||||
bashio::log.info "Postgres-init: done."
|
||||
|
||||
#################
|
||||
# Minio startup #
|
||||
#################
|
||||
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# shellcheck shell=bash
|
||||
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 "MinIO-init: waiting for API..."
|
||||
until /usr/local/bin/mc alias set h0 http://127.0.0.1:3200 "${MINIO_USER}" "${MINIO_PASS}" 2>/dev/null; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
bashio::log.info "MinIO-init: ensuring bucket ${S3_BUCKET}..."
|
||||
/usr/local/bin/mc mb -p "h0/${S3_BUCKET}" || true
|
||||
|
||||
bashio::log.info "MinIO-init: done."
|
||||
|
||||
sleep infinity
|
||||
|
||||
Reference in New Issue
Block a user