From 4575a03c95475ccf1c19765c3d06b40d739599ba Mon Sep 17 00:00:00 2001 From: Alexandre Date: Thu, 21 Sep 2023 20:17:43 +0200 Subject: [PATCH] Update --- immich/Dockerfile | 16 +-- immich/rootfs/etc/cont-init.d/20-folders.sh | 2 + immich/rootfs/etc/cont-init.d/99-database.sh | 74 ------------ immich/rootfs/etc/cont-init.d/99-run.sh | 120 +++++++++---------- immich/stats.png | Bin 1603 -> 1565 bytes 5 files changed, 69 insertions(+), 143 deletions(-) delete mode 100755 immich/rootfs/etc/cont-init.d/99-database.sh diff --git a/immich/Dockerfile b/immich/Dockerfile index 02aa72335..399c8e23c 100644 --- a/immich/Dockerfile +++ b/immich/Dockerfile @@ -2,11 +2,11 @@ # ALEXBELGIUM'S DOCKERFILE # #============================# # _.------. -# _.-` ('>.-`"1.57.1""-. +# _.-` ('>.-`"""-. # '.--'` _'` _ .--.) # -' '-.-';` ` # ' - _.' ``'--. -# d '---` .-'"1.57.1"` +# d '---` .-'""` # /` #=== Home Assistant Addon ===# @@ -27,19 +27,19 @@ ENV S6_CMD_WAIT_FOR_SERVICES=1 \ S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 \ S6_SERVICES_GRACETIME=0 +USER root + # Global LSIO modifications ADD --chmod=744 "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/ha_lsio.sh" "/ha_lsio.sh" ARG CONFIGLOCATION="/config/addons_config/immich" RUN if grep -qr "lsio" /etc; then /ha_lsio.sh "$CONFIGLOCATION"; fi && rm /ha_lsio.sh -USER root - # Install REDIS ENV DOCKER_MODS="imagegenius/mods:universal-redis" RUN \ echo "Installing REDIS" \ - && chmod 777 -R /docker-mods \ - && /./docker-mods/* || ls / \ + && chmod 777 -R /docker-mods \ + && /./docker-mods/* || ls / \ && if [ !-f /defaults/redis.conf ]; then echo "Not installed" && exit 1; fi ENV DOCKER_MODS="" @@ -57,8 +57,9 @@ ARG MODULES="00-banner.sh 01-custom_script.sh 00-global_var.sh 00-local_mounts.s ADD --chmod=744 "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/ha_automodules.sh" "/ha_automodules.sh" RUN /ha_automodules.sh "$MODULES" && rm /ha_automodules.sh + # Manual apps -ENV PACKAGES="sudo redis-server yamllint pip libxml2-dev libxslt-dev libjpeg-dev zlib1g-dev build-essential" +ENV PACKAGES="sudo yamllint pip postgresql-client" # Automatic apps & bashio ADD --chmod=744 "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/ha_autoapps.sh" "/ha_autoapps.sh" @@ -76,7 +77,6 @@ ADD --chmod=777 "https://raw.githubusercontent.com/alexbelgium/hassio-addons/mas ADD --chmod=777 "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/ha_entrypoint_modif.sh" "/ha_entrypoint_modif.sh" RUN /ha_entrypoint_modif.sh && rm /ha_entrypoint_modif.sh -# #ENTRYPOINT [ "/usr/bin/env" ] #CMD [ "/ha_entrypoint.sh" ] diff --git a/immich/rootfs/etc/cont-init.d/20-folders.sh b/immich/rootfs/etc/cont-init.d/20-folders.sh index 239b729b9..e2fa65b3e 100755 --- a/immich/rootfs/etc/cont-init.d/20-folders.sh +++ b/immich/rootfs/etc/cont-init.d/20-folders.sh @@ -30,3 +30,5 @@ ln -sf "$DATA_LOCATION" /photos chown -R "$PUID":"$PGID" /photos mkdir -p "$MACHINE_LEARNING_CACHE_FOLDER" "$TYPESENSE_DATA_DIR" +chown -R "$PUID":"$PGID" "$MACHINE_LEARNING_CACHE_FOLDER" +chown -R "$PUID":"$PGID" "$TYPESENSE_DATA_DIR" diff --git a/immich/rootfs/etc/cont-init.d/99-database.sh b/immich/rootfs/etc/cont-init.d/99-database.sh deleted file mode 100755 index 3f55e2322..000000000 --- a/immich/rootfs/etc/cont-init.d/99-database.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env bashio -# 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 # -################### - -bashio::log.info "Defining database" -bashio::log.info "-----------------" - -bashio::log.info "Connecting to external postgresql" -bashio::log.info "" - -# 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') - -# 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 - printf "%s" "$DB_USERNAME" > /var/run/s6/container_environment/DB_USERNAME - printf "%s" "$DB_PASSWORD" > /var/run/s6/container_environment/DB_PASSWORD - printf "%s" "$DB_DATABASE_NAME" > /var/run/s6/container_environment/DB_DATABASE_NAME - printf "%s" "$DB_PORT" > /var/run/s6/container_environment/DB_PORT - printf "%s" "$DB_HOSTNAME" > /var/run/s6/container_environment/DB_HOSTNAME - printf "%s" "$JWT_SECRET" > /var/run/s6/container_environment/JWT_SECRET -fi - -{ - printf "%s" "DB_USERNAME=\"$DB_USERNAME\"" - printf "%s" "DB_PASSWORD=\"$DB_PASSWORD\"" - printf "%s" "DB_DATABASE_NAME=\"$DB_DATABASE_NAME\"" - printf "%s" "DB_PORT=\"$DB_PORT\"" - printf "%s" "DB_HOSTNAME=\"$DB_HOSTNAME\"" - printf "%s" "JWT_SECRET=\"$JWT_SECRET\"" -} >> ~/.bashrc diff --git a/immich/rootfs/etc/cont-init.d/99-run.sh b/immich/rootfs/etc/cont-init.d/99-run.sh index d75d30a0c..7d15352a4 100755 --- a/immich/rootfs/etc/cont-init.d/99-run.sh +++ b/immich/rootfs/etc/cont-init.d/99-run.sh @@ -29,6 +29,20 @@ for KEYS in "${arr[@]}"; do export "${KEYS}=${VALUE//[\"\']/}" done +###################### +# 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 # ################### @@ -36,71 +50,55 @@ done 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 +# Export variables +if [ -d /var/run/s6/container_environment ]; then + printf "%s" "$DB_USERNAME" > /var/run/s6/container_environment/DB_USERNAME + printf "%s" "$DB_PASSWORD" > /var/run/s6/container_environment/DB_PASSWORD + printf "%s" "$DB_DATABASE_NAME" > /var/run/s6/container_environment/DB_DATABASE_NAME + printf "%s" "$DB_PORT" > /var/run/s6/container_environment/DB_PORT + printf "%s" "$DB_HOSTNAME" > /var/run/s6/container_environment/DB_HOSTNAME + printf "%s" "$JWT_SECRET" > /var/run/s6/container_environment/JWT_SECRET +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') - ;; +{ + printf "%s" "DB_USERNAME=\"$DB_USERNAME\"" + printf "%s" "DB_PASSWORD=\"$DB_PASSWORD\"" + printf "%s" "DB_DATABASE_NAME=\"$DB_DATABASE_NAME\"" + printf "%s" "DB_PORT=\"$DB_PORT\"" + printf "%s" "DB_HOSTNAME=\"$DB_HOSTNAME\"" + printf "%s" "JWT_SECRET=\"$JWT_SECRET\"" +} >> ~/.bashrc - **) +################### +# Create database # +################### - bashio::log.info "Using internal postgresql" - bashio::log.info "" +# Create database if does not exist +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 +psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" < setup_postgres.sql || true - # 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 - -################## -# Starting redis # -################## -exec redis-server & bashio::log.info "Starting redis" +# Clean +rm setup_postgres.sql diff --git a/immich/stats.png b/immich/stats.png index 1e5ce520576c9f0811d063f8749a1cb6b370bd4a..3a983df810ade2a6da53c02e73ffc4f78c8b55c4 100644 GIT binary patch delta 1222 zcmV;%1UdV|44n+HXaRqqNklCr|M`JYnM|+F{j%x4e_=$B zZVx|K>r1^p*Xqk_NCyA_000000Dw1GhN$KND=@(_G(G=|bu)jg^NdKh!+M${-407* zev*X}a!1YwUhsiM6m`l5mC#6cNFM`L_3pMc zkx1_um9M2W53G?ZS|+H=g|0)J?!Wgr(2?tys4vfT`miWFa_U5&K^UAd2+|EA`eKdT zn9!yhB;I>h-1CI=zF-lBLFmXCghdnv;SLvr(0ezCZfbuuBN1p1I&uclOs&o}zCS-l z4(WX%56<}GYij^2XL?4MPY=B7*L$6i-ZMI1>uHYku2D<(A?aA}3Dp`oSNb_}@D8eu zoH`L`5?x15n+P-sgEIy}x9(T$W2&mbneU<*7Ex$Wxh!lxl$tC(uv`l1>ExfhWyHr)5y##` zYvhog#(iz~Qjns>5xHdPSpTJ91zn|{(COllVj`8gV!9+#_Lj%q8JtPsfr~Ej;!b_# z$8~x>FI-{o^3Bd)Zqo}SG9GUXr<8@2Gs$%CdV_zd)g;D{y`sBo_1b?J_I|}pZA;xsQL7RSLaN!e3|HXjt38b$W5k7(R2}8msOiLfQgDzrLxR-0`R;Y^PY!yea5H7Fg|0{Z!M zACQ0Ej&)>TlcVeWOtA)>BU`}$_opLUOUJWpoZPu|DjnH(=&X9@>@Gn^!?4IMMf=hj zUMWty(s5ml_M{`bI_*eD_G7#%{qL6&1%V`9yO#~m@A3FutDM;H^XQq5>^6Apu2qD$ zLw-k2v4{fUZJ~S6P~=T15rnsg?vY}F^Xxxz!FFPDO0K)N|@w)oH~XX*28Y=>*L=%ySOPe#B0o$>`@ ze!uR;j_FQrB|i^2E|B+frRKM7|C`8RQ;v%#qu>8d`67Ac9@9l!u!NUKR`T<>ii>}w z^F1~%Ze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