2026-02-04 14:29:54 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
#
|
|
|
|
|
# Utility to manage the userland program called RaspScreen by Systemec B.V.
|
|
|
|
|
#
|
|
|
|
|
# Where it should live: /opt/raspscreen/bin/manage.sh
|
|
|
|
|
#
|
|
|
|
|
# Examples:
|
|
|
|
|
# ./manage.sh (restart|stop|start) (presentation|video)
|
2026-02-09 13:39:32 +00:00
|
|
|
#
|
|
|
|
|
# systemctl must be reachable from the path of the executing user.
|
|
|
|
|
|
|
|
|
|
app_name="raspscreen"
|
2026-02-04 14:29:54 +01:00
|
|
|
|
|
|
|
|
runtime_id=$(id -u)
|
|
|
|
|
if [[ "$runtime_id" -eq 0 ]]; then
|
|
|
|
|
echo "Do not run as root. Run as the graphical user."
|
2026-02-09 13:39:32 +00:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
printf "Checking input..."
|
|
|
|
|
|
|
|
|
|
# Action performed
|
|
|
|
|
case "$1" in
|
|
|
|
|
restart|stop|start|switch-state)
|
|
|
|
|
printf "Valid command...";;
|
|
|
|
|
*)
|
|
|
|
|
echo "Invalid command!"
|
|
|
|
|
exit 1;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
# Type to select
|
|
|
|
|
case "$2" in
|
|
|
|
|
presentation|video)
|
|
|
|
|
echo "Valid service...";;
|
|
|
|
|
*)
|
|
|
|
|
echo "Invalid service!"
|
|
|
|
|
exit 1;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
# Foreground or operator mode
|
|
|
|
|
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
|
|
|
|
|
echo "Finding and moving media..."
|
2026-02-09 17:00:01 +01:00
|
|
|
media_file=$(find /opt/raspscreen/media \
|
|
|
|
|
-path /opt/raspscreen/media/current -prune -o \
|
|
|
|
|
-type f \( -iname "*.pptx" -o -iname "*.odp" \) \
|
|
|
|
|
-printf '%T@ %p\n' | sort -n | tail -1 | cut -d' ' -f2-)
|
|
|
|
|
|
|
|
|
|
media_file_ext="${media_file##*.}"
|
2026-02-09 13:39:32 +00:00
|
|
|
echo "New media file: $media_file"
|
|
|
|
|
|
2026-02-12 16:49:52 +01:00
|
|
|
old_file=$(find /opt/raspscreen/media/current -type f \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.mov" -o -iname "*.webm" -o -iname "*.pptx" -o -iname "*.odp" \))
|
2026-02-09 13:39:32 +00:00
|
|
|
echo "Old file: $old_file"
|
2026-02-09 17:00:01 +01:00
|
|
|
|
2026-02-09 13:39:32 +00:00
|
|
|
echo "Copying new media into staging area..."
|
|
|
|
|
cp "$media_file" /opt/raspscreen/media/current
|
2026-02-09 17:00:01 +01:00
|
|
|
|
|
|
|
|
current_media=$(find /opt/raspscreen/media/current -name "*.$media_file_ext")
|
2026-02-09 13:39:32 +00:00
|
|
|
echo "Prepared media: $current_media"
|
|
|
|
|
|
|
|
|
|
if [[ -z "$current_media" ]]; then
|
|
|
|
|
echo "No compatible media file found. Wrong mode?"
|
|
|
|
|
echo "Exiting in 20 seconds..."
|
|
|
|
|
sleep 20s
|
|
|
|
|
exit 1
|
|
|
|
|
else
|
2026-02-09 15:41:56 +01:00
|
|
|
echo "Starting LibreOffice Present..."
|
2026-02-09 13:39:32 +00:00
|
|
|
/usr/bin/libreoffice --impress --show --norestore "$current_media"
|
|
|
|
|
fi
|
|
|
|
|
elif [[ "$2" == "video" ]]; then
|
2026-02-09 17:00:01 +01:00
|
|
|
echo "Finding media..."
|
|
|
|
|
media_file=$(find /opt/raspscreen/media \
|
|
|
|
|
-path /opt/raspscreen/media/current -prune -o \
|
|
|
|
|
-type f \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.mov" -o -iname "*.webm" \) \
|
|
|
|
|
-printf '%T@ %p\n' | sort -n | tail -1 | cut -d' ' -f2-)
|
|
|
|
|
|
|
|
|
|
media_file_ext="${media_file##*.}"
|
2026-02-09 13:39:32 +00:00
|
|
|
echo "New media file: $media_file"
|
|
|
|
|
|
2026-02-12 16:49:52 +01:00
|
|
|
old_file=$(find /opt/raspscreen/media/current -type f \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.mov" -o -iname "*.webm" -o -iname "*.pptx" -o -iname "*.odp" \))
|
2026-02-09 13:39:32 +00:00
|
|
|
echo "Old file: $old_file"
|
2026-02-09 17:00:01 +01:00
|
|
|
|
2026-02-09 13:39:32 +00:00
|
|
|
echo "Copying new media into staging area..."
|
|
|
|
|
cp "$media_file" /opt/raspscreen/media/current
|
2026-02-09 17:00:01 +01:00
|
|
|
|
|
|
|
|
current_media=$(find /opt/raspscreen/media/current -name "*.$media_file_ext")
|
2026-02-09 13:39:32 +00:00
|
|
|
echo "Prepared media: $current_media"
|
|
|
|
|
|
|
|
|
|
if [[ -z "$current_media" ]]; then
|
|
|
|
|
echo "No compatible media file found. Wrong mode?"
|
|
|
|
|
echo "Exiting in 20 seconds..."
|
|
|
|
|
sleep 20s
|
|
|
|
|
exit 1
|
|
|
|
|
else
|
2026-02-09 15:41:56 +01:00
|
|
|
echo "Starting VLC..."
|
2026-02-09 13:39:32 +00:00
|
|
|
/usr/bin/vlc --fullscreen --loop --no-video-title --video-on-top --no-qt-fs-controller --qt-continue=0 "$current_media"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
echo "Process exited..."
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "Running in task mode...";;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
echo "Executing task..."
|
|
|
|
|
if [[ "$1" != "switch-state" ]]; then
|
|
|
|
|
cmd_result=$(systemctl --user "$1" "$2" 2>&1)
|
|
|
|
|
cmd_exit=$?
|
|
|
|
|
elif [[ "$1" == "switch-state" ]]; then
|
|
|
|
|
last_state=$(cat /opt/raspscreen/currentstate.txt)
|
|
|
|
|
|
|
|
|
|
if [[ "$2" == "video" ]]; then
|
|
|
|
|
alt_serv="presentation"
|
|
|
|
|
elif [[ "$2" == "presentation" ]]; then
|
|
|
|
|
alt_serv="video"
|
|
|
|
|
fi
|
|
|
|
|
echo "alt_serv: $alt_serv"
|
|
|
|
|
|
|
|
|
|
if [ "$last_state" != "$2" ] || [ -z "$last_state" ]; then
|
|
|
|
|
systemctl --user disable "$alt_serv"
|
|
|
|
|
systemctl --user enable "$2"
|
|
|
|
|
fi
|
|
|
|
|
systemctl --user restart "$2"
|
|
|
|
|
|
|
|
|
|
echo "$2" > /opt/raspscreen/currentstate.txt
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ "$cmd_exit" -eq 0 ]]; then
|
|
|
|
|
echo "Succesfully exited!"
|
|
|
|
|
else
|
|
|
|
|
echo "Something went wrong, see..."
|
|
|
|
|
echo " -> $cmd_result"
|
|
|
|
|
fi
|
2026-02-12 16:49:52 +01:00
|
|
|
exit 0
|