1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2023-10-10 13:37:24 +02:00
raspap-webgui/config/client_config/onoff_huawei_hilink.sh

59 lines
2.3 KiB
Bash
Raw Normal View History

#!/bin/bash
# connect/disconnect Huawei mobile data stick in Hilink mode (e.g. E3372h)
# ========================================================================
#
2021-05-21 14:57:14 +02:00
# options: -u, --user - user name (default "admin")
# -P, --password - password
# -h, --host - host ip address (default 192.168.8.1)
2021-06-18 14:04:56 +02:00
# -d, --devname - device name (IP is extracted using default route)
2021-05-21 14:57:14 +02:00
# -p, --pin - PIN of SIM card
# -c, --connect - connect 0/1 to set datamode off/on
#
# required software: curl, base64, sha256sum
#
# zbchristian 2021
2021-06-18 14:04:56 +02:00
# include the hilink API (defaults: hilink_user=admin, hilink_host=192.168.8.1)
source /usr/local/sbin/huawei_hilink_api.sh
2021-06-18 14:04:56 +02:00
# include the raspap helper functions
source /usr/local/sbin/raspap_helpers.sh
datamode=""
2021-06-18 14:04:56 +02:00
devname=""
2021-05-21 14:57:14 +02:00
while [ -n "$1" ]; do
case "$1" in
2021-06-18 14:04:56 +02:00
-u|--user) hilink_user="$2"; shift ;;
-P|--password) hilink_password="$2"; shift ;;
-p|--pin) if [[ $2 =~ ^[0-9]{4,8} ]]; then hilink_pin="$2"; fi; shift ;;
-h|--host) hilink_host="$2"; shift ;;
-d|--devname) devname="$2"; shift ;;
2021-05-21 14:57:14 +02:00
-c|--connect) if [ "$2" = "1" ]; then datamode=1; else datamode=0; fi; shift ;;
esac
shift
done
2021-06-18 14:04:56 +02:00
if [ ! -z "$devname" ]; then # get host IP for given device name
gw=$(ip route list | sed -rn "s/default via (([0-9]{1,3}\.){3}[0-9]{1,3}).*dev $devname.*/\1/p")
if [ -z "$gw" ]; then exit; fi # device name not found in routing list -> abort
hilink_host="$gw"
fi
if [ -z "$hilink_password" ] || [ -z "$hilink_pin" ]; then
_getAuthRouter
if [ ! -z "$raspap_user" ]; then hilink_user="$raspap_user"; fi
if [ ! -z "$raspap_password" ]; then hilink_password="$raspap_password"; fi
if [ ! -z "$raspap_pin" ]; then hilink_pin="$raspap_pin"; fi
fi
2021-06-18 14:04:56 +02:00
echo "Hilink: switch device at $hilink_host to mode $datamode" | systemd-cat
2021-06-18 14:04:56 +02:00
status="usage: -c 1/0 to disconnect/connect"
if [ -z "$datamode" ] || [ ! _initHilinkAPI ]; then echo "Hilink: failed - return status: $status"; exit; fi
2021-05-21 14:57:14 +02:00
if ! _switchMobileData "$datamode"; then echo -n "Hilink: could not switch the data mode on/off . Error: ";_getErrorText; fi
if ! _closeHilinkAPI; then echo -n "Hilink: failed - return status: $status . Error: ";_getErrorText; fi