#!/bin/bash # AI-Cockpit – Installation und Aktualisierung für macOS # # curl -fsSL https://comanu.de/ai-cockpit/install.sh | bash # # Lädt die aktuelle Version, prüft die SHA-256-Prüfsumme und legt AI-Cockpit.app # nach /Applications (oder ~/Applications, falls /Applications nicht beschreibbar ist). # Projekte, Einstellungen und Sitzungen bleiben bei einer Aktualisierung erhalten. # # Umgebungsvariablen (optional): # AI_COCKPIT_BASE Download-Adresse (Standard: https://comanu.de/ai-cockpit/download) # AI_COCKPIT_DEST Zielordner (Standard: /Applications) # AI_COCKPIT_OPEN=0 App danach nicht starten # Alles steckt in main(): Bricht der Download des Skripts mittendrin ab, wird nichts # halb ausgeführt. main() { set -euo pipefail local BASE="${AI_COCKPIT_BASE:-https://comanu.de/ai-cockpit/download}" local DEST="${AI_COCKPIT_DEST:-/Applications}" local APP="AI-Cockpit.app" say() { printf '\033[1;33m◆\033[0m %s\n' "$*"; } ok() { printf '\033[1;32m✓\033[0m %s\n' "$*"; } warn() { printf '\033[1;33m!\033[0m %s\n' "$*"; } fail() { printf '\033[1;31m✗\033[0m %s\n' "$*" >&2; exit 1; } [ "$(uname -s)" = "Darwin" ] || fail "AI-Cockpit gibt es bisher nur für macOS." local major major="$(sw_vers -productVersion | cut -d. -f1)" [ "$major" -ge 11 ] 2>/dev/null || fail "AI-Cockpit braucht macOS 11 oder neuer (gefunden: $(sw_vers -productVersion))." say "Suche die aktuelle Version …" # Global (nicht local), weil der EXIT-Trap erst nach dem Ende von main() läuft. AI_COCKPIT_TMP="$(mktemp -d -t ai-cockpit)" trap 'rm -rf "${AI_COCKPIT_TMP:-}"' EXIT local tmp="$AI_COCKPIT_TMP" curl -fsSL "$BASE/latest.txt" -o "$tmp/latest.txt" \ || fail "Konnte $BASE/latest.txt nicht laden. Besteht eine Internetverbindung?" # Die Datei wird nur gelesen, nicht ausgeführt. local version file sha version="$(sed -n 's/^VERSION=//p' "$tmp/latest.txt" | head -1 | tr -d '\r')" file="$(sed -n 's/^FILE=//p' "$tmp/latest.txt" | head -1 | tr -d '\r')" sha="$(sed -n 's/^SHA256=//p' "$tmp/latest.txt" | head -1 | tr -d '\r')" [[ "$version" =~ ^[0-9A-Za-z.-]+$ ]] || fail "Ungültige Versionsangabe in latest.txt." [[ "$file" =~ ^[0-9A-Za-z.-]+\.zip$ ]] || fail "Ungültiger Dateiname in latest.txt." [[ "$sha" =~ ^[0-9a-f]{64}$ ]] || fail "Ungültige Prüfsumme in latest.txt." local installed="" if [ -d "$DEST/$APP" ]; then installed="$(defaults read "$DEST/$APP/Contents/Info" CFBundleShortVersionString 2>/dev/null || true)" fi if [ -n "$installed" ]; then say "Installiert: $installed · aktuell: $version" fi say "Lade AI-Cockpit $version …" curl -fL --progress-bar "$BASE/$file" -o "$tmp/$file" || fail "Download fehlgeschlagen." local actual actual="$(shasum -a 256 "$tmp/$file" | cut -d' ' -f1)" [ "$actual" = "$sha" ] || fail "Prüfsumme stimmt nicht – die Datei ist beschädigt oder verändert. Abbruch." ok "Prüfsumme stimmt." ditto -x -k "$tmp/$file" "$tmp/unpacked" [ -d "$tmp/unpacked/$APP" ] || fail "Im Archiv fehlt $APP." # Eine laufende App würde beim Austausch abstürzen. Ihre Sitzungen werden beim # normalen Beenden gespeichert und beim nächsten Start fortgesetzt. if pgrep -f "$DEST/$APP/Contents/MacOS/" >/dev/null 2>&1; then warn "AI-Cockpit läuft gerade." if [ -t 0 ] || [ -r /dev/tty ]; then printf " Jetzt beenden und aktualisieren? Laufende Sitzungen werden gespeichert und fortgesetzt. [j/N] " local answer="" read -r answer /dev/null 2>&1 || true local i for i in $(seq 1 30); do pgrep -f "$DEST/$APP/Contents/MacOS/" >/dev/null 2>&1 || break sleep 0.5 done pgrep -f "$DEST/$APP/Contents/MacOS/" >/dev/null 2>&1 && fail "AI-Cockpit ließ sich nicht beenden. Bitte von Hand beenden und erneut versuchen." fi mkdir -p "$DEST" 2>/dev/null || true if [ ! -w "$DEST" ]; then DEST="$HOME/Applications" mkdir -p "$DEST" warn "Keine Schreibrechte in /Applications – installiere nach $DEST." fi # Erst daneben ablegen, dann tauschen: So bleibt bei einem Fehler die alte Version. rm -rf "$DEST/.$APP.neu" ditto "$tmp/unpacked/$APP" "$DEST/.$APP.neu" # Mit curl geladene Dateien tragen kein Quarantäne-Kennzeichen; sicherheitshalber entfernen. xattr -dr com.apple.quarantine "$DEST/.$APP.neu" 2>/dev/null || true rm -rf "$DEST/$APP" mv "$DEST/.$APP.neu" "$DEST/$APP" ok "AI-Cockpit $version liegt in $DEST." if ! command -v claude >/dev/null 2>&1 && [ ! -x "$HOME/.local/bin/claude" ] && [ ! -x "$HOME/.claude/local/claude" ]; then warn "Claude Code wurde nicht gefunden. AI-Cockpit braucht es für Claude-Sitzungen." echo " Installation: curl -fsSL https://claude.ai/install.sh | bash" echo " Mehr dazu: https://docs.anthropic.com/de/docs/claude-code/overview" fi if [ "${AI_COCKPIT_OPEN:-1}" != "0" ]; then open "$DEST/$APP" || true fi ok "Fertig. Aktualisieren: denselben Befehl einfach erneut ausführen." } main "$@"