123 lines
5.6 KiB
Bash
123 lines
5.6 KiB
Bash
#!/usr/bin/env bash
|
||
# ============================================================
|
||
# PiCopy – Installer
|
||
# https://git.leuschner.dev/Tobias/PiCopy
|
||
#
|
||
# Usage:
|
||
# sudo bash install.sh
|
||
# or one-line:
|
||
# curl -sSL https://git.leuschner.dev/Tobias/PiCopy/raw/branch/main/install.sh | sudo bash
|
||
# ============================================================
|
||
set -euo pipefail
|
||
|
||
INSTALL_DIR="/opt/picopy"
|
||
SERVICE_NAME="picopy"
|
||
PORT=8080
|
||
REPO_RAW="https://git.leuschner.dev/Tobias/PiCopy/raw/branch/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"
|
||
|
||
# ── Versionsdatei kopieren oder herunterladen ────────────────────────────────
|
||
if [ -f "./version.txt" ]; then
|
||
info "Lokale version.txt wird verwendet..."
|
||
cp version.txt "$INSTALL_DIR/version.txt"
|
||
else
|
||
info "version.txt wird heruntergeladen..."
|
||
curl -sSfL "$REPO_RAW/version.txt" -o "$INSTALL_DIR/version.txt" \
|
||
|| fail "Download der version.txt fehlgeschlagen. Prüfe die Internet-Verbindung."
|
||
fi
|
||
ok "version.txt 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
|