diff options
author | Felix Fietkau <nbd@openwrt.org> | 2013-09-24 09:42:17 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2013-10-19 17:31:56 +0200 |
commit | bdb28375d9872a49f7008fbdf2d8a1fad3790344 (patch) | |
tree | d19e3fbe117226b159dc97a953c95986f1b04008 /scripts | |
parent | c8e879595400e3485b5a075797290a1061c0b04f (diff) |
scripts: move some utility functions out of netifd-proto.sh into utils.sh
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/netifd-proto.sh | 31 | ||||
-rw-r--r-- | scripts/utils.sh | 33 |
2 files changed, 39 insertions, 25 deletions
diff --git a/scripts/netifd-proto.sh b/scripts/netifd-proto.sh index 6f20de9..76dcd8d 100755 --- a/scripts/netifd-proto.sh +++ b/scripts/netifd-proto.sh @@ -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 index 0000000..6a137c0 --- /dev/null +++ b/scripts/utils.sh @@ -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 +} |