base-files: allow default value for config_get
authorFelix Fietkau <nbd@openwrt.org>
Fri, 7 Aug 2009 00:07:42 +0000 (00:07 +0000)
committerFelix Fietkau <nbd@openwrt.org>
Fri, 7 Aug 2009 00:07:42 +0000 (00:07 +0000)
Signed-off-by: Malte S. Stretz <mss@apache.org>
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
SVN-Revision: 17155

package/base-files/files/etc/functions.sh

index 828e37e40441a0b5f7a78e142ca9526c3d9ca131..efa378f0061db4b526efb179d7994a85659d8536 100755 (executable)
@@ -134,22 +134,25 @@ config_clear() {
        done
 }
 
        done
 }
 
+# config_get <variable> <section> <option> [<default>]
+# config_get <section> <option>
 config_get() {
        case "$3" in
 config_get() {
        case "$3" in
-               "") eval "echo \"\${CONFIG_${1}_${2}}\"";;
-               *)  eval "export ${NO_EXPORT:+-n} -- \"$1=\${CONFIG_${2}_${3}}\"";;
+               "") eval echo "\${CONFIG_${1}_${2}:-\${4}}";;
+               *)  eval export ${NO_EXPORT:+-n} -- "${1}=\${CONFIG_${2}_${3}:-\${4}}";;
        esac
 }
 
 # config_get_bool <variable> <section> <option> [<default>]
 config_get_bool() {
        local _tmp
        esac
 }
 
 # config_get_bool <variable> <section> <option> [<default>]
 config_get_bool() {
        local _tmp
-       config_get "_tmp" "$2" "$3"
+       config_get _tmp "$2" "$3" "$4"
        case "$_tmp" in
        case "$_tmp" in
-               1|on|true|enabled) export ${NO_EXPORT:+-n} "$1=1";;
-               0|off|false|disabled) export ${NO_EXPORT:+-n} "$1=0";;
-               *) eval "$1=$4";;
+               1|on|true|enabled) _tmp=1;;
+               0|off|false|disabled) _tmp=0;;
+               *) _tmp="$4";;
        esac
        esac
+       export ${NO_EXPORT:+-n} "$1=$_tmp"
 }
 
 config_set() {
 }
 
 config_set() {