#!/usr/bin/env bash # Runs only on 103 from a verified imgproxy native release directory. set -euo pipefail ROOT="${ROOT:-/Users/john/Project/Memind}" RUNTIME_BASE="${IMGPROXY_RUNTIME_BASE:-/Users/john/Project/imgproxy-runtime}" RUNTIME_DIR="${IMGPROXY_RUNTIME_DIR:?IMGPROXY_RUNTIME_DIR is required}" IMGPROXY_BIN="${RUNTIME_DIR}/vendor/imgproxy-runtime/bin/imgproxy" RUN_SCRIPT="${RUNTIME_DIR}/scripts/run-imgproxy-prod.sh" NODE_BIN="${NODE_BIN:-/opt/homebrew/opt/node@24/bin/node}" DOCKER_BIN="${DOCKER_BIN:-/opt/homebrew/bin/docker}" CONTAINER="${IMGPROXY_CONTAINER:-memind-imgproxy}" NATIVE_LABEL="cn.tkmind.imgproxy" COMPAT_LABEL="cn.tkmind.imgproxy-compat" NATIVE_PLIST="${HOME}/Library/LaunchAgents/${NATIVE_LABEL}.plist" COMPAT_PLIST="${HOME}/Library/LaunchAgents/${COMPAT_LABEL}.plist" LOG_DIR="${HOME}/Library/Logs" GUI="gui/$(id -u)" [[ -x "${IMGPROXY_BIN}" ]] || { echo "missing vendor imgproxy binary: ${IMGPROXY_BIN}" >&2 exit 1 } [[ -x "${RUN_SCRIPT}" ]] || { echo "missing imgproxy run script: ${RUN_SCRIPT}" >&2 exit 1 } 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}" cd "${RUNTIME_DIR}/vendor/imgproxy-runtime" shasum -a 256 -c SHA256SUMS >/dev/null mkdir -p "${HOME}/Library/LaunchAgents" "${LOG_DIR}" cat > "${NATIVE_PLIST}" < Label ${NATIVE_LABEL} ProgramArguments ${IMGPROXY_BIN} EnvironmentVariables IMGPROXY_BIND 127.0.0.1:20082 IMGPROXY_LOCAL_FILESYSTEM_ROOT ${MINDSPACE_STORAGE_ROOT} IMGPROXY_KEY ${IMGPROXY_SIGNING_KEY} IMGPROXY_SALT ${IMGPROXY_SIGNING_SALT} IMGPROXY_USE_ETAG true IMGPROXY_ENABLE_WEBP_DETECTION true WorkingDirectory ${ROOT} RunAtLoad KeepAlive ThrottleInterval 10 StandardOutPath ${LOG_DIR}/imgproxy.log StandardErrorPath ${LOG_DIR}/imgproxy.log EOF xattr -cr "${RUNTIME_DIR}" 2>/dev/null || true if [[ -x "${DOCKER_BIN}" ]]; then "${DOCKER_BIN}" stop "${CONTAINER}" >/dev/null 2>&1 || true "${DOCKER_BIN}" rm -f "${CONTAINER}" >/dev/null 2>&1 || true "${DOCKER_BIN}" update --restart=no "${CONTAINER}" >/dev/null 2>&1 || true fi launchctl bootout "${GUI}/${NATIVE_LABEL}" 2>/dev/null || true plutil -lint "${NATIVE_PLIST}" >/dev/null launchctl enable "${GUI}/${NATIVE_LABEL}" 2>/dev/null || true launchctl bootstrap "${GUI}" "${NATIVE_PLIST}" launchctl kickstart -k "${GUI}/${NATIVE_LABEL}" for _ in $(seq 1 30); 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 > "${COMPAT_PLIST}" < Label${COMPAT_LABEL} 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${LOG_DIR}/imgproxy-compat.logStandardErrorPath${LOG_DIR}/imgproxy-compat.log EOF launchctl bootout "${GUI}/${COMPAT_LABEL}" 2>/dev/null || true plutil -lint "${COMPAT_PLIST}" >/dev/null launchctl enable "${GUI}/${COMPAT_LABEL}" 2>/dev/null || true launchctl bootstrap "${GUI}" "${COMPAT_PLIST}" launchctl kickstart -k "${GUI}/${COMPAT_LABEL}" for _ in $(seq 1 30); 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 printf 'imgproxy native installed from %s (%s)\n' "${RUNTIME_DIR}" "$("${IMGPROXY_BIN}" version)"