treewide: fix shellscript syntax errors/typos
[openwrt/openwrt.git] / package / network / utils / comgt / files / directip.sh
index 2bfdf8051662a9bd8c4cbcd2a21b1765a3e8ea16..3452fa5db702c944ce985a064a545e5316ebbe0e 100644 (file)
@@ -1,8 +1,10 @@
 #!/bin/sh
 
-. /lib/functions.sh
-. ../netifd-proto.sh
-init_proto "$@"
+[ -n "$INCLUDE_ONLY" ] || {
+       . /lib/functions.sh
+       . ../netifd-proto.sh
+       init_proto "$@"
+}
 
 proto_directip_init_config() {
        available=1
@@ -13,15 +15,19 @@ proto_directip_init_config() {
        proto_config_add_string "auth"
        proto_config_add_string "username"
        proto_config_add_string "password"
+       proto_config_add_defaults
 }
 
 proto_directip_setup() {
        local interface="$1"
        local chat devpath devname
 
-       local device apn pincode ifname auth username password
-       json_get_vars device apn pincode auth username password
+       local device apn pincode ifname auth username password $PROTO_DEFAULT_OPTIONS
+       json_get_vars device apn pincode auth username password $PROTO_DEFAULT_OPTIONS
+
+       [ -n "$ctl_device" ] && device=$ctl_device
 
+       device="$(readlink -f $device)"
        [ -e "$device" ] || {
                proto_notify_error "$interface" NO_DEVICE
                proto_set_available "$interface" 0
@@ -38,8 +44,7 @@ proto_directip_setup() {
                return 1
        }
 
-       cardinfo=$(gcom -d "$device" -s /etc/gcom/getcardinfo.gcom)
-       [ -n $(echo "$cardinfo" | grep -q "Sierra Wireless") ] || {
+       gcom -d "$device" -s /etc/gcom/getcardinfo.gcom | grep -q "Sierra Wireless" || {
                proto_notify_error "$interface" BAD_DEVICE
                proto_block_restart "$interface"
                return 1
@@ -56,9 +61,9 @@ proto_directip_setup() {
        gcom -d "$device" -s /etc/gcom/getcarrier.gcom || return 1
 
        local auth_type=0
-       [ -z "$auth" ] && case $auth in
+       case $auth in
        pap) auth_type=1;;
-       chap) auth_type=1;;
+       chap) auth_type=2;;
        esac
 
        USE_APN="$apn" USE_USER="$username" USE_PASS="$password" USE_AUTH="$auth_type" \
@@ -73,15 +78,18 @@ proto_directip_setup() {
        proto_send_update "$interface"
 
        json_init
-       json_add_string name "${interface}_dhcp"
+       json_add_string name "${interface}_4"
        json_add_string ifname "@$interface"
        json_add_string proto "dhcp"
+       proto_add_dynamic_defaults
        ubus call network add_dynamic "$(json_dump)"
 
        json_init
-       json_add_string name "${interface}_dhcpv6"
+       json_add_string name "${interface}_6"
        json_add_string ifname "@$interface"
        json_add_string proto "dhcpv6"
+       json_add_string extendprefix 1
+       proto_add_dynamic_defaults
        ubus call network add_dynamic "$(json_dump)"
 
        return 0
@@ -93,10 +101,14 @@ proto_directip_teardown() {
        local device
        json_get_vars device
 
+       [ -n "$ctl_device" ] && device=$ctl_device
+
        gcom -d "$device" -s /etc/gcom/directip-stop.gcom || proto_notify_error "$interface" CONNECT_FAILED
 
        proto_init_update "*" 0
        proto_send_update "$interface"
 }
 
-add_protocol directip
+[ -n "$INCLUDE_ONLY" ] || {
+       add_protocol directip
+}