wireless: fix channel check
[project/netifd.git] / scripts / utils.sh
1 N="
2 "
3
4 append() {
5         local var="$1"
6         local value="$2"
7         local sep="${3:- }"
8
9         eval "export -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
10 }
11
12 add_default_handler() {
13         case "$(type $1 2>/dev/null)" in
14                 *function*) return;;
15                 *) eval "$1() { return; }"
16         esac
17 }
18
19 set_default() {
20         local __s_var="$1"
21         local __s_val="$2"
22         eval "export -- \"$__s_var=\${$__s_var:-\$__s_val}\""
23 }
24
25 _config_add_generic() {
26         local type="$1"; shift
27
28         for name in "$@"; do
29                 json_add_array ""
30                 json_add_string "" "$name"
31                 json_add_int "" "$type"
32                 json_close_array
33         done
34 }
35
36 config_add_int() {
37         _config_add_generic 5 "$@"
38 }
39
40 config_add_array() {
41         _config_add_generic 1 "$@"
42 }
43
44 config_add_string() {
45         _config_add_generic 3 "$@"
46 }
47
48 config_add_boolean() {
49         _config_add_generic 7 "$@"
50 }