From f3b93d2a501eb582603b328d2c1016b47f688b43 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:43:18 +0100 Subject: [PATCH] Update 99-run.sh --- linkwarden/rootfs/etc/cont-init.d/99-run.sh | 55 +++++++++++---------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/linkwarden/rootfs/etc/cont-init.d/99-run.sh b/linkwarden/rootfs/etc/cont-init.d/99-run.sh index 6deffd7bc..1e08463fc 100755 --- a/linkwarden/rootfs/etc/cont-init.d/99-run.sh +++ b/linkwarden/rootfs/etc/cont-init.d/99-run.sh @@ -15,33 +15,34 @@ mkdir -p /config/library bashio::log.info "Setting postgres..." if [[ "$DATABASE_URL" == *"localhost"* ]]; then -echo "... with local database" -echo "... set database in /config/postgres" -mkdir -p /config/postgres -mkdir -p /var/run/postgresql -chown postgres:postgres /var/run/postgresql -chown -R postgres:postgres /config/postgres -chmod 0700 /config/postgres -if [ ! -e /config/postgres/postgresql.conf ]; then - sudo -u postgres /usr/lib/postgresql/16/bin/initdb -D /config/postgres -fi -chown -R postgres:postgres /config/postgres -chmod 0700 /config/postgres - -echo "... starting server" -sudo -u postgres service postgresql start -sleep 5 - -echo "... create user and table" -# Set password -sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'homeassistant';" - -# Create database if does not exist -echo "CREATE ROLE postgres WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD 'homeassistant'; - CREATE DATABASE linkwarden; CREATE USER postgres WITH ENCRYPTED PASSWORD 'homeassistant'; GRANT ALL PRIVILEGES ON DATABASE linkwarden to postgres; -\q"> setup_postgres.sql -sudo -u postgres psql "postgres://postgres:homeassistant@localhost:5432" < setup_postgres.sql || true - + echo "... with local database" + echo "... set database in /config/postgres" + mkdir -p /config/postgres + mkdir -p /var/run/postgresql + chown postgres:postgres /var/run/postgresql + chown -R postgres:postgres /config/postgres + chmod 0700 /config/postgres + # Create folder + if [ ! -e /config/postgres/postgresql.conf ]; then + echo "... init folder" + sudo -u postgres /usr/lib/postgresql/16/bin/initdb -D /config/postgres + fi + chown -R postgres:postgres /config/postgres + chmod 0700 /config/postgres + + echo "... starting server" + sudo -u postgres service postgresql start + sleep 5 + + echo "... create user and table" + # Set password + sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'homeassistant';" + + # Create database if does not exist + echo "CREATE ROLE postgres WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD 'homeassistant'; + CREATE DATABASE linkwarden; CREATE USER postgres WITH ENCRYPTED PASSWORD 'homeassistant'; GRANT ALL PRIVILEGES ON DATABASE linkwarden to postgres; + \q"> setup_postgres.sql + sudo -u postgres psql "postgres://postgres:homeassistant@localhost:5432" < setup_postgres.sql || true fi ########################