mirror of
				https://github.com/karl0ss/AnotterKiosk.git
				synced 2025-10-26 04:03:59 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			87 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			87 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/bash
 | |
| 
 | |
| INI_FILE="/boot/kioskbrowser.ini"
 | |
| SYSTEMD_DIR="/etc/systemd/system"
 | |
| 
 | |
| 
 | |
| # Function to safely remount root FS
 | |
| remount_root() {
 | |
|     local mode=$1
 | |
|     echo "Remounting root filesystem as $mode..."
 | |
|     mount -o remount,"$mode" / || {
 | |
|         echo "Failed to remount root as $mode"
 | |
|         exit 1
 | |
|     }
 | |
| }
 | |
| 
 | |
| 
 | |
| get_ini_value() {
 | |
|     get-ini "$INI_FILE" "$1" "$2"
 | |
| }
 | |
| 
 | |
| create_recurring_timer() {
 | |
|     local action=$1
 | |
|     local time=$2
 | |
|     local value
 | |
| 
 | |
|     if [[ "$action" == "on" ]]; then
 | |
|         value=1
 | |
|     elif [[ "$action" == "off" ]]; then
 | |
|         value=0
 | |
|     else
 | |
|         echo "Invalid action: $action"
 | |
|         return 1
 | |
|     fi
 | |
| 
 | |
|     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
 | |
| ExecStart=/usr/bin/vcgencmd display_power ${value}
 | |
| User=pi
 | |
| 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
 | |
| }
 | |
| 
 | |
| remount_root rw
 | |
| 
 | |
| # === 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"
 | |
| 
 | |
| remount_root ro
 |