From b5090bf982235ca20dea1b2cfb540c8f3e721385 Mon Sep 17 00:00:00 2001 From: chmistry Date: Tue, 27 Aug 2024 21:43:08 +0200 Subject: [PATCH] first pass immich lxc script and installer --- ct/immich.sh | 104 +++++++++++++++++++++ install/immich-install.sh | 191 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 295 insertions(+) create mode 100644 ct/immich.sh create mode 100644 install/immich-install.sh diff --git a/ct/immich.sh b/ct/immich.sh new file mode 100644 index 00000000..3873739e --- /dev/null +++ b/ct/immich.sh @@ -0,0 +1,104 @@ +#!/usr/bin/env bash +source <(curl -s https://raw.githubusercontent.com/tteck/Proxmox/main/misc/build.func) +# Copyright (c) 2024 chmistry +# Author: chmistry +# License: MIT +# https://github.com/tteck/Proxmox/raw/main/LICENSE + +function header_info { +clear +cat <<"EOF" +.__ .__ .__ +|__| _____ _____ |__| ____ | |__ +| |/ \ / \| |/ ___\| | \ +| | Y Y \ Y Y \ \ \___| Y \ +|__|__|_| /__|_| /__|\___ >___| / + \/ \/ \/ \/ +EOF +} +header_info +echo -e "Loading..." +APP="immich" +var_disk="50" +var_cpu="4" +var_ram="8193" +var_os="ubuntu" +var_version="24.04" +variables +color +catch_errors + +function default_settings() { + CT_TYPE="1" + PW="" + CT_ID=$NEXTID + HN=$NSAPP + DISK_SIZE="$var_disk" + CORE_COUNT="$var_cpu" + RAM_SIZE="$var_ram" + BRG="vmbr0" + NET="dhcp" + GATE="" + APT_CACHER="" + APT_CACHER_IP="" + DISABLEIP6="no" + MTU="" + SD="" + NS="" + MAC="" + VLAN="" + SSH="no" + VERB="no" + echo_default +} + +function update_script() { +header_info +INSTALL_DIR_app=/home/immich/app +if [[ ! -d $INSTALL_DIR_app ]]; then msg_error "No ${APP} Installation Found!"; exit; fi +if (( $(df /boot | awk 'NR==2{gsub("%","",$5); print $5}') > 80 )); then + read -r -p "Warning: Storage is dangerously low, continue anyway? " prompt + [[ ${prompt,,} =~ ^(y|yes)$ ]] || exit +fi +rm -rf $INSTALL_DIR_app + +su immich -c "git clone https://github.com/loeeeee/immich-in-lxc.git /tmp" + +msg_info "Stopping immich" +systemctl stop immich-microservices.service +systemctl stop immich-ml.service +systemctl stop immich-web.service +msg_ok "Stopped immich" + +cd /tmp/immich-in-lxc +#su immich -c "/tmp/install.sh" # creates env file +# Replace password in runtime.env file +#sed -i 's/A_SEHR_SAFE_PASSWORD/YUaaWZAvtL@JpNgpi3z6uL4MmDMR_w/g' runtime.env + +msg_info "Updating immich" + +su immich -c "/tmp/install.sh" # runs rest of script + +msg_ok "Updated immich" + +msg_info "Starting immich" +systemctl stop immich-microservices.service +systemctl stop immich-ml.service +systemctl stop immich-web.service +msg_ok "Started immich" + +msg_info "Cleaning Up" +rm -rf /tmp/immich-in-lxc +msg_ok "Cleaned" +msg_ok "Updated Successfully" +exit +} + +start +build_container +description + +msg_ok "Completed Successfully!\n" +echo -e "${APP} Setup should be reachable by going to the following URL. + ${BL}http://${IP}:3001${CL} \n" + diff --git a/install/immich-install.sh b/install/immich-install.sh new file mode 100644 index 00000000..4c6d3ecd --- /dev/null +++ b/install/immich-install.sh @@ -0,0 +1,191 @@ +#!/usr/bin/env bash + +# Copyright (c) 2024 chmistry +# Author: chmistry +# License: MIT +# https://github.com/tteck/Proxmox/raw/main/LICENSE + +source /dev/stdin <<< "$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +msg_info "Installing Dependencies" +$STD apt install -y curl +$STD apt install -y git +$STD apt install -y python3-venv +$STD apt install -y python3-dev +$STD apt install -y build-essential +$STD apt install -y unzip +$STD apt install -y postgresql-common +$STD apt install -y gnupg +$STD apt install -y software-properties-common +$STD apt install -y redis +msg_ok "Installed Dependencies" + +msg_info "Installing Postgresql and pgvector" +$STD /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y +apt install -y postgresql postgresql-16-pgvector +msg_ok "Installed Postgresql and pgvector" + +msg_info "Setting up database" +#test this: +$STD su postgres -s /bin/sh -c "psql \ +CREATE DATABASE immich; +CREATE USER immich WITH ENCRYPTED PASSWORD 'YUaaWZAvtL@JpNgpi3z6uL4MmDMR_w'; +GRANT ALL PRIVILEGES ON DATABASE immich to immich; +ALTER USER immich WITH SUPERUSER; +\q" + +#otherwise this: +#su postgres </etc/systemd/system/immich-microservices.service +[Unit] +Description=immich microservices +Documentation=https://github.com/immich-app/immich +Requires=redis-server.service +Requires=postgresql.service + +[Service] +User=immich +Group=immich +Type=simple +Restart=on-failure +UMask=0077 + +ExecStart=/bin/bash /home/immich/app/start.sh microservices + +SyslogIdentifier=immich-microservices +StandardOutput=append:/var/log/immich/microservices.log +StandardError=append:/var/log/immich/microservices.log + +[Install] +WantedBy=multi-user.target +EOF + +cat </etc/systemd/system/immich-ml.service +[Unit] +Description=immich machine-learning +Documentation=https://github.com/immich-app/immich + +[Service] +User=immich +Group=immich +Type=simple +Restart=on-failure +UMask=0077 + +WorkingDirectory=/home/immich/app +EnvironmentFile=/home/immich/runtime.env +ExecStart=/home/immich/app/machine-learning/start.sh + +SyslogIdentifier=immich-machine-learning +StandardOutput=append:/var/log/immich/ml.log +StandardError=append:/var/log/immich/ml.log + +[Install] +WantedBy=multi-user.target +EOF + +cat </etc/systemd/system/immich-web.service +[Unit] +Description=immich web server +Documentation=https://github.com/immich-app/immich +Requires=redis-server.service +Requires=postgresql.service +Requires=immich-ml.service +Requires=immich-microservices.service + +[Service] +User=immich +Group=immich +Type=simple +Restart=on-failure +UMask=0077 + +ExecStart=/bin/bash /home/immich/app/start.sh immich + +SyslogIdentifier=immich-web +StandardOutput=append:/var/log/immich/web.log +StandardError=append:/var/log/immich/web.log + +[Install] +WantedBy=multi-user.target +EOF + +systemctl enable -q --now immich-microservices.service +systemctl enable -q --now immich-ml.service +systemctl enable -q --now immich-web.service + +msg_ok "Created Services" + +motd_ssh +customize + +msg_info "Cleaning up" + +$STD apt-get -y autoremove +$STD apt-get -y autoclean +msg_ok "Cleaned" +