Compare commits

..

9 Commits

Author SHA1 Message Date
5fdb39ea81
Merge pull request #3 from karl0ss/display-power-control
Display power control
2025-04-21 16:31:14 +01:00
7565fb2bdc Merge remote-tracking branch 'origin/main' into display-power-control 2025-04-21 15:29:06 +00:00
8dce7fb3fd support for turning on and off the screen at certain times 2025-04-21 15:26:59 +00:00
df89a6b54e
Merge pull request #2 from karl0ss/scheduled-reboot
logic to schedule reboot based on time in ini file
2025-04-21 16:04:00 +01:00
956ac7bf66 logic to schedule reboot based on time in ini file 2025-04-21 14:33:11 +00:00
ba0da7622c initial ini update for new keys 2025-04-21 14:13:31 +00:00
5046d5249c
Merge branch 'Manawyrm:main' into main 2025-04-21 12:58:53 +01:00
Manawyrm
1c702f90e4
Merge pull request #14 from karl0ss/add_screen_rotation
Add screen rotation
2025-04-11 15:16:05 +02:00
2fb4f35f6b
Update kioskbrowser.ini
update description in ini file
2025-04-11 14:10:57 +01:00
6 changed files with 149 additions and 1 deletions

View File

@ -2,13 +2,21 @@
[general]
hostname = "kioskpi"
[reboot]
; can be used to set an automatic reboot on a specific time (time in 24 horus format)
enabled=0
reboot_time = 04:00
[screen]
; can be used to force 1080p on 4k screens or workaround broken EDID communication
;force_resolution = "1920x1080"
; force a custom modelines (for specialty diplays like embedded monitors, car screens, etc.)
;custom_modeline = "40.141 1024 1032 1064 1104 600 604 612 618 +HSync -VSync"
; can be used for forcing screen rotation on raspberry pi boards (normal, left, right, inverted)
; set screen rotation to be used (normal, left, right, inverted)
;rotate_screen = "normal"
; configure screen to power on/off as specific time of day (time format in 24 hours)
;screen_off_time=23:00
;screen_on_time=07:00
[wifi]
; If you need more complex WiFi settings (like WPA2-Enterprise, hidden SSIDs, etc.)

View File

@ -78,6 +78,9 @@ systemctl enable ntpdate
systemctl enable lightdm
systemctl enable nginx
systemctl enable ssh
systemctl enable kiosk-sechedule-screen.service
systemctl enable schedule-reboot.service
# generate a version info/build info file
echo -n "Chromium version: " >> /version-info

View File

@ -0,0 +1,11 @@
# /etc/systemd/system/kiosk-sechedule-screen.service
[Unit]
Description=Schedule Screen On/Off Timers
After=multi-user.target
[Service]
Type=oneshot
ExecStart=/usr/bin/schedule-screen-timers
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,10 @@
[Unit]
Description=Schedule Reboot from kioskbrowser.ini
After=multi-user.target
[Service]
Type=oneshot
ExecStart=/usr/bin/schedule-reboot
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,51 @@
#!/bin/bash
INI_FILE="/boot/kioskbrowser.ini"
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..."
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
# Create the associated service
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
else
echo "Reboot not scheduled (disabled or invalid time)"
fi

View File

@ -0,0 +1,65 @@
#!/bin/bash
INI_FILE="/boot/kioskbrowser.ini"
SYSTEMD_DIR="/etc/systemd/system"
get_ini_value() {
local section=$1 key=$2
awk -F '=' -v sec="$section" -v k="$key" '
$0 ~ /^\[.*\]/ { in_section = ($0 == "[" sec "]") }
in_section && $1 ~ "^"k"$" {
gsub(/^[ \t]+|[ \t]+$/, "", $2)
print $2
exit
}' "$INI_FILE"
}
create_recurring_timer() {
local action=$1
local time=$2
local name="screen-${action}"
echo "Setting daily screen ${action} at ${time}"
cat <<EOF > "$SYSTEMD_DIR/${name}.timer"
[Unit]
Description=Daily screen ${action} timer
[Timer]
OnCalendar=*-*-* ${time}:00
Persistent=true
[Install]
WantedBy=timers.target
EOF
cat <<EOF > "$SYSTEMD_DIR/${name}.service"
[Unit]
Description=Turn screen ${action}
[Service]
Type=oneshot
Environment=DISPLAY=:0
ExecStart=/usr/bin/xset dpms force ${action}
EOF
systemctl daemon-reload
systemctl enable --now "${name}.timer"
}
cleanup_screen_timers() {
for action in on off; do
systemctl disable --now screen-${action}.timer 2>/dev/null
rm -f "$SYSTEMD_DIR/screen-${action}.timer" "$SYSTEMD_DIR/screen-${action}.service"
done
systemctl daemon-reload
}
# === MAIN ===
SCREEN_ON=$(get_ini_value screen screen_on_time)
SCREEN_OFF=$(get_ini_value screen screen_off_time)
cleanup_screen_timers
[[ "$SCREEN_ON" =~ ^[0-2][0-9]:[0-5][0-9]$ ]] && create_recurring_timer on "$SCREEN_ON"
[[ "$SCREEN_OFF" =~ ^[0-2][0-9]:[0-5][0-9]$ ]] && create_recurring_timer off "$SCREEN_OFF"