summaryrefslogblamecommitdiffstats
path: root/core/modules/kiosk-chromium/data/opt/openslx/scripts/kiosk-launch.d/00-chromium
blob: 9ee4ca19dd6dc3bba79088406df9725321cbadb1 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                      

                                            
                                       
 
                                  



                                                 
 





                                                             

                                                              
                  
                   
                      
                              


                                                                                                                            
                                                                                
                     

                                          

 




















                                                                         
                 



                    

                            
                                                                                                                                             
 





                                                                              
 




                                                      
 





























                                                                                                
 

                                                                                         

  

                                           
#!/bin/bash -- sourced
# prepares and run chromium as kiosk browser

command -v chromium-browser || return 0

# clear state of previous sessions
if [ "$(whoami)" = "demo" ]; then
	rm -rf -- "$HOME/.config/chromium"
	mkdir -p "$HOME/.config/chromium/Default"
fi

# Helper to decode URL-encoded strings
# e.g. urldecode http%3A%2F%2Ffoobar.com -> http://foobar.com
urldecode() {
	: "${*//+/ }"; echo -e "${_//%/\\x}"
}

# Helper to json'ize bookmarks given as arguments in the form:
#    <name>,<url>  ->  e.g. Google,https://www.google.com
json_bookmarks() {
	local cur=0
	local name url
	while [ $# -ne 0 ]; do
		name="${1%%,*}"
		url="$(urldecode ${1#*,})"
		jq --null-input --join-output --compact-output --arg id "$(( cur++ ))" --arg name "$name" --arg url "$url" \
			'{"id": $id, "type": "url", "name": $name, "url": $url}'
		shift
		[ $# -ne 0 ] && printf ","
	done
}

# Pass SLX_BROWSER_BOOKMARKS without quotes for splitting into arguments
cat > "$HOME/.config/chromium/Default/Bookmarks" <<EOF
{
	"roots": {
		"bookmark_bar": {
		"children": [ $(json_bookmarks $SLX_BROWSER_BOOKMARKS) ],
			"id": "1",
			"name": "Lesezeichenleiste",
			"type": "folder"
		},
		"other": {
			"children": [  ],
			"id": "2",
			"name": "Weitere Lesezeichen",
			"type": "folder"
		},
		"synced": {
			"children": [  ],
			"id": "3",
			"name": "Mobile Lesezeichen",
			"type": "folder"
		}
	},
	"version": 1
}
EOF

# default chromium arguments
chromium_args=("--noerrdialogs" "--disable-translate" "--disable-new-avatar-menu" "--disable-infobars" "--test-type" "--fast" "--fast-start")

# simulate a future build date to remove those update notification
# TODO properly disable auto update feature when chromium supports it
chromium_args+=("--simulate-outdated-no-au=\"Tue, 31 Dec 2099 23:59:59 GMT\"")

# default to maximized on startup
chromium_args+=("--start-maximized")

if [ -z "$SLX_BROWSER_INTERACTIVE" ]; then
	if [ -n "${SLX_AUTOLOGIN%OFF}" ]; then
		# Autologin active, go full fullscreen
		chromium_args+=("--kiosk")
	fi

	# swallow keyboard shortcuts of chromium
	cat <<- EOF > "$HOME/.xbindkeysrc"
	"true"
		Control+d
	"true"
		Control+t
	"true"
		Control+s
	"true"
		Control+n
	"true"
		Control+j
	"true"
		Control+p
	"true"
		Control+h
	"true"
		Control+Shift+o
	EOF
	# xbinkeys requires a daemon, run it
	xbindkeys_autostart &

	if [ -n "$SLX_BROWSER_RELOAD_SECS" ]; then
		while true; do
			xdotool windowactivate "$(xdotool search --onlyvisible --class browser)"
			xdotool key Alt+Home
			sleep "$SLX_BROWSER_RELOAD_SECS"
		done &
	fi
fi

if [ -n "$SLX_BROWSER_INSECURE" ]; then
	chromium_args+=("--allow-running-insecure-content" "--ignore-certificate-errors")
fi

# finally exec to chromium
exec chromium-browser "${chromium_args[@]}"