From 2ec543530689bb3ee17e0b9a3a0b1adceed1e7ed Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 12 Nov 2019 15:36:44 +0100 Subject: [kiosk-chromium] Simplify json generation, add sanity check Only wipe chromium profile if it's actually the demo user, to be safe. Json generation of bookmarks was simplified to use jq instead of awk, with the added benefit of properly quoting special chars in URL/Name. --- .../opt/openslx/scripts/kiosk-launch.d/00-chromium | 70 +++++++++++----------- 1 file changed, 34 insertions(+), 36 deletions(-) (limited to 'core/modules/kiosk-chromium') diff --git a/core/modules/kiosk-chromium/data/opt/openslx/scripts/kiosk-launch.d/00-chromium b/core/modules/kiosk-chromium/data/opt/openslx/scripts/kiosk-launch.d/00-chromium index caf67ab9..226b274b 100644 --- a/core/modules/kiosk-chromium/data/opt/openslx/scripts/kiosk-launch.d/00-chromium +++ b/core/modules/kiosk-chromium/data/opt/openslx/scripts/kiosk-launch.d/00-chromium @@ -4,51 +4,49 @@ command -v chromium-browser || return 0 # clear state of previous sessions -[ -e "$HOME/.config/chromium" ] && rm -rf -- "$HOME/.config/chromium" -mkdir -p "$HOME/.config/chromium/Default" +if [ "$(whoami)" = "demo" ]; then + rm -rf -- "$HOME/.config/chromium" + mkdir -p "$HOME/.config/chromium/Default" +fi # Helper to json'ize bookmarks given as arguments in the form: # , -> e.g. Google,https://www.google.com json_bookmarks() { - cur=0 - echo -n '[' + local cur=0 while [ $# -ne 0 ]; do - local bb="$1" + jq --null-input --join-output --compact-output --arg id "$(( cur++ ))" --arg name "${1%%,*}" --arg url "${1#*,}" \ + '{"id": $id, "type": "url", "name": $name, "url": $url}' shift - awk -F, '{printf "%s","{\"id\": \"'$cur'\", \"type\": \"url\", \"name\": \""$1"\", \"url\": \""$2"\"}"}' <<< "$bb" - [ $# -ne 0 ] && echo -n ',' - (( cur ++ )) - done - echo -n ']' + [ $# -ne 0 ] && printf "," + done } -jq ".roots.bookmark_bar.children += $(json_bookmarks $SLX_BROWSER_BOOKMARKS)" \ - <(cat <<-EOF - { - "roots": { - "bookmark_bar": { - "children": [ ], - "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 +# Pass SLX_BROWSER_BOOKMARKS without quotes for splitting into arguments +cat > "$HOME/.config/chromium/Default/Bookmarks" < "$HOME/.config/chromium/Default/Bookmarks" + }, + "version": 1 +} +EOF # default chromium arguments chromium_args=("--noerrdialogs" "--disable-new-avatar-menu" "--disable-infobars" "--test-type") -- cgit v1.2.3-55-g7522