aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Gianelloni <wolf31o2@gentoo.org>2007-11-07 21:38:12 +0000
committerChris Gianelloni <wolf31o2@gentoo.org>2007-11-07 21:38:12 +0000
commitfba39b8f1146a6eecc8430fa459bdaa5216948c4 (patch)
tree9a574be325f3a1e7dc574a4d8033865a0d96e5ea /gen_funcs.sh
parentFixed the noload module code. Thanks to Mijail Fedorovich <mfedorovich@gmail... (diff)
downloadgenkernel-fba39b8f1146a6eecc8430fa459bdaa5216948c4.tar.gz
genkernel-fba39b8f1146a6eecc8430fa459bdaa5216948c4.tar.bz2
genkernel-fba39b8f1146a6eecc8430fa459bdaa5216948c4.zip
Added a nice patch from John R. Graham <john_r_graham@mindspring.com> to allow all command line options to be configurable from within the genkernel.conf file. This is for bug #182616. This is genkernel 3.4.9_pre8 for testing.
git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/genkernel/trunk@557 67a159dc-881f-0410-a524-ba9dfbe2cb84
Diffstat (limited to 'gen_funcs.sh')
-rwxr-xr-xgen_funcs.sh87
1 files changed, 85 insertions, 2 deletions
diff --git a/gen_funcs.sh b/gen_funcs.sh
index 80e4883..4ebf57b 100755
--- a/gen_funcs.sh
+++ b/gen_funcs.sh
@@ -139,13 +139,13 @@ print_info() {
if [ "${NEWLINE}" = '0' ]
then
- if [ "${TODEBUGCACHE}" -eq 1 ]; then
+ if [ "${TODEBUGCACHE}" -eq '1' ]; then
DEBUGCACHE="${DEBUGCACHE}${STR}"
else
echo -ne "${STR}" >> ${LOGFILE}
fi
else
- if [ "${TODEBUGCACHE}" -eq 1 ]; then
+ if [ "${TODEBUGCACHE}" -eq '1' ]; then
DEBUGCACHE="${DEBUGCACHE}${STR}"$'\n'
else
echo "${STR}" >> ${LOGFILE}
@@ -428,3 +428,86 @@ copy_image_with_preserve() {
fi
}
+#
+# Helper function to allow command line arguments to override configuration
+# file specified values and to apply defaults.
+#
+# Arguments:
+# $1 Argument type:
+# 1 Switch type arguments (e.g., --color / --no-color).
+# 2 Value type arguments (e.g., --debuglevel=5).
+# $2 Config file variable name.
+# $3 Command line variable name.
+# $4 Default. If both the config file variable and the command line
+# option are not present, then the config file variable is set to
+# this default value. Optional.
+#
+# The order of priority of these three sources (highest first) is:
+# Command line, which overrides
+# Config file (/etc/genkernel.conf), which overrides
+# Default.
+#
+# Arguments $2 and $3 are variable *names*, not *values*. This function uses
+# various forms of indirection to access the values.
+#
+# For switch type arguments, all forms of "True" are converted to a numeric 1
+# and all forms of "False" (everything else, really) to a numeric 0.
+#
+# - JRG
+#
+set_config_with_override() {
+ local VarType=$1
+ local CfgVar=$2
+ local OverrideVar=$3
+ local Default=$4
+ local Result
+
+ #
+ # Syntax check the function arguments.
+ #
+ case "$VarType" in
+ 1|2)
+ ;;
+ *)
+ gen_die "Illegal variable type \"$VarType\" passed to set_config_with_override()."
+ ;;
+ esac
+
+ if [ -n "${!OverrideVar}" ]
+ then
+ Result=${!OverrideVar}
+ if [ -n "${!CfgVar}" ]
+ then
+ print_info 5 " $CfgVar overridden on command line to \"$Result\"."
+ else
+ print_info 5 " $CfgVar set on command line to \"$Result\"."
+ fi
+ else
+ if [ -n "${!CfgVar}" ]
+ then
+ Result=${!CfgVar}
+ print_info 5 " $CfgVar set in config file to \"${Result}\"."
+ else
+ if [ -n "$Default" ]
+ then
+ Result=${Default}
+ print_info 5 " $CfgVar defaulted to \"${Result}\"."
+ else
+ print_info 5 " $CfgVar not set."
+ fi
+ fi
+ fi
+
+ if [ "$VarType" -eq "1" ]
+ then
+ if isTrue "${Result}"
+ then
+ Result=1
+ else
+ Result=0
+ fi
+ fi
+
+ eval ${CfgVar}=${Result}
+}
+