Ensure dropbear is installed before disabling telnet (#920)
[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 CONFIG_SECTION=
81 local DIR="./"
82 _C=0
83 [ \! -e "$1" -a -e "/etc/config/$1" ] && {
84 DIR="/etc/config/"
85 }
86 [ -e "$DIR$1" ] && {
87 CONFIG_FILENAME="$DIR$1"
88 . ${CONFIG_FILENAME}
89 } || return 1
90 ${CD:+cd -} >/dev/null
91 ${CONFIG_SECTION:+config_cb}
92 }
93
94 config_get() {
95 case "$3" in
96 "") eval "echo \"\${CONFIG_${1}_${2}}\"";;
97 *) eval "$1=\"\${CONFIG_${2}_${3}}\"";;
98 esac
99 }
100
101 config_set() {
102 export CONFIG_${1}_${2}="${3}"
103 }
104
105 load_modules() {
106 sed 's/^[^#]/insmod &/' $* | ash 2>&- || :
107 }
108
109 include() {
110 for file in $(ls $1/*.sh 2>/dev/null); do
111 . $file
112 done
113 }
114
115 find_mtd_part() {
116 local PART="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
117 PART="${PART##mtd}"
118 echo "${PART:+/dev/mtdblock/$PART}"
119 }
120
This page took 0.062302 seconds and 5 git commands to generate.