Cross-platform support (macOS + Linux): venv-based install, launchd & systemd autostart, CLI-override bugfix

This commit is contained in:
claude-ai
2026-06-03 18:50:27 +00:00
commit db8f6ad976
7 changed files with 749 additions and 0 deletions
Executable
+147
View File
@@ -0,0 +1,147 @@
#!/usr/bin/env bash
# ══════════════════════════════════════════════════════════════
# Image Folder Watcher plattformübergreifende Installation
# Unterstützt: macOS (launchd) und Linux (systemd)
# Nutzt ein Python-venv kein --break-system-packages nötig.
# ══════════════════════════════════════════════════════════════
set -euo pipefail
GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; NC='\033[0m'
info() { echo -e "${YELLOW}$*${NC}"; }
ok() { echo -e "${GREEN}$*${NC}"; }
err() { echo -e "${RED}$*${NC}" >&2; }
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OS="$(uname -s)"
echo -e "${GREEN}══════════════════════════════════════════════════${NC}"
echo -e "${GREEN} Image Folder Watcher Installation (${OS})${NC}"
echo -e "${GREEN}══════════════════════════════════════════════════${NC}"
INSTALL_DIR="${INSTALL_DIR:-$HOME/image-folder-watcher}"
VENV_DIR="$INSTALL_DIR/.venv"
# Sinnvolle Standard-Überwachungsordner je Plattform (per ENV überschreibbar)
if [[ "$OS" == "Darwin" ]]; then
WATCH_DIR="${WATCH_DIR:-$HOME/Pictures/Eingang}"
else
WATCH_DIR="${WATCH_DIR:-$HOME/Bilder/Eingang}"
fi
# ── 1. Python sicherstellen + System-Pakete ──────────────────────────────────
info "\n[1/4] Prüfe Python & installiere ggf. System-Voraussetzungen..."
ensure_python_linux() {
if command -v pacman &>/dev/null; then
sudo pacman -S --needed --noconfirm python
elif command -v apt-get &>/dev/null; then
sudo apt-get update -qq
sudo apt-get install -y python3 python3-venv python3-pip
elif command -v dnf &>/dev/null; then
sudo dnf install -y python3 python3-pip
elif command -v zypper &>/dev/null; then
sudo zypper install -y python3 python3-pip
else
err " Kein bekannter Paketmanager (pacman/apt/dnf/zypper) gefunden."
err " Bitte Python 3 + venv manuell installieren und Script erneut starten."
exit 1
fi
}
ensure_python_macos() {
if ! command -v python3 &>/dev/null; then
if command -v brew &>/dev/null; then
brew install python
else
err " Python 3 nicht gefunden und Homebrew ist nicht installiert."
err " Installiere Python von https://www.python.org/downloads/ ODER"
err " Homebrew von https://brew.sh und starte dann erneut."
exit 1
fi
fi
# Xcode Command Line Tools liefern viele Build-Voraussetzungen; pillow-heif
# nutzt aber vorgebaute Wheels, daher i.d.R. nicht zwingend nötig.
}
case "$OS" in
Darwin) ensure_python_macos ;;
Linux) ensure_python_linux ;;
*) err " Nicht unterstütztes OS: $OS"; exit 1 ;;
esac
PYTHON="$(command -v python3)"
ok " ✅ Python: $PYTHON ($($PYTHON --version))"
# ── 2. venv anlegen & Abhängigkeiten installieren ────────────────────────────
info "\n[2/4] Erstelle virtuelle Umgebung & installiere Abhängigkeiten..."
mkdir -p "$INSTALL_DIR"
if [[ ! -d "$VENV_DIR" ]]; then
"$PYTHON" -m venv "$VENV_DIR"
fi
"$VENV_DIR/bin/pip" install --upgrade pip --quiet
"$VENV_DIR/bin/pip" install -r "$SCRIPT_DIR/requirements.txt"
ok " ✅ Pillow, watchdog, pillow-heif (HEIC/HEIF) installiert."
# ── 3. Script + Überwachungsordner ───────────────────────────────────────────
info "\n[3/4] Kopiere Script nach $INSTALL_DIR & erstelle Ordner..."
cp "$SCRIPT_DIR/watcher.py" "$INSTALL_DIR/watcher.py"
chmod +x "$INSTALL_DIR/watcher.py"
mkdir -p "$WATCH_DIR"
ok " ✅ Überwachungsordner: $WATCH_DIR"
VENV_PYTHON="$VENV_DIR/bin/python"
# ── 4. Autostart (optional, plattformabhängig) ───────────────────────────────
info "\n[4/4] Autostart einrichten?"
read -rp "Autostart-Dienst installieren? [j/N] " INSTALL_SERVICE
if [[ "$INSTALL_SERVICE" =~ ^[jJyY]$ ]]; then
if [[ "$OS" == "Darwin" ]]; then
# ── macOS: launchd User-Agent ──
LABEL="work.datenhimmel.image-watcher"
PLIST_DIR="$HOME/Library/LaunchAgents"
PLIST="$PLIST_DIR/$LABEL.plist"
mkdir -p "$PLIST_DIR"
sed -e "s|__LABEL__|$LABEL|g" \
-e "s|__PYTHON__|$VENV_PYTHON|g" \
-e "s|__SCRIPT__|$INSTALL_DIR/watcher.py|g" \
-e "s|__WATCH_DIR__|$WATCH_DIR|g" \
-e "s|__WORKDIR__|$INSTALL_DIR|g" \
"$SCRIPT_DIR/launchd/image-watcher.plist.template" > "$PLIST"
# Neu laden (bootout ignoriert Fehler falls noch nicht geladen)
launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null || true
launchctl bootstrap "gui/$(id -u)" "$PLIST"
ok " ✅ launchd-Agent installiert & gestartet!"
echo " Status: launchctl print gui/$(id -u)/$LABEL | head"
echo " Stoppen: launchctl bootout gui/$(id -u)/$LABEL"
echo " Logs: tail -f $INSTALL_DIR/watcher.out.log"
else
# ── Linux: systemd System-Service ──
SERVICE_NAME="image-watcher.service"
TMP_SERVICE="$INSTALL_DIR/$SERVICE_NAME"
sed -e "s|__PYTHON__|$VENV_PYTHON|g" \
-e "s|__SCRIPT__|$INSTALL_DIR/watcher.py|g" \
-e "s|__WATCH_DIR__|$WATCH_DIR|g" \
-e "s|__WORKDIR__|$INSTALL_DIR|g" \
-e "s|__USER__|$USER|g" \
"$SCRIPT_DIR/systemd/image-watcher.service.template" > "$TMP_SERVICE"
sudo cp "$TMP_SERVICE" "/etc/systemd/system/$SERVICE_NAME"
sudo systemctl daemon-reload
sudo systemctl enable "$SERVICE_NAME"
sudo systemctl restart "$SERVICE_NAME"
ok " ✅ systemd-Service installiert & gestartet!"
echo " Status: sudo systemctl status image-watcher"
echo " Logs: journalctl -u image-watcher -f"
fi
fi
echo -e "\n${GREEN}══════════════════════════════════════════════════${NC}"
ok " ✅ Installation abgeschlossen!"
echo -e "${GREEN}══════════════════════════════════════════════════${NC}"
echo ""
echo " Manuell starten:"
echo " $VENV_PYTHON $INSTALL_DIR/watcher.py \"$WATCH_DIR\""
echo ""
echo " Mit Optionen:"
echo " $VENV_PYTHON $INSTALL_DIR/watcher.py \"$WATCH_DIR\" --width 1920 --dpi 72 --format JPEG"
echo ""