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:-:}
|
|
|
|
|
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
|
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
|
|
|
}
|
|
|
|
|
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; }
|
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
|
|
|
|
|
|
|
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="$*"
|
2006-11-21 02:13:08 +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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2006-11-21 02:13:08 +00:00
|
|
|
[ "$OLD" -a "$NEW" ] || return
|
|
|
|
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
|
|
|
|
|
2007-02-26 20:04:04 +00:00
|
|
|
export ${NO_EXPORT:+-n} CONFIG_SECTIONS="$(echo " $CONFIG_SECTIONS " | sed -e "s, $OLD , ,")"
|
|
|
|
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_load() {
|
2007-02-26 20:04:04 +00:00
|
|
|
local file="$UCI_ROOT/etc/config/$1"
|
2006-06-25 15:32:30 +00:00
|
|
|
_C=0
|
2007-02-26 20:04:04 +00:00
|
|
|
export ${NO_EXPORT:+-n} CONFIG_SECTIONS=
|
|
|
|
export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS=0
|
|
|
|
export ${NO_EXPORT:+-n} CONFIG_SECTION=
|
2006-11-21 02:13:08 +00:00
|
|
|
|
|
|
|
[ -e "$file" ] && {
|
|
|
|
. $file
|
2006-06-25 15:32:30 +00:00
|
|
|
} || return 1
|
2006-11-21 02:13:08 +00:00
|
|
|
|
2006-05-10 18:17:12 +00:00
|
|
|
${CONFIG_SECTION:+config_cb}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
1|on|enabled) export ${NO_EXPORT:+-n} "$1=1";;
|
|
|
|
0|off|disabled) export ${NO_EXPORT:+-n} "$1=0";;
|
|
|
|
*) eval "$1=${4:-0}";;
|
|
|
|
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-03-02 15:48:29 +00:00
|
|
|
local type="$2"
|
|
|
|
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
|
|
|
|
[ -n "$type" -a "$cfgtype" != "$type" ] && continue
|
2006-12-20 04:15:13 +00:00
|
|
|
eval "$function \"\$section\""
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2006-05-30 19:38:38 +00:00
|
|
|
load_modules() {
|
2006-11-23 18:22:06 +00:00
|
|
|
cd /etc/modules.d
|
2006-05-30 19:38:38 +00:00
|
|
|
sed 's/^[^#]/insmod &/' $* | ash 2>&- || :
|
|
|
|
}
|
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
|
|
|
|
|
2006-11-21 02:13:08 +00:00
|
|
|
if [ $# -gt 0 -a "$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"
|
|
|
|
}
|