mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-03-14 17:04:26 +01:00
GitHub bot: fix linting issues (nobuild)
This commit is contained in:
225
ente/rootfs/etc/cont-init.d/99-run.sh
Executable file → Normal file
225
ente/rootfs/etc/cont-init.d/99-run.sh
Executable file → Normal file
@@ -16,7 +16,7 @@ mkdir -p /config/scripts/compose
|
|||||||
############################################
|
############################################
|
||||||
USE_EXTERNAL_DB=false
|
USE_EXTERNAL_DB=false
|
||||||
if bashio::config.true 'USE_EXTERNAL_DB'; then
|
if bashio::config.true 'USE_EXTERNAL_DB'; then
|
||||||
USE_EXTERNAL_DB=true
|
USE_EXTERNAL_DB=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DB_NAME="$(bashio::config 'DB_DATABASE_NAME')"
|
DB_NAME="$(bashio::config 'DB_DATABASE_NAME')"
|
||||||
@@ -34,7 +34,7 @@ S3_BUCKET="$(bashio::config 'S3_BUCKET')"
|
|||||||
|
|
||||||
DISABLE_WEB_UI=false
|
DISABLE_WEB_UI=false
|
||||||
if bashio::config.true 'DISABLE_WEB_UI'; then
|
if bashio::config.true 'DISABLE_WEB_UI'; then
|
||||||
DISABLE_WEB_UI=true
|
DISABLE_WEB_UI=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
############################################
|
############################################
|
||||||
@@ -47,28 +47,35 @@ MC_BIN="/usr/local/bin/mc"
|
|||||||
|
|
||||||
# runtime binary resolver
|
# runtime binary resolver
|
||||||
resolve_bin() {
|
resolve_bin() {
|
||||||
local name="$1"; shift
|
local name="$1"
|
||||||
local cand
|
shift
|
||||||
for cand in "$@"; do
|
local cand
|
||||||
[ -x "$cand" ] && { echo "$cand"; return 0; }
|
for cand in "$@"; do
|
||||||
done
|
[ -x "$cand" ] && {
|
||||||
cand="$(command -v "$name" 2>/dev/null || true)"
|
echo "$cand"
|
||||||
[ -n "$cand" ] && { echo "$cand"; return 0; }
|
return 0
|
||||||
echo ""
|
}
|
||||||
return 1
|
done
|
||||||
|
cand="$(command -v "$name" 2>/dev/null || true)"
|
||||||
|
[ -n "$cand" ] && {
|
||||||
|
echo "$cand"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
echo ""
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
MUSEUM_BIN="$(resolve_bin museum /usr/bin/museum /usr/local/bin/museum /app/museum /museum)"
|
MUSEUM_BIN="$(resolve_bin museum /usr/bin/museum /usr/local/bin/museum /app/museum /museum)"
|
||||||
WEB_BIN="$(resolve_bin ente-web /usr/bin/ente-web /usr/local/bin/ente-web /app/ente-web /ente-web)"
|
WEB_BIN="$(resolve_bin ente-web /usr/bin/ente-web /usr/local/bin/ente-web /app/ente-web /ente-web)"
|
||||||
|
|
||||||
if [ -z "$MUSEUM_BIN" ]; then
|
if [ -z "$MUSEUM_BIN" ]; then
|
||||||
bashio::log.error "museum binary not found; cannot start Ente API."
|
bashio::log.error "museum binary not found; cannot start Ente API."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! $DISABLE_WEB_UI && [ -z "$WEB_BIN" ]; then
|
if ! $DISABLE_WEB_UI && [ -z "$WEB_BIN" ]; then
|
||||||
bashio::log.warning "Ente web binary not found; disabling web UI."
|
bashio::log.warning "Ente web binary not found; disabling web UI."
|
||||||
DISABLE_WEB_UI=true
|
DISABLE_WEB_UI=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PGDATA="/config/postgres"
|
PGDATA="/config/postgres"
|
||||||
@@ -78,126 +85,126 @@ PGDATA="/config/postgres"
|
|||||||
############################################
|
############################################
|
||||||
|
|
||||||
start_postgres() {
|
start_postgres() {
|
||||||
if $USE_EXTERNAL_DB; then
|
if $USE_EXTERNAL_DB; then
|
||||||
bashio::log.info "External DB enabled; skipping internal Postgres start."
|
bashio::log.info "External DB enabled; skipping internal Postgres start."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# runtime socket dir
|
# runtime socket dir
|
||||||
mkdir -p /run/postgresql
|
mkdir -p /run/postgresql
|
||||||
chown postgres:postgres /run/postgresql
|
chown postgres:postgres /run/postgresql
|
||||||
chmod 775 /run/postgresql
|
chmod 775 /run/postgresql
|
||||||
|
|
||||||
# data dir
|
# data dir
|
||||||
mkdir -p "$PGDATA"
|
mkdir -p "$PGDATA"
|
||||||
chown -R postgres:postgres "$PGDATA"
|
chown -R postgres:postgres "$PGDATA"
|
||||||
chmod 0700 "$PGDATA"
|
chmod 0700 "$PGDATA"
|
||||||
|
|
||||||
if [[ ! -s "$PGDATA/PG_VERSION" ]]; then
|
if [[ ! -s "$PGDATA/PG_VERSION" ]]; then
|
||||||
bashio::log.info "Initializing Postgres data directory..."
|
bashio::log.info "Initializing Postgres data directory..."
|
||||||
su - postgres -c "$INITDB -D $PGDATA"
|
su - postgres -c "$INITDB -D $PGDATA"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
bashio::log.info "Starting Postgres (127.0.0.1:5432)..."
|
bashio::log.info "Starting Postgres (127.0.0.1:5432)..."
|
||||||
su - postgres -c "$POSTGRES_BIN -D $PGDATA -c listen_addresses='127.0.0.1'" &
|
su - postgres -c "$POSTGRES_BIN -D $PGDATA -c listen_addresses='127.0.0.1'" &
|
||||||
PG_PID=$!
|
PG_PID=$!
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_postgres_ready() {
|
wait_postgres_ready() {
|
||||||
local host port user
|
local host port user
|
||||||
if $USE_EXTERNAL_DB; then
|
if $USE_EXTERNAL_DB; then
|
||||||
host="$DB_HOST_EXT"
|
host="$DB_HOST_EXT"
|
||||||
port="$DB_PORT_EXT"
|
port="$DB_PORT_EXT"
|
||||||
user="$DB_USER"
|
user="$DB_USER"
|
||||||
bashio::log.info "Waiting for EXTERNAL Postgres at ${host}:${port}..."
|
bashio::log.info "Waiting for EXTERNAL Postgres at ${host}:${port}..."
|
||||||
else
|
else
|
||||||
host="$DB_HOST_INTERNAL"
|
host="$DB_HOST_INTERNAL"
|
||||||
port="$DB_PORT_INTERNAL"
|
port="$DB_PORT_INTERNAL"
|
||||||
user="postgres" # superuser for first readiness check
|
user="postgres" # superuser for first readiness check
|
||||||
bashio::log.info "Waiting for internal Postgres..."
|
bashio::log.info "Waiting for internal Postgres..."
|
||||||
fi
|
fi
|
||||||
until pg_isready -q -h "$host" -p "$port" -U "$user"; do
|
until pg_isready -q -h "$host" -p "$port" -U "$user"; do
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
bashio::log.info "Postgres reachable."
|
bashio::log.info "Postgres reachable."
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap_internal_db() {
|
bootstrap_internal_db() {
|
||||||
if $USE_EXTERNAL_DB; then
|
if $USE_EXTERNAL_DB; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
bashio::log.info "Ensuring role ${DB_USER} exists..."
|
bashio::log.info "Ensuring role ${DB_USER} exists..."
|
||||||
if ! psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -tAc \
|
if ! psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -tAc \
|
||||||
"SELECT 1 FROM pg_roles WHERE rolname='${DB_USER}'" \
|
"SELECT 1 FROM pg_roles WHERE rolname='${DB_USER}'" |
|
||||||
| grep -q 1; then
|
grep -q 1; then
|
||||||
# password quoting: single quotes doubled
|
# password quoting: single quotes doubled
|
||||||
esc_pass="${DB_PASS//\'/\'\'}"
|
esc_pass="${DB_PASS//\'/\'\'}"
|
||||||
psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -c \
|
psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -c \
|
||||||
"CREATE ROLE ${DB_USER} LOGIN PASSWORD '${esc_pass}'" || true
|
"CREATE ROLE ${DB_USER} LOGIN PASSWORD '${esc_pass}'" || true
|
||||||
else
|
else
|
||||||
psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -c \
|
psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -c \
|
||||||
"ALTER ROLE ${DB_USER} LOGIN PASSWORD '${DB_PASS//\'/\'\'}'" >/dev/null 2>&1 || true
|
"ALTER ROLE ${DB_USER} LOGIN PASSWORD '${DB_PASS//\'/\'\'}'" >/dev/null 2>&1 || true
|
||||||
fi
|
fi
|
||||||
bashio::log.info "Ensuring database ${DB_NAME} exists (owner ${DB_USER})..."
|
bashio::log.info "Ensuring database ${DB_NAME} exists (owner ${DB_USER})..."
|
||||||
if ! psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -tAc \
|
if ! psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -tAc \
|
||||||
"SELECT 1 FROM pg_database WHERE datname='${DB_NAME}'" \
|
"SELECT 1 FROM pg_database WHERE datname='${DB_NAME}'" |
|
||||||
| grep -q 1; then
|
grep -q 1; then
|
||||||
# CREATE DATABASE must be top-level (not in DO/transaction). :contentReference[oaicite:2]{index=2}
|
# CREATE DATABASE must be top-level (not in DO/transaction). :contentReference[oaicite:2]{index=2}
|
||||||
psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -c \
|
psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -c \
|
||||||
"CREATE DATABASE ${DB_NAME} OWNER ${DB_USER}"
|
"CREATE DATABASE ${DB_NAME} OWNER ${DB_USER}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
bashio::log.info "Internal Postgres ready."
|
bashio::log.info "Internal Postgres ready."
|
||||||
}
|
}
|
||||||
|
|
||||||
start_minio() {
|
start_minio() {
|
||||||
bashio::log.info "Starting MinIO (:3200)..."
|
bashio::log.info "Starting MinIO (:3200)..."
|
||||||
mkdir -p /config/minio-data
|
mkdir -p /config/minio-data
|
||||||
"$MINIO_BIN" server /config/minio-data --address ":3200" &
|
"$MINIO_BIN" server /config/minio-data --address ":3200" &
|
||||||
MINIO_PID=$!
|
MINIO_PID=$!
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_minio_ready_and_bucket() {
|
wait_minio_ready_and_bucket() {
|
||||||
bashio::log.info "Waiting for MinIO API..."
|
bashio::log.info "Waiting for MinIO API..."
|
||||||
until "$MC_BIN" alias set h0 http://127.0.0.1:3200 "$MINIO_USER" "$MINIO_PASS" 2>/dev/null; do
|
until "$MC_BIN" alias set h0 http://127.0.0.1:3200 "$MINIO_USER" "$MINIO_PASS" 2>/dev/null; do
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
bashio::log.info "Ensuring bucket ${S3_BUCKET}..."
|
bashio::log.info "Ensuring bucket ${S3_BUCKET}..."
|
||||||
"$MC_BIN" mb -p "h0/${S3_BUCKET}" || true
|
"$MC_BIN" mb -p "h0/${S3_BUCKET}" || true
|
||||||
bashio::log.info "MinIO bucket ready."
|
bashio::log.info "MinIO bucket ready."
|
||||||
}
|
}
|
||||||
|
|
||||||
start_web() {
|
start_web() {
|
||||||
if $DISABLE_WEB_UI; then
|
if $DISABLE_WEB_UI; then
|
||||||
bashio::log.info "Web UI disabled."
|
bashio::log.info "Web UI disabled."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
bashio::log.info "Starting Ente web (:3000) using $WEB_BIN ..."
|
bashio::log.info "Starting Ente web (:3000) using $WEB_BIN ..."
|
||||||
"$WEB_BIN" &
|
"$WEB_BIN" &
|
||||||
WEB_PID=$!
|
WEB_PID=$!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_museum_foreground() {
|
start_museum_foreground() {
|
||||||
local cfg=/config/museum.yaml
|
local cfg=/config/museum.yaml
|
||||||
if ! bashio::fs.file_exists "$cfg"; then
|
if ! bashio::fs.file_exists "$cfg"; then
|
||||||
bashio::log.error "$cfg missing; cannot start museum."
|
bashio::log.error "$cfg missing; cannot start museum."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# For internal DB: verify reached DB_NAME
|
# For internal DB: verify reached DB_NAME
|
||||||
if ! $USE_EXTERNAL_DB; then
|
if ! $USE_EXTERNAL_DB; then
|
||||||
bashio::log.info "Verifying internal DB '${DB_NAME}' as '${DB_USER}'..."
|
bashio::log.info "Verifying internal DB '${DB_NAME}' as '${DB_USER}'..."
|
||||||
until PGPASSWORD="$DB_PASS" psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U "$DB_USER" -d "$DB_NAME" -c 'SELECT 1;' >/dev/null 2>&1; do
|
until PGPASSWORD="$DB_PASS" psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U "$DB_USER" -d "$DB_NAME" -c 'SELECT 1;' >/dev/null 2>&1; do
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
bashio::log.info "Using external DB; skipping final local verification."
|
bashio::log.info "Using external DB; skipping final local verification."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
bashio::log.info "Starting museum (foreground) using $MUSEUM_BIN ..."
|
bashio::log.info "Starting museum (foreground) using $MUSEUM_BIN ..."
|
||||||
# museum loads /config/museum.yaml to override defaults. :contentReference[oaicite:3]{index=3}
|
# museum loads /config/museum.yaml to override defaults. :contentReference[oaicite:3]{index=3}
|
||||||
exec "$MUSEUM_BIN" --config "$cfg"
|
exec "$MUSEUM_BIN" --config "$cfg"
|
||||||
}
|
}
|
||||||
|
|
||||||
############################################
|
############################################
|
||||||
|
|||||||
Reference in New Issue
Block a user