a89a3e91b00bc5df420c01ab7c2ef61121f99d4d
2 # Copyright (C) 2006-2011 OpenWrt.org
3 # Copyright (C) 2006 Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
23 env
-i ACTION
=$1 INTERFACE
=$2 /sbin
/hotplug-call net
31 eval "export ${NO_EXPORT:+-n} -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
39 eval "val=\" \${$var} \""
40 [ "${val%% $str *}" != "$val" ]
48 eval "val=\" \${$var} \""
49 val1
="${val%% $remove *}"
50 [ "$val1" = "$val" ] && return
51 val2
="${val##* $remove }"
52 [ "$val2" = "$val" ] && return
53 val
="${val1## } ${val2%% }"
55 eval "export ${NO_EXPORT:+-n} -- \"$var=\$val\""
59 [ -n "$IPKG_INSTROOT" ] && return 0
64 config_cb
() { return 0; }
65 option_cb
() { return 0; }
66 list_cb
() { return 0; }
78 export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS
=$
(($CONFIG_NUM_SECTIONS + 1))
79 name
="${name:-cfg$CONFIG_NUM_SECTIONS}"
80 append CONFIG_SECTIONS
"$name"
81 [ -n "$NO_CALLBACK" ] || config_cb
"$cfgtype" "$name"
82 export ${NO_EXPORT:+-n} CONFIG_SECTION
="$name"
83 export ${NO_EXPORT:+-n} "CONFIG_${CONFIG_SECTION}_TYPE=$cfgtype"
87 local varname
="$1"; shift
90 export ${NO_EXPORT:+-n} "CONFIG_${CONFIG_SECTION}_${varname}=$value"
91 [ -n "$NO_CALLBACK" ] || option_cb "$varname" "$
*"
95 local varname="$1"; shift
99 config_get len "$CONFIG_SECTION" "${varname}_LENGTH
" 0
100 [ $len = 0 ] && append CONFIG_LIST_STATE "${CONFIG_SECTION}_
${varname}"
102 config_set "$CONFIG_SECTION" "${varname}_ITEM
$len" "$value"
103 config_set "$CONFIG_SECTION" "${varname}_LENGTH
" "$len"
104 append "CONFIG_
${CONFIG_SECTION}_
${varname}" "$value" "$LIST_SEP"
105 list_cb "$varname" "$
*"
114 [ -n "$OLD" -a -n "$NEW" ] || return
115 for oldvar in `set | grep ^CONFIG_${OLD}_ | \
116 sed -e 's/\(.*\)=.*$/\1/'` ; do
117 newvar="CONFIG_
${NEW}_${oldvar##CONFIG_${OLD}_}"
118 eval "export ${NO_EXPORT:+-n} \"$newvar=\
${$oldvar}\""
121 export ${NO_EXPORT:+-n} CONFIG_SECTIONS="$
(echo " $CONFIG_SECTIONS " |
sed -e "s, $OLD , $NEW ,")"
123 [ "$CONFIG_SECTION" = "$OLD" ] && export ${NO_EXPORT:+-n} CONFIG_SECTION="$NEW"
127 config_set "$1" "$2" ""
134 list_remove CONFIG_SECTIONS "$SECTION"
135 export ${NO_EXPORT:+-n} CONFIG_SECTIONS="${SECTION:+$CONFIG_SECTIONS}"
137 for oldvar in `set | grep ^CONFIG_${SECTION:+${SECTION}_} | \
138 sed -e 's/\(.*\)=.*$/\1/'` ; do
143 # config_get <variable> <section> <option> [<default>]
144 # config_get <section> <option>
147 "") eval echo "\
${CONFIG_${1}_${2}:-\${4}}";;
148 *) eval export ${NO_EXPORT:+-n} -- "${1}=\${CONFIG_${2}_${3}:-\${4}}";;
152 # config_get_bool <variable> <section> <option> [<default>]
155 config_get _tmp
"$2" "$3" "$4"
157 1|on|true|enabled
) _tmp
=1;;
158 0|off|false|disabled
) _tmp
=0;;
161 export ${NO_EXPORT:+-n} "$1=$_tmp"
168 local old_section
="$CONFIG_SECTION"
170 CONFIG_SECTION
="$section"
171 option
"$option" "$value"
172 CONFIG_SECTION
="$old_section"
177 [ "$#" -ge 1 ] && shift
179 [ "$#" -ge 1 ] && shift
180 local section cfgtype
182 [ -z "$CONFIG_SECTIONS" ] && return 0
183 for section
in ${CONFIG_SECTIONS}; do
184 config_get cfgtype
"$section" TYPE
185 [ -n "$type" -a "x$cfgtype" != "x$type" ] && continue
186 eval "$function \"\$section\" \"\$@\""
190 config_list_foreach
() {
191 [ "$#" -ge 3 ] ||
return 0
192 local section
="$1"; shift
193 local option
="$1"; shift
194 local function="$1"; shift
199 config_get len
"${section}" "${option}_LENGTH"
200 [ -z "$len" ] && return 0
201 while [ $c -le "$len" ]; do
202 config_get val
"${section}" "${option}_ITEM$c"
203 eval "$function \"\$val\" \"$@\""
209 [ -d /etc
/modules.d
] && {
211 sed 's/^[^#]/insmod &/' $
* | ash
2>&- ||
:
218 for file in $
(ls $1/*.sh
2>/dev
/null
); do
224 local PART
="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
225 local PREFIX
=/dev
/mtdblock
228 [ -d /dev
/mtdblock
] && PREFIX
=/dev
/mtdblock
/
229 echo "${PART:+$PREFIX$PART}"
232 strtok
() { # <string> { <variable> [<separator>] ... }
239 while [ $# -gt 1 ]; do
242 [ "$tmp" = "$val" ] && break
246 export ${NO_EXPORT:+-n} "$1=$tmp"; count
=$
((count
+1))
250 if [ $# -gt 0 -a -n "$val" ]; then
251 export ${NO_EXPORT:+-n} "$1=$val"; count
=$
((count
+1))
259 local part
="$(find_mtd_part "$1")"
261 echo Partition not found.
264 echo -e "\xde\xad\xc0\xde" | mtd
-qq write - "$1"
267 uci_apply_defaults
() {
268 cd /etc
/uci-defaults ||
return 0
270 [ -z "$files" ] && return 0
272 for file in $files; do
273 ( .
"./$(basename $file)" ) && rm -f "$file"
279 # service: simple wrapper around start-stop-daemon
281 # Usage: service ACTION EXEC ARGS...
284 # -C check if EXEC is alive
285 # -S start EXEC, passing it ARGS as its arguments
286 # -K kill EXEC, sending it a TERM signal if not specified otherwise
288 # Environment variables exposed:
289 # SERVICE_DAEMONIZE run EXEC in background
290 # SERVICE_WRITE_PID create a pid file and use it
291 # SERVICE_USE_PID assume EXEC creates its own pid file and use it
292 # SERVICE_PID_FILE pid file to use (default to /var/run/EXEC.pid)
293 # SERVICE_SIG signal to send when using -K
294 # SERVICE_SIG_RELOAD default signal used for reloading
295 # SERVICE_SIG_STOP default signal used for stopping
296 # SERVICE_STOP_TIME time to wait for a process to stop gracefully before killing it
297 # SERVICE_UID user EXEC should be run as
298 # SERVICE_GID group EXEC should be run as
300 # SERVICE_DEBUG don't do anything, but show what would be done
301 # SERVICE_QUIET don't print anything
305 SERVICE_SIG_RELOAD
="HUP"
306 SERVICE_SIG_STOP
="TERM"
311 ssd
="${SERVICE_DEBUG:+echo }start-stop-daemon${SERVICE_QUIET:+ -q}"
317 ssd
="$ssd -S${SERVICE_DAEMONIZE:+ -b}${SERVICE_WRITE_PID:+ -m}"
320 ssd
="$ssd -K${SERVICE_SIG:+ -s $SERVICE_SIG}"
323 echo "ssd: unknow action '$1'" 1>&2
328 echo "ssd: missing arguments" 1>&2
332 if [ -n "$SERVICE_PID_FILE$SERVICE_USE_PID$SERVICE_WRITE_PID" ]; then
333 ssd
="$ssd -p ${SERVICE_PID_FILE:-/var/run/${1##*/}.pid}"
335 ssd
="$ssd${SERVICE_UID:+ -c $SERVICE_UID${SERVICE_GID:+:$SERVICE_GID}}"
345 SERVICE_SIG
="${SERVICE_SIG:-USR1}" service
-K "$@"
354 SERVICE_SIG
="${SERVICE_SIG:-$SERVICE_SIG_STOP}" service
-K "$@" ||
return 1
355 while [ $
((try
++)) -lt $SERVICE_STOP_TIME ]; do
356 service
-C "$@" ||
return 0
359 SERVICE_SIG
="KILL" service
-K "$@"
365 SERVICE_SIG
="${SERVICE_SIG:-$SERVICE_SIG_RELOAD}" service
-K "$@"
369 cat 1>&2 << __END_OF_WARNING__
371 # WARNING: the 'service_kill' function is now deprecated and might be
372 # removed soon. Consider using the other new service_* wrappers instead.
376 local pid
="${2:-$(pidof "$name")}"
377 local grace
="${3:-5}"
379 [ -f "$pid" ] && pid
="$(head -n1 "$pid" 2>/dev/null)"
382 [ -d "/proc/$pid" ] ||
continue
384 kill -TERM $pid 2>/dev
/null
&& \
385 while grep -qs "$name" "/proc/$pid/cmdline" && [ $
((try
++)) -lt $grace ]; do sleep 1; done
386 kill -KILL $pid 2>/dev
/null
&& \
387 while grep -qs "$name" "/proc/$pid/cmdline"; do sleep 1; done
396 [ -f "${IPKG_INSTROOT}/etc/group" ] ||
return 1
397 [ -n "$IPKG_INSTROOT" ] || lock
/var
/lock
/group
398 echo "${name}:x:${gid}:" >> ${IPKG_INSTROOT}/etc/group
400 [ -n "$IPKG_INSTROOT" ] || lock -u /var/lock/group
405 grep -qs "^
${1}:" ${IPKG_INSTROOT}/etc/group
412 local desc="${4:-$1}"
413 local home="${5:-/var/run/$1}"
414 local shell="${6:-/bin/false}"
416 [ -f "${IPKG_INSTROOT}/etc
/passwd
" ] || return 1
417 [ -n "$IPKG_INSTROOT" ] || lock /var/lock/passwd
418 echo "${name}:x:${uid}:${gid}:${desc}:${home}:${shell}" >> ${IPKG_INSTROOT}/etc
/passwd
420 [ -n "$IPKG_INSTROOT" ] || lock
-u /var
/lock
/passwd
425 grep -qs "^${1}:" ${IPKG_INSTROOT}/etc
/passwd
430 if [ -f "/tmp/overlay/$1" ]; then
432 elif [ -f "$1" ]; then
434 elif [ -d "/tmp/overlay/$1" ]; then
435 if [ -n "$(ls /tmp/overlay/$1/*.sh 2>/dev/null)" ]; then
436 for src_script
in /tmp
/overlay
/$1/*.sh
; do
440 elif [ -d "$1" ]; then
441 if [ -n "$(ls $1/*.sh 2>/dev/null)" ]; then
442 for src_script
in $1/*.sh
; do
447 echo "WARNING: $1 not found"
453 [ -z "$IPKG_INSTROOT" -a -f /lib
/config
/uci.sh
] && .
/lib
/config
/uci.sh
This page took 0.069368 seconds and 3 git commands to generate.