16 Commits
v1.2 ... v1.3

8 changed files with 139 additions and 35 deletions

View File

@@ -3,13 +3,14 @@ Description=A Service to monitor the Kiosk's current site
After=network.target getty@tty1.service After=network.target getty@tty1.service
[Service] [Service]
ExecStartPre=-/bin/sleep 120 ExecStartPre=-/bin/sleep 10
Type=simple Type=simple
ExecStart=/usr/bin/chromium-monitor User=loginuser
ExecStart=/usr/bin/custom/chromium-monitor
Restart=on-failure Restart=on-failure
RestartSec=5s RestartSec=5s
StandardOutput=append:/var/log/chromium-monitor StandardOutput=append:/var/log/chromium-monitor.log
StandardError=append:/var/log/chromium-monitor StandardError=append:/var/log/chromium-monitor.log
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@@ -0,0 +1,11 @@
[Unit]
Description=Set Hostname from DHCP
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/bin/custom/hostname
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

View File

@@ -3,9 +3,10 @@ Description=Watchdog Monitor Service
After=network.target getty@tty1.service After=network.target getty@tty1.service
[Service] [Service]
ExecStartPre=-/bin/sleep 120 ExecStartPre=-/bin/sleep 10
Type=simple Type=simple
ExecStart=/usr/bin/watchdog User=loginuser
ExecStart=/usr/bin/watchdog/watchdog
Restart=on-failure Restart=on-failure
RestartSec=5s RestartSec=5s
StandardOutput=append:/var/log/watchdog StandardOutput=append:/var/log/watchdog

View File

@@ -45,6 +45,7 @@ sudo rsync -a --numeric-ids --info=progress2 --no-owner --no-group \
./rps-client/boot/ro-root.sh /boot/ro-root.sh \ ./rps-client/boot/ro-root.sh /boot/ro-root.sh \
./rps-client/boot/firmware/ro-root.sh /boot/firmware/ro-root.sh \ ./rps-client/boot/firmware/ro-root.sh /boot/firmware/ro-root.sh \
./rps-client/etc/dhcp/dhclient.conf /etc/dhcp/dhclient.conf \ ./rps-client/etc/dhcp/dhclient.conf /etc/dhcp/dhclient.conf \
./rps-client/etc/systemd/system/hostname.service /etc/systemd/system/hostname.service \
./rps-client/etc/systemd/system/watchdog.service /etc/systemd/system/watchdog.service \ ./rps-client/etc/systemd/system/watchdog.service /etc/systemd/system/watchdog.service \
./rps-client/etc/systemd/system/chromium-monitor.service /etc/systemd/system/chromium-monitor.service \ ./rps-client/etc/systemd/system/chromium-monitor.service /etc/systemd/system/chromium-monitor.service \
./rps-client/etc/systemd/system/getty@tty1.service.d/override.conf /etc/systemd/system/getty@tty1.service.d/override.conf \ ./rps-client/etc/systemd/system/getty@tty1.service.d/override.conf /etc/systemd/system/getty@tty1.service.d/override.conf \
@@ -54,18 +55,27 @@ sudo rsync -a --numeric-ids --info=progress2 --no-owner --no-group \
./rps-client/home/wis/.ssh/id_rsa.pub /home/wis/.ssh/id_rsa.pub \ ./rps-client/home/wis/.ssh/id_rsa.pub /home/wis/.ssh/id_rsa.pub \
./rps-client/root/remove_unused_kernel.sh /root/remove_unused_kernel.sh \ ./rps-client/root/remove_unused_kernel.sh /root/remove_unused_kernel.sh \
./rps-client/root/.vnc/config.d/vncserver-x11 /root/.vnc/config.d/vncserver-x11 \ ./rps-client/root/.vnc/config.d/vncserver-x11 /root/.vnc/config.d/vncserver-x11 \
./rps-client/usr/bin/chromium-monitor /usr/bin/chromium-monitor \ ./rps-client/usr/bin/custom/hostname /usr/bin/custom/hostname \
./rps-client/usr/bin/watchdog /usr/bin/watchdog >>/var/log/install 2>&1 && print_status "Required files copied" ./rps-client/usr/bin/custom/chromium-monitor /usr/bin/custom/chromium-monitor \
./rps-client/usr/bin/custom/watchdog /usr/bin/custom/watchdog >>/var/log/install 2>&1 && print_status "Required files copied"
echo -e "${RED}${NC} Setting file permissions..." echo -e "${RED}${NC} Setting file permissions..."
sudo chown loginuser:loginuser -R /home/loginuser >>/var/log/install 2>&1 && print_status "File permissions set" sudo chown loginuser:loginuser -R /home/loginuser >>/var/log/install 2>&1 && print_status "File permissions set"
echo -e "${RED}${NC} Creating log files..."
sudo touch /var/log/watchdog.log /var/log/chromium-monitor.log >>/var/log/install 2>&1 && print_status "Log files created"
echo -e "${RED}${NC} Setting ownership for log files..."
sudo chown loginuser:loginuser /var/log/watchdog.log /var/log/chromium-monitor.log >>/var/log/install 2>&1 && print_status "Ownership set for log files"
echo -e "${RED}${NC} Setting permissions for log files..."
sudo chmod 664 /var/log/watchdog.log /var/log/chromium-monitor.log >>/var/log/install 2>&1 && print_status "Permissions set for log files"
echo -e "${RED}${NC} Enabling services..." echo -e "${RED}${NC} Enabling services..."
sudo systemctl daemon-reload >>/var/log/install 2>&1 && print_status "Daemon reloaded" sudo systemctl daemon-reload >>/var/log/install 2>&1 && print_status "Daemon reloaded"
sudo systemctl enable watchdog chromium-monitor vncserver-x11-serviced.service >>/var/log/install 2>&1 && print_status "Services enabled" sudo systemctl enable hostname watchdog chromium-monitor vncserver-x11-serviced.service >>/var/log/install 2>&1 && print_status "Services enabled"
sudo systemctl restart getty@tty1 >>/var/log/install 2>&1 && print_status "getty service restarted" sudo systemctl restart getty@tty1 >>/var/log/install 2>&1 && print_status "getty service restarted"
# Ask user about cleaning unused kernels
echo -e "${RED}${NC} Do you want to clean up unused kernels? (yes/y/ye to proceed):" echo -e "${RED}${NC} Do you want to clean up unused kernels? (yes/y/ye to proceed):"
read -r clean_kernels read -r clean_kernels
if [[ "$clean_kernels" =~ ^[Yy](e[Ss]?)?$ ]]; then if [[ "$clean_kernels" =~ ^[Yy](e[Ss]?)?$ ]]; then

