modem-manager-autosetup: jq fails to get APN info for mcc="262", mnc="07"
Hi,
when trying to use the modem-manager-autosetup
script with a SIM card from O2/Germany (IMSI: 26207...), the resultung jq
command:
jq '.apns.apn| [ .[] | select(.mcc == "'"262"'" and .mnc == "'"07"'" and (.type | contains("default"))) ]' < /usr/share/modem-manager-autosetup/apns-conf.json
which is used to get the APN information fails with:
jq: error (at <stdin>:41387): null (null) and string ("default") cannot have their containment checked
The reason for that is the following entry in apns-conf.json
:
{
"carrier": "Alice",
"mcc": "262",
"mnc": "07",
"apn": "internet.partner1",
"authtype": "0",
"mmsc": "http://10.81.0.7:8002",
"mmsproxy": "82.113.100.41",
"mmsport": "8080",
"mvno_type": "spn",
"mvno_match_data": "Alice"
},
which does not contain a "type"
key.
In total, according to:
jq '.apns.apn| [ .[] | select(has("type") | not) ] | length' < /usr/share/modem-manager-autosetup/apns-conf.json
there are 17 such entries. So I'd assume that this is not just an oversight/error in apns-conf.json
.
In order to avoid the problem, the failing jq
command can be modified to check for the presence of the "type"
key before trying to check its content with an additional and has("type")
in the select
function. Here's a corresponding patch for the develop
branch:
diff --git a/utils/modem-manager-autosetup/files/autosetup.sh b/utils/modem-manager-autosetup/files/autosetup.sh
index 2a8bd26d0..3abd1d027 100644
--- a/utils/modem-manager-autosetup/files/autosetup.sh
+++ b/utils/modem-manager-autosetup/files/autosetup.sh
@@ -3,7 +3,7 @@
get_settings() {
local mcc="$(echo "$1" | head -c 3)"
local mnc="$(echo "$1" | tail -c +4)"
- local info="$(jq '.apns.apn| [ .[] | select(.mcc == "'"$mcc"'" and .mnc == "'"$mnc"'" and (.type | contains("default"))) ][0]' < /usr/share/modem-manager-autosetup/apns-conf.json)"
+ local info="$(jq '.apns.apn| [ .[] | select(.mcc == "'"$mcc"'" and .mnc == "'"$mnc"'" and has("type") and (.type | contains("default"))) ][0]' < /usr/share/modem-manager-autosetup/apns-conf.json)"
if [ -n "$info" ] && [ "$info" != null ]; then
APN="$(echo "$info" | jq -r .apn)"
USER="$(echo "$info" | jq -r .user)"