summaryrefslogtreecommitdiffstats
path: root/core/modules/kiosk-chromium/data/opt/openslx/pam/hooks/session-open.d/00-chromium-policies
blob: e1350a4d05e48eb2745a348092cfe2a85c19840e (plain) (blame)
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
#!/bin/bash
# ^SOURCED, actually running in ash

. /opt/openslx/config

# creates managed policy file, those settings cannot be changed by the user
# (if he even gets to the settings dialog in the first place)
create_chromium_policies() {
	local bookmarkbar url
	if [ -n "$SLX_BROWSER_BOOKMARKS" ]; then
		bookmarkbar=true
	else
		bookmarkbar=false
	fi

	url=$( printf "%s" "$SLX_BROWSER_URL" | jq -R . )
	mkdir -p "/etc/chromium-browser/policies/managed" "/etc/chromium/policies/managed"
	cat <<- EOF > "/etc/chromium-browser/policies/managed/kiosk-mode.json"
	{
		"AutoFillEnabled": false,
		"BackgroundModeEnabled": false,
		"BookmarkBarEnabled": $bookmarkbar,
		"DefaultBrowserSettingEnabled": true,
		"DeviceAutoUpdateDisabled": true,
		"DownloadRestrictions": 3,
		"HomepageLocation": $url,
		"HomepageIsNewTabPage": false,
		"NewTabPageLocation": "about:blank",
		"PasswordManagerEnabled": false,
		"RestoreOnStartup": 4,
		"RestoreOnStartupURLs": $url,
		"ShowAppsShortcutInBookmarkBar": false,
		"ImportBookmarks": false,
		"TranslateEnabled": false
	}
	EOF
	# Ubuntu uses chromium-browser, Debian chromium (...)
	ln -nfs "/etc/chromium-browser/policies/managed/kiosk-mode.json" \
		"/etc/chromium/policies/managed/kiosk-mode.json"
	# Disable importing bookmarks
	for i in chromium chromium-browser; do
		i="/etc/$i/master_preferences"
		[ -f "$i" ] || continue
		< "$i"  jq 'del(.distribution.import_bookmarks_from_file) | .distribution.import_bookmarks = false' \
			> "$i.new"
		mv -f "$i.new" "$i"
	done
}

if [ "${PAM_SERVICE//autologin/}" != "$PAM_SERVICE" -a "$PAM_TTY" = ":0" ]; then
	create_chromium_policies
fi
true