scripts: move some utility functions out of netifd-proto.sh into utils.sh
authorFelix Fietkau <nbd@openwrt.org>
Tue, 24 Sep 2013 07:42:17 +0000 (09:42 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 19 Oct 2013 15:31:56 +0000 (17:31 +0200)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
examples/proto/ppp.sh
examples/proto/pptp.sh
scripts/netifd-proto.sh
scripts/utils.sh [new file with mode: 0644]

index f0d0ca3efb9581c8a11e4dd11a39424945ce23e1..4750f4003e471e3fb29dbf2b4ea5c8595fcb9a0c 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
-DUMMY=1
-. ../../scripts/netifd-proto.sh
+NETIFD_MAIN_DIR=../../scripts
+. $NETIFD_MAIN_DIR/netifd-proto.sh
 
 init_proto "$@"
 
index 5189e95287996094a8e2b0d3f10560595db92f6e..7c8a13daf9f444a58f774ce49749861f0f3d2cee 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/sh
-. ../../scripts/netifd-proto.sh
+NETIFD_MAIN_DIR=../../scripts
+. $NETIFD_MAIN_DIR/netifd-proto.sh
+
 init_proto "$@"
 
 proto_pptp_init_config() {
index 6f20de91a7ce464fa4612dae7a2bff83f01b1ba5..76dcd8dcae777213383642c970e42e802f95377e 100755 (executable)
@@ -1,37 +1,18 @@
-. /usr/share/libubox/jshn.sh
-
-append() {
-       local var="$1"
-       local value="$2"
-       local sep="${3:- }"
-
-       eval "export -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
-}
+NETIFD_MAIN_DIR="${NETIFD_MAIN_DIR:-/lib/netifd}"
 
-proto_config_add_generic() {
-       json_add_array ""
-       json_add_string "" "$1"
-       json_add_int "" "$2"
-       json_close_array
-}
+. /usr/share/libubox/jshn.sh
+. $NETIFD_MAIN_DIR/utils.sh
 
 proto_config_add_int() {
-       proto_config_add_generic "$1" 5
+       _config_add_generic "$1" 5
 }
 
 proto_config_add_string() {
-       proto_config_add_generic "$1" 3
+       _config_add_generic "$1" 3
 }
 
 proto_config_add_boolean() {
-       proto_config_add_generic "$1" 7
-}
-
-add_default_handler() {
-       case "$(type $1 2>/dev/null)" in
-               *function*) return;;
-               *) eval "$1() { return; }"
-       esac
+       _config_add_generic "$1" 7
 }
 
 _proto_do_teardown() {
diff --git a/scripts/utils.sh b/scripts/utils.sh
new file mode 100644 (file)
index 0000000..6a137c0
--- /dev/null
@@ -0,0 +1,33 @@
+append() {
+       local var="$1"
+       local value="$2"
+       local sep="${3:- }"
+
+       eval "export -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
+}
+
+add_default_handler() {
+       case "$(type $1 2>/dev/null)" in
+               *function*) return;;
+               *) eval "$1() { return; }"
+       esac
+}
+
+_config_add_generic() {
+       json_add_array ""
+       json_add_string "" "$1"
+       json_add_int "" "$2"
+       json_close_array
+}
+
+config_add_int() {
+       _config_add_generic "$1" 5
+}
+
+config_add_string() {
+       _config_add_generic "$1" 3
+}
+
+config_add_boolean() {
+       _config_add_generic "$1" 7
+}