From 1840eb8f7df789c9af6113bafe2e1b90e9c54232 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Mon, 28 Aug 2023 12:39:35 +0200 Subject: [PATCH] update --- immich/config.json | 3 +- immich/rootfs/etc/cont-init.d/99-database.sh | 101 ++++++++----------- 2 files changed, 42 insertions(+), 62 deletions(-) diff --git a/immich/config.json b/immich/config.json index ec84b3df0..f4772b8a0 100644 --- a/immich/config.json +++ b/immich/config.json @@ -105,7 +105,6 @@ "cifspassword": "str?", "cifsusername": "str?", "data_location": "str", - "database": "list(internal|external_postgresql)?", "localdisks": "str?", "networkdisks": "str?" }, @@ -116,4 +115,4 @@ "url": "https://github.com/alexbelgium/hassio-addons", "version": "1.75.2", "webui": "http://[HOST]:[PORT:8080]" -} +} \ No newline at end of file diff --git a/immich/rootfs/etc/cont-init.d/99-database.sh b/immich/rootfs/etc/cont-init.d/99-database.sh index 77e677b9d..3f55e2322 100755 --- a/immich/rootfs/etc/cont-init.d/99-database.sh +++ b/immich/rootfs/etc/cont-init.d/99-database.sh @@ -2,6 +2,20 @@ # shellcheck shell=bash # shellcheck disable=SC2155,SC2016 +###################### +# Switch of database # +###################### + +if [ -f /share/postgresql_immich.tar.gz ]; then + bashio::log.warning "Your previous database was exported to /share/postgresql_immich.tar.gz" +elif [ -d /data/postgresql ]; then + bashio::log.warning "------------------------------------" + bashio::log.warning "Internal postgres database detected, copying to /share/postgresql_immich.tar.gz" + bashio::log.warning "------------------------------------" + tar -zcvf /share/postgresql_immich.tar.gz /data/postgresql + rm -r /data/postgresql +fi + ################### # Define database # ################### @@ -9,69 +23,36 @@ bashio::log.info "Defining database" bashio::log.info "-----------------" -case $(bashio::config 'database') in +bashio::log.info "Connecting to external postgresql" +bashio::log.info "" - "external_postgresql") +# Check if values exist +if ! bashio::config.has_value 'DB_USERNAME' && \ + ! bashio::config.has_value 'DB_HOSTNAME' && \ + ! bashio::config.has_value 'DB_PASSWORD' && \ + ! bashio::config.has_value 'DB_DATABASE_NAME' && \ + ! bashio::config.has_value 'JWT_SECRET' && \ + ! bashio::config.has_value 'DB_PORT'; then + ! bashio::exit.nok "Please make sure that the following options are set : DB_USERNAME, DB_HOSTNAME, DB_PASSWORD, DB_DATABASE_NAME, DB_PORT" +fi - bashio::log.info "Using external postgresql" - bashio::log.info "" +# Settings parameters +export DB_USERNAME=$(bashio::config 'DB_USERNAME') +export DB_HOSTNAME=$(bashio::config 'DB_HOSTNAME') +export DB_PASSWORD=$(bashio::config 'DB_PASSWORD') +export DB_DATABASE_NAME=$(bashio::config 'DB_DATABASE_NAME') +export DB_PORT=$(bashio::config 'DB_PORT') +export JWT_SECRET=$(bashio::config 'JWT_SECRET') - # Check if values exist - if ! bashio::config.has_value 'DB_USERNAME' && \ - ! bashio::config.has_value 'DB_HOSTNAME' && \ - ! bashio::config.has_value 'DB_PASSWORD' && \ - ! bashio::config.has_value 'DB_DATABASE_NAME' && \ - ! bashio::config.has_value 'JWT_SECRET' && \ - ! bashio::config.has_value 'DB_PORT' - then - ! bashio::exit.nok "Please make sure that the following options are set : DB_USERNAME, DB_HOSTNAME, DB_PASSWORD, DB_DATABASE_NAME, DB_PORT" - fi - - # Settings parameters - export DB_USERNAME=$(bashio::config 'DB_USERNAME') - export DB_HOSTNAME=$(bashio::config 'DB_HOSTNAME') - export DB_PASSWORD=$(bashio::config 'DB_PASSWORD') - export DB_DATABASE_NAME=$(bashio::config 'DB_DATABASE_NAME') - export DB_PORT=$(bashio::config 'DB_PORT') - export JWT_SECRET=$(bashio::config 'JWT_SECRET') - ;; - - **) - - bashio::log.info "Using internal postgresql" - bashio::log.info "" - - # Settings files & permissions - ln -s /usr/lib/postgresql/14/bin/postgres /usr/bin || true - ln -s /usr/lib/postgresql/14/bin/psql /usr/psql || true - mkdir -p /data/postgresql - cp -rnf /var/lib/postgresql/14/main/* /data/postgresql/ - chown -R postgres /data/postgresql - chmod -R 700 /data/postgresql - - # Start postgresql - /etc/init.d/postgresql start - - # Create database - echo "CREATE ROLE root WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD 'securepassword'; - CREATE DATABASE immich; CREATE USER immich WITH ENCRYPTED PASSWORD 'immich'; - GRANT ALL PRIVILEGES ON DATABASE immich to immich; - \q"> setup_postgres.sql - chown postgres setup_postgres.sql - # shellcheck disable=SC2024 - sudo -iu postgres psql < setup_postgres.sql - rm setup_postgres.sql - - # Settings parameters - export DB_USERNAME=immich - export DB_HOSTNAME=localhost - export DB_PASSWORD=immich - export DB_DATABASE_NAME=immich - export DB_PORT=5432 - export JWT_SECRET=$(bashio::config 'JWT_SECRET') - ;; - -esac +# Create database +echo "CREATE ROLE root WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD 'securepassword'; + CREATE DATABASE immich; CREATE USER immich WITH ENCRYPTED PASSWORD 'immich'; + GRANT ALL PRIVILEGES ON DATABASE immich to immich; +\q"> setup_postgres.sql +chown postgres setup_postgres.sql +# shellcheck disable=SC2024 +sudo -iu postgres psql < setup_postgres.sql +rm setup_postgres.sql # Export variables if [ -d /var/run/s6/container_environment ]; then