add a list append function to functions.sh
[openwrt.git] / package / base-files / default / etc / functions.sh
1 #!/bin/sh
2 alias debug=${DEBUG:-:}
3
4 # newline
5 N="
6 "
7
8 # valid interface?
9 if_valid () (
10 ifconfig "$1" >&- 2>&- ||
11 [ "${1%%[0-9]}" = "br" ] ||
12 { debug "# missing interface '$1' ignored"; false; }
13 )
14
15 hotplug_dev() {
16 env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug net
17 }
18
19 append() {
20 local var="$1"
21 local value="$2"
22 local sep="${3:- }"
23 eval "export ${var}=\"\${${var}:+\${${var}}${value:+$sep}}$value\""
24 }
25
26 config_cb() {
27 return 0
28 }
29 option_cb() {
30 return 0
31 }
32
33 config () {
34 config_cb "$@"
35 _C=$((${_C:-0} + 1))
36 export CONFIG_SECTION="${2:-cfg${_C}}"
37 export CONFIG_${CONFIG_SECTION}_TYPE="$1"
38 }
39
40 option () {
41 local varname="$1" ; shift
42 export CONFIG_${CONFIG_SECTION}_${varname}="$*"
43 option_cb "$varname" "$*"
44 }
45
46 config_clear() {
47 [ -z "$CONFIG_SECTION" ] && return
48 for oldsetting in `set | grep ^CONFIG_${CONFIG_SECTION}_ | \
49 sed -e 's/\(.*\)=.*$/\1/'` ; do
50 unset $oldsetting
51 done
52 unset CONFIG_SECTION
53 }
54
55 config_load() {
56 local CD=""
57 if [ \! -e "$1" -a -e "/etc/config/$1" ]; then
58 cd /etc/config && local CD=1
59 fi
60 [ -e "$1" ] && . $1
61 ${CD:+cd - >/dev/null}
62 ${CONFIG_SECTION:+config_cb}
63 }
64
65 config_get() {
66 case "$3" in
67 "") eval "echo \${CONFIG_${1}_${2}}";;
68 *) eval "$1=\"\${CONFIG_${2}_${3}}\"";;
69 esac
70 }
71
72 config_set() {
73 export CONFIG_${1}_${2}="${3}"
74 }
75
76 load_modules() {
77 sed 's/^[^#]/insmod &/' $* | ash 2>&- || :
78 }
This page took 0.057486 seconds and 5 git commands to generate.