1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
#!/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:
# <name>,<url> -> 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" <<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
fi
if [ -n "$SLX_BROWSER_ZOOM" ]; then
v="${SLX_BROWSER_ZOOM}"
while [ "${#v}" -lt 3 ]; do
v="0$v"
done
chromium_args+=( "--force-device-scale-factor=${v:0:-2}.${v:${#v}-2}" )
fi
if [ -n "$SLX_BROWSER_RELOAD_SECS" ] && [ "$SLX_BROWSER_RELOAD_SECS" -gt 0 ]; then
(
# Wake up to force refresh
idle-daemon --send 'get :0' &> /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
exit 0
else
xdotool windowactivate "$wid"
xdotool key Alt+Home
last="$current_idle"
sleep "$(( SLX_BROWSER_RELOAD_SECS - 10 ))"
# Wake up to force refresh
idle-daemon --send 'get :0' &> /dev/null
sleep 10
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 + 5 ) ))"
(( 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[@]}"
|