47 lines
1.3 KiB
Bash
47 lines
1.3 KiB
Bash
#!/bin/bash
|
|
|
|
LOGFILE="/var/log/chromium-monitor.log"
|
|
|
|
# Function to get the monitor value from DHCP
|
|
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}'
|
|
}
|
|
|
|
# Function to get the current window name
|
|
get_current_window() {
|
|
DISPLAY=:0 xdotool getwindowfocus getwindowname | awk -F '- Chromium' '{print $1}'
|
|
}
|
|
|
|
# Initialize monitor variable
|
|
monitor=""
|
|
while [ -z "$monitor" ]; do
|
|
monitor=$(get_monitor)
|
|
if [ -n "$monitor" ]; then
|
|
echo "Initial monitor detected: $monitor" >> $LOGFILE # Log initial monitor
|
|
fi
|
|
sleep 5
|
|
done
|
|
|
|
# Main loop to continuously check the current window
|
|
while true; do
|
|
new_current=$(get_current_window | awk '{print $1}') # Get the first word of the current window
|
|
|
|
if [ -n "$new_current" ]; then
|
|
# Check for mismatch
|
|
if [ "$new_current" != "$monitor" ]; then
|
|
echo "Mismatch detected! Monitor: $monitor, Current: $new_current" >> $LOGFILE
|
|
echo "Rebooting now." >> $LOGFILE
|
|
sudo reboot
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Sleep for a short duration before the next check
|
|
sleep 5
|
|
done
|
|
|
|
# Version 1.0:
|
|
# Created 2024 by Tim Eertmoed, Christian Hampp @ WiS IT-Solutions GmbH, Germany to work on Raspbian as custom PXE init script.
|