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? <y/N> " 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 <<EOF +#psql -c "CREATE DATABASE immich;" +#psql -c "CREATE USER immich WITH ENCRYPTED PASSWORD 'YUaaWZAvtL@JpNgpi3z6uL4MmDMR_w';" +#psql -c "GRANT ALL PRIVILEGES ON DATABASE immich to immich;" +#psql -c "ALTER USER immich WITH SUPERUSER;" +#EOF + +msg_ok "Database setup completed" + +msg_info "Installing ffmpeg yellyfin" +$STD add-apt-repository universe -y +$STD mkdir -p /etc/apt/keyrings +$STD curl -fsSL https://repo.jellyfin.org/jellyfin_team.gpg.key | gpg --dearmor -o /etc/apt/keyrings/jellyfin.gpg +$STD export VERSION_OS="$( awk -F'=' '/^ID=/{ print $NF }' /etc/os-release )" +$STD export VERSION_CODENAME="$( awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release )" +$STD export DPKG_ARCHITECTURE="$( dpkg --print-architecture )" +cat <<EOF | tee /etc/apt/sources.list.d/jellyfin.sources +Types: deb +URIs: https://repo.jellyfin.org/${VERSION_OS} +Suites: ${VERSION_CODENAME} +Components: main +Architectures: ${DPKG_ARCHITECTURE} +Signed-By: /etc/apt/keyrings/jellyfin.gpg +EOF +$STD apt update + +$STD apt install -y jellyfin-ffmpeg6 + +ln -s /usr/lib/jellyfin-ffmpeg/ffmpeg /bin/ffmpeg +ln -s /usr/lib/jellyfin-ffmpeg/ffprobe /bin/ffprobe +msg_ok "Installed ffmpeg yellyfin" + +msg_info "Adding immich user" +$STD useradd -m immich +#TODO: strip user login etc. (make it more a daemon user) +msg_ok "User immich added" + +msg_info "Installing Node.js" +$STD bash <(curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh) +source ~/.bashrc +$STD nvm install 20 +ln -sf /root/.nvm/versions/node/v20/bin/node /usr/bin/node +msg_ok "Installed Node.js" + +msg_info "Installing ${APPLICATION}" + +su immich -c "git clone https://github.com/loeeeee/immich-in-lxc.git /tmp" +cd /tmp/immich-in-lxc +su immich -c "./install.sh" # creates env file +# Replace password in runtime.env file +sed -i 's/A_SEHR_SAFE_PASSWORD/YUaaWZAvtL@JpNgpi3z6uL4MmDMR_w/g' runtime.env +su immich -c "./install.sh" # runs rest of script +msg_ok "Installed ${APPLICATION}" + +msg_info "Creating log directory /var/log/immich" +mkdir -p /var/log/immich +msg_ok "Log directory created" + +msg_info "Creating Services" +cat <<EOF >/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 <<EOF >/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 <<EOF >/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" +