#!/bin/bash # LOGO! Soft Comfort V8.4.x - portable macOS installation from a local Siemens media folder. # Requires a trusted, complete LOGOCOMFORT folder; never downloads Siemens software. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" INSTALL_ROOT="$HOME/Applications/LOGOComfort" SYSTEM_LAUNCHER='/Applications/LOGO! Soft Comfort starten.app' USER_LAUNCHER="$HOME/Applications/LOGO! Soft Comfort starten.app" CORRETTO_URL='https://corretto.aws/downloads/latest/amazon-corretto-11-x64-macos-jdk.pkg' CORRETTO_SHA_URL='https://corretto.aws/downloads/latest_sha256/amazon-corretto-11-x64-macos-jdk.pkg' REPLACE=0 SOURCE='' STAGE='' info() { printf '\n[INFO] %s\n' "$*"; } warn() { printf '\n[WARNUNG] %s\n' "$*" >&2; } die() { printf '\n[FEHLER] %s\n' "$*" >&2; exit 1; } cleanup() { if [ -n "$STAGE" ] && [ -d "$STAGE" ]; then rm -rf "$STAGE"; fi; } trap cleanup EXIT usage() { cat <<'HELP' LOGO! Soft Comfort V8.4.x - lokaler macOS-Installer Aufruf: bash install.sh [Pfad_zum_LOGOCOMFORT_Ordner] [--replace] Beispiel: bash install.sh "$HOME/Downloads/LOGOCOMFORT" Falls kein Pfad angegeben ist, wird LOGOCOMFORT neben dem Skript, oberhalb des Skripts oder unter ~/Downloads/LOGOCOMFORT gesucht. --replace Vorhandene Programmdateien aktualisieren (Backup wird erstellt). --help Diese Hilfe anzeigen. HELP } for arg in "$@"; do case "$arg" in --replace) REPLACE=1 ;; --help|-h) usage; exit 0 ;; --*) die "Unbekannter Parameter: $arg" ;; *) if [ -n "$SOURCE" ]; then die 'Bitte nur einen Quellordner angeben.'; fi; SOURCE="$arg" ;; esac done [ "$(uname -s)" = 'Darwin' ] || die 'Dieser Installer ist nur fuer macOS geeignet.' [ "$(id -u)" -ne 0 ] || die 'Bitte als normaler Benutzer starten (ohne sudo). sudo wird nur gezielt verwendet.' # The media may have been unzipped next to the repository or downloaded separately. if [ -z "$SOURCE" ]; then for candidate in "$SCRIPT_DIR/LOGOCOMFORT" "$SCRIPT_DIR/../LOGOCOMFORT" "$HOME/Downloads/LOGOCOMFORT"; do if [ -d "$candidate/Mac/Application" ]; then SOURCE="$candidate"; break; fi done fi if [ -n "$SOURCE" ]; then [ -d "$SOURCE" ] || die "Quellordner fehlt: $SOURCE" SOURCE="$(cd "$SOURCE" && pwd)" if [ -d "$SOURCE/Mac/Application" ]; then SOURCE_APPDIR="$SOURCE/Mac/Application" elif [ -d "$SOURCE/Application" ]; then SOURCE_APPDIR="$SOURCE/Application" elif [ -d "$SOURCE/LOGOComfort.app" ] && [ -d "$SOURCE/lib" ]; then SOURCE_APPDIR="$SOURCE" else die "Im Quellordner fehlt Mac/Application (oder Application bzw. LOGOComfort.app + lib): $SOURCE" fi [ -x "$SOURCE_APPDIR/LOGOComfort.app/Contents/MacOS/LOGOComfort" ] || die 'LOGOComfort.app ist unvollstaendig oder nicht ausfuehrbar.' [ -d "$SOURCE_APPDIR/lib" ] || die 'Die benoetigten Programmbibliotheken (lib) fehlen.' info "Installationsquelle: $SOURCE_APPDIR" else if [ -d "$INSTALL_ROOT/LOGOComfort.app" ] && [ -d "$INSTALL_ROOT/lib" ]; then info 'Kein Quellordner angegeben; vorhandene Installation wird beibehalten und der Starter erneuert.' else die 'Keinen lokalen LOGOCOMFORT-Ordner gefunden. Bitte Pfad angeben, z. B. bash install.sh "$HOME/Downloads/LOGOCOMFORT"' fi fi # On Intel Macs arch -x86_64 works natively; on Apple Silicon Rosetta is required. if ! /usr/bin/arch -x86_64 /usr/bin/true >/dev/null 2>&1; then info 'Rosetta 2 fehlt und wird fuer die Intel-Anwendung benoetigt.' printf 'Rosetta 2 jetzt mit Apple softwareupdate installieren? [j/N]: ' read -r answer case "$answer" in j|J|ja|JA|Ja) /usr/sbin/softwareupdate --install-rosetta --agree-to-license || die 'Rosetta-Installation fehlgeschlagen.' ;; *) die 'Ohne Rosetta kann die Intel-Anwendung nicht starten.' ;; esac fi info 'Rosetta / Intel-Ausfuehrung: OK' find_java11() { local path path="$(/usr/bin/arch -x86_64 /usr/libexec/java_home -v 11 -a x86_64 2>/dev/null || true)" if [ -n "$path" ] && [ -x "$path/bin/java" ] && /usr/bin/arch -x86_64 "$path/bin/java" -version 2>&1 | /usr/bin/grep -q 'version "11\.'; then printf '%s\n' "$path" return 0 fi return 1 } if ! JAVA11="$(find_java11)"; then warn 'Java 11 (Intel/x86_64) ist nicht vorhanden.' printf 'Amazon Corretto 11 x64 von Amazon laden, SHA-256 pruefen und als macOS-Paket installieren? [j/N]: ' read -r answer case "$answer" in j|J|ja|JA|Ja) ;; *) die "Bitte Java 11 Intel installieren: $CORRETTO_URL" ;; esac STAGE="$(/usr/bin/mktemp -d "${TMPDIR:-/tmp}logo-install.XXXXXX")" info 'Lade Amazon Corretto 11 (offizielle Quelle) ...' /usr/bin/curl --fail --location --retry 2 --silent --show-error "$CORRETTO_URL" -o "$STAGE/corretto.pkg" || die 'Download des Java-Pakets fehlgeschlagen.' /usr/bin/curl --fail --location --retry 2 --silent --show-error "$CORRETTO_SHA_URL" -o "$STAGE/corretto.sha256" || die 'SHA-256-Referenz konnte nicht geladen werden.' expected="$(/usr/bin/awk 'NR==1 {print $1}' "$STAGE/corretto.sha256" | /usr/bin/tr '[:upper:]' '[:lower:]')" actual="$(/usr/bin/shasum -a 256 "$STAGE/corretto.pkg" | /usr/bin/awk '{print $1}')" [ "${#expected}" -eq 64 ] && [ "$expected" = "$actual" ] || die 'SHA-256 stimmt nicht ueberein: Installation abgebrochen.' info 'SHA-256 der Java-Datei: OK' /usr/sbin/pkgutil --check-signature "$STAGE/corretto.pkg" | /usr/bin/grep -E 'Status: signed by a certificate trusted by Mac OS X|Status: signed by a certificate trusted by macOS' >/dev/null || die 'macOS konnte die Paketsignatur nicht als vertrauenswuerdig bestaetigen.' /usr/sbin/pkgutil --check-signature "$STAGE/corretto.pkg" | /usr/bin/grep -i 'Amazon' >/dev/null || die 'Die Java-Paketsignatur enthaelt keinen Amazon-Aussteller.' info 'Paketsignatur: vertraut, Amazon als Signaturinhaber gefunden.' /usr/bin/sudo /usr/sbin/installer -pkg "$STAGE/corretto.pkg" -target / || die 'Java-Installation fehlgeschlagen.' JAVA11="$(find_java11)" || die 'Java 11 Intel ist nach der Installation nicht nutzbar.' rm -rf "$STAGE" STAGE='' fi info "Java 11 Intel: $JAVA11" # Never overwrite an existing working installation automatically. if [ -d "$INSTALL_ROOT" ] && [ "$REPLACE" -ne 1 ]; then [ -x "$INSTALL_ROOT/LOGOComfort.app/Contents/MacOS/LOGOComfort" ] && [ -d "$INSTALL_ROOT/lib" ] || die 'Die vorhandene Installation ist unvollstaendig. Erneut mit --replace ausfuehren.' info "Vorhandene Programmdateien bleiben bestehen: $INSTALL_ROOT" else [ -n "$SOURCE" ] || die 'Fuer --replace ist ein Quellordner notwendig.' /bin/mkdir -p "$HOME/Applications" STAGE="$(/usr/bin/mktemp -d "$HOME/Applications/.logo-stage.XXXXXX")" info 'Kopiere vollstaendigen Mac/Application-Ordner (ohne problematische Quell-Metadaten) ...' /usr/bin/ditto --norsrc "$SOURCE_APPDIR" "$STAGE/LOGOComfort" || die 'Kopieren fehlgeschlagen.' /bin/chmod -R u+rwX "$STAGE/LOGOComfort" [ -x "$STAGE/LOGOComfort/LOGOComfort.app/Contents/MacOS/LOGOComfort" ] && [ -d "$STAGE/LOGOComfort/lib" ] || die 'Installationsdateien sind nach dem Kopieren unvollstaendig.' if [ -d "$INSTALL_ROOT" ]; then BACKUP="$HOME/Applications/LOGOComfort.backup.$(/bin/date +%Y%m%d-%H%M%S)" /bin/mv "$INSTALL_ROOT" "$BACKUP" info "Backup der vorherigen Installation: $BACKUP" fi /bin/mv "$STAGE/LOGOComfort" "$INSTALL_ROOT" rm -rf "$STAGE" STAGE='' info "Programm installiert: $INSTALL_ROOT" fi # Helper resides next to the Siemens application and its lib folder. cat > "$INSTALL_ROOT/launch-logo.sh" <<'LAUNCHER' #!/bin/bash set -euo pipefail BASE="$(cd "$(dirname "$0")" && pwd)" JAVA11="$(/usr/bin/arch -x86_64 /usr/libexec/java_home -v 11 -a x86_64 2>/dev/null || true)" if [ -z "$JAVA11" ] || [ ! -x "$JAVA11/bin/java" ]; then echo 'FEHLER: Java 11 Intel (x86_64) fehlt.' >&2 exit 1 fi if ! /usr/bin/arch -x86_64 "$JAVA11/bin/java" -version 2>&1 | /usr/bin/grep -q 'version "11\.'; then echo 'FEHLER: Java 11 Intel ist nicht lauffaehig.' >&2 exit 1 fi cd "$BASE" exec /usr/bin/env JAVA_HOME="$JAVA11" JAVA_VERSION=11 \ "$BASE/LOGOComfort.app/Contents/MacOS/LOGOComfort" "$@" LAUNCHER /bin/chmod 755 "$INSTALL_ROOT/launch-logo.sh" # Compile real macOS launcher app, retaining user-specific locations at runtime. STAGE="$(/usr/bin/mktemp -d "$HOME/Applications/.logo-starter.XXXXXX")" cat > "$STAGE/starter.applescript" <<'APPLESCRIPT' on run set homePath to POSIX path of (path to home folder) set runFile to homePath & "Applications/LOGOComfort/launch-logo.sh" set logFile to homePath & "Library/Logs/LOGOComfort.log" set commandText to "nohup " & quoted form of runFile & " >> " & quoted form of logFile & " 2>&1 < /dev/null &" do shell script commandText end run APPLESCRIPT BUILT_LAUNCHER="$STAGE/LOGO! Soft Comfort starten.app" /usr/bin/osacompile -o "$BUILT_LAUNCHER" "$STAGE/starter.applescript" || die 'Konnte die macOS-Starter-App nicht erzeugen.' ICON="$INSTALL_ROOT/LOGOComfort.app/Contents/Resources/LaunchAnywhere.icns" if [ -f "$ICON" ]; then /bin/cp "$ICON" "$BUILT_LAUNCHER/Contents/Resources/applet.icns" fi /usr/bin/codesign --force --sign - "$BUILT_LAUNCHER" || die 'Starter konnte nicht lokal signiert werden.' info 'Installiere Starter im normalen macOS-Programme-Ordner (/Applications) ...' /usr/bin/sudo /usr/bin/ditto "$BUILT_LAUNCHER" "$SYSTEM_LAUNCHER" || die 'Starter konnte nicht nach /Applications kopiert werden.' # Remove an old user-local duplicate only when it matches the same name. if [ -d "$USER_LAUNCHER" ]; then warn "Ein alter Starter liegt auch unter $USER_LAUNCHER. Er wird nicht automatisch geloescht." fi rm -rf "$STAGE" STAGE='' printf '\n===============================================\n' printf 'LOGO! SOFT COMFORT - INSTALLATION ABGESCHLOSSEN\n' printf 'Programm: %s\n' "$INSTALL_ROOT/LOGOComfort.app" printf 'Starter: %s\n' "$SYSTEM_LAUNCHER" printf 'Java: %s\n' "$JAVA11" printf 'Log: %s\n' "$HOME/Library/Logs/LOGOComfort.log" printf '===============================================\n' printf '\nStarter im Finder unter Programme per Doppelklick testen.\n' printf 'Bei Bedarf den Starter ins Dock ziehen.\n' printf 'Check: bash "%s/check.sh"\n' "$SCRIPT_DIR"