Files
PiCopy/install.sh
Tobias Leuschner a15d27ce14 Release v1.0 – PiCopy vollständig dokumentiert und bereit zur Veröffentlichung
- README.md mit vollständiger Anleitung, Features, Tabellen und Schnellstart
- install.sh neu geschrieben: sauberer Installer mit Farbausgabe, apt-Check,
  Download-Fallback und abschließender Statusmeldung mit URL
- LICENSE (MIT) hinzugefügt
- .gitignore: config.json, state.json, rclone.conf, logs/ und deploy.sh excluded
- deploy.sh entfernt (enthielt Zugangsdaten)
- requirements.txt aktualisiert

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 01:58:47 +02:00

112 lines
5.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# ============================================================
# PiCopy Installer
# https://github.com/YOUR_USERNAME/picopy
#
# Usage:
# sudo bash install.sh
# or one-line:
# curl -sSL https://raw.githubusercontent.com/YOUR_USERNAME/picopy/main/install.sh | sudo bash
# ============================================================
set -euo pipefail
INSTALL_DIR="/opt/picopy"
SERVICE_NAME="picopy"
PORT=8080
REPO_RAW="https://raw.githubusercontent.com/YOUR_USERNAME/picopy/main"
# ── Farben ───────────────────────────────────────────────────────────────────
R='\033[0;31m'; G='\033[0;32m'; Y='\033[1;33m'; B='\033[0;34m'; N='\033[0m'
info() { echo -e "${B}[PiCopy]${N} $1"; }
ok() { echo -e "${G}[ OK ]${N} $1"; }
warn() { echo -e "${Y}[ WARN ]${N} $1"; }
fail() { echo -e "${R}[ FAIL ]${N} $1"; exit 1; }
# ── Voraussetzungen ───────────────────────────────────────────────────────────
[ "$EUID" -eq 0 ] || fail "Bitte als root ausführen: sudo bash install.sh"
command -v apt-get &>/dev/null || fail "apt-get nicht gefunden (nur Debian/Raspberry Pi OS unterstützt)"
echo ""
echo -e "${B}╔══════════════════════════════════════════╗${N}"
echo -e "${B}║ PiCopy Installation ║${N}"
echo -e "${B}╚══════════════════════════════════════════╝${N}"
echo ""
# ── System-Pakete ─────────────────────────────────────────────────────────────
info "Systemabhängigkeiten werden installiert..."
apt-get update -q
apt-get install -y -q python3 python3-venv python3-pip util-linux rclone
ok "Systemabhängigkeiten installiert"
# ── Verzeichnis anlegen ───────────────────────────────────────────────────────
info "Installationsverzeichnis: $INSTALL_DIR"
mkdir -p "$INSTALL_DIR/logs"
# ── App-Datei kopieren oder herunterladen ─────────────────────────────────────
if [ -f "./app.py" ]; then
info "Lokale app.py wird verwendet..."
cp app.py "$INSTALL_DIR/app.py"
else
info "app.py wird heruntergeladen..."
curl -sSfL "$REPO_RAW/app.py" -o "$INSTALL_DIR/app.py" \
|| fail "Download fehlgeschlagen. Prüfe die Internet-Verbindung."
fi
ok "app.py installiert"
# ── Python-Umgebung ───────────────────────────────────────────────────────────
info "Python venv wird erstellt..."
python3 -m venv "$INSTALL_DIR/venv"
"$INSTALL_DIR/venv/bin/pip" install --quiet --upgrade pip
"$INSTALL_DIR/venv/bin/pip" install --quiet flask pyudev
ok "Python-Umgebung erstellt"
# ── Systemd-Service ───────────────────────────────────────────────────────────
info "Systemd-Service wird eingerichtet..."
if [ -f "./picopy.service" ]; then
cp picopy.service /etc/systemd/system/picopy.service
else
cat > /etc/systemd/system/picopy.service << 'EOF'
[Unit]
Description=PiCopy Automatischer USB-Kopierdienst
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/picopy
ExecStart=/opt/picopy/venv/bin/python /opt/picopy/app.py
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
EOF
fi
systemctl daemon-reload
systemctl enable "$SERVICE_NAME"
systemctl restart "$SERVICE_NAME"
# ── Ergebnis ─────────────────────────────────────────────────────────────────
sleep 3
if systemctl is-active --quiet "$SERVICE_NAME"; then
IP=$(hostname -I | awk '{print $1}')
echo ""
echo -e "${G}╔══════════════════════════════════════════╗${N}"
echo -e "${G}║ PiCopy ist bereit! ║${N}"
echo -e "${G}╚══════════════════════════════════════════╝${N}"
echo ""
echo -e " Web-Interface: ${B}http://$IP:$PORT${N}"
echo ""
echo " Nützliche Befehle:"
echo " sudo systemctl status $SERVICE_NAME # Status"
echo " journalctl -u $SERVICE_NAME -f # Live-Logs"
echo " sudo systemctl restart $SERVICE_NAME # Neustart"
echo ""
else
fail "PiCopy konnte nicht gestartet werden."$'\n'"Logs: journalctl -u $SERVICE_NAME -n 50"
fi