new file: DocForWiki.md -> Expanded Dokumentation
modified: README.md -> Added Warning about change of video Files deleted: setup-gpt.sh -> Changed to setup.sh new file: setup-old.sh -> Original setup.sh moved to old as Backup modified: setup.sh -> see setup-gpt.sh
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
# Überblick
|
||||||
|
Diese Codebase wured 08/09 2024 von Tim Schilling entwickelt um ein alltes gerät im Lechfeldmuseum der Stadt Königsbrunn zu ersetzten. Das Script ist für die Verwendung auf einen Raspberry Pi gedacht.
|
||||||
|
Dieses Script verwendet für das Spielen von Videos VLC bzw die Commandline variante '''cvlc''', das Scipt weches für das Automatische Abspeielen der Videos sowie der wechsel zwischen den zwei Videos ist in Pyhton geschrieben.
|
||||||
|
|
||||||
|
## Abhängigkeiten
|
||||||
|
- vlc -> Video Lan Client, anwendung zum Abspielen von Videos
|
||||||
|
- python3-rpi.gpio -> Python Bibliothek welche für die Verwendung der GPIO gebraucht wird.
|
||||||
|
|
||||||
|
## Skripte
|
||||||
|
Zusätzlich wurden für die Leichte Installation des Systems sowie für die Kontrolle im betrieb einige Shellskipts angelegt welche folgende Aufgaben haben:
|
||||||
|
|
||||||
|
- setup.sh -> Setup Script welches mehrere aufgaben erfüllt, dies führt (in Reienfolge der Ausführtung)
|
||||||
|
1. Fragt den Nutzer ob für diesen der Autostart dienst Verwendet werden soll.
|
||||||
|
2. Fragt den Nutzer ob die GPIO Shutdown funktion des Raspberry Pi verwendet werden soll.
|
||||||
|
3. Führt ein Systemupdate über den APT aus
|
||||||
|
4. Installiert die Abhängigkeiten
|
||||||
|
5. Herunterladen der Aktuellen Scripte aus dem GitHub Repo
|
||||||
|
6. Herunterladen der Videos aus dem GitHub Repo (**ACHTUNG: Wenn sich die Datein im Repo Geänder haben müssen die Datein im Skript entsprechend Angepasst werden.**)
|
||||||
|
7. Festlegen von SystemD dienst Datein Inhalt
|
||||||
|
8. Erstellen der System D Service Datein und Einschalten dieser je nach vorheriger Nutzerauswahl
|
||||||
|
9. Einfügen der zeile in /boot/config.txt für GPIO Shutdown
|
||||||
|
|
||||||
|
- video.py -> Script welches die Videos Abspielt
|
||||||
|
- start.sh -> Skript zum starten der Wiedergabe, schaltet gleichzeitig den Autostart der Anwendung über einen SystemD dienst **EIN**
|
||||||
|
- stop.sh -> Skript zum stoppen der Wiedergabe, schaltet gleichzeitig den Autostart der Anwendung über einen SystemD dienst **AUS**
|
||||||
|
- reload.sh -> Skript zum Neustarten der Wiedergabe, stop diese über System D und startet diese wieder
|
||||||
|
|
||||||
|
## Dateistrucktur
|
||||||
|
```
|
||||||
|
- PiVideo/
|
||||||
|
|- videos/
|
||||||
|
| |- loop.mp4
|
||||||
|
| |- trigger.mp4
|
||||||
|
|- video.py
|
||||||
|
|- start.sh
|
||||||
|
|- stop.sh
|
||||||
|
|- reload.sh
|
||||||
|
```
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
- Remove old files when reinstalling
|
- Remove old files when reinstalling
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
This is a collection of scripts which run a video in a loop until a Button connected to GPIO is Pressed.
|
This is a collection of scripts which run a video in a loop until a Button connected to GPIO is Pressed.
|
||||||
Then another video is played once.
|
Then another video is played once.
|
||||||
|
|
||||||
@@ -13,6 +12,8 @@ Then another video is played once.
|
|||||||
For installation download and run setup.sh. This will install the nesecary dependencys, create the needed folder structure and download the Script.
|
For installation download and run setup.sh. This will install the nesecary dependencys, create the needed folder structure and download the Script.
|
||||||
It will also create a SystemD service to automaticly start the program when the Pi is booted.
|
It will also create a SystemD service to automaticly start the program when the Pi is booted.
|
||||||
|
|
||||||
|
**CAUTION: IF THE VIDEO FILES IN THE REPO HAVE CHANGED PLEASE CHECK THE SCRIPT IF THEY ARE CORRECT!**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
wget -L "https://raw.githubusercontent.com/miT-nib-hcI/PiVideo/main/setup.sh" &&
|
wget -L "https://raw.githubusercontent.com/miT-nib-hcI/PiVideo/main/setup.sh" &&
|
||||||
chmod 755 setup.sh &&
|
chmod 755 setup.sh &&
|
||||||
|
|||||||
-156
@@ -1,156 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Define colors for text output
|
|
||||||
GREEN='\033[0;32m'
|
|
||||||
CYAN_BACK='\x1b[46m'
|
|
||||||
RED='\033[0;31m'
|
|
||||||
NOCOLOR='\033[0m'
|
|
||||||
|
|
||||||
# Function for error handling
|
|
||||||
function check_error {
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo -e "${RED}Error: $1${NOCOLOR}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if the script is being run as root
|
|
||||||
if [ "$(id -u)" -ne 0 ]; then
|
|
||||||
echo -e "${RED}This script must be run as root (e.g., with sudo).${NOCOLOR}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -e "${GREEN}======== Starting Installation =========${NOCOLOR}"
|
|
||||||
|
|
||||||
# Prompt the user to add a systemd service for autostart
|
|
||||||
read -p "Do you want to add a systemd service for autostart? [y|n] " INPUT
|
|
||||||
SYSD=1
|
|
||||||
|
|
||||||
# Decide whether to set up systemd based on user input
|
|
||||||
case $INPUT in
|
|
||||||
y|Y) SYSD=0 ;;
|
|
||||||
n|N) SYSD=1 ;;
|
|
||||||
*) echo "Systemd service will not be added...." ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Prompt the user to add GPIO power control
|
|
||||||
read -p "Do you want to add GPIO power control? [y|n] " INPUT
|
|
||||||
GPPower=1
|
|
||||||
|
|
||||||
# Decide whether to set up GPIO power control based on user input
|
|
||||||
case $INPUT in
|
|
||||||
y|Y) GPPower=0 ;;
|
|
||||||
n|N) GPPower=1 ;;
|
|
||||||
*) echo "GPIO power control will not be added.........." ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Variables for paths and files
|
|
||||||
CURRENT_USER=$(logname) # Get the username of the person who invoked the script
|
|
||||||
SERVICE_NAME="pivideo.service"
|
|
||||||
PYTHON_SCRIPT="/home/$CURRENT_USER/PiVideo/video.py"
|
|
||||||
GH_URL="https://raw.githubusercontent.com/miT-nib-hcI/PiVideo/main/"
|
|
||||||
|
|
||||||
# Update and install dependencies
|
|
||||||
echo -e "${GREEN}======== Performing system update =========${NOCOLOR}"
|
|
||||||
sudo apt update && sudo apt upgrade -y
|
|
||||||
check_error "Failed to update packages."
|
|
||||||
|
|
||||||
echo -e "${GREEN}======== Installing dependencies =========${NOCOLOR}"
|
|
||||||
sudo apt install -y vlc python3-rpi.gpio git
|
|
||||||
check_error "Failed to install dependencies."
|
|
||||||
|
|
||||||
# Create directories and download files
|
|
||||||
echo -e "${GREEN}======== Downloading files ========${NOCOLOR}"
|
|
||||||
|
|
||||||
# Ensure directories exist and change to the correct directory
|
|
||||||
mkdir -p ~/PiVideo/videos/
|
|
||||||
cd ~/PiVideo/
|
|
||||||
|
|
||||||
# Function to download a file and check for errors
|
|
||||||
function download_file {
|
|
||||||
local file=$1
|
|
||||||
wget -q -O "$file" "$GH_URL$file"
|
|
||||||
check_error "Failed to download $file"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Download necessary scripts
|
|
||||||
download_file "video.py"
|
|
||||||
download_file "start.sh"
|
|
||||||
download_file "stop.sh"
|
|
||||||
download_file "reload.sh"
|
|
||||||
|
|
||||||
# Make the scripts executable
|
|
||||||
chmod 755 *.sh
|
|
||||||
|
|
||||||
echo -e "${GREEN}======== Downloading videos ========${NOCOLOR}"
|
|
||||||
|
|
||||||
cd videos/
|
|
||||||
|
|
||||||
# Download video files
|
|
||||||
download_file "videos/loop.mp4"
|
|
||||||
download_file "videos/trigger.webm"
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
# Create the systemd service for autologin and video control
|
|
||||||
echo -e "${GREEN}======== Creating systemd service ========${NOCOLOR}"
|
|
||||||
|
|
||||||
# Autologin service content
|
|
||||||
AUTOLOGIN_SERVICE_CONTENT="[Service]
|
|
||||||
ExecStart=
|
|
||||||
ExecStart=-/sbin/agetty --autologin $CURRENT_USER --noclear tty1 linux
|
|
||||||
"
|
|
||||||
|
|
||||||
# Video control service content
|
|
||||||
SERVICE_CONTENT="[Unit]
|
|
||||||
Description=Video Control Script
|
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
ExecStart=/usr/bin/python3 $PYTHON_SCRIPT
|
|
||||||
WorkingDirectory=$(dirname $PYTHON_SCRIPT)
|
|
||||||
StandardOutput=inherit
|
|
||||||
StandardError=inherit
|
|
||||||
Restart=always
|
|
||||||
User=$CURRENT_USER
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
"
|
|
||||||
|
|
||||||
# If the user opted for autostart, create the service files
|
|
||||||
if [ $SYSD -eq 0 ]; then
|
|
||||||
echo "$AUTOLOGIN_SERVICE_CONTENT" | sudo tee /etc/systemd/system/getty@tty1.service.d/override.conf > /dev/null
|
|
||||||
check_error "Failed to create autologin service."
|
|
||||||
|
|
||||||
echo "$SERVICE_CONTENT" | sudo tee /etc/systemd/system/$SERVICE_NAME > /dev/null
|
|
||||||
check_error "Failed to create PiVideo service."
|
|
||||||
|
|
||||||
# Reload systemd and enable the service
|
|
||||||
echo -e "${GREEN}======== Reloading services ========${NOCOLOR}"
|
|
||||||
sudo systemctl daemon-reload
|
|
||||||
check_error "Failed to reload systemd services."
|
|
||||||
|
|
||||||
echo -e "${GREEN}======== Enabling the service ========${NOCOLOR}"
|
|
||||||
sudo systemctl enable $SERVICE_NAME
|
|
||||||
check_error "Failed to enable PiVideo service."
|
|
||||||
|
|
||||||
echo -e "${GREEN}======== Starting the service ========${NOCOLOR}"
|
|
||||||
sudo systemctl start $SERVICE_NAME
|
|
||||||
check_error "Failed to start PiVideo service."
|
|
||||||
else
|
|
||||||
echo -e "${CYAN_BACK}Automatic start of playback disabled${NOCOLOR}"
|
|
||||||
echo -e "${CYAN_BACK}Did not start service, to start use \"sudo systemctl start $SERVICE_NAME\"${NOCOLOR}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Configure GPIO power control if the user opted in
|
|
||||||
if [ $GPPower -eq 0 ]; then
|
|
||||||
echo "dtoverlay=gpio-shutdown,gpio-pin=3" | sudo tee -a /boot/config.txt > /dev/null
|
|
||||||
check_error "Failed to configure GPIO power control."
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -e "${GREEN}=========================================================${NOCOLOR}"
|
|
||||||
echo -e "${GREEN}======== The script was executed successfully ========${NOCOLOR}"
|
|
||||||
echo -e "${GREEN}=========================================================${NOCOLOR}"
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
+170
@@ -0,0 +1,170 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
# Definition of colors for text output
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
CYAN_BACK='\x1b[46m'
|
||||||
|
|
||||||
|
NOCOLOR='\033[0m'
|
||||||
|
|
||||||
|
echo -e "${GREEN}======== Starte Installation =========${NOCOLOR}"
|
||||||
|
|
||||||
|
read -p "Do you want to add a SystemD Service for Autostart [y|n]" INPUT
|
||||||
|
SYSD=1
|
||||||
|
|
||||||
|
case $INPUT in
|
||||||
|
y|Y) SYSD=0 ;;
|
||||||
|
n|N) SYSD=1 ;;
|
||||||
|
*) echo "SystemD Service will not be Added...." ;;
|
||||||
|
esac
|
||||||
|
INPUT=""
|
||||||
|
|
||||||
|
read -p "Do you want to add GPIO Power Controle [y|n]" INPUT
|
||||||
|
GPPower=1
|
||||||
|
|
||||||
|
case $INPUT in
|
||||||
|
y|Y) GPPower=0 ;;
|
||||||
|
n|N) GPPower=1 ;;
|
||||||
|
*) echo "GPIO Power controll will not be Addaded.........." ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
CURRENT_USER=$(whoami)
|
||||||
|
SERVICE_NAME="pivideo.service"
|
||||||
|
AUTOLOGIN_SERVICE_NAME="autologin@tty1.service"
|
||||||
|
|
||||||
|
PYTHON_SCRIPT="/home/$CURRENT_USER/PiVideo/video.py"
|
||||||
|
|
||||||
|
|
||||||
|
echo -e "${GREEN}======== Führe Update durch =========${NOCOLOR}"
|
||||||
|
|
||||||
|
sudo apt update && sudo apt upgrade -y
|
||||||
|
|
||||||
|
echo -e "${GREEN}======== Installiere Abhängigkeiten =========${NOCOLOR}"
|
||||||
|
sudo apt install vlc python3-rpi.gpio git -y
|
||||||
|
|
||||||
|
|
||||||
|
echo -e "${GREEN}======== Holle Datein ========${NOCOLOR}"
|
||||||
|
|
||||||
|
if ls ~/PiVideo/ 1> /dev/null 2>&1; # Checking if file exsists
|
||||||
|
then
|
||||||
|
echo "Folders Already Exist Scipping"
|
||||||
|
else
|
||||||
|
echo "Creating Folders"
|
||||||
|
mkdir ~/PiVideo/ ~/PiVideo/videos/
|
||||||
|
cd ~/PiVideo/
|
||||||
|
fi
|
||||||
|
|
||||||
|
GH_URL="https://raw.githubusercontent.com/miT-nib-hcI/PiVideo/main/"
|
||||||
|
|
||||||
|
if ls ~/PiVideo/video.py 1> /dev/null 2>&1; # Checking if file exsists
|
||||||
|
then
|
||||||
|
echo "Script exists, updateing ..."
|
||||||
|
rm ~/PiVideo/video.py # Removing Old File
|
||||||
|
|
||||||
|
wget -L $GH_URL"video.py"
|
||||||
|
|
||||||
|
rm ~/PiVideo/*.sh # Removing Old Files
|
||||||
|
wget -L $GH_URL"start.sh"
|
||||||
|
wget -L $GH_URL"stop.sh"
|
||||||
|
wget -L $GH_URL"reload.sh"
|
||||||
|
else
|
||||||
|
wget -L $GH_URL"video.py"
|
||||||
|
wget -L $GH_URL"start.sh"
|
||||||
|
wget -L $GH_URL"stop.sh"
|
||||||
|
wget -L $GH_URL"reload.sh"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
chmod 755 *.sh
|
||||||
|
|
||||||
|
echo -e "${GREEN}======== Holle Videos========${NOCOLOR}"
|
||||||
|
|
||||||
|
cd videos/
|
||||||
|
|
||||||
|
if ls ~/PiVideo/videos/loop* 1> /dev/null 2>&1; # Checking if file exsists
|
||||||
|
then
|
||||||
|
echo "Video exists, updateing ..."
|
||||||
|
rm ~/PiVideo/videos/loop* # Removing Old Files
|
||||||
|
|
||||||
|
wget -L $GH_URL"videos/loop.mp4"
|
||||||
|
else
|
||||||
|
wget -L $GH_URL"videos/loop.mp4"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if ls ~/PiVideo/videos/trigger* 1> /dev/null 2>&1; # Checking if file exsists
|
||||||
|
then
|
||||||
|
echo "Video exists, updateing ..."
|
||||||
|
rm ~/PiVideo/videos/trigger* # Removing Old Files
|
||||||
|
|
||||||
|
wget -L $GH_URL"videos/trigger.webm"
|
||||||
|
else
|
||||||
|
wget -L $GH_URL"videos/trigger.webm"
|
||||||
|
fi
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
echo -e "${GREEN}======== Erestele Systemd Service ========${NOCOLOR}"
|
||||||
|
|
||||||
|
AUTOLOGIN_SERVICE_CONTENT="[Service]
|
||||||
|
ExecStart=
|
||||||
|
ExecStart=-/sbin/agetty --autologin $CURRENT_USER --noclear tty1 linux
|
||||||
|
"
|
||||||
|
|
||||||
|
# Erstelle die Autologin-Service-Datei
|
||||||
|
echo "Erstelle die Autologin-Service-Datei unter /etc/systemd/system/getty@tty1.service.d/override.conf..."
|
||||||
|
sudo mkdir -p /etc/systemd/system/getty@tty1.service.d/
|
||||||
|
|
||||||
|
SERVICE_CONTENT="[Unit]
|
||||||
|
Description=Video Control Script
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/bin/python3 $PYTHON_SCRIPT
|
||||||
|
WorkingDirectory=$(dirname $PYTHON_SCRIPT)
|
||||||
|
StandardOutput=inherit
|
||||||
|
StandardError=inherit
|
||||||
|
Restart=always
|
||||||
|
User=$CURRENT_USER
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
"
|
||||||
|
|
||||||
|
|
||||||
|
echo "$AUTOLOGIN_SERVICE_CONTENT" | sudo tee /etc/systemd/system/getty@tty1.service.d/override.conf > /dev/null
|
||||||
|
|
||||||
|
# Erstelle der PiVideo Service-Datei
|
||||||
|
echo "$SERVICE_CONTENT" | sudo tee /etc/systemd/system/$SERVICE_NAME > /dev/null
|
||||||
|
|
||||||
|
# Lade die Systemd-Dienste neu
|
||||||
|
echo -e "${GREEN}======== Lade Dienste neu ========${NOCOLOR}"
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
|
||||||
|
if [ $SYSD -eq 0 ]
|
||||||
|
then
|
||||||
|
# Aktiviere den Service, damit er beim Booten gestartet wird
|
||||||
|
echo -e "${GREEN}======== Aktiviern des Dienstes ========${NOCOLOR}"
|
||||||
|
|
||||||
|
echo "Aktivire den PiVideo-Service..."
|
||||||
|
sudo systemctl enable $SERVICE_NAME
|
||||||
|
|
||||||
|
# Starten des Services
|
||||||
|
echo -e "${GREEN}======== Starente des Dienstes ========${NOCOLOR}"
|
||||||
|
sudo systemctl start $SERVICE_NAME
|
||||||
|
else
|
||||||
|
echo -e "${CYAN_BACK} Automatic start of Playback disabled ${NOCOLOR}"
|
||||||
|
echo -e "${CYAN_BACK} Did not start Service, to start use \"sudo systemctl start pivideo.service\" ${NOCOLOR}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $GPPower -eq 0 ]
|
||||||
|
then
|
||||||
|
echo "dtoverlay=gpio-shutdown,gpio-pin=3" | sudo tee /boot/config.txt > /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${GREEN}=========================================================${NOCOLOR}"
|
||||||
|
echo -e "${GREEN}======== Das Script wurde Erfolgreich Ausgeführt ========${NOCOLOR}"
|
||||||
|
echo -e "${GREEN}=========================================================${NOCOLOR}"
|
||||||
|
|
||||||
|
exit 0
|
||||||
@@ -1,121 +1,113 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Definition of colors for text output
|
# Define colors for text output
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
CYAN_BACK='\x1b[46m'
|
CYAN_BACK='\x1b[46m'
|
||||||
|
RED='\033[0;31m'
|
||||||
NOCOLOR='\033[0m'
|
NOCOLOR='\033[0m'
|
||||||
|
|
||||||
echo -e "${GREEN}======== Starte Installation =========${NOCOLOR}"
|
# Function for error handling
|
||||||
|
function check_error {
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "${RED}Error: $1${NOCOLOR}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
read -p "Do you want to add a SystemD Service for Autostart [y|n]" INPUT
|
|
||||||
|
# Check if the script is being run as root
|
||||||
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
|
echo -e "${RED}This script must be run as root (e.g., with sudo).${NOCOLOR}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${GREEN}======== Starting Installation =========${NOCOLOR}"
|
||||||
|
|
||||||
|
# Prompt the user to add a systemd service for autostart
|
||||||
|
read -p "Do you want to add a systemd service for autostart? [y|n] " INPUT
|
||||||
SYSD=1
|
SYSD=1
|
||||||
|
|
||||||
|
# Decide whether to set up systemd based on user input
|
||||||
case $INPUT in
|
case $INPUT in
|
||||||
y|Y) SYSD=0 ;;
|
y|Y) SYSD=0 ;;
|
||||||
n|N) SYSD=1 ;;
|
n|N) SYSD=1 ;;
|
||||||
*) echo "SystemD Service will not be Added...." ;;
|
*) echo "Systemd service will not be added...." ;;
|
||||||
esac
|
esac
|
||||||
INPUT=""
|
|
||||||
|
|
||||||
read -p "Do you want to add GPIO Power Controle [y|n]" INPUT
|
# Prompt the user to add GPIO power control
|
||||||
|
read -p "Do you want to add GPIO power control? [y|n] " INPUT
|
||||||
GPPower=1
|
GPPower=1
|
||||||
|
|
||||||
|
# Decide whether to set up GPIO power control based on user input
|
||||||
case $INPUT in
|
case $INPUT in
|
||||||
y|Y) GPPower=0 ;;
|
y|Y) GPPower=0 ;;
|
||||||
n|N) GPPower=1 ;;
|
n|N) GPPower=1 ;;
|
||||||
*) echo "GPIO Power controll will not be Addaded.........." ;;
|
*) echo "GPIO power control will not be added.........." ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# Variables for paths and files
|
||||||
CURRENT_USER=$(whoami)
|
CURRENT_USER=$(logname) # Get the username of the person who invoked the script
|
||||||
SERVICE_NAME="pivideo.service"
|
SERVICE_NAME="pivideo.service"
|
||||||
AUTOLOGIN_SERVICE_NAME="autologin@tty1.service"
|
|
||||||
|
|
||||||
PYTHON_SCRIPT="/home/$CURRENT_USER/PiVideo/video.py"
|
PYTHON_SCRIPT="/home/$CURRENT_USER/PiVideo/video.py"
|
||||||
|
|
||||||
|
|
||||||
echo -e "${GREEN}======== Führe Update durch =========${NOCOLOR}"
|
|
||||||
|
|
||||||
sudo apt update && sudo apt upgrade -y
|
|
||||||
|
|
||||||
echo -e "${GREEN}======== Installiere Abhängigkeiten =========${NOCOLOR}"
|
|
||||||
sudo apt install vlc python3-rpi.gpio git -y
|
|
||||||
|
|
||||||
|
|
||||||
echo -e "${GREEN}======== Holle Datein ========${NOCOLOR}"
|
|
||||||
|
|
||||||
if ls ~/PiVideo/ 1> /dev/null 2>&1; # Checking if file exsists
|
|
||||||
then
|
|
||||||
echo "Folders Already Exist Scipping"
|
|
||||||
else
|
|
||||||
echo "Creating Folders"
|
|
||||||
mkdir ~/PiVideo/ ~/PiVideo/videos/
|
|
||||||
cd ~/PiVideo/
|
|
||||||
fi
|
|
||||||
|
|
||||||
GH_URL="https://raw.githubusercontent.com/miT-nib-hcI/PiVideo/main/"
|
GH_URL="https://raw.githubusercontent.com/miT-nib-hcI/PiVideo/main/"
|
||||||
|
|
||||||
if ls ~/PiVideo/video.py 1> /dev/null 2>&1; # Checking if file exsists
|
|
||||||
then
|
|
||||||
echo "Script exists, updateing ..."
|
|
||||||
rm ~/PiVideo/video.py # Removing Old File
|
|
||||||
|
|
||||||
wget -L $GH_URL"video.py"
|
# Update and install dependencies
|
||||||
|
echo -e "${GREEN}======== Performing system update =========${NOCOLOR}"
|
||||||
rm ~/PiVideo/*.sh # Removing Old Files
|
sudo apt update && sudo apt upgrade -y
|
||||||
wget -L $GH_URL"start.sh"
|
check_error "Failed to update packages."
|
||||||
wget -L $GH_URL"stop.sh"
|
|
||||||
wget -L $GH_URL"reload.sh"
|
|
||||||
else
|
|
||||||
wget -L $GH_URL"video.py"
|
|
||||||
wget -L $GH_URL"start.sh"
|
|
||||||
wget -L $GH_URL"stop.sh"
|
|
||||||
wget -L $GH_URL"reload.sh"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
echo -e "${GREEN}======== Installing dependencies =========${NOCOLOR}"
|
||||||
|
sudo apt install -y vlc python3-rpi.gpio git
|
||||||
|
check_error "Failed to install dependencies."
|
||||||
|
|
||||||
|
|
||||||
|
# Create directories and download files
|
||||||
|
echo -e "${GREEN}======== Downloading files ========${NOCOLOR}"
|
||||||
|
|
||||||
|
|
||||||
|
# Ensure directories exist and change to the correct directory
|
||||||
|
mkdir -p /home/$CURRENT_USER/PiVideo/videos/
|
||||||
|
cd /home/$CURRENT_USER/PiVideo/
|
||||||
|
|
||||||
|
|
||||||
|
# Function to download a file and check for errors
|
||||||
|
function download_file {
|
||||||
|
local file=$1
|
||||||
|
wget -q "$GH_URL$file"
|
||||||
|
check_error "Failed to download $file"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Download necessary scripts
|
||||||
|
download_file "video.py"
|
||||||
|
download_file "start.sh"
|
||||||
|
download_file "stop.sh"
|
||||||
|
download_file "reload.sh"
|
||||||
|
|
||||||
|
# Make the scripts executable
|
||||||
chmod 755 *.sh
|
chmod 755 *.sh
|
||||||
|
|
||||||
echo -e "${GREEN}======== Holle Videos========${NOCOLOR}"
|
echo -e "${GREEN}======== Downloading videos ========${NOCOLOR}"
|
||||||
|
|
||||||
cd videos/
|
cd videos/
|
||||||
|
|
||||||
if ls ~/PiVideo/videos/loop* 1> /dev/null 2>&1; # Checking if file exsists
|
# Download video files
|
||||||
then
|
download_file "videos/loop.mp4"
|
||||||
echo "Video exists, updateing ..."
|
download_file "videos/trigger.webm"
|
||||||
rm ~/PiVideo/videos/loop* # Removing Old Files
|
|
||||||
|
|
||||||
wget -L $GH_URL"videos/loop.mp4"
|
|
||||||
else
|
|
||||||
wget -L $GH_URL"videos/loop.mp4"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ls ~/PiVideo/videos/trigger* 1> /dev/null 2>&1; # Checking if file exsists
|
|
||||||
then
|
|
||||||
echo "Video exists, updateing ..."
|
|
||||||
rm ~/PiVideo/videos/trigger* # Removing Old Files
|
|
||||||
|
|
||||||
wget -L $GH_URL"videos/trigger.webm"
|
|
||||||
else
|
|
||||||
wget -L $GH_URL"videos/trigger.webm"
|
|
||||||
fi
|
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
echo -e "${GREEN}======== Erestele Systemd Service ========${NOCOLOR}"
|
# Create the systemd service for autologin and video control
|
||||||
|
echo -e "${GREEN}======== Creating systemd service ========${NOCOLOR}"
|
||||||
|
|
||||||
|
# Autologin service content
|
||||||
AUTOLOGIN_SERVICE_CONTENT="[Service]
|
AUTOLOGIN_SERVICE_CONTENT="[Service]
|
||||||
ExecStart=
|
ExecStart=
|
||||||
ExecStart=-/sbin/agetty --autologin $CURRENT_USER --noclear tty1 linux
|
ExecStart=-/sbin/agetty --autologin $CURRENT_USER --noclear tty1 linux
|
||||||
"
|
"
|
||||||
|
|
||||||
# Erstelle die Autologin-Service-Datei
|
# Video control service content
|
||||||
echo "Erstelle die Autologin-Service-Datei unter /etc/systemd/system/getty@tty1.service.d/override.conf..."
|
|
||||||
sudo mkdir -p /etc/systemd/system/getty@tty1.service.d/
|
|
||||||
|
|
||||||
SERVICE_CONTENT="[Unit]
|
SERVICE_CONTENT="[Unit]
|
||||||
Description=Video Control Script
|
Description=Video Control Script
|
||||||
After=network.target
|
After=network.target
|
||||||
@@ -132,39 +124,49 @@ User=$CURRENT_USER
|
|||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
"
|
"
|
||||||
|
|
||||||
|
# If the user opted for autostart, create the service files
|
||||||
|
if [ $SYSD -eq 0 ]; then
|
||||||
|
# Creating Service file for Autologin of the Current User
|
||||||
echo "$AUTOLOGIN_SERVICE_CONTENT" | sudo tee /etc/systemd/system/getty@tty1.service.d/override.conf > /dev/null
|
echo "$AUTOLOGIN_SERVICE_CONTENT" | sudo tee /etc/systemd/system/getty@tty1.service.d/override.conf > /dev/null
|
||||||
|
check_error "Failed to create autologin service."
|
||||||
|
|
||||||
# Erstelle der PiVideo Service-Datei
|
# Craating Service file for Video Playback
|
||||||
echo "$SERVICE_CONTENT" | sudo tee /etc/systemd/system/$SERVICE_NAME > /dev/null
|
echo "$SERVICE_CONTENT" | sudo tee /etc/systemd/system/$SERVICE_NAME > /dev/null
|
||||||
|
check_error "Failed to create PiVideo service."
|
||||||
|
|
||||||
# Lade die Systemd-Dienste neu
|
# Reload systemd and enable the service
|
||||||
echo -e "${GREEN}======== Lade Dienste neu ========${NOCOLOR}"
|
echo -e "${GREEN}======== Reloading services ========${NOCOLOR}"
|
||||||
sudo systemctl daemon-reload
|
sudo systemctl daemon-reload
|
||||||
|
check_error "Failed to reload systemd services."
|
||||||
|
|
||||||
if [ $SYSD -eq 0 ]
|
echo -e "${GREEN}======== Enabling the service ========${NOCOLOR}"
|
||||||
then
|
|
||||||
# Aktiviere den Service, damit er beim Booten gestartet wird
|
|
||||||
echo -e "${GREEN}======== Aktiviern des Dienstes ========${NOCOLOR}"
|
|
||||||
|
|
||||||
echo "Aktivire den PiVideo-Service..."
|
|
||||||
sudo systemctl enable $SERVICE_NAME
|
sudo systemctl enable $SERVICE_NAME
|
||||||
|
check_error "Failed to enable PiVideo service."
|
||||||
|
|
||||||
# Starten des Services
|
echo -e "${GREEN}======== Starting the service ========${NOCOLOR}"
|
||||||
echo -e "${GREEN}======== Starente des Dienstes ========${NOCOLOR}"
|
|
||||||
sudo systemctl start $SERVICE_NAME
|
sudo systemctl start $SERVICE_NAME
|
||||||
|
check_error "Failed to start PiVideo service."
|
||||||
else
|
else
|
||||||
echo -e "${CYAN_BACK} Automatic start of Playback disabled ${NOCOLOR}"
|
# Creating Service file for Autologin of the Current User
|
||||||
echo -e "${CYAN_BACK} Did not start Service, to start use \"sudo systemctl start pivideo.service\" ${NOCOLOR}"
|
echo "$AUTOLOGIN_SERVICE_CONTENT" | sudo tee /etc/systemd/system/getty@tty1.service.d/override.conf > /dev/null
|
||||||
|
check_error "Failed to create autologin service."
|
||||||
|
|
||||||
|
# Creating Service file for Video Playback
|
||||||
|
echo "$SERVICE_CONTENT" | sudo tee /etc/systemd/system/$SERVICE_NAME > /dev/null
|
||||||
|
check_error "Failed to create PiVideo service."
|
||||||
|
|
||||||
|
echo -e "${CYAN_BACK}Automatic start of playback disabled${NOCOLOR}"
|
||||||
|
echo -e "${CYAN_BACK}Did not start service, to start use \"sudo systemctl start $SERVICE_NAME\"${NOCOLOR}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $GPPower -eq 0 ]
|
# Configure GPIO power control if the user opted in
|
||||||
then
|
if [ $GPPower -eq 0 ]; then
|
||||||
echo "dtoverlay=gpio-shutdown,gpio-pin=3" | sudo tee /boot/config.txt > /dev/null
|
echo "dtoverlay=gpio-shutdown,gpio-pin=3" | sudo tee -a /boot/config.txt > /dev/null
|
||||||
|
check_error "Failed to configure GPIO power control."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${GREEN}=========================================================${NOCOLOR}"
|
echo -e "${GREEN}=========================================================${NOCOLOR}"
|
||||||
echo -e "${GREEN}======== Das Script wurde Erfolgreich Ausgeführt ========${NOCOLOR}"
|
echo -e "${GREEN}======== The script was executed successfully ========${NOCOLOR}"
|
||||||
echo -e "${GREEN}=========================================================${NOCOLOR}"
|
echo -e "${GREEN}=========================================================${NOCOLOR}"
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
Reference in New Issue
Block a user