proto-shell: move all proto init code to a separate function
authorFelix Fietkau <nbd@openwrt.org>
Mon, 10 Oct 2011 13:50:35 +0000 (15:50 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 10 Oct 2011 13:50:38 +0000 (15:50 +0200)
dummy/netifd-proto.sh
dummy/proto/ppp.sh

index 2fbfd4e6d51985b0db2cbe43086514efb26e58e7..7ce88ee9bef2697f60b1a2397332def516f60b85 100755 (executable)
@@ -36,41 +36,43 @@ _proto_do_setup() {
        eval "$1_setup \"$interface\" \"$ifname\""
 }
 
-proto="$1"; shift
-cmd="$1"; shift
+init_proto() {
+       proto="$1"; shift
+       cmd="$1"; shift
 
-case "$cmd" in
-       dump)
-               add_protocol() {
-                       no_device=0
-                       available=0
+       case "$cmd" in
+               dump)
+                       add_protocol() {
+                               no_device=0
+                               available=0
 
-                       add_default_handler "$1_init_config"
+                               add_default_handler "$1_init_config"
 
-                       json_init
-                       json_add_string "name" "$1"
-                       eval "$1_init"
-                       json_add_boolean no-device "$no_device"
-                       json_add_boolean available "$available"
-                       json_add_array "config"
-                       eval "$1_init_config"
-                       json_close_array
-                       json_dump
-               }
-       ;;
-       setup|teardown)
-               interface="$1"; shift
-               data="$1"; shift
-               ifname="$1"; shift
+                               json_init
+                               json_add_string "name" "$1"
+                               eval "$1_init"
+                               json_add_boolean no-device "$no_device"
+                               json_add_boolean available "$available"
+                               json_add_array "config"
+                               eval "$1_init_config"
+                               json_close_array
+                               json_dump
+                       }
+               ;;
+               setup|teardown)
+                       interface="$1"; shift
+                       data="$1"; shift
+                       ifname="$1"; shift
 
-               add_protocol() {
-                       [[ "$proto" == "$1" ]] || return 0
+                       add_protocol() {
+                               [[ "$proto" == "$1" ]] || return 0
 
-                       case "$cmd" in
-                               setup) _proto_do_setup "$1";;
-                               teardown) _proto_do_teardown "$1" ;;
-                               *) return 1 ;;
-                       esac
-               }
-       ;;
-esac
+                               case "$cmd" in
+                                       setup) _proto_do_setup "$1";;
+                                       teardown) _proto_do_teardown "$1" ;;
+                                       *) return 1 ;;
+                               esac
+                       }
+               ;;
+       esac
+}
index 9a35fc9da292e00f32358bebf1116c292c56da12..50788334c014a1ef92c4f65826e40135dafc371f 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/sh
 
 . ../netifd-proto.sh
+init_proto "$@"
 
 ppp_init_config() {
        proto_config_add_string "username"