2005-11-19 03:17:20 +00:00
|
|
|
#!/bin/sh
|
2006-06-27 00:36:13 +00:00
|
|
|
# Copyright (C) 2006 OpenWrt.org
|
2006-07-29 19:59:45 +00:00
|
|
|
# Copyright (C) 2006 Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
|
2006-06-27 00:36:13 +00:00
|
|
|
|
2005-02-06 00:52:16 +00:00
|
|
|
alias debug=${DEBUG:-:}
|
2008-08-25 05:21:42 +00:00
|
|
|
alias mount='busybox mount'
|
2005-02-06 00:52:16 +00:00
|
|
|
|
2006-06-19 21:45:07 +00:00
|
|
|
# newline
|
2006-11-23 18:22:06 +00:00
|
|
|
N="
|
2006-06-19 21:45:07 +00:00
|
|
|
"
|
|
|
|
|
2006-06-25 15:32:30 +00:00
|
|
|
_C=0
|
2007-02-26 20:04:04 +00:00
|
|
|
NO_EXPORT=1
|
2008-02-03 06:48:15 +00:00
|
|
|
LOAD_STATE=1
|
2008-08-20 15:38:51 +00:00
|
|
|
LIST_SEP=" "
|
2006-06-25 15:32:30 +00:00
|
|
|
|
2005-11-19 03:17:20 +00:00
|
|
|
hotplug_dev() {
|
2007-03-04 20:31:53 +00:00
|
|
|
env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug-call net
|
2005-10-22 20:47:19 +00:00
|
|
|
}
|
2006-05-10 18:17:12 +00:00
|
|
|
|
2006-06-19 21:45:07 +00:00
|
|
|
append() {
|
|
|
|
local var="$1"
|
|
|
|
local value="$2"
|
|
|
|
local sep="${3:- }"
|
2006-11-21 02:13:08 +00:00
|
|
|
|
2007-02-26 20:04:04 +00:00
|
|
|
eval "export ${NO_EXPORT:+-n} -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
|
2006-06-19 21:45:07 +00:00
|
|
|
}
|
|
|
|
|
2008-07-30 22:39:43 +00:00
|
|
|
list_contains() {
|
|
|
|
local var="$1"
|
|
|
|
local str="$2"
|
|
|
|
local val
|
|
|
|
|
|
|
|
eval "val=\" \${$var} \""
|
|
|
|
[ "${val%% $str *}" != "$val" ]
|
|
|
|
}
|
|
|
|
|
2008-07-30 20:35:22 +00:00
|
|
|
list_remove() {
|
|
|
|
local var="$1"
|
|
|
|
local remove="$2"
|
|
|
|
local val
|
|
|
|
|
|
|
|
eval "val=\" \${$var} \""
|
|
|
|
val1="${val%% $remove *}"
|
|
|
|
[ "$val1" = "$val" ] && return
|
|
|
|
val2="${val##* $remove }"
|
|
|
|
[ "$val2" = "$val" ] && return
|
|
|
|
val="${val1## } ${val2%% }"
|
2008-07-31 03:04:32 +00:00
|
|
|
val="${val%% }"
|
2008-07-30 20:35:22 +00:00
|
|
|
eval "export ${NO_EXPORT:+-n} -- \"$var=\$val\""
|
|
|
|
}
|
|
|
|
|
2008-02-03 06:48:15 +00:00
|
|
|
config_load() {
|
|
|
|
[ -n "$IPKG_INSTROOT" ] && return 0
|
|
|
|
uci_load "$@"
|
|
|
|
}
|
|
|
|
|
2006-06-25 15:32:30 +00:00
|
|
|
reset_cb() {
|
2006-11-21 02:13:08 +00:00
|
|
|
config_cb() { return 0; }
|
|
|
|
option_cb() { return 0; }
|
2008-08-20 15:38:51 +00:00
|
|
|
list_cb() { return 0; }
|
2006-05-10 18:17:12 +00:00
|
|
|
}
|
2006-06-25 15:32:30 +00:00
|
|
|
reset_cb
|
2006-05-10 18:17:12 +00:00
|
|
|
|
2008-02-03 06:48:15 +00:00
|
|
|
package() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2006-05-10 18:17:12 +00:00
|
|
|
config () {
|
2006-11-21 02:13:08 +00:00
|
|
|
local cfgtype="$1"
|
|
|
|
local name="$2"
|
2006-12-20 04:15:13 +00:00
|
|
|
|
2007-02-26 20:04:04 +00:00
|
|
|
export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS=$(($CONFIG_NUM_SECTIONS + 1))
|
2006-12-20 04:15:13 +00:00
|
|
|
name="${name:-cfg$CONFIG_NUM_SECTIONS}"
|
|
|
|
append CONFIG_SECTIONS "$name"
|
2007-04-11 19:34:20 +00:00
|
|
|
[ -n "$NO_CALLBACK" ] || config_cb "$cfgtype" "$name"
|
2007-02-26 20:04:04 +00:00
|
|
|
export ${NO_EXPORT:+-n} CONFIG_SECTION="$name"
|
|
|
|
export ${NO_EXPORT:+-n} "CONFIG_${CONFIG_SECTION}_TYPE=$cfgtype"
|
2006-05-10 18:17:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
option () {
|
2006-07-29 19:59:45 +00:00
|
|
|
local varname="$1"; shift
|
2006-11-22 13:32:24 +00:00
|
|
|
local value="$*"
|
2008-08-20 15:38:51 +00:00
|
|
|
|
2007-02-26 20:04:04 +00:00
|
|
|
export ${NO_EXPORT:+-n} "CONFIG_${CONFIG_SECTION}_${varname}=$value"
|
2007-04-11 19:34:20 +00:00
|
|
|
[ -n "$NO_CALLBACK" ] || option_cb "$varname" "$*"
|
2006-05-10 18:17:12 +00:00
|
|
|
}
|
|
|
|
|
2008-08-20 15:38:51 +00:00
|
|
|
list() {
|
|
|
|
local varname="$1"; shift
|
|
|
|
local value="$*"
|
|
|
|
local len
|
|
|
|
|
|
|
|
config_get len "$CONFIG_SECTION" "${varname}_LENGTH"
|
|
|
|
len="$((${len:-0} + 1))"
|
|
|
|
config_set "$CONFIG_SECTION" "${varname}_ITEM$len" "$value"
|
|
|
|
config_set "$CONFIG_SECTION" "${varname}_LENGTH" "$len"
|
|
|
|
append "CONFIG_${CONFIG_SECTION}_${varname}" "$value" "$LIST_SEP"
|
|
|
|
list_cb "$varname" "$*"
|
|
|
|
}
|
|
|
|
|
2006-10-09 05:59:26 +00:00
|
|
|
config_rename() {
|
|
|
|
local OLD="$1"
|
|
|
|
local NEW="$2"
|
2006-11-21 02:13:08 +00:00
|
|
|
local oldvar
|
2006-10-09 05:59:26 +00:00
|
|
|
local newvar
|
|
|
|
|
2007-06-15 15:59:56 +00:00
|
|
|
[ -n "$OLD" -a -n "$NEW" ] || return
|
2006-11-21 02:13:08 +00:00
|
|
|
for oldvar in `set | grep ^CONFIG_${OLD}_ | \
|
2006-10-09 05:59:26 +00:00
|
|
|
sed -e 's/\(.*\)=.*$/\1/'` ; do
|
2006-11-21 02:13:08 +00:00
|
|
|
newvar="CONFIG_${NEW}_${oldvar##CONFIG_${OLD}_}"
|
2007-02-26 20:04:04 +00:00
|
|
|
eval "export ${NO_EXPORT:+-n} \"$newvar=\${$oldvar}\""
|
2006-11-21 02:13:08 +00:00
|
|
|
unset "$oldvar"
|
2006-10-09 05:59:26 +00:00
|
|
|
done
|
2007-02-26 20:04:04 +00:00
|
|
|
export ${NO_EXPORT:+-n} CONFIG_SECTIONS="$(echo " $CONFIG_SECTIONS " | sed -e "s, $OLD , $NEW ,")"
|
2006-11-21 02:13:08 +00:00
|
|
|
|
2007-02-26 20:04:04 +00:00
|
|
|
[ "$CONFIG_SECTION" = "$OLD" ] && export ${NO_EXPORT:+-n} CONFIG_SECTION="$NEW"
|
2006-10-09 05:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
config_unset() {
|
|
|
|
config_set "$1" "$2" ""
|
|
|
|
}
|
|
|
|
|
2006-05-10 18:17:12 +00:00
|
|
|
config_clear() {
|
2006-11-21 02:13:08 +00:00
|
|
|
local SECTION="$1"
|
|
|
|
local oldvar
|
2008-07-31 03:04:32 +00:00
|
|
|
|
|
|
|
list_remove CONFIG_SECTIONS "$SECTION"
|
2007-02-26 20:04:04 +00:00
|
|
|
export ${NO_EXPORT:+-n} CONFIG_SECTIONS="${SECTION:+$CONFIG_SECTIONS}"
|
2006-12-20 04:15:13 +00:00
|
|
|
|
2007-01-29 22:07:17 +00:00
|
|
|
for oldvar in `set | grep ^CONFIG_${SECTION:+${SECTION}_} | \
|
2006-05-10 18:17:12 +00:00
|
|
|
sed -e 's/\(.*\)=.*$/\1/'` ; do
|
2006-11-21 02:13:08 +00:00
|
|
|
unset $oldvar
|
2006-05-10 18:17:12 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
config_get() {
|
|
|
|
case "$3" in
|
2006-10-09 05:59:26 +00:00
|
|
|
"") eval "echo \"\${CONFIG_${1}_${2}}\"";;
|
2007-02-26 20:04:04 +00:00
|
|
|
*) eval "export ${NO_EXPORT:+-n} -- \"$1=\${CONFIG_${2}_${3}}\"";;
|
2006-05-10 18:17:12 +00:00
|
|
|
esac
|
2007-02-27 23:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# config_get_bool <variable> <section> <option> [<default>]
|
|
|
|
config_get_bool() {
|
|
|
|
local _tmp
|
|
|
|
config_get "_tmp" "$2" "$3"
|
|
|
|
case "$_tmp" in
|
2007-09-19 14:43:29 +00:00
|
|
|
1|on|true|enabled) export ${NO_EXPORT:+-n} "$1=1";;
|
|
|
|
0|off|false|disabled) export ${NO_EXPORT:+-n} "$1=0";;
|
2007-11-28 19:02:46 +00:00
|
|
|
*) eval "$1=$4";;
|
2007-02-27 23:09:57 +00:00
|
|
|
esac
|
2006-05-10 18:17:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
config_set() {
|
2006-11-22 13:32:24 +00:00
|
|
|
local section="$1"
|
|
|
|
local option="$2"
|
|
|
|
local value="$3"
|
2007-03-24 13:43:04 +00:00
|
|
|
local old_section="$CONFIG_SECTION"
|
|
|
|
|
|
|
|
CONFIG_SECTION="$section"
|
|
|
|
option "$option" "$value"
|
|
|
|
CONFIG_SECTION="$old_section"
|
2006-05-10 18:17:12 +00:00
|
|
|
}
|
2006-05-30 19:38:38 +00:00
|
|
|
|
2006-12-20 04:15:13 +00:00
|
|
|
config_foreach() {
|
|
|
|
local function="$1"
|
2007-07-22 16:55:31 +00:00
|
|
|
[ "$#" -ge 1 ] && shift
|
|
|
|
local type="$1"
|
|
|
|
[ "$#" -ge 1 ] && shift
|
2007-03-02 15:48:29 +00:00
|
|
|
local section cfgtype
|
2006-12-20 04:15:13 +00:00
|
|
|
|
|
|
|
[ -z "$CONFIG_SECTIONS" ] && return 0
|
|
|
|
for section in ${CONFIG_SECTIONS}; do
|
2007-03-02 15:48:29 +00:00
|
|
|
config_get cfgtype "$section" TYPE
|
2007-06-15 15:59:56 +00:00
|
|
|
[ -n "$type" -a "x$cfgtype" != "x$type" ] && continue
|
2007-07-22 16:55:31 +00:00
|
|
|
eval "$function \"\$section\" \"\$@\""
|
2006-12-20 04:15:13 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2008-08-20 15:38:51 +00:00
|
|
|
config_list_foreach() {
|
|
|
|
[ "$#" -ge 3 ] || return 0
|
|
|
|
local section="$1"; shift
|
|
|
|
local option="$1"; shift
|
|
|
|
local function="$1"; shift
|
|
|
|
local val
|
|
|
|
local len
|
|
|
|
local c=1
|
|
|
|
|
|
|
|
config_get len "${section}" "${option}_LENGTH"
|
|
|
|
[ -z "$len" ] && return 0
|
|
|
|
while [ $c -le "$len" ]; do
|
|
|
|
config_get val "${section}" "${option}_ITEM$c"
|
|
|
|
eval "$function \"\$val\" \"$@\""
|
|
|
|
c="$(($c + 1))"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2006-05-30 19:38:38 +00:00
|
|
|
load_modules() {
|
2007-05-31 15:58:43 +00:00
|
|
|
[ -d /etc/modules.d ] && {
|
|
|
|
cd /etc/modules.d
|
|
|
|
sed 's/^[^#]/insmod &/' $* | ash 2>&- || :
|
|
|
|
}
|
2006-05-30 19:38:38 +00:00
|
|
|
}
|
2006-07-29 19:59:45 +00:00
|
|
|
|
|
|
|
include() {
|
2006-11-21 02:13:08 +00:00
|
|
|
local file
|
|
|
|
|
2006-09-24 13:32:18 +00:00
|
|
|
for file in $(ls $1/*.sh 2>/dev/null); do
|
2006-07-29 19:59:45 +00:00
|
|
|
. $file
|
|
|
|
done
|
|
|
|
}
|
2006-10-26 01:35:50 +00:00
|
|
|
|
|
|
|
find_mtd_part() {
|
|
|
|
local PART="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
|
2007-03-02 19:01:49 +00:00
|
|
|
local PREFIX=/dev/mtdblock
|
2006-11-21 02:13:08 +00:00
|
|
|
|
2006-10-26 01:35:50 +00:00
|
|
|
PART="${PART##mtd}"
|
2007-03-02 19:01:49 +00:00
|
|
|
[ -d /dev/mtdblock ] && PREFIX=/dev/mtdblock/
|
|
|
|
echo "${PART:+$PREFIX$PART}"
|
2006-10-26 01:35:50 +00:00
|
|
|
}
|
|
|
|
|
2006-11-21 02:13:08 +00:00
|
|
|
strtok() { # <string> { <variable> [<separator>] ... }
|
|
|
|
local tmp
|
|
|
|
local val="$1"
|
2006-11-20 19:30:50 +00:00
|
|
|
local count=0
|
|
|
|
|
|
|
|
shift
|
|
|
|
|
|
|
|
while [ $# -gt 1 ]; do
|
2006-11-21 02:13:08 +00:00
|
|
|
tmp="${val%%$2*}"
|
2006-11-20 19:30:50 +00:00
|
|
|
|
2006-11-21 02:13:08 +00:00
|
|
|
[ "$tmp" = "$val" ] && break
|
2006-11-20 19:30:50 +00:00
|
|
|
|
2006-11-21 02:13:08 +00:00
|
|
|
val="${val#$tmp$2}"
|
2006-11-20 19:30:50 +00:00
|
|
|
|
2007-02-26 20:04:04 +00:00
|
|
|
export ${NO_EXPORT:+-n} "$1=$tmp"; count=$((count+1))
|
2006-11-20 19:30:50 +00:00
|
|
|
shift 2
|
|
|
|
done
|
|
|
|
|
2007-06-15 15:59:56 +00:00
|
|
|
if [ $# -gt 0 -a -n "$val" ]; then
|
2007-02-26 20:04:04 +00:00
|
|
|
export ${NO_EXPORT:+-n} "$1=$val"; count=$((count+1))
|
2006-11-20 19:30:50 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
return $count
|
|
|
|
}
|
2007-04-16 23:29:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
jffs2_mark_erase() {
|
|
|
|
local part="$(find_mtd_part "$1")"
|
|
|
|
[ -z "$part" ] && {
|
|
|
|
echo Partition not found.
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
echo -e "\xde\xad\xc0\xde" | mtd -qq write - "$1"
|
|
|
|
}
|
2008-01-02 17:10:16 +00:00
|
|
|
|
2008-02-03 06:48:15 +00:00
|
|
|
uci_apply_defaults() {(
|
|
|
|
cd /etc/uci-defaults || return 0
|
|
|
|
files="$(ls)"
|
|
|
|
[ -z "$files" ] && return 0
|
|
|
|
mkdir -p /tmp/.uci
|
|
|
|
for file in $files; do
|
|
|
|
( . "./$(basename $file)" ) && rm -f "$file"
|
|
|
|
done
|
|
|
|
uci commit
|
|
|
|
)}
|
|
|
|
|
2008-02-05 01:47:47 +00:00
|
|
|
[ -z "$IPKG_INSTROOT" -a -f /lib/config/uci.sh ] && . /lib/config/uci.sh
|