avoid using a reserved word as a variable name
[openwrt.git] / package / base-files / default / etc / functions.sh
1 #!/bin/sh
2 # Copyright (C) 2006 OpenWrt.org
3 # Copyright (C) 2006 Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
4
5 alias debug=${DEBUG:-:}
6
7 # newline
8 N="
9 "
10
11 _C=0
12
13 # valid interface?
14 if_valid () (
15 ifconfig "$1" >&- 2>&- ||
16 [ "${1%%[0-9]}" = "br" ] ||
17 { debug "# missing interface '$1' ignored"; false; }
18 )
19
20 hotplug_dev() {
21 env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug net
22 }
23
24 append() {
25 local var="$1"
26 local value="$2"
27 local sep="${3:- }"
28 eval "export ${var}=\"\${${var}:+\${${var}}${value:+$sep}}$value\""
29 }
30
31 reset_cb() {
32 config_cb() {
33 return 0
34 }
35 option_cb() {
36 return 0
37 }
38 }
39 reset_cb
40
41 config () {
42 local cfgtype="$1"
43 local name="$2"
44 _C=$(($_C + 1))
45 name="${name:-cfg${_C}}"
46 config_cb "$cfgtype" "$name"
47 export CONFIG_SECTION="$name"
48 export CONFIG_${CONFIG_SECTION}_TYPE="$cfgtype"
49 }
50
51 option () {
52 local varname="$1"; shift
53 export CONFIG_${CONFIG_SECTION}_${varname}="$*"
54 option_cb "$varname" "$*"
55 }
56
57 config_clear() {
58 [ -z "$CONFIG_SECTION" ] && return
59 for oldsetting in `set | grep ^CONFIG_${CONFIG_SECTION}_ | \
60 sed -e 's/\(.*\)=.*$/\1/'` ; do
61 unset $oldsetting
62 done
63 unset CONFIG_SECTION
64 }
65
66 config_load() {
67 local DIR="./"
68 _C=0
69 [ \! -e "$1" -a -e "/etc/config/$1" ] && {
70 DIR="/etc/config/"
71 }
72 [ -e "$DIR$1" ] && {
73 CONFIG_FILENAME="$DIR$1"
74 . ${CONFIG_FILENAME}
75 } || return 1
76 ${CD:+cd -} >/dev/null
77 ${CONFIG_SECTION:+config_cb}
78 }
79
80 config_get() {
81 case "$3" in
82 "") eval "echo \${CONFIG_${1}_${2}}";;
83 *) eval "$1=\"\${CONFIG_${2}_${3}}\"";;
84 esac
85 }
86
87 config_set() {
88 export CONFIG_${1}_${2}="${3}"
89 }
90
91 load_modules() {
92 sed 's/^[^#]/insmod &/' $* | ash 2>&- || :
93 }
94
95 include() {
96 for file in $(ls /lib/$1/*.sh 2>/dev/null); do
97 . $file
98 done
99 }
This page took 0.047008 seconds and 5 git commands to generate.