diff options
Diffstat (limited to 'recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-set-apn')
-rwxr-xr-x | recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-set-apn | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-set-apn b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-set-apn new file mode 100755 index 0000000..ebe8096 --- /dev/null +++ b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-set-apn @@ -0,0 +1,117 @@ +#!/bin/bash + +# Copyright (C) 2014,2017,2019 Multi-Tech Systems + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +noapn_modems=(lvw2 lsp3 cdma) + +# Comment out AT+CGDCONT= statement +remove_apn_sedcmd="s/^(OK[[:space:]]+'|#MT[[:space:]]+)(AT\+CGDCONT=[0-9]+[^\']*)'*/#comment by mlinux-set-apn \2/" + + + +function usage { + echo "Usage: $(basename $0) [--] APN" + echo "Or $(basename $0) -c to clear the APN line" + echo "-- is requied if the APN begins with -" + exit 1 +} + + +((clear=0)) +if (($# < 1)); then + usage +fi +if [[ $1 == "--" ]] ; then + apn=$2 +elif [[ $1 == "-c" ]] ; then + clear=1 +elif [[ $1 =~ ^- ]] ; then + usage +else + apn=$1 +fi + + +set_apn_sedcmd="s/^(#comment by mlinux-set-apn )*(OK[[:space:]]+'|#MT[[:space:]]+)*AT\+CGDCONT=([0-9]+),\"([^\"]*)\",\"[^\"]*\".*/#MT AT\+CGDCONT=\3,\"\4\",\"${apn}\"/" + + + +getmodem() +{ + radioproduct=$(/usr/sbin/mts-io-sysfs show product-id) # LNA3? + if (($? != 0)) ; then + echo "Radio is not ready or not found and cannot determine the type" + exit 1 + fi + if [[ $radioproduct =~ [^-]*-([^-]*)- ]] ; then + echo "${BASH_REMATCH[1]}" + fi +} +function findItem +{ + local s check="$1" + shift + for s ; do [[ "$s" == "$check" ]] && return 0; done + return 1 +} + + +cd /var/config/ppp/peers +if ((clear != 1)) ; then + for f in $noapn ; do + echo "Not allowed to set APN for $f" + done + + for f in *_chat *_chat_non_vz ; do + if [[ -L $f ]] ; then + continue + fi + [[ $f =~ ([^_]*) ]] + m=${BASH_REMATCH[1]} + if findItem "$m" "${noapn_modems[@]}" ; then + continue + fi + + if sed -r -i "${set_apn_sedcmd}" ${f}; then + echo "Set APN to \"${apn}\" in ${f}" + if ! grep -q /usr/libexec/ppp/chat_wrapper ${m} ; then + sed -i "s?connect '/usr/sbin/chat?connect '/usr/libexec/ppp/chat_wrapper /usr/sbin/chat?" ${m} + fi + else + echo "Failed to set APN in $f_chat" + fi + done +else + for f in *_chat *_chat_non_vz ; do + if sed -i -r "${remove_apn_sedcmd}" $f ; then + echo "Commented out APN in $f" + else + if [[ $f =~ ([^_]*) ]] ; then + m=${BASH_REMATCH[1]} + if ! findItem "$m" "${noapn_modems[@]}" ; then + echo "Failed to remove APN setting in $f" + fi + fi + fi + done +fi + +exit 0 |