stable #2

Merged
alientim merged 89 commits from stable into dev 2024-11-15 10:37:11 +01:00
Showing only changes of commit d96260222c - Show all commits

View File

@@ -1,36 +1,58 @@
#!/bin/bash
LOGFILE="/var/log/chromium-monitor.log"
get_monitor() {
sudo cat /var/lib/dhcp/* | grep -a "option monitor" | tail -1 | \
awk '{ s = ""; for (i = 3; i <= NF; i++) s = s $i " "; print s}' | \
awk -F '"' '{print $2}'
}
get_current_window() {
DISPLAY=:0 xdotool getwindowfocus getwindowname | awk -F '- Chromium' '{print $1}'
}
monitor=""
while [ -z "$monitor" ]; do
monitor=$(get_monitor)
echo "Current monitor: $monitor" >> $LOGFILE # Debug output
if [ -z "$monitor" ]; then
sleep 5
fi
done
monitor_md5=$(echo -n ${monitor^^} | sed -e 's/^[[:space:]]*//' | md5sum | awk '{print $1}')
echo "Monitor MD5: $monitor_md5" >> $LOGFILE # Debug output
while true; do
new_monitor=$(get_monitor)
new_current=$(get_current_window)
# Log the current state
echo "New monitor: $new_monitor" >> $LOGFILE # Debug output
echo "New current window: $new_current" >> $LOGFILE # Debug output
if [ -n "$new_monitor" ] && [ -n "$new_current" ]; then
new_monitor_md5=$(echo -n ${new_monitor^^} | sed -e 's/^[[:space:]]*//' | md5sum | awk '{print $1}')
current_md5=$(echo -n ${new_current^^} | sed -e 's/^[[:space:]]*//' | md5sum | awk '{print $1}')
# Log the computed MD5 hashes
echo "New monitor MD5: $new_monitor_md5" >> $LOGFILE # Debug output
echo "Current window MD5: $current_md5" >> $LOGFILE # Debug output
if [ "$new_monitor_md5" != "$monitor_md5" ] && [ "$current_md5" != "$monitor_md5" ]; then
echo "Mismatch detected. Rebooting now." >> /var/log/chromium-monitor
echo "Mismatch detected. Rebooting now." >> $LOGFILE
sudo reboot
exit 1
fi
else
echo "Either monitor or current is not available, skipping check." >> /var/log/chromium-monitor
echo "Either monitor or current is not available, skipping check." >> $LOGFILE
fi
# Log the status before sleeping
echo "Sleeping for 5 seconds before the next check..." >> $LOGFILE
sleep 5s
done
# Version 1.0:
# Created 2024 by Tim Eertmoed, Christian Hampp @ WiS IT-Solutions GmbH, Germany to work on Raspian as custom pxe init script.
# Created 2024 by Tim Eertmoed, Christian Hampp @ WiS IT-Solutions GmbH, Germany to work on Raspian as custom pxe init script.