+
+ # When symlinks are not being managed by genkernel, old symlinks might
+ # still be useful. Leave 'em alone unless managed.
+ if [ "${SYMLINK}" = '1' ]
+ then
+ print_info 5 " Deleting old symlinks, if any."
+ rm -f "${BOOTDIR}/${symlinkName}"
+ rm -f "${BOOTDIR}/${symlinkName}.old"
+ fi
+
+ # We only erase the .old image when it is the exact same version as the
+ # current and new images. Different version .old (and current) images are
+ # left behind. This is consistent with how "make install" of the manual
+ # kernel build works.
+ if [ "${currDestImage}" == "${fullDestName}" ]
+ then
+ #
+ # Case for new and currrent of the same base version.
+ #
+ print_info 5 " Same base version. May have to delete old image to make room."
+
+ if [ "${currDestImageExists}" = '1' ]
+ then
+ if [ -e "${BOOTDIR}/${currDestImage}.old" ]
+ then
+ print_info 5 " Deleting old identical version ${symlinkName}."
+ rm -f "${BOOTDIR}/${currDestImage}.old"
+ fi
+ print_info 5 " Moving ${BOOTDIR}/${currDestImage}"
+ print_info 5 " to ${BOOTDIR}/${currDestImage}.old"
+ mv "${BOOTDIR}/${currDestImage}" "${BOOTDIR}/${currDestImage}.old" ||
+ gen_die "Could not rename the old ${symlinkName} image!"
+ prevDestImage="${currDestImage}.old"
+ prevDestImageExists=1
+ fi
+ else
+ #
+ # Case for new / current not of the same base version.
+ #
+ print_info 5 " Different base version. Do not delete old images."
+ prevDestImage="${currDestImage}"
+ currDestImage="${fullDestName}"
+ fi
+
+ print_info 5 " Copying ${symlinkName}: ${newSrceImage}"
+ print_info 5 " to ${BOOTDIR}/${currDestImage}"
+ cp "${newSrceImage}" "${BOOTDIR}/${currDestImage}" ||
+ gen_die "Could not copy the ${symlinkName} image to ${BOOTDIR}!"
+
+ if [ "${SYMLINK}" = '1' ]
+ then
+ print_info 5 " Make new symlink(s) (from ${BOOTDIR}):"
+ print_info 5 " ${symlinkName} -> ${currDestImage}"
+ pushd ${BOOTDIR} >/dev/null
+ ln -s "${currDestImage}" "${symlinkName}" ||
+ gen_die "Could not create the ${symlinkName} symlink!"
+ if [ "${prevDestImageExists}" = '1' ]
+ then
+ print_info 5 " ${symlinkName}.old -> ${prevDestImage}"
+ ln -s "${prevDestImage}" "${symlinkName}.old" ||
+ gen_die "Could not create the ${symlinkName}.old symlink!"
+ fi
+ popd >/dev/null
+ 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
+ BOOL|STRING)
+ ;;
+ *)
+ 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}
+ # we need to set the CMD_* according to configfile...
+ eval ${OverrideVar}=\"${Result}\"
+ print_info 5 " $CfgVar set in config file to \"${Result}\"."
+ else
+ if [ -n "$Default" ]
+ then
+ Result=${Default}
+ # set OverrideVar to Result, otherwise CMD_* may not be initialized...
+ eval ${OverrideVar}=\"${Result}\"
+ print_info 5 " $CfgVar defaulted to \"${Result}\"."
+ else
+ print_info 5 " $CfgVar not set."
+ fi
+ fi
+ fi
+
+ if [ "${VarType}" = BOOL ]
+ then
+ if isTrue "${Result}"
+ then
+ Result=1
+ else
+ Result=0
+ fi
+ fi
+
+ eval ${CfgVar}=\"${Result}\"
+}
+
+check_distfiles() {
+ for i in $BUSYBOX_SRCTAR $MULTIPATH_SRCTAR $LVM_SRCTAR $DMRAID_SRCTAR $ISCSI_SRCTAR $GPG_SRCTAR
+ do
+ if [ ! -f "${i}" ]
+ then
+ small_die "Could not find source tarball ${i}. Please refetch."
+ fi
+ done
+}
+
+find_kernel_binary() {
+ local kernel_binary=$*
+ local curdir=$(pwd)
+
+ cd "${KERNEL_OUTPUTDIR}"
+ for i in ${kernel_binary}
+ do
+ if [ -e "${i}" ]
+ then
+ tmp_kernel_binary=$i
+ break
+ fi
+ done
+# if [ -z "${tmp_kernel_binary}" ]
+# then
+# gen_die "Cannot locate kernel binary!"
+# fi
+ cd "${curdir}"
+ echo "${tmp_kernel_binary}"