[packages] libnetfilter-conntrack: update to v0.0.101 (#6466)
[openwrt/svn-archive/archive.git] / net / mac-to-devinfo / files / devinfo-functions.sh
1 #!/bin/sh
2 # Shell script compatibility wrappers for /sbin/uci
3 #
4 # Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
5 # Copyright (C) 2009 Daniel Dickinson <crazycshore@gmail.com>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21 # $UCI and $UCISTATE must be set
22
23 CONFIG_APPEND=
24 _C=0
25 LOAD_STATE=1
26 LIST_SEP=" "
27
28 config_load() {
29 local PACKAGE="$1"
30 local DATA
31 local RET
32
33 _C=0
34
35 if [ -z "$CONFIG_APPEND" ]; then
36 CONFIG_SECTIONS=
37 CONFIG_NUM_SECTIONS=0
38 CONFIG_SECTION=
39 fi
40 export NO_EXPORT=
41 DATA="$($UCI -P $UCISTATE -S -n export "$PACKAGE" 2>/dev/null)"
42 RET="$?"
43 [ "$RET" != 0 -o -z "$DATA" ] || eval "$DATA"
44 unset DATA
45
46 ${CONFIG_SECTION:+config_cb}
47 return "$RET"
48 }
49
50 reset_cb() {
51 config_cb() { return 0; }
52 option_cb() { return 0; }
53 list_cb() { return 0; }
54 }
55 reset_cb
56 config () {
57 local cfgtype="$1"
58 local name="$2"
59
60 CONFIG_NUM_SECTIONS=$(($CONFIG_NUM_SECTIONS + 1))
61 name="${name:-cfg$CONFIG_NUM_SECTIONS}"
62 append CONFIG_SECTIONS "$name"
63 [ -n "$NO_CALLBACK" ] || config_cb "$cfgtype" "$name"
64 CONFIG_SECTION="$name"
65 eval "CONFIG_${CONFIG_SECTION}_TYPE=\"$cfgtype\""
66 }
67
68 option () {
69 local varname="$1"; shift
70 local value="$*"
71
72 eval "CONFIG_${CONFIG_SECTION}_${varname}=\"$value\""
73 [ -n "$NO_CALLBACK" ] || option_cb "$varname" "$*"
74 }
75
76 list() {
77 local varname="$1"; shift
78 local value="$*"
79 local len
80
81 config_get len "$CONFIG_SECTION" "${varname}_LENGTH"
82 len="$((${len:-0} + 1))"
83 config_set "$CONFIG_SECTION" "${varname}_ITEM$len" "$value"
84 config_set "$CONFIG_SECTION" "${varname}_LENGTH" "$len"
85 append "CONFIG_${CONFIG_SECTION}_${varname}" "$value" "$LIST_SEP"
86 list_cb "$varname" "$*"
87 }
88
89 config_get() {
90 case "$3" in
91 "") eval "echo \"\${CONFIG_${1}_${2}}\"";;
92 *) eval "$1=\${CONFIG_${2}_${3}}";;
93 esac
94 }
95
96 config_foreach() {
97 local function="$1"
98 [ "$#" -ge 1 ] && shift
99 local type="$1"
100 [ "$#" -ge 1 ] && shift
101 local section cfgtype
102
103 [ -z "$CONFIG_SECTIONS" ] && return 0
104 for section in ${CONFIG_SECTIONS}; do
105 config_get cfgtype "$section" TYPE
106 [ -n "$type" -a "x$cfgtype" != "x$type" ] && continue
107 $function "$section" "$@"
108 done
109 }
110
111 package() {
112 return 0
113 }
114
115 append() {
116 local var="$1"
117 local value="$2"
118 local sep="${3:- }"
119
120 eval "$var=\${$var:+\${$var}\${value:+\$sep}}\$value"
121 }
122