#!/bin/bash -- sourced # prepares and run chromium as kiosk browser command -v chromium \ || 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 cert_to_nssdb /etc/ssl/certs/ "${HOME}/.pki/nssdb" & nss_pid=$! # 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: # , -> e.g. Google,https://www.google.com json_bookmarks() { local cur=0 local name url while [ $# -ne 0 ]; do name="$( urldecode "${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" < /dev/null wid= while [ -z "$wid" ]; do sleep 1 [ -z "$wid" ] && wid="$( xdotool search --onlyvisible --class chromium-browser )" [ -z "$wid" ] && wid="$( xdotool search --onlyvisible --class chromium )" [ -z "$wid" ] && wid="$( xdotool search --onlyvisible --class browser )" done readonly wid wpid="$( xprop -id "$wid" | awk '$1 == "_NET_WM_PID(CARDINAL)" {print $3}' )" if [ -z "$wpid" ]; then # logs to ~/.xsession-errors echo "Failed to get the pid of chromium-browser via xprop..." exit 1 fi readonly wpid activity=init last="$(idle-daemon --send 'get :0' | grep -oP '(?<=idleSeconds=)[0-9]+')" sleep 1 while true; do if [ ! -d "/proc/$wpid" ]; then echo "Process with PID $wpid stopped, exiting auto-reload loop." exit 0 fi current_idle="$(idle-daemon --send 'get :0' | grep -oP '(?<=idleSeconds=)[0-9]+')" if (( current_idle >= SLX_BROWSER_RELOAD_SECS )); then if [ "$activity" = "yes" ] && [ -n "$SLX_BROWSER_INTERACTIVE" ]; then # activity was seen, interactive browser (UI) -> kill session killall chromium-browser chromium loginctl terminate-user demo else xdotool windowactivate "$wid" xdotool key Alt+Home last="$current_idle" sleep "$SLX_BROWSER_RELOAD_SECS" # Wake up to force refresh idle-daemon --send 'get :0' &> /dev/null sleep 1 activity=init continue fi elif [ "$activity" = "init" ]; then activity=no elif [ -n "$last" ] && (( last > current_idle )); then activity=yes fi last="$current_idle" num="$(( SLX_BROWSER_RELOAD_SECS - ( current_idle + 3 ) ))" (( num < 1 )) && num=1 sleep "$num" done ) & fi if [ -n "$SLX_BROWSER_INSECURE" ]; then chromium_args+=("--allow-running-insecure-content" "--ignore-certificate-errors") fi # Wait until cert store is fully populated wait $nss_pid chromium_args+=( "$SLX_BROWSER_URL" ) # finally exec to chromium exec chromium "${chromium_args[@]}" exec chromium-browser "${chromium_args[@]}"