diff options
Diffstat (limited to 'recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-set-apn')
-rwxr-xr-x | recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-set-apn | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-set-apn b/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-set-apn new file mode 100755 index 0000000..0935542 --- /dev/null +++ b/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-set-apn @@ -0,0 +1,105 @@ +#!/bin/bash + +# Copyright (C) 2014,2017 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. + +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 +gsm_chat_file=/etc/ppp/peers/gsm_chat +lvw2_chat_file=/etc/ppp/peers/lvw2_chat +leu1_chat_file=/etc/ppp/peers/leu1_chat +lna3_chat_file=/etc/ppp/peers/lna3_chat +echo clear is $clear + +model=$(radio-query --model 2>/dev/null) + +if [[ $model == "LE910-NA1" ]] ; then + if ((clear != 1)) ; then + if sed -r -i "s/^(#comment by mlinux-set-apn )*OK\s+'AT\+CGDCONT=3,\"IPV4V6\",\"[^\"]*\"'$/OK 'AT\+CGDCONT=3,\"IPV4V6\",\"${apn}\"'/" $lna3_chat_file ; then + echo "Set APN to \"${apn}\" in $lna3_chat_file" + else + echo "Failed to set APN in $lna3_chat_file" + fi + fw=$(radio-query --active-firmware 2>/dev/null) || ((fw=-1)) + if (( fw == 1 )) ; then + # Verizon is active, so comment out the APN + echo "Temporarily commenting out APN, since Verizon is active and no APN is allowed in a Verizon chat file." + sed -r -i "s/^(OK\s+'AT\+CGDCONT=3,\"IPV4V6\",\"[^\"]*\"'$)/#comment by mlinux-set-apn \1/" $lna3_chat_file + fi + else + if sed -r -i "s/^(OK\s+'AT\+CGDCONT=3,\"IPV4V6\",\"[^\"]*\"'$)/#comment by mlinux-set-apn \1/" $lna3_chat_file ; then + echo "Commented out APN in $lna3_chat_file" + else + echo "Failed to comment out APN in $lna3_chat_file" + fi + fi + exit 0 +fi + + +if ((clear != 1)) ; then + if sed -r -i "s/^(#comment by mlinux-set-apn )*OK\s+'AT\+CGDCONT=1,\"IP\",\"[^\"]*\"'$/OK 'AT\+CGDCONT=1,\"IP\",\"${apn}\"'/" $gsm_chat_file ; then + echo "Set APN to \"${apn}\" in $gsm_chat_file" + else + echo "Failed to set APN in $gsm_chat_file" + fi + echo "Not allowed to set APN for $lvw2_chat_file" + # We cannot set the APN for a Verizon modem + # sed -r -i "s/^(#comment by mlinux-set-apn )*OK\s+'AT\+CGDCONT=3,\"IPV4V6\",\"[^\"]*\"'$/OK 'AT\+CGDCONT=3,\"IPV4V6\",\"${apn}\"'/" $lvw2_chat_file + if sed -r -i "s/^(#comment by mlinux-set-apn )*OK\s+'AT\+CGDCONT=1,\"IPV4V6\",\"[^\"]*\"'$/OK 'AT\+CGDCONT=1,\"IPV4V6\",\"${apn}\"'/" $leu1_chat_file ; then + echo "Set APN to \"${apn}\" in $leu1_chat_file" + else + echo "Failed to set APN in $leu1_chat_file" + fi +else + if sed -r -i "s/^(OK\s+'AT\+CGDCONT=1,\"IP\",\"[^\"]*\"'$)/#comment by mlinux-set-apn \1/" $gsm_chat_file ; then + echo "Commented out APN in $gsm_chat_file" + else + echo "Failed to comment out APN in $gsm_chat_file" + fi + # Not setting APN in lvw2 is OK, since Verizon should not have an APN in a chat file. + if sed -r -i "s/^(OK\s+'AT\+CGDCONT=3,\"IPV4V6\",\"[^\"]*\"'$)/#comment by mlinux-set-apn \1/" $lvw2_chat_file ; then + echo "Commented out APN in $lvw2_chat_file" + fi + if sed -r -i "s/^(OK\s+'AT\+CGDCONT=1,\"IPV4V6\",\"[^\"]*\"'$)/#comment by mlinux-set-apn \1/" $leu1_chat_file ; then + echo "Commented out APN in $leu1_chat_file" + else + echo "Failed to comment out APN in $leu1_chat_file" + fi +fi +exit 0 |