#!/bin/bash # Trixy Installationsskript (Linux) # Interaktive Einrichtung: Modus, Konfiguration, Autostart/Service, WiFi-Hotspot set -e # Ins Projektverzeichnis wechseln PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)" cd "$PROJECT_DIR" echo "" echo "========================================" echo " Trixy - Interaktive Installation" echo "========================================" echo "" # ------------------------------------------------------- # Schritt 1: Update ausfuehren # ------------------------------------------------------- echo "[1/8] Update ausfuehren..." if [ -f "bash/update_linux.sh" ]; then bash bash/update_linux.sh else echo " Hinweis: Update-Skript nicht gefunden, ueberspringe." fi echo "" # ------------------------------------------------------- # Schritt 2: Python-Abhaengigkeiten installieren # ------------------------------------------------------- echo "[2/8] Python-Abhaengigkeiten pruefen..." if ! command -v python3 &>/dev/null; then echo " FEHLER: python3 nicht gefunden! Bitte Python 3.10+ installieren." exit 1 fi if ! command -v pip3 &>/dev/null; then echo " Hinweis: pip3 nicht gefunden. Abhaengigkeiten muessen manuell installiert werden." else if [ -f "requirements.txt" ]; then echo " Installiere Abhaengigkeiten aus requirements.txt..." pip3 install -r requirements.txt else echo " Keine requirements.txt gefunden, ueberspringe." fi fi echo "" # ------------------------------------------------------- # Schritt 3: Modus waehlen # ------------------------------------------------------- echo "[3/8] Modus waehlen" echo "" echo " Welchen Modus moechtest du installieren?" echo " [1] Server - Zentraler Server fuer Satellite-Management" echo " [2] Standalone - All-in-One ohne Server" echo " [3] Client - Leichtgewichtiger Satellite" echo "" while true; do read -rp " Auswahl [1/2/3]: " MODE_CHOICE case "$MODE_CHOICE" in 1) MODE="server"; CONFIG_FILE="config/server_config.json"; break ;; 2) MODE="standalone"; CONFIG_FILE="config/standalone_config.json"; break ;; 3) MODE="client"; CONFIG_FILE="config/client_config.json"; break ;; *) echo " Ungueltige Auswahl. Bitte 1, 2 oder 3 eingeben." ;; esac done echo "" # ------------------------------------------------------- # Schritt 4: Device-Name abfragen # ------------------------------------------------------- echo "[4/8] Geraetename festlegen" CURRENT_HOSTNAME=$(hostname) echo " Aktueller Hostname: $CURRENT_HOSTNAME" read -rp " Neuer Geraetename (leer = beibehalten): " DEVICE_NAME if [ -n "$DEVICE_NAME" ]; then echo " Setze Hostname auf: $DEVICE_NAME" sudo hostnamectl set-hostname "$DEVICE_NAME" else DEVICE_NAME="$CURRENT_HOSTNAME" fi echo "" # ------------------------------------------------------- # Schritt 5: Modus-spezifische Abfragen # ------------------------------------------------------- echo "[5/8] Konfiguration fuer Modus: $MODE" echo "" # Variablen fuer Zusammenfassung NETWORK_MODE="" WIFI_SSID="" HOTSPOT_METHOD="" if [ "$MODE" = "client" ]; then read -rp " Alias (Satellite-Name): " ALIAS read -rp " Raum-Kennung: " ROOM read -rp " Server-Host (IP-Adresse): " HOST echo "" read -rp " Eigenen Port verwenden? [j/n]: " CUSTOM_PORT if [ "$CUSTOM_PORT" = "j" ] || [ "$CUSTOM_PORT" = "J" ]; then read -rp " Port-Nummer: " PORT else PORT=2101 fi echo " Schreibe $CONFIG_FILE..." python3 -c " import json with open('$CONFIG_FILE', 'r') as f: cfg = json.load(f) cfg['server']['host'] = '$HOST' cfg['server']['port'] = $PORT cfg['identity']['room'] = '$ROOM' cfg['identity']['alias'] = '$ALIAS' with open('$CONFIG_FILE', 'w') as f: json.dump(cfg, f, indent=4, ensure_ascii=False) " echo " Konfiguration geschrieben." elif [ "$MODE" = "standalone" ]; then read -rp " Alias: " ALIAS read -rp " Raum-Kennung: " ROOM echo " Schreibe $CONFIG_FILE..." python3 -c " import json with open('$CONFIG_FILE', 'r') as f: cfg = json.load(f) cfg['room'] = '$ROOM' cfg['alias'] = '$ALIAS' with open('$CONFIG_FILE', 'w') as f: json.dump(cfg, f, indent=4, ensure_ascii=False) " echo " Konfiguration geschrieben." elif [ "$MODE" = "server" ]; then echo " Netzwerk-Konfiguration:" echo " [1] Normales Netzwerk - Server laeuft im bestehenden LAN" echo " [2] WiFi-Hotspot - Geraet eroeffnet eigenes WLAN" echo "" while true; do read -rp " Auswahl [1/2]: " NET_CHOICE case "$NET_CHOICE" in 1) NETWORK_MODE="LAN"; break ;; 2) NETWORK_MODE="Hotspot"; break ;; *) echo " Ungueltige Auswahl." ;; esac done BIND_ADDRESS="0.0.0.0" if [ "$NETWORK_MODE" = "Hotspot" ]; then echo "" read -rp " WiFi-Name (SSID): " WIFI_SSID while true; do read -rsp " WiFi-Passwort (min. 8 Zeichen): " WIFI_PASS echo "" if [ ${#WIFI_PASS} -ge 8 ]; then break else echo " Passwort zu kurz! Mindestens 8 Zeichen." fi done echo "" echo " Hotspot-Methode:" echo " [1] NetworkManager (nmcli) - Einfach, fuer Desktop-Systeme" echo " [2] hostapd + dnsmasq - Robust, fuer Headless/Raspberry Pi" echo "" while true; do read -rp " Auswahl [1/2]: " HOTSPOT_CHOICE case "$HOTSPOT_CHOICE" in 1) HOTSPOT_METHOD="nmcli"; break ;; 2) HOTSPOT_METHOD="hostapd"; break ;; *) echo " Ungueltige Auswahl." ;; esac done BIND_ADDRESS="10.42.0.1" # WLAN-Interface ermitteln WLAN_IF=$(iw dev 2>/dev/null | awk '/Interface/{print $2}' | head -n1) if [ -z "$WLAN_IF" ]; then WLAN_IF="wlan0" echo " Hinweis: Kein WLAN-Interface erkannt, verwende '$WLAN_IF'." else echo " WLAN-Interface: $WLAN_IF" fi if [ "$HOTSPOT_METHOD" = "nmcli" ]; then echo " Richte Hotspot via NetworkManager ein..." # Bestehende Trixy-Verbindung entfernen falls vorhanden nmcli connection delete trixy-hotspot 2>/dev/null || true nmcli connection add type wifi \ ifname "$WLAN_IF" \ con-name trixy-hotspot \ autoconnect yes \ ssid "$WIFI_SSID" \ -- \ wifi.mode ap \ wifi-sec.key-mgmt wpa-psk \ wifi-sec.psk "$WIFI_PASS" \ ipv4.method shared \ ipv4.addresses "10.42.0.1/24" echo " NetworkManager-Hotspot 'trixy-hotspot' erstellt." elif [ "$HOTSPOT_METHOD" = "hostapd" ]; then echo " Richte Hotspot via hostapd + dnsmasq ein..." # hostapd-Konfiguration sudo tee /etc/hostapd/hostapd.conf > /dev/null < /dev/null </dev/null || true sudo ip addr add 10.42.0.1/24 dev "$WLAN_IF" sudo ip link set "$WLAN_IF" up # Services aktivieren sudo systemctl unmask hostapd 2>/dev/null || true sudo systemctl enable hostapd dnsmasq sudo systemctl restart hostapd dnsmasq echo " hostapd + dnsmasq konfiguriert und aktiviert." fi fi echo " Schreibe $CONFIG_FILE..." python3 -c " import json with open('$CONFIG_FILE', 'r') as f: cfg = json.load(f) cfg['network']['bind_address'] = '$BIND_ADDRESS' with open('$CONFIG_FILE', 'w') as f: json.dump(cfg, f, indent=4, ensure_ascii=False) " echo " Konfiguration geschrieben." fi echo "" # ------------------------------------------------------- # Schritt 6: Autostart / Service einrichten # ------------------------------------------------------- echo "[6/8] Startmethode waehlen" echo "" echo " Wie soll Trixy gestartet werden?" echo " [1] Autostart - Startet beim Login des Benutzers (Desktop-Systeme)" echo " [2] System-Service - Startet beim Systemstart als Dienst (Server/Headless)" echo "" START_METHOD="" while true; do read -rp " Auswahl [1/2]: " START_CHOICE case "$START_CHOICE" in 1) START_METHOD="Autostart"; break ;; 2) START_METHOD="Systemd-Service"; break ;; *) echo " Ungueltige Auswahl." ;; esac done if [ "$START_METHOD" = "Autostart" ]; then AUTOSTART_DIR="$HOME/.config/autostart" mkdir -p "$AUTOSTART_DIR" cat > "$AUTOSTART_DIR/trixy.desktop" < /dev/null </dev/null || true chmod +x "$PROJECT_DIR/run_linux.sh" 2>/dev/null || true chmod +x "$PROJECT_DIR"/bash/*.sh 2>/dev/null || true echo " Fertig." echo ""