diff --git a/install.sh b/install.sh index 82b43c6..0b47511 100755 --- a/install.sh +++ b/install.sh @@ -25,7 +25,7 @@ fi # THIS MUST BE THE SAME AR $REPO/service-files/presentation.service cat > /home/${userland_name}/.config/systemd/user/presentation.service << EOF [Unit] -Description="Systemec RaspScreen" +Description="Systemec RaspScreen Presentation" Conflicts=video.service After=graphical.target @@ -34,9 +34,10 @@ Type=simple Environment=DISPLAY=:0 WorkingDirectory=/opt/raspscreen ExecStartPre=/usr/bin/sleep 5 -ExecStart=/bin/sh -c 'exec /usr/bin/libreoffice --impress --show --norestore $(find /opt/raspscreen/media \( -name "*.pptx" -o -name "*.odp" \))' -ExecStop=/usr/bin/killall libreoffice +ExecStart=/opt/raspscreen/bin/manage.sh start presentation --foreground +ExecStop=/opt/raspscreen/bin/manage kill video Restart=always +Restart=on-failure RestartSec=2 [Install] @@ -46,7 +47,7 @@ EOF # THIS MUST BE THE SAME AR $REPO/service-files/video.service cat > /home/${userland_name}/.config/systemd/user/video.service << EOF [Unit] -Description="Systemec RaspScreen" +Description="Systemec RaspScreen Video" Conflicts=presentation.service After=graphical.target @@ -55,9 +56,10 @@ Type=simple Environment=DISPLAY=:0 WorkingDirectory=/opt/raspscreen ExecStartPre=/usr/bin/sleep 5 -ExecStart=/bin/sh -c 'exec /usr/bin/vlc --fullscreen --loop --no-video-title --video-on-top --no-qt-fs-controller --qt-continue=0 $(find /opt/raspscreen/media \( -name "*.mp4" -o -name "*.mkv" -o -name "*.mov" -o -name "*.webm" \))' -ExecStop=/usr/bin/killall vlc +ExecStart=/opt/raspscreen/bin/manage.sh start video --foreground +ExecStop=/opt/raspscreen/bin/manage kill video Restart=always +Restart=on-failure RestartSec=2 [Install] diff --git a/manage.sh b/manage.sh index 8a229a8..672c129 100755 --- a/manage.sh +++ b/manage.sh @@ -9,6 +9,14 @@ # # systemctl must be reachable from the path of the executing user. +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." @@ -17,7 +25,7 @@ fi printf "Checking input..." case "$1" in - restart|stop|start) + restart|stop|start|kill) printf "Valid command...";; *) echo "Invalid command!" @@ -32,14 +40,46 @@ 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) if [[ "$2" == "presentation" ]]; then - /bin/sh -c 'exec /usr/bin/libreoffice --impress --show --norestore $(find /opt/raspscreen/media \( -name "*.pptx" -o -name "*.odp" \))' + media_file=$(find /opt/raspscreen/media \( -name "*.pptx" -o -name "*.odp" \)) + + if [[ -z "$media_file" ]]; then + echo "No compatible media file found. Wrong mode?" + echo "Exiting in 20 seconds..." + sleep 20s + exit 1 + else + /usr/bin/libreoffice --impress --show --norestore "$media_file" + fi fi if [[ "$2" == "video" ]]; then - /bin/sh -c 'exec /usr/bin/libreoffice --impress --show --norestore $(find /opt/raspscreen/media \( -name "*.pptx" -o -name "*.odp" \))' + media_file=$(find /opt/raspscreen/media \( -name "*.mp4" -o -name "*.mkv" -o -name "*.mov" -o -name "*.webm" \)) + + if [[ -z "$media_file" ]]; then + echo "No compatible media file found. Wrong mode?" + echo "Exiting in 20 seconds..." + sleep 20s + exit 1 + else + /usr/bin/vlc --fullscreen --loop --no-video-title --video-on-top --no-qt-fs-controller --qt-continue=0 "$media_file" + fi fi + echo "Process exited..." + exit 0 + ;; *) echo "Running in task mode...";; esac diff --git a/service-files/presentation.service b/service-files/presentation.service index 3e1b0bb..c9173f6 100644 --- a/service-files/presentation.service +++ b/service-files/presentation.service @@ -1,5 +1,5 @@ [Unit] -Description="Systemec RaspScreen" +Description="Systemec RaspScreen Presentation" Conflicts=video.service After=graphical.target @@ -8,9 +8,10 @@ Type=simple Environment=DISPLAY=:0 WorkingDirectory=/opt/raspscreen ExecStartPre=/usr/bin/sleep 5 -ExecStart=/bin/sh -c 'exec /usr/bin/libreoffice --impress --show --norestore $(find /opt/raspscreen/media \( -name "*.pptx" -o -name "*.odp" \))' -ExecStop=/usr/bin/killall libreoffice +ExecStart=/opt/raspscreen/bin/manage.sh start presentation --foreground +ExecStop=/opt/raspscreen/bin/manage kill video Restart=always +Restart=on-failure RestartSec=2 [Install] diff --git a/service-files/video.service b/service-files/video.service index cb3591f..2071750 100644 --- a/service-files/video.service +++ b/service-files/video.service @@ -1,5 +1,5 @@ [Unit] -Description="Systemec RaspScreen" +Description="Systemec RaspScreen Video" Conflicts=presentation.service After=graphical.target @@ -8,9 +8,10 @@ Type=simple Environment=DISPLAY=:0 WorkingDirectory=/opt/raspscreen ExecStartPre=/usr/bin/sleep 5 -ExecStart=/bin/sh -c 'exec /usr/bin/vlc --fullscreen --loop --no-video-title --video-on-top --no-qt-fs-controller --qt-continue=0 $(find /opt/raspscreen/media \( -name "*.mp4" -o -name "*.mkv" -o -name "*.mov" -o -name "*.webm" \))' -ExecStop=/usr/bin/killall vlc +ExecStart=/opt/raspscreen/bin/manage.sh start video --foreground +ExecStop=/opt/raspscreen/bin/manage kill video Restart=always +Restart=on-failure RestartSec=2 [Install]