#!/usr/bin/env bash # Runs only on 103 from a verified release directory. It never downloads images. set -euo pipefail ROOT="${ROOT:-/Users/john/Project/Memind}" RUNTIME_DIR="${IMGPROXY_RUNTIME_DIR:?IMGPROXY_RUNTIME_DIR is required}" IMAGE_TAG="${IMGPROXY_IMAGE_TAG:?IMGPROXY_IMAGE_TAG is required}" CONTAINER="${IMGPROXY_CONTAINER:-memind-imgproxy}" NODE_BIN="${NODE_BIN:-/opt/homebrew/opt/node@24/bin/node}" DOCKER_BIN="${DOCKER_BIN:-/opt/homebrew/bin/docker}" PLIST="$HOME/Library/LaunchAgents/cn.tkmind.imgproxy-compat.plist" GUI="gui/$(id -u)" set -a source "$ROOT/.env" set +a : "${IMGPROXY_SIGNING_KEY:?missing IMGPROXY_SIGNING_KEY}" : "${IMGPROXY_SIGNING_SALT:?missing IMGPROXY_SIGNING_SALT}" : "${MINDSPACE_STORAGE_ROOT:?missing MINDSPACE_STORAGE_ROOT}" "$DOCKER_BIN" rm -f "$CONTAINER" >/dev/null 2>&1 || true "$DOCKER_BIN" run -d --name "$CONTAINER" --restart unless-stopped \ -p 127.0.0.1:20082:8080 \ -v "$MINDSPACE_STORAGE_ROOT:/mnt/images:ro" \ -e IMGPROXY_LOCAL_FILESYSTEM_ROOT=/mnt/images \ -e IMGPROXY_KEY="$IMGPROXY_SIGNING_KEY" \ -e IMGPROXY_SALT="$IMGPROXY_SIGNING_SALT" \ -e IMGPROXY_USE_ETAG=true \ -e IMGPROXY_ENABLE_WEBP_DETECTION=true \ "$IMAGE_TAG" >/dev/null for _ in $(seq 1 20); do curl -fsS --max-time 2 http://127.0.0.1:20082/health >/dev/null && break sleep 1 done curl -fsS --max-time 3 http://127.0.0.1:20082/health >/dev/null cat > "$PLIST" < Labelcn.tkmind.imgproxy-compat ProgramArguments$NODE_BIN$RUNTIME_DIR/imgproxy-compat-proxy.mjs WorkingDirectory$RUNTIME_DIR EnvironmentVariablesIMGPROXY_COMPAT_HOST10.10.0.2IMGPROXY_COMPAT_PORT20081IMGPROXY_UPSTREAMhttp://127.0.0.1:20082 RunAtLoadKeepAliveThrottleInterval10 StandardOutPath$HOME/Library/Logs/imgproxy-compat.logStandardErrorPath$HOME/Library/Logs/imgproxy-compat.log EOF plutil -lint "$PLIST" >/dev/null launchctl bootout "$GUI/cn.tkmind.imgproxy" 2>/dev/null || true launchctl disable "$GUI/cn.tkmind.imgproxy" 2>/dev/null || true launchctl bootout "$GUI/cn.tkmind.imgproxy-compat" 2>/dev/null || true launchctl bootstrap "$GUI" "$PLIST" launchctl enable "$GUI/cn.tkmind.imgproxy-compat" launchctl kickstart -k "$GUI/cn.tkmind.imgproxy-compat" for _ in $(seq 1 20); do curl -fsS --max-time 2 http://10.10.0.2:20081/health >/dev/null && break sleep 1 done curl -fsS --max-time 3 http://10.10.0.2:20081/health >/dev/null