53 lines
1.7 KiB
Bash
53 lines
1.7 KiB
Bash
#!/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
|
|
|
|
# Filter the first word from the initial monitor
|
|
initial_monitor_first_word=$(echo "$monitor" | awk '{print $1}')
|
|
echo "Monitor (first word): $initial_monitor_first_word" >> $LOGFILE # Debug output
|
|
|
|
while true; do
|
|
new_monitor=$(get_monitor | awk '{print $1}')
|
|
new_current=$(get_current_window | awk '{print $1}')
|
|
|
|
# Log the current state
|
|
echo "New monitor (first word): '$new_monitor'" >> $LOGFILE # Debug output
|
|
echo "New current window (first word): '$new_current'" >> $LOGFILE # Debug output
|
|
|
|
if [ -n "$new_monitor" ] && [ -n "$new_current" ]; then
|
|
if [ "$new_monitor" != "$initial_monitor_first_word" ] || [ "$new_current" != "$initial_monitor_first_word" ]; then
|
|
echo "Mismatch detected. Rebooting now." >> $LOGFILE
|
|
sudo reboot
|
|
exit 1
|
|
fi
|
|
else
|
|
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.
|