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