Update 99-run.sh

This commit is contained in:
Alexandre
2024-03-19 12:43:18 +01:00
committed by GitHub
parent f79f8805fd
commit f3b93d2a50

View File

@@ -15,33 +15,34 @@ mkdir -p /config/library
bashio::log.info "Setting postgres..." bashio::log.info "Setting postgres..."
if [[ "$DATABASE_URL" == *"localhost"* ]]; then if [[ "$DATABASE_URL" == *"localhost"* ]]; then
echo "... with local database" echo "... with local database"
echo "... set database in /config/postgres" echo "... set database in /config/postgres"
mkdir -p /config/postgres mkdir -p /config/postgres
mkdir -p /var/run/postgresql mkdir -p /var/run/postgresql
chown postgres:postgres /var/run/postgresql chown postgres:postgres /var/run/postgresql
chown -R postgres:postgres /config/postgres chown -R postgres:postgres /config/postgres
chmod 0700 /config/postgres chmod 0700 /config/postgres
if [ ! -e /config/postgres/postgresql.conf ]; then # Create folder
sudo -u postgres /usr/lib/postgresql/16/bin/initdb -D /config/postgres if [ ! -e /config/postgres/postgresql.conf ]; then
fi echo "... init folder"
chown -R postgres:postgres /config/postgres sudo -u postgres /usr/lib/postgresql/16/bin/initdb -D /config/postgres
chmod 0700 /config/postgres fi
chown -R postgres:postgres /config/postgres
echo "... starting server" chmod 0700 /config/postgres
sudo -u postgres service postgresql start
sleep 5 echo "... starting server"
sudo -u postgres service postgresql start
echo "... create user and table" sleep 5
# Set password
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'homeassistant';" echo "... create user and table"
# Set password
# Create database if does not exist sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'homeassistant';"
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; # Create database if does not exist
\q"> setup_postgres.sql echo "CREATE ROLE postgres WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD 'homeassistant';
sudo -u postgres psql "postgres://postgres:homeassistant@localhost:5432" < setup_postgres.sql || true 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 fi
######################## ########################