#!/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: # , -> 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" < "$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 & fi if [ -n "$SLX_BROWSER_RELOAD_SECS" ]; then ( wid= wpid= while true; do if [ -z "$wid" ]; then wid="$(xdotool search --onlyvisible --class browser)" [ -z "$wid" ] && sleep 1 && continue readonly wid fi if [ -z "$wpid" ]; then wpid="$(xprop -id "$wid" | awk -F= '$1 ~ /_NET_WM_PID\(CARDINAL\)/ {print $2}' | tr -d ' ')" if [ -z "$wpid" ]; then # logs to ~/.xsession-errors echo "Failed to get the pid of chromium-browser via xprop..." exit 1 fi readonly wpid fi 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 " -ge "$SLX_BROWSER_RELOAD_SECS" ]; then xdotool windowactivate "$wid" xdotool key Alt+Home continue fi sleep "$(( SLX_BROWSER_RELOAD_SECS - current_idle ))" done ) & 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[@]}"