From 66cc9dae97a16e90c31ff90bd430034040c90693 Mon Sep 17 00:00:00 2001 From: DaanSelen Date: Thu, 5 Feb 2026 16:22:18 +0100 Subject: [PATCH] feat: account for post-reboot --- install.sh | 16 +++++++--------- manage.sh | 30 ++++++++++-------------------- service-files/presentation.service | 6 ++---- service-files/video.service | 6 ++---- src/action.go | 12 ++++++------ 5 files changed, 27 insertions(+), 43 deletions(-) diff --git a/install.sh b/install.sh index 0b47511..624b6cb 100755 --- a/install.sh +++ b/install.sh @@ -9,7 +9,9 @@ if [[ "$runtime_id" -ne 0 ]]; then echo "Not running as root, please run as root." exit 1 fi -apt-get -y install libreoffice-impress psmisc ssh vlc +apt-get -y install \ + default-jre libreoffice-impress libreoffice-java-common psmisc ssh vlc + systemctl enable --now ssh # Create the systemd userland folder @@ -27,16 +29,14 @@ cat > /home/${userland_name}/.config/systemd/user/presentation.service << EOF [Unit] Description="Systemec RaspScreen Presentation" Conflicts=video.service -After=graphical.target +After=graphical-session.target [Service] Type=simple Environment=DISPLAY=:0 WorkingDirectory=/opt/raspscreen -ExecStartPre=/usr/bin/sleep 5 ExecStart=/opt/raspscreen/bin/manage.sh start presentation --foreground -ExecStop=/opt/raspscreen/bin/manage kill video -Restart=always +KillSignal=SIGKILL Restart=on-failure RestartSec=2 @@ -49,16 +49,14 @@ cat > /home/${userland_name}/.config/systemd/user/video.service << EOF [Unit] Description="Systemec RaspScreen Video" Conflicts=presentation.service -After=graphical.target +After=graphical-session.target [Service] Type=simple Environment=DISPLAY=:0 WorkingDirectory=/opt/raspscreen -ExecStartPre=/usr/bin/sleep 5 ExecStart=/opt/raspscreen/bin/manage.sh start video --foreground -ExecStop=/opt/raspscreen/bin/manage kill video -Restart=always +KillSignal=SIGKILL Restart=on-failure RestartSec=2 diff --git a/manage.sh b/manage.sh index 1fc9b83..28c7fe2 100755 --- a/manage.sh +++ b/manage.sh @@ -11,12 +11,6 @@ app_name="raspscreen" -# Fallback for display selection -if [[ -z $DISPLAY ]]; then - echo "Triggered exporting display variable fallback..." - export DISPLAY=:0 -fi - runtime_id=$(id -u) if [[ "$runtime_id" -eq 0 ]]; then echo "Do not run as root. Run as the graphical user." @@ -25,7 +19,7 @@ fi printf "Checking input..." case "$1" in - restart|stop|start|kill) + restart|stop|start) printf "Valid command...";; *) echo "Invalid command!" @@ -40,19 +34,16 @@ case "$2" in exit 1;; esac -if [[ "$1" == "kill" ]]; then - if [[ "$2" == "presentation" ]]; then - /usr/bin/killall libreoffice - exit $? - fi - if [[ "$2" == "video" ]]; then - /usr/bin/killall vlc - exit $? - fi -fi - case "$3" in --foreground) + echo "Gathering uptime data..." + sys_uptime=$(cat /proc/uptime | awk '{print int($1)}') + + if [[ "$sys_uptime" -lt 60 ]]; then + echo "Detected a recent restart - giving the operating system some time..." + sleep 10s + fi + if [[ "$2" == "presentation" ]]; then media_file=$(find /opt/raspscreen/media \( -name "*.pptx" -o -name "*.odp" \)) @@ -64,8 +55,7 @@ case "$3" in else /usr/bin/libreoffice --impress --show --norestore "$media_file" fi - fi - if [[ "$2" == "video" ]]; then + elif [[ "$2" == "video" ]]; then media_file=$(find /opt/raspscreen/media \( -name "*.mp4" -o -name "*.mkv" -o -name "*.mov" -o -name "*.webm" \)) if [[ -z "$media_file" ]]; then diff --git a/service-files/presentation.service b/service-files/presentation.service index 8f8d24b..e676bb6 100644 --- a/service-files/presentation.service +++ b/service-files/presentation.service @@ -1,16 +1,14 @@ [Unit] Description="Systemec RaspScreen Presentation" Conflicts=video.service -After=graphical.target +After=graphical-session.target [Service] Type=simple Environment=DISPLAY=:0 WorkingDirectory=/opt/raspscreen -ExecStartPre=/usr/bin/sleep 5 ExecStart=/opt/raspscreen/bin/manage.sh start presentation --foreground -ExecStop=/opt/raspscreen/bin/manage.sh kill presentation -Restart=always +KillSignal=SIGKILL Restart=on-failure RestartSec=2 diff --git a/service-files/video.service b/service-files/video.service index 5f37617..39eb977 100644 --- a/service-files/video.service +++ b/service-files/video.service @@ -1,16 +1,14 @@ [Unit] Description="Systemec RaspScreen Video" Conflicts=presentation.service -After=graphical.target +After=graphical-session.target [Service] Type=simple Environment=DISPLAY=:0 WorkingDirectory=/opt/raspscreen -ExecStartPre=/usr/bin/sleep 5 ExecStart=/opt/raspscreen/bin/manage.sh start video --foreground -ExecStop=/opt/raspscreen/bin/manage.sh kill video -Restart=always +KillSignal=SIGKILL Restart=on-failure RestartSec=2 diff --git a/src/action.go b/src/action.go index f00f9df..53e8424 100644 --- a/src/action.go +++ b/src/action.go @@ -141,14 +141,14 @@ func restartShow(targetName string, targetMode int, cfg RaspiConfig) bool { switch targetMode { case 1: log.Println("Configuring application workflow: Presentation") - _, err = runSSHCommand(sshClient, disableVideo) - _, err = runSSHCommand(sshClient, restartPresentation) - _, err = runSSHCommand(sshClient, enablePresentation) + _, err = runSSHCommand(sshClient, disableVideo) // Disable the conflicting service + _, err = runSSHCommand(sshClient, restartPresentation) // Restart the wanted service (which MUST be a restart because the media might have changed) + _, err = runSSHCommand(sshClient, enablePresentation) // Make sure the wanted service starts on reboot case 2: log.Println("Configuring application workflow: Video") - _, err = runSSHCommand(sshClient, disablePresentation) - _, err = runSSHCommand(sshClient, restartVideo) - _, err = runSSHCommand(sshClient, enableVideo) + _, err = runSSHCommand(sshClient, disablePresentation) // Disable the conflicting service + _, err = runSSHCommand(sshClient, restartVideo) // Restart the wanted service (which MUST be a restart because the media might have changed) + _, err = runSSHCommand(sshClient, enableVideo) // Make sure the wanted service starts on reboot } if err != nil {