optimizied installer.sh
This commit is contained in:
parent
4f8b859c36
commit
584fa3331e
2 changed files with 73 additions and 23 deletions
84
install.sh
84
install.sh
|
|
@ -1,27 +1,89 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Projektpfad und venv-Verzeichnis definieren
|
||||||
|
PROJECT_PATH="/home/pi/pi-race-timer"
|
||||||
|
VENV_PATH="$PROJECT_PATH/venv"
|
||||||
|
SERVICE_NAME="pi-race-timer.service"
|
||||||
|
INSTALLER_PATH="/home/pi/install.sh"
|
||||||
|
|
||||||
|
# Funktion für das Skript-Neustarten
|
||||||
|
restart_installer() {
|
||||||
|
echo "🔄 Installer wurde geändert, Neustart erfolgt..."
|
||||||
|
exec $SHELL "$INSTALLER_PATH"
|
||||||
|
}
|
||||||
|
|
||||||
echo "📦 Projekt wird installiert..."
|
echo "📦 Projekt wird installiert..."
|
||||||
|
|
||||||
# System aktualisieren
|
# Prüfen, ob das Projektverzeichnis existiert
|
||||||
sudo apt update && sudo apt upgrade -y
|
if [ -d "$PROJECT_PATH" ]; then
|
||||||
sudo apt install python3-venv git -y
|
echo "Projektverzeichnis gefunden. Führe Git Pull aus..."
|
||||||
|
|
||||||
|
# Projekt aktualisieren
|
||||||
|
cd $PROJECT_PATH
|
||||||
|
git pull origin main
|
||||||
|
|
||||||
# Projekt klonen
|
# Prüfen, ob das Installations-Skript selbst geändert wurde
|
||||||
git clone https://git.geigernet.eu/rainer/pi-race-timer.git /home/pi/pi-race-timer
|
if [ "$(git log -1 --pretty=%H -- $INSTALLER_PATH)" != "$(cat $INSTALLER_PATH.sha)" ]; then
|
||||||
cd /home/pi/pi-race-timer
|
# Installer wurde geändert, daher neu starten
|
||||||
|
echo "Installationsskript wurde geändert."
|
||||||
|
git log -1 --pretty=%H -- $INSTALLER_PATH > $INSTALLER_PATH.sha
|
||||||
|
restart_installer
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Virtuelle Umgebung löschen
|
||||||
|
if [ -d "$VENV_PATH" ]; then
|
||||||
|
echo "Lösche vorhandene virtuelle Umgebung..."
|
||||||
|
rm -rf $VENV_PATH
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Systemd-Dienst entfernen
|
||||||
|
echo "Entferne alten systemd-Dienst..."
|
||||||
|
sudo systemctl stop $SERVICE_NAME
|
||||||
|
sudo systemctl disable $SERVICE_NAME
|
||||||
|
sudo rm /etc/systemd/system/$SERVICE_NAME
|
||||||
|
else
|
||||||
|
# Projekt klonen, wenn es nicht existiert
|
||||||
|
echo "Projektverzeichnis nicht gefunden. Klone das Projekt..."
|
||||||
|
git clone https://git.geigernet.eu/rainer/pi-race-timer.git $PROJECT_PATH
|
||||||
|
cd $PROJECT_PATH
|
||||||
|
git log -1 --pretty=%H -- $INSTALLER_PATH > $INSTALLER_PATH.sha
|
||||||
|
fi
|
||||||
|
|
||||||
# Virtuelle Umgebung einrichten
|
# Virtuelle Umgebung einrichten
|
||||||
python3 -m venv venv
|
echo "Erstelle virtuelle Umgebung..."
|
||||||
source venv/bin/activate
|
python3 -m venv $VENV_PATH
|
||||||
|
source $VENV_PATH/bin/activate
|
||||||
|
|
||||||
# Python-Abhängigkeiten installieren
|
# Python-Abhängigkeiten installieren
|
||||||
|
echo "Installiere Python-Abhängigkeiten..."
|
||||||
pip install -U pip
|
pip install -U pip
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
# Erstelle die systemd-Service-Datei
|
||||||
|
echo "Erstelle systemd-Service-Datei..."
|
||||||
|
echo "[Unit]
|
||||||
|
Description=Pi Race Timer
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=pi
|
||||||
|
WorkingDirectory=$PROJECT_PATH
|
||||||
|
ExecStart=$VENV_PATH/bin/python $PROJECT_PATH/app.py
|
||||||
|
Environment=\"PATH=$VENV_PATH/bin:$PATH\"
|
||||||
|
Environment=\"VIRTUAL_ENV=$VENV_PATH\"
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
StandardOutput=journal
|
||||||
|
StandardError=journal
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/$SERVICE_NAME > /dev/null
|
||||||
|
|
||||||
# systemd-Dienst einrichten
|
# systemd-Dienst einrichten
|
||||||
sudo cp pi-race-timer.service /etc/systemd/system/
|
echo "Richte systemd-Dienst ein..."
|
||||||
sudo systemctl daemon-reexec
|
sudo systemctl daemon-reexec
|
||||||
sudo systemctl enable pi-race-timer
|
sudo systemctl enable $SERVICE_NAME
|
||||||
sudo systemctl start pi-race-timer
|
sudo systemctl start $SERVICE_NAME
|
||||||
|
|
||||||
echo "✅ Installation abgeschlossen. Webinterface erreichbar unter: http://<raspberry-ip>:5000"
|
echo "✅ Installation abgeschlossen. Webinterface erreichbar unter: http://<raspberry-ip>:5000"
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=Race Timer Webserver
|
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
ExecStart=/home/pi/pi-race-timer/venv/bin/python3 /home/pi/pi-race-timer/main.py
|
|
||||||
WorkingDirectory=/home/pi/pi-race-timer
|
|
||||||
Restart=always
|
|
||||||
User=pi
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
Reference in a new issue