mirror of
https://github.com/Mesteriis/hassio-addons-avm.git
synced 2026-01-10 23:41:02 +01:00
WIP
This commit is contained in:
27
postgres/rootfs/docker-entrypoint-initdb.d/10-vector.sh
Executable file
27
postgres/rootfs/docker-entrypoint-initdb.d/10-vector.sh
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bashio
|
||||
# shellcheck shell=bash
|
||||
set -e
|
||||
|
||||
bashio::log.info "Waiting for port 5432 to open..."
|
||||
|
||||
# Wait for transmission to become available
|
||||
bashio::net.wait_for 5432 localhost 900
|
||||
|
||||
bashio::log.info "Enabling vector.rs"
|
||||
|
||||
# Set variables for vector.rs
|
||||
DB_PORT=5432
|
||||
DB_HOSTNAME=localhost
|
||||
DB_PASSWORD="$(bashio::config 'POSTGRES_PASSWORD')"
|
||||
if bashio::config.has_value "POSTGRES_USER"; then DB_USERNAME="$(bashio::config "POSTGRES_USER")"; else DB_USERNAME=postgres; fi
|
||||
|
||||
export DB_PORT
|
||||
export DB_HOSTNAME
|
||||
export DB_USERNAME
|
||||
export DB_PASSWORD
|
||||
echo "DROP EXTENSION IF EXISTS vectors;
|
||||
CREATE EXTENSION vectors;
|
||||
\q"> setup_postgres.sql
|
||||
|
||||
# Enable vectors
|
||||
psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" < setup_postgres.sql || true
|
||||
17
postgres/rootfs/etc/cont-init.d/20-folders.sh
Executable file
17
postgres/rootfs/etc/cont-init.d/20-folders.sh
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# shellcheck shell=bash
|
||||
set -e
|
||||
|
||||
# Migration
|
||||
if [ -d /data/database ]; then
|
||||
bashio::log.warning "Database migrated to /config"
|
||||
mv /data/database /config
|
||||
fi
|
||||
|
||||
if [ -f /homeassistant/addons_config/postgres/config.yaml ]; then
|
||||
bashio::log.warning "Config migrated to /config"
|
||||
mv /homeassistant/addons_config/postgres/* /config/
|
||||
rm -r /homeassistant/addons_config/postgres
|
||||
# Correct database location
|
||||
sed -i "s|/data/database|/config/database|g" /config/postgresql.conf
|
||||
fi
|
||||
50
postgres/rootfs/etc/cont-init.d/99-run.sh
Executable file
50
postgres/rootfs/etc/cont-init.d/99-run.sh
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bashio
|
||||
# shellcheck shell=bash
|
||||
set -e
|
||||
|
||||
# Use new config file
|
||||
CONFIG_HOME="/config"
|
||||
mkdir -p "$CONFIG_HOME"
|
||||
if [ ! -f "$CONFIG_HOME"/postgresql.conf ]; then
|
||||
# Copy default config.env
|
||||
if [ -f /usr/local/share/postgresql/postgresql.conf.sample ]; then
|
||||
cp /usr/local/share/postgresql/postgresql.conf.sample "$CONFIG_HOME"/postgresql.conf
|
||||
elif [ -f /usr/share/postgresql/postgresql.conf.sample ]; then
|
||||
cp /usr/share/postgresql/postgresql.conf.sample "$CONFIG_HOME"/postgresql.conf
|
||||
else
|
||||
bashio::exit.nok "Config file not found, please ask maintainer"
|
||||
fi
|
||||
bashio::log.warning "A default config.env file was copied in $CONFIG_HOME. Please customize according to https://hub.docker.com/_/postgres and restart the add-on"
|
||||
else
|
||||
bashio::log.warning "The config.env file found in $CONFIG_HOME will be used (mapped to /addon_configs/xxx-postgres when accessing from Filebrowser). Please customize according to https://hub.docker.com/_/postgres and restart the add-on"
|
||||
fi
|
||||
|
||||
# Define home
|
||||
# Creating config location
|
||||
mkdir -p "$PGDATA"
|
||||
chown -R postgres:postgres "$PGDATA"
|
||||
chmod 777 "$PGDATA"
|
||||
|
||||
# Permissions
|
||||
chmod -R 777 "$CONFIG_HOME"
|
||||
|
||||
##############
|
||||
# Launch App #
|
||||
##############
|
||||
|
||||
# Go to folder
|
||||
cd /config || true
|
||||
|
||||
echo " "
|
||||
bashio::log.info "Starting the app"
|
||||
echo " "
|
||||
|
||||
# Add docker-entrypoint command
|
||||
if [ "$(bashio::info.arch)" != "armv7" ]; then
|
||||
# Exec vecto modification
|
||||
/./docker-entrypoint-initdb.d/10-vector.sh & \
|
||||
docker-entrypoint.sh postgres -c shared_preload_libraries=vectors.so
|
||||
else
|
||||
bashio::log.warning "Your architecture is armv7, pgvecto.rs is disabled as not supported"
|
||||
docker-entrypoint.sh postgres
|
||||
fi
|
||||
Reference in New Issue
Block a user