Skip to content

Commit

Permalink
modem-manager-autosetup: Fix jq filter for apn without 'type' attribute
Browse files Browse the repository at this point in the history
The initial jq filter used to extract the APN info from apns-conf.json
fails with:

``` text
jq: error (...): null (null) and string ("default") cannot have their containment checked
```
when one of the apn objects selected by mcc/mnc doesn't have a
'type' attribute (as is the case for mcc=262, mnc=07). As a result,
otherwise matching APN objects will not be considered.

This commit fixes the jq filter by checking for the presence of
the 'type' attribute.
  • Loading branch information
ktetzlaff committed Apr 8, 2024
1 parent 47cbf50 commit c61ac41
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion utils/modem-manager-autosetup/files/autosetup.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ get_settings() {
[ -n "$1" ] || return
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)"
[ -n "$info" ] || info="$(jq '.apns.apn| [ .[] | select(.mcc == "'"$mcc"'" and .mnc == "'"$mnc"'") ][0]' < /usr/share/modem-manager-autosetup/apns-conf.json)"
if [ -n "$info" ] && [ "$info" != null ]; then
APN="$(echo "$info" | jq -r .apn)"
Expand Down

0 comments on commit c61ac41

Please sign in to comment.