@@ -13,15 +13,15 @@ CFGF="/etc/open-normal-extension.cfg"
1313# Send browser extension API message. First send four bytes of the length of
1414# the payload and then the actual payload.
1515function Msg {
16- local len b1 b2 b3 b4
16+ local len b1 b2 b3 b4
1717
18- len=" ${# 1} "
19- b1=" $(( len & 255 )) "
20- b2=" $(( (len >> 8 ) & 255 )) "
21- b3=" $(( (len >> 16 ) & 255 )) "
22- b4=" $(( (len >> 24 ) & 255 )) "
23- printf " %b" " $( printf " \\\\ x%02x\\\\ x%02x\\\\ x%02x\\\\ x%02x" " $b1 " " $b2 " " $b3 " " $b4 " ) "
24- printf " %s" " $1 "
18+ len=" ${# 1} "
19+ b1=" $(( len & 255 )) "
20+ b2=" $(( (len >> 8 ) & 255 )) "
21+ b3=" $(( (len >> 16 ) & 255 )) "
22+ b4=" $(( (len >> 24 ) & 255 )) "
23+ printf " %b" " $( printf ' \\ x%02x\\x%02x\\x%02x\\x%02x' " $b1 " " $b2 " " $b3 " " $b4 " ) "
24+ printf " %s" " $1 "
2525}
2626
2727# Read the four bytes of length in the received API message
@@ -32,39 +32,39 @@ LEN="$(od -t u4 -A n -N 4 --endian=little)"
3232# So 8k should be plenty for the time being
3333# If length is negative or zero or larger than 8k, then message is invalid
3434if [ -z " $LEN " ] || [ " $LEN " -le 0 ] || [ " $LEN " -gt 8192 ]; then
35- Msg " { \ " status\" : \ " Failed to read parameters from API\" } "
36- exit 100
35+ Msg ' { "status": "Failed to read parameters from API"} '
36+ exit 100
3737fi
3838
3939# Read the json payload
4040LANG=C IFS= read -r -d ' ' -n " $LEN " JSON
4141# Remove json prefix
42- PFX=" { \ " URL\" : \" "
42+ PFX=' { "URL":" '
4343URL=" ${JSON## " $PFX " } "
4444# Remove json suffix
45- SFX=" \" } "
45+ SFX=' "} '
4646URL=" ${URL%% " $SFX " } "
4747
4848# Check that config file is readable
4949if [ -r " $CFGF " ]; then
50- # Do not complain about not being able to follow non-constant source
51- # shellcheck disable=SC1090
52- . " $CFGF "
53- # Sanity check settings
54- if [ -z " $GIVC_PATH " ] || [ -z " $GIVC_OPTS " ] || [ ! -x " ${GIVC_PATH} /bin/givc-cli" ]; then
55- Msg " {\" status\" :\" Invalid config in ${CFGF} \" }"
56- exit 102
57- else
58- # Do not complain about double quotes, $GIVC_OPTS is purposefully unquoted here
59- # shellcheck disable=SC2086
60- " ${GIVC_PATH} /bin/givc-cli" $GIVC_OPTS start app --vm chrome-vm google-chrome -- " ${URL} " > /dev/null 2>&1
61- RES=$?
62- # Just return the exit value of givc-cli back to the browser
63- Msg " {\" status\" :\" ${RES} \" }"
64- exit " $RES "
65- fi
50+ # Do not complain about not being able to follow non-constant source
51+ # shellcheck disable=SC1090
52+ . " $CFGF "
53+ # Sanity check settings
54+ if [ -z " $GIVC_PATH " ] || [ -z " $GIVC_OPTS " ] || [ ! -x " ${GIVC_PATH} /bin/givc-cli" ]; then
55+ Msg " {\" status\" :\" Invalid config in ${CFGF} \" }"
56+ exit 102
57+ else
58+ # Do not complain about double quotes, $GIVC_OPTS is purposefully unquoted here
59+ # shellcheck disable=SC2086
60+ " ${GIVC_PATH} /bin/givc-cli" $GIVC_OPTS start app --vm chrome-vm google-chrome -- " ${URL} " > /dev/null 2>&1
61+ RES=$?
62+ # Just return the exit value of givc-cli back to the browser
63+ Msg " {\" status\" :\" ${RES} \" }"
64+ exit " $RES "
65+ fi
6666else
67- # Report error to the browser, config was nonexistent or unreadable
68- Msg " {\" status\" :\" Failed to read ${CFGF} \" }"
69- exit 101
67+ # Report error to the browser, config was nonexistent or unreadable
68+ Msg " {\" status\" :\" Failed to read ${CFGF} \" }"
69+ exit 101
7070fi
0 commit comments