Check for modules.d existence before loading modules
[openwrt.git] / package / base-files / files / etc / functions.sh
index 931f4be..f757ffa 100755 (executable)
@@ -12,7 +12,7 @@ _C=0
 NO_EXPORT=1
 
 hotplug_dev() {
-       env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug net
+       env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug-call net
 }
 
 append() {
@@ -36,7 +36,7 @@ config () {
        export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS=$(($CONFIG_NUM_SECTIONS + 1))
        name="${name:-cfg$CONFIG_NUM_SECTIONS}"
        append CONFIG_SECTIONS "$name"
-       config_cb "$cfgtype" "$name"
+       [ -n "$NO_CALLBACK" ] || config_cb "$cfgtype" "$name"
        export ${NO_EXPORT:+-n} CONFIG_SECTION="$name"
        export ${NO_EXPORT:+-n} "CONFIG_${CONFIG_SECTION}_TYPE=$cfgtype"
 }
@@ -46,7 +46,7 @@ option () {
        local value="$*"
        
        export ${NO_EXPORT:+-n} "CONFIG_${CONFIG_SECTION}_${varname}=$value"
-       option_cb "$varname" "$*"
+       [ -n "$NO_CALLBACK" ] || option_cb "$varname" "$*"
 }
 
 config_rename() {
@@ -120,22 +120,31 @@ config_set() {
        local section="$1"
        local option="$2"
        local value="$3"
-       export ${NO_EXPORT:+-n} "CONFIG_${section}_${option}=$value"
+       local old_section="$CONFIG_SECTION"
+
+       CONFIG_SECTION="$section"
+       option "$option" "$value"
+       CONFIG_SECTION="$old_section"
 }
 
 config_foreach() {
        local function="$1"
-       local section
+       local type="$2"
+       local section cfgtype
        
        [ -z "$CONFIG_SECTIONS" ] && return 0
        for section in ${CONFIG_SECTIONS}; do
+               config_get cfgtype "$section" TYPE
+               [ -n "$type" -a "$cfgtype" != "$type" ] && continue
                eval "$function \"\$section\""
        done
 }
 
 load_modules() {
-       cd /etc/modules.d
-       sed 's/^[^#]/insmod &/' $* | ash 2>&- || :
+       [ -d /etc/modules.d ] && {
+               cd /etc/modules.d
+               sed 's/^[^#]/insmod &/' $* | ash 2>&- || :
+       }
 }
 
 include() {
@@ -148,9 +157,11 @@ include() {
 
 find_mtd_part() {
        local PART="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
+       local PREFIX=/dev/mtdblock
        
        PART="${PART##mtd}"
-       echo "${PART:+/dev/mtdblock/$PART}"
+       [ -d /dev/mtdblock ] && PREFIX=/dev/mtdblock/
+       echo "${PART:+$PREFIX$PART}"
 }
 
 strtok() { # <string> { <variable> [<separator>] ... }
@@ -177,3 +188,13 @@ strtok() { # <string> { <variable> [<separator>] ... }
 
        return $count
 }
+
+
+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"
+}
This page took 0.021664 seconds and 4 git commands to generate.