#!/bin/sh -e
#
# (C) Copyright 2016 Axis Communications AB, LUND, SWEDEN
show_devmode_status() {
local val cmd
cmd="gdbus call -y -d com.axis.AddonDevMode1 -o /com/axis/AddonDevMode1 -m com.axis.AddonDevMode1.GetAllowed"
val=$($cmd) || val=Unknown
# Get the content of the array, assuming enclosed in square brackets
val=${val##*[}
val=${val%%]*}
# No entry regarding devmode if it is disabled
[ -n "$val" ] || return 0
# Echo help text for special cases empty list and '*'
[ "$val" = "'*'" ] && val="All APIs" || {
val=$(echo "$val" | sed s/', '/'\n'/g)
}
printf "\nPackage manager developer mode configuration:\n%s\n" "$val"
}
get_next_value() {
local delim=" ^ " escaped_delim="~^"
local continue_iter=false value= rest= remain= escaped_value=
value=${1%%"$delim"*}
rest=${1#*"$delim"}
#Unescape the value
[ "${value#*$escaped_delim}" = "$value" ] ||
{ continue_iter=true && remain="$value"; }
while [ $continue_iter = true ]; do
case $remain in
*$escaped_delim*)
escaped_value=$escaped_value${remain%%$escaped_delim*}'^'
remain=${remain#*$escaped_delim}
;
*)
value="$escaped_value$remain"
continue_iter=false
;
esac
done
eval $2=\$value
eval $3=\$rest
}
list_applications() {
local IFS=$IFS oldIFS=$IFS
local resp string code
local info line next id verno vername license signed webpage state gen
local name maintainer licensekey license_state
resp=$(gdbus call -y -d com.axis.AddonManager -o /com/axis/AddonManager -m com.axis.AddonManager.info '') || return 1
# Remove paranthesis
resp=${resp#\(}
resp=${resp%\)}
# Get the response code and string
string=${resp#*, }
code=${resp%, "$string"}
# Validate that the response code part of the response string is '0'
[ "$code" = 0 ] || return 1
# Get a cleaned up result value from the response string:
# - Remove surrounding single quotes
# - Convert all \n to newlines
string=${string#\'}
string=${string%\'}
info=$(echo "$string" | sed -e 's#\\n$##;s#\\n#\n#g')
IFS="
"
for line in $info; do
IFS=$oldIFS
get_next_value "$line" id next
get_next_value "$next" verno next
get_next_value "$next" vername next
get_next_value "$next" license next
get_next_value "$next" signed next
get_next_value "$next" webpage next
get_next_value "$next" state next
get_next_value "$next" gen next
if [ "$next" = "$gen" ]; then
maintainer= name=
else
get_next_value "$next" name next
get_next_value "$next" maintainer next
fi
licensekey=$(gdbus call -y -d com.axis.PackageManager.LicenseKeyConf1 -o /com/axis/PackageManager/LicenseKeyConf1 -m com.axis.PackageManager.LicenseKeyConf1.GetMainLicenseKeyInfo \"$id\") || return 1
# Handle three types of license key answers
# - No license key required
# - Extract state from license key
case $licensekey in
*\[\]*)
licensekey_state=
;
*\[*\]*)
licensekey=${licensekey%,*}
licensekey=${licensekey%,*}
licensekey=${licensekey##*,}
licensekey=${licensekey%\'*}
licensekey_state=${licensekey#*\'}
;
*)
licensekey_state=
;
esac
[ $gen -ne 3 ] || {
printf "\nId: %s" "$id"
[ -z "$name" ] ||
printf "\nName: %s\nMaintainer: %s" "$name" "$maintainer"
printf "\nVersion: %s\nOpen source license: %s\nSigned: %s\nState: %s
Mainpage: %s\n" "$vername" "$license" "$signed" "$state" "$webpage"
[ -z "$licensekey_state" ] ||
printf "Copy protection state: %s\n" "$licensekey_state"
}
done
}
printf "\n## ACAP3 applications ##\n"
show_devmode_status
list_applications