#!/usr/bin/env bash # Create an unprivileged Debian 13 LXC container on a Proxmox VE host and # install Immich Magic Proxy in it. Run as root on the Proxmox host, with the # release tarball and lxc/install.sh beside this script: # # IMMICH_URL=http://192.168.1.20:2283 PUBLIC_BASE_URL=https://photos.example.com \ # ADMIN_PASSWORD='long random string' ./proxmox-create.sh immich-magic-proxy-.tar.gz # # Optional settings (environment variables, defaults in brackets): # CTID [next free] CT_HOSTNAME [immich-magic-proxy] STORAGE [local-lvm] # TEMPLATE_STORAGE [local] BRIDGE [vmbr0] IP [dhcp, or e.g. 192.168.1.50/24] # GATEWAY [] VLAN [] CORES [1] MEMORY [512] DISK [4] PORT [3000] # SMTP_URL MAIL_FROM SITE_NAME DIGEST_HOUR TZ [host's timezone] set -euo pipefail die () { echo "error: $*" >&2; exit 1; } log () { echo "==> $*"; } command -v pct >/dev/null || die "run this on a Proxmox VE host" [ "$(id -u)" -eq 0 ] || die "run as root" [ $# -eq 1 ] && [ -f "$1" ] || die "usage: $0 " tarball=$(readlink -f "$1") installer="$(dirname "$(readlink -f "$0")")/install.sh" [ -f "$installer" ] || die "install.sh must be next to this script" : "${IMMICH_URL:?set IMMICH_URL to the internal URL of Immich}" : "${PUBLIC_BASE_URL:?set PUBLIC_BASE_URL to the public URL of this proxy}" : "${ADMIN_PASSWORD:?set ADMIN_PASSWORD for the /admin console}" CTID=${CTID:-$(pvesh get /cluster/nextid)} # Not HOSTNAME: bash sets that to the Proxmox host's own name CT_HOSTNAME=${CT_HOSTNAME:-immich-magic-proxy} STORAGE=${STORAGE:-local-lvm} TEMPLATE_STORAGE=${TEMPLATE_STORAGE:-local} BRIDGE=${BRIDGE:-vmbr0} IP=${IP:-dhcp} CORES=${CORES:-1} MEMORY=${MEMORY:-512} DISK=${DISK:-4} PORT=${PORT:-3000} TZ=${TZ:-$(cat /etc/timezone 2>/dev/null || timedatectl show -p Timezone --value 2>/dev/null || echo Etc/UTC)} net="name=eth0,bridge=$BRIDGE,ip=$IP" [ -n "${GATEWAY:-}" ] && net="$net,gw=$GATEWAY" [ -n "${VLAN:-}" ] && net="$net,tag=$VLAN" # ----- Debian 13 template ---------------------------------------------------- log "Finding the Debian 13 template" pveam update >/dev/null template=$(pveam available --section system | awk '{print $2}' | grep -E '^debian-13-standard_.*_amd64\.tar\.(zst|xz|gz)$' | sort -V | tail -n1) [ -n "$template" ] || die "no debian-13-standard template offered by pveam" if ! pveam list "$TEMPLATE_STORAGE" | grep -q "$template"; then log "Downloading $template" pveam download "$TEMPLATE_STORAGE" "$template" fi # ----- container ------------------------------------------------------------- log "Creating container $CTID ($CT_HOSTNAME)" pct create "$CTID" "$TEMPLATE_STORAGE:vztmpl/$template" \ --hostname "$CT_HOSTNAME" \ --unprivileged 1 \ --features nesting=1 \ --cores "$CORES" --memory "$MEMORY" --swap 512 \ --rootfs "$STORAGE:$DISK" \ --net0 "$net" \ --timezone "$TZ" \ --onboot 1 \ --description "Immich Magic Proxy: invite-only sharing for Immich" pct start "$CTID" log "Waiting for the network" for _ in $(seq 1 60); do pct exec "$CTID" -- sh -c 'getent hosts deb.debian.org >/dev/null' && break sleep 2 done pct exec "$CTID" -- sh -c 'getent hosts deb.debian.org >/dev/null' || die "container $CTID has no network or DNS" log "Updating Debian" pct exec "$CTID" -- sh -c 'DEBIAN_FRONTEND=noninteractive apt-get update -q && DEBIAN_FRONTEND=noninteractive apt-get -y -q dist-upgrade' # ----- settings, then install ------------------------------------------------ # Double-quoted with \ " $ ` escaped: the form systemd's EnvironmentFile # parser reads back exactly, so passwords keep any spaces, quotes or # backslashes. (It does not support shell-style 'a'\''b' concatenation.) env_line () { local value=$2 value=${value//\\/\\\\} value=${value//\"/\\\"} value=${value//\$/\\\$} value=${value//\`/\\\`} printf '%s="%s"\n' "$1" "$value" } settings=$(mktemp) trap 'rm -f -- "$settings"' EXIT { env_line IMMICH_URL "$IMMICH_URL" env_line PUBLIC_BASE_URL "$PUBLIC_BASE_URL" env_line ADMIN_PASSWORD "$ADMIN_PASSWORD" for name in SMTP_URL SMTP_HOST SMTP_PORT SMTP_USER SMTP_PASS SMTP_SECURE MAIL_FROM SITE_NAME DIGEST_HOUR; do if [ -n "${!name:-}" ]; then env_line "$name" "${!name}"; fi done env_line TZ "$TZ" env_line IPP_PORT "$PORT" } > "$settings" pct exec "$CTID" -- install -d -m 0755 /root/imp-install pct push "$CTID" "$tarball" /root/imp-install/release.tar.gz pct push "$CTID" "$installer" /root/imp-install/install.sh --perms 0755 # The env file is written before install.sh runs, so it starts the service pct exec "$CTID" -- install -d -m 0750 /etc/immich-magic-proxy pct push "$CTID" "$settings" /etc/immich-magic-proxy/env --perms 0600 pct exec "$CTID" -- /root/imp-install/install.sh /root/imp-install/release.tar.gz pct exec "$CTID" -- rm -rf /root/imp-install log "Checking the service" for _ in $(seq 1 30); do pct exec "$CTID" -- curl -s -o /dev/null "http://127.0.0.1:$PORT/share/healthcheck" && break sleep 1 done pct exec "$CTID" -- systemctl --no-pager --lines=5 status immich-magic-proxy || true address=$(pct exec "$CTID" -- hostname -I | awk '{print $1}') cat < /root/release.tar.gz && pct push $CTID install.sh /root/install.sh --perms 0755 && pct exec $CTID -- /root/install.sh /root/release.tar.gz EOF