summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2016-06-30 09:35:16 +0200
committerAleksander Morgado <aleksander@aleksander.es>2016-06-30 10:10:20 +0200
commitc252c998ea5c1516e2c2d30220c265e56a8dcfb7 (patch)
treea851f6aff02ca1ea36860f5fa5b8e23be4e1c269
parent202349ce952712cd37415d91b5511491f0769d65 (diff)
downloadlibmbim-c252c998ea5c1516e2c2d30220c265e56a8dcfb7.tar.gz
mbim-network: allow loading profile from a different path
This effectively makes mbim-network work with multiple devices in a single system.
-rwxr-xr-xutils/mbim-network.in74
1 files changed, 60 insertions, 14 deletions
diff --git a/utils/mbim-network.in b/utils/mbim-network.in
index 48d6e11..1717375 100755
--- a/utils/mbim-network.in
+++ b/utils/mbim-network.in
@@ -14,7 +14,7 @@
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
-# Copyright (C) 2013 Aleksander Morgado <aleksander@gnu.org>
+# Copyright (C) 2013-2016 Aleksander Morgado <aleksander@aleksander.es>
#
# Based on libqmi's qmi-network script
#
@@ -36,6 +36,7 @@ help ()
echo " status Query network connection status"
echo
echo "Options:"
+ echo " --profile=[PATH] Use the profile in the specified path"
echo " --help Show help options"
echo " --version Show version"
echo
@@ -45,12 +46,13 @@ help ()
echo " device, e.g.:"
echo " /dev/cdc-wdm0"
echo
- echo " 2) The mbim-network script requires a profile to be available"
- echo " in the following path:"
+ echo " 2) The mbim-network script requires a profile to work. Unless"
+ echo " explicitly specified with \`--profile', the file is assumed to"
+ echo " be available in the following path:"
echo " /etc/mbim-network.conf"
echo
echo " 3) The APN to use should be configured in the profile, in the"
- echo " following way (e.g. assuming APN is called 'internet':"
+ echo " following way (e.g. assuming APN is called 'internet'):"
echo " APN=internet"
echo
echo " 4) Once the mbim-network script reports a successful connection"
@@ -69,7 +71,8 @@ version ()
echo
}
-if [ $# -ne 2 ]; then
+# Basic options
+if [ $# -lt 2 ]; then
if [ "$1" = "--help" ]; then
help
exit 0
@@ -83,20 +86,63 @@ if [ $# -ne 2 ]; then
exit 255
fi
+# Defaults
+PROFILE_FILE=/etc/mbim-network.conf
+
+# Device + Command with options; options given first
+while [ $# -gt 2 ]; do
+ OPT="$1"
+ shift
+
+ case "$OPT" in
+ "--")
+ break 2;;
+ "--profile")
+ if [ $# -gt 2 ]; then
+ PROFILE_FILE="$1"
+ shift
+ else
+ PROFILE_FILE=""
+ fi
+ ;;
+ "--profile="*)
+ PROFILE_FILE="${OPT#*=}";;
+ *)
+ echo >&2 "Invalid option: $OPT"
+ print_usage
+ exit 255;;
+ esac
+done
+
+if [ -z "$PROFILE_FILE" ]; then
+ echo "error: empty profile path given" 1>&2
+ print_usage
+ exit 255
+fi
+
+if [ $# -ne 2 ] || [[ $1 == --* ]] || [[ $2 == --* ]]; then
+ echo "error: missing arguments" 1>&2
+ print_usage
+ exit 255
+fi
+
DEVICE=$1
COMMAND=$2
-STATE_FILE=/tmp/mbim-network-state
-PROFILE_FILE=/etc/mbim-network.conf
+
+STATE_FILE=/tmp/mbim-network-state-`basename $DEVICE`
+
load_profile ()
{
- if [ -f $PROFILE_FILE ]; then
- echo "Loading profile..."
+ if [ -f "$PROFILE_FILE" ]; then
+ echo "Loading profile at ${PROFILE_FILE}..."
. $PROFILE_FILE
if [ "x$APN" != "x" ]; then
echo " APN: $APN"
fi
+ else
+ echo "Profile at '$PROFILE_FILE' not found..."
fi
}
@@ -105,9 +151,9 @@ save_state ()
KEY=$1
VAL=$2
- echo "Saving state... ($KEY: $VAL)"
+ echo "Saving state at ${STATE_FILE}... ($KEY: $VAL)"
- if [ -f $STATE_FILE ]; then
+ if [ -f "$STATE_FILE" ]; then
PREVIOUS=`cat $STATE_FILE`
PREVIOUS=`echo "$PREVIOUS" | grep -v $KEY`
if [ "x$PREVIOUS" != "x" ]; then
@@ -124,8 +170,8 @@ save_state ()
load_state ()
{
- if [ -f $STATE_FILE ]; then
- echo "Loading previous state..."
+ if [ -f "$STATE_FILE" ]; then
+ echo "Loading previous state from ${STATE_FILE}..."
. $STATE_FILE
if [ "x$TRID" != "x" ]; then
@@ -136,7 +182,7 @@ load_state ()
clear_state ()
{
- echo "Clearing state..."
+ echo "Clearing state at ${STATE_FILE}..."
rm -f $STATE_FILE
}