feat: account for post-reboot
This commit is contained in:
16
install.sh
16
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
|
||||
|
||||
|
||||
30
manage.sh
30
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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user