View File

@@ -1,36 +1,58 @@
#!/bin/bash #!/bin/bash
LOGFILE="/var/log/chromium-monitor.log"
get_monitor() { get_monitor() {
sudo cat /var/lib/dhcp/* | grep -a "option monitor" | tail -1 | \ 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 '{ s = ""; for (i = 3; i <= NF; i++) s = s $i " "; print s}' | \
awk -F '"' '{print $2}' awk -F '"' '{print $2}'
} }
get_current_window() { get_current_window() {
DISPLAY=:0 xdotool getwindowfocus getwindowname | awk -F '- Chromium' '{print $1}' DISPLAY=:0 xdotool getwindowfocus getwindowname | awk -F '- Chromium' '{print $1}'
} }
monitor="" monitor=""
while [ -z "$monitor" ]; do while [ -z "$monitor" ]; do
monitor=$(get_monitor) monitor=$(get_monitor)
echo "Current monitor: $monitor" >> $LOGFILE # Debug output
if [ -z "$monitor" ]; then if [ -z "$monitor" ]; then
sleep 5 sleep 5
fi fi
done done
monitor_md5=$(echo -n ${monitor^^} | sed -e 's/^[[:space:]]*//' | md5sum | awk '{print $1}') monitor_md5=$(echo -n ${monitor^^} | sed -e 's/^[[:space:]]*//' | md5sum | awk '{print $1}')
echo "Monitor MD5: $monitor_md5" >> $LOGFILE # Debug output
while true; do while true; do
new_monitor=$(get_monitor) new_monitor=$(get_monitor)
new_current=$(get_current_window) 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 if [ -n "$new_monitor" ] && [ -n "$new_current" ]; then
new_monitor_md5=$(echo -n ${new_monitor^^} | sed -e 's/^[[:space:]]*//' | md5sum | awk '{print $1}') 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}') 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 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 sudo reboot
exit 1 exit 1
fi fi
else 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 fi
# Log the status before sleeping
echo "Sleeping for 5 seconds before the next check..." >> $LOGFILE
sleep 5s sleep 5s
done done
# Version 1.0: # 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.

35
usr/bin/custom/hostname Normal file
View File

@@ -0,0 +1,35 @@
#!/bin/bash
LOGFILE="/var/log/hostname.log"
# Function to read the hostname from the DHCP lease file
get_hostname() {
sudo cat /var/lib/dhcp/* | grep -a "option host-name" | tail -1 | \
awk -F '"' '{print $2}'
}
# Function to update /etc/hosts with the new hostname
update_hosts() {
local hostname="$1"
# Replace the second line with the new hostname
sudo sed -i "2s/.*/127.0.1.1 ${hostname}/" /etc/hosts
echo "Updated /etc/hosts with hostname: $hostname" >> $LOGFILE
}
# Read the hostname from DHCP
hostname=$(get_hostname)
if [ -n "$hostname" ]; then
# Set the hostname using hostnamectl
sudo hostnamectl set-hostname "$hostname"
echo "Set hostname to: $hostname" >> $LOGFILE
update_hosts "$hostname"
else
echo "No hostname found." >> $LOGFILE
fi
# Log completion
echo "Hostname update script completed." >> $LOGFILE
# Version 1.0:
# Created 2024 by Tim Eertmoed, Christian Hampp @ WiS IT-Solutions GmbH, Germany to work on Raspian as custom pxe init script.

46
usr/bin/custom/watchdog Normal file
View File

@@ -0,0 +1,46 @@
#!/bin/bash
# Log file
log_file="/var/log/watchdog.log"
# Extract watchdog IP addresses
watchdog=$(sudo cat /var/lib/dhcp/* | grep -a "option watchdog" | tail -1 | \
awk '{for (i=3; i<=NF; i++) printf "%s ", $i}' | tr -d '";')
IFS=' ' read -r -a ip_array <<< "$watchdog"
# Configuration file
config_file="/etc/watchdog.conf"
# Backup current configuration
if sudo cp "$config_file" "$config_file.bak"; then
echo "Backup of $config_file created successfully." >> "$log_file"
else
echo "Failed to create backup of $config_file." >> "$log_file"
fi
# Clean existing configurations
sudo sed -i '/ping/d' "$config_file"
sudo sed -i '/^interval/d' "$config_file"
# Set interval
echo "interval = 60" | sudo tee -a "$config_file" > /dev/null
if [ ${#ip_array[@]} -eq 0 ]; then
echo "No IP addresses found. Watchdog configuration cleared." >> "$log_file"
sudo systemctl stop watchdog
else
for ip in "${ip_array[@]}"; do
echo "ping = $ip" | sudo tee -a "$config_file" > /dev/null
done
echo "Configured watchdog to ping: ${ip_array[*]}" >> "$log_file"
fi
# Restart watchdog service
if sudo systemctl restart watchdog; then
echo "Watchdog service restarted successfully." >> "$log_file"
else
echo "Failed to restart watchdog service." >> "$log_file"
fi
# Version 1.1:
# Created 2024 by Tim Eertmoed @ WiS IT-Solutions GmbH, Germany to work on Raspian as custom pxe init script.

View File

@@ -1,22 +0,0 @@
#!/bin/bash
watchdog=$(sudo cat /var/lib/dhcp/* | grep -a "option watchdog" | tail -1 | \
awk '{for (i=3; i<=NF; i++) printf "%s ", $i}' | tr -d '";')
IFS=' ' read -r -a ip_array <<< "$watchdog"
config_file="/etc/watchdog.conf"
sudo cp "$config_file" "$config_file.bak"
sudo sed -i '/ping/d' "$config_file"
sudo sed -i '/^interval/d' "$config_file"
echo "interval = 60" | sudo tee -a "$config_file" > /dev/null
if [ ${#ip_array[@]} -eq 0 ]; then
sudo sed -i '/interval/d' "$config_file"
echo "No IP addresses found. Watchdog configuration cleared." >> /var/log/watchdog 2>&1
sudo systemctl stop watchdog
else
for ip in "${ip_array[@]}"; do
echo "ping = $ip" | sudo tee -a "$config_file" > /dev/null
done
fi
sudo systemctl restart watchdog >> /var/log/watchdog 2>&1
# Version 1.1:
# Created 2024 by Tim Eertmoed @ WiS IT-Solutions GmbH, Germany to work on Raspian as custom pxe init script.