remove an obsolete function
[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 hotplug_dev() {
14         env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug net
15 }
16
17 append() {
18         local var="$1"
19         local value="$2"
20         local sep="${3:- }"
21         eval "export ${var}=\"\${${var}:+\${${var}}${value:+$sep}}\$value\""
22 }
23
24 reset_cb() {
25         config_cb() {
26                 return 0
27         }
28         option_cb() {
29                 return 0
30         }
31 }
32 reset_cb
33
34 config () {
35     local cfgtype="$1"
36     local name="$2"
37     _C=$(($_C + 1))
38     name="${name:-cfg${_C}}"
39     config_cb "$cfgtype" "$name"
40     export CONFIG_SECTION="$name"
41     export CONFIG_${CONFIG_SECTION}_TYPE="$cfgtype"
42 }
43
44 option () {
45         local varname="$1"; shift
46         export CONFIG_${CONFIG_SECTION}_${varname}="$*"
47         option_cb "$varname" "$*"
48 }
49
50 config_rename() {
51         local OLD="$1"
52         local NEW="$2"
53         local oldsetting
54         local newvar
55         
56         [ -z "$OLD" -o -z "$NEW" ] && return
57         for oldsetting in `set | grep ^CONFIG_${OLD}_ | \
58                 sed -e 's/\(.*\)=.*$/\1/'` ; do
59                 newvar="CONFIG_${NEW}_${oldsetting##CONFIG_${OLD}_}"
60                 eval "${newvar}=\${$oldsetting}"
61                 unset "$oldsetting"
62         done
63         [ "$CONFIG_SECTION" = "$OLD" ] && CONFIG_SECTION="$NEW"
64 }
65
66 config_unset() {
67         config_set "$1" "$2" ""
68 }
69
70 config_clear() {
71         [ -z "$CONFIG_SECTION" ] && return
72         for oldsetting in `set | grep ^CONFIG_${CONFIG_SECTION}_ | \
73                 sed -e 's/\(.*\)=.*$/\1/'` ; do 
74                 unset $oldsetting 
75         done
76         unset CONFIG_SECTION
77 }
78
79 config_load() {
80         local DIR="./"
81         _C=0
82         [ \! -e "$1" -a -e "/etc/config/$1" ] && {
83                 DIR="/etc/config/"
84         }
85         [ -e "$DIR$1" ] && {
86                 CONFIG_FILENAME="$DIR$1"
87                 . ${CONFIG_FILENAME}
88         } || return 1
89         ${CD:+cd -} >/dev/null
90         ${CONFIG_SECTION:+config_cb}
91 }
92
93 config_get() {
94         case "$3" in
95                 "") eval "echo \"\${CONFIG_${1}_${2}}\"";;
96                 *) eval "$1=\"\${CONFIG_${2}_${3}}\"";;
97         esac
98 }
99
100 config_set() {
101         export CONFIG_${1}_${2}="${3}"
102 }
103
104 load_modules() {
105         sed 's/^[^#]/insmod &/' $* | ash 2>&- || :
106 }
107
108 include() {
109         for file in $(ls $1/*.sh 2>/dev/null); do
110                 . $file
111         done
112 }