2025-04-21 14:33:11 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
INI_FILE="/boot/kioskbrowser.ini"
|
2025-06-04 12:59:05 +01:00
|
|
|
|
|
|
|
remount_root() {
|
|
|
|
local mode=$1
|
|
|
|
echo "Remounting root filesystem as $mode..."
|
|
|
|
mount -o remount,"$mode" / || {
|
|
|
|
echo "Failed to remount root as $mode"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-21 14:33:11 +00:00
|
|
|
REBOOT_ENABLED=$(awk -F '=' '/^\[reboot\]/ { in_reboot=1; next }
|
|
|
|
in_reboot && /^\[/ { in_reboot=0 }
|
|
|
|
in_reboot && $1 ~ /enabled/ { gsub(/ /, "", $2); print $2 }' "$INI_FILE")
|
|
|
|
|
|
|
|
REBOOT_TIME=$(awk -F '=' '/^\[reboot\]/ { in_reboot=1; next }
|
|
|
|
in_reboot && /^\[/ { in_reboot=0 }
|
|
|
|
in_reboot && $1 ~ /reboot_time/ { gsub(/ /, "", $2); print $2 }' "$INI_FILE")
|
|
|
|
|
|
|
|
if [[ "$REBOOT_ENABLED" -eq 1 ]] && [[ "$REBOOT_TIME" =~ ^[0-2][0-9]:[0-5][0-9]$ ]]; then
|
|
|
|
echo "Scheduling reboot for $REBOOT_TIME..."
|
|
|
|
|
2025-06-04 12:59:05 +01:00
|
|
|
remount_root rw
|
|
|
|
|
2025-04-21 14:33:11 +00:00
|
|
|
TARGET_TIME=$(date -d "$REBOOT_TIME" +%s)
|
|
|
|
NOW=$(date +%s)
|
|
|
|
|
|
|
|
if [ "$TARGET_TIME" -le "$NOW" ]; then
|
|
|
|
TARGET_TIME=$(date -d "tomorrow $REBOOT_TIME" +%s)
|
|
|
|
fi
|
|
|
|
|
|
|
|
TARGET_ISO=$(date -d "@$TARGET_TIME" --iso-8601=seconds)
|
|
|
|
|
|
|
|
REBOOT_UNIT="/etc/systemd/system/reboot-at.timer"
|
|
|
|
cat <<EOF > "$REBOOT_UNIT"
|
|
|
|
[Unit]
|
|
|
|
Description=One-off reboot timer
|
|
|
|
|
|
|
|
[Timer]
|
|
|
|
OnCalendar=$TARGET_ISO
|
|
|
|
Persistent=false
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=timers.target
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat <<EOF > /etc/systemd/system/reboot-at.service
|
|
|
|
[Unit]
|
|
|
|
Description=Scheduled Reboot
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=oneshot
|
|
|
|
ExecStart=/sbin/reboot
|
|
|
|
EOF
|
|
|
|
|
|
|
|
systemctl daemon-reload
|
|
|
|
systemctl enable --now reboot-at.timer
|
2025-06-04 12:59:05 +01:00
|
|
|
|
|
|
|
remount_root ro
|
2025-04-21 14:33:11 +00:00
|
|
|
else
|
|
|
|
echo "Reboot not scheduled (disabled or invalid time)"
|
|
|
|
fi
|