47 echo "${DEBUGCACHE}" >> ${LOGFILE}
50 # print_info(loglevel, print [, newline [, prefixline [, forcefile ] ] ])
59 if [ "$#" -lt '2' ] ; then return 1; fi
61 # IF 3 OR MORE ARGS, CHECK IF WE WANT A NEWLINE AFTER PRINT
72 # IF 4 OR MORE ARGS, CHECK IF WE WANT TO PREFIX WITH A *
83 # IF 5 OR MORE ARGS, CHECK IF WE WANT TO FORCE OUTPUT TO DEBUG
84 # FILE EVEN IF IT DOESN'T MEET THE MINIMUM DEBUG REQS
95 # PRINT TO SCREEN ONLY IF PASSED LOGLEVEL IS HIGHER THAN
96 # OR EQUAL TO SET DEBUG LEVEL
97 if [ "$1" -lt "${LOGLEVEL}" -o "$1" -eq "${LOGLEVEL}" ]
102 # RETURN IF NOT OUTPUTTING ANYWHERE
103 if [ "${SCRPRINT}" != '1' -a "${FORCEFILE}" != '1' ]
108 # STRUCTURE DATA TO BE OUTPUT TO SCREEN, AND OUTPUT IT
109 if [ "${SCRPRINT}" -eq '1' ]
111 if [ "${PREFIXLINE}" = '1' ]
113 STR="${GOOD}*${NORMAL} ${2}"
118 if [ "${NEWLINE}" = '0' ]
126 # STRUCTURE DATA TO BE OUTPUT TO FILE, AND OUTPUT IT
127 if [ "${SCRPRINT}" -eq '1' -o "${FORCEFILE}" -eq '1' ]
130 STRR=${STRR//${BAD}/}
131 STRR=${STRR//${BOLD}/}
132 STRR=${STRR//${NORMAL}/}
134 if [ "${PREFIXLINE}" = '1' ]
141 if [ "${NEWLINE}" = '0' ]
143 if [ "${TODEBUGCACHE}" -eq '1' ]; then
144 DEBUGCACHE="${DEBUGCACHE}${STR}"
146 echo -ne "${STR}" >> ${LOGFILE}
149 if [ "${TODEBUGCACHE}" -eq '1' ]; then
150 DEBUGCACHE="${DEBUGCACHE}${STR}"$'\n'
152 echo "${STR}" >> ${LOGFILE}
162 GOOD=${BAD} print_info "$@"
167 GOOD=${WARN} print_info "$@"
170 # var_replace(var_name, var_value, string)
172 # $2 = variable value
177 # Escape '\' and '.' in $2 to make it safe to use
178 # in the later sed expression
180 SAFE_VAR=`echo "${2}" | sed -e 's/\([\/\.]\)/\\\\\\1/g'`
182 echo "${3}" | sed -e "s/%%${1}%%/${SAFE_VAR}/g" -
186 var_replace "ARCH" "${ARCH}" "${1}"
190 var_replace "KV" "${KV}" "${1}"
194 var_replace "CACHE" "${CACHE_DIR}" "${1}"
198 if [ -f "${LOGFILE}" ]
200 (echo > "${LOGFILE}") 2>/dev/null || small_die "Genkernel: Could not write to ${LOGFILE}."
209 print_error 1 "ERROR: ${1}"
212 print_info 1 "-- Grepping log... --"
215 if isTrue ${USECOLOR}
217 GREP_COLOR='1' grep -B5 -E --colour=always "([Ww][Aa][Rr][Nn][Ii][Nn][Gg]|[Ee][Rr][Rr][Oo][Rr][ :,!]|[Ff][Aa][Ii][Ll][Ee]?[Dd]?)" ${LOGFILE}
219 grep -B5 -E "([Ww][Aa][Rr][Nn][Ii][Nn][Gg]|[Ee][Rr][Rr][Oo][Rr][ :,!]|[Ff][Aa][Ii][Ll][Ee]?[Dd]?)" ${LOGFILE}
222 print_info 1 "-- End log... --"
224 print_info 1 "Please consult ${LOGFILE} for more information and any"
225 print_info 1 "errors that were reported above."
227 print_info 1 "Report any genkernel bugs to bugs.gentoo.org and"
228 print_info 1 "assign your bug to genkernel@gentoo.org. Please include"
229 print_info 1 "as much information as you can in your bug report; attaching"
230 print_info 1 "${LOGFILE} so that your issue can be dealt with effectively."
232 print_info 1 'Please do *not* report compilation failures as genkernel bugs!'
235 # Cleanup temp dirs and caches if requested
242 return $(awk '( $2 == "'${BOOTDIR}'" && $4 ~ /(^|,)ro(,|$)/){ I=1; exit }END{print !I }' /proc/mounts);
248 [ ! -d "${CACHE_DIR}" ] && mkdir -p "${CACHE_DIR}"
250 if [ "${CLEAR_CACHE_DIR}" == 'yes' ]
252 print_info 1 "Clearing cache dir contents from ${CACHE_DIR}"
253 CACHE_DIR_CONTENTS=`ls ${CACHE_DIR}|grep -v CVS|grep -v cpio|grep -v README`
255 for i in ${CACHE_DIR_CONTENTS}
257 print_info 1 " >> removing ${i}"
266 if ! isTrue ${CMD_NOINSTALL}
268 TMPDIR_CONTENTS=`ls ${TMPDIR}`
269 print_info 1 "Removing tmp dir contents"
270 for i in ${TMPDIR_CONTENTS}
272 print_info 1 " >> removing ${i}"
279 # Function to copy various kernel boot image products to the boot directory,
280 # preserve a generation of old images (just like the manual kernel build's
281 # "make install" does), and maintain the symlinks (if enabled).
284 # $1 Symlink name. Symlink on the boot directory. Path not included.
285 # $2 Source image. Fully qualified path name of the source image.
286 # $3 Dest image. Name of the destination image in the boot directory,
287 # no path included. This script pushd's into ${BOOTDIR} in order to
288 # create relative symlinks just like the manual kernel build.
292 copy_image_with_preserve() {
294 local newSrceImage=$2
295 local fullDestName=$3
299 local currDestImageExists=0
300 local prevDestImageExists=0
302 print_info 4 "Copying new ${symlinkName} image, " 0
304 # Old product might be a different version. If so, we need to read
305 # the symlink to see what it's name is, if there are symlinks.
306 if [ "${SYMLINK}" -eq '1' ]
308 print_info 4 "automatically managing symlinks and old images." 1 0
309 if [ -e "${BOOTDIR}/${symlinkName}" ]
311 # JRG: Do I need a special case here for when the standard symlink
312 # name is, in fact, not a symlink?
313 currDestImage=`readlink --no-newline ${BOOTDIR}/${symlinkName}`
314 print_info 5 " Current ${symlinkName} symlink exists:"
315 print_info 5 " ${currDestImage}"
317 currDestImage="${fullDestName}"
318 print_info 5 " Current ${symlinkName} symlink did not exist."
319 print_info 5 " Defaulted to: ${currDestImage}"
321 if [ -e "${BOOTDIR}/${currDestImage}" ]
323 currDestImageExists=1
324 print_info 5 " Actual image file exists."
327 if [ -e "${BOOTDIR}/${symlinkName}.old" ]
329 # JRG: Do I need a special case here for when the standard symlink
330 # name is, in fact, not a symlink?
331 prevDestImage=`readlink --no-newline ${BOOTDIR}/${symlinkName}.old`
332 print_info 5 " Old ${symlinkName} symlink exists:"
333 print_info 5 " ${prevDestImage}"
335 prevDestImage="${fullDestName}.old"
336 print_info 5 " Old ${symlinkName} symlink did not exist."
337 print_info 5 " Defaulted to: ${prevDestImage}"
339 if [ -e "${BOOTDIR}/${prevDestImage}" ]
341 prevDestImageExists=1
342 print_info 5 " Actual old image file exists."
345 print_info 4 "symlinks not being handled by genkernel." 1 0
346 currDestImage="${fullDestName}"
347 prevDestImage="${fullDestName}.old"
350 # When symlinks are not being managed by genkernel, old symlinks might
351 # still be useful. Leave 'em alone unless managed.
352 if [ "${SYMLINK}" -eq '1' ]
354 print_info 5 " Deleting old symlinks, if any."
355 rm -f "${BOOTDIR}/${symlinkName}"
356 rm -f "${BOOTDIR}/${symlinkName}.old"
359 # We only erase the .old image when it is the exact same version as the
360 # current and new images. Different version .old (and current) images are
361 # left behind. This is consistent with how "make install" of the manual
362 # kernel build works.
363 if [ "${currDestImage}" == "${fullDestName}" ]
366 # Case for new and currrent of the same base version.
368 print_info 5 " Same base version. May have to delete old image to make room."
370 if [ "${currDestImageExists}" -eq '1' ]
372 if [ -e "${BOOTDIR}/${currDestImage}.old" ]
374 print_info 5 " Deleting old identical version ${symlinkName}."
375 rm -f "${BOOTDIR}/${currDestImage}.old"
377 print_info 5 " Moving ${BOOTDIR}/${currDestImage}"
378 print_info 5 " to ${BOOTDIR}/${currDestImage}.old"
379 mv "${BOOTDIR}/${currDestImage}" "${BOOTDIR}/${currDestImage}.old" ||
380 gen_die "Could not rename the old ${symlinkName} image!"
381 prevDestImage="${currDestImage}.old"
382 prevDestImageExists=1
386 # Case for new / current not of the same base version.
388 print_info 5 " Different base version. Do not delete old images."
389 prevDestImage="${currDestImage}"
390 currDestImage="${fullDestName}"
393 print_info 5 " Copying ${symlinkName}: ${newSrceImage}"
394 print_info 5 " to ${BOOTDIR}/${currDestImage}"
395 cp "${newSrceImage}" "${BOOTDIR}/${currDestImage}" ||
396 gen_die "Could not copy the ${symlinkName} image to ${BOOTDIR}!"
398 if [ "${SYMLINK}" -eq '1' ]
400 print_info 5 " Make new symlink(s) (from ${BOOTDIR}):"
401 print_info 5 " ${symlinkName} -> ${currDestImage}"
402 pushd ${BOOTDIR} >/dev/null
403 ln -s "${currDestImage}" "${symlinkName}" ||
404 gen_die "Could not create the ${symlinkName} symlink!"
405 if [ "${prevDestImageExists}" -eq '1' ]
407 print_info 5 " ${symlinkName}.old -> ${prevDestImage}"
408 ln -s "${prevDestImage}" "${symlinkName}.old" ||
409 gen_die "Could not create the ${symlinkName}.old symlink!"
416 # Helper function to allow command line arguments to override configuration
417 # file specified values and to apply defaults.
421 # 1 Switch type arguments (e.g., --color / --no-color).
422 # 2 Value type arguments (e.g., --debuglevel=5).
423 # $2 Config file variable name.
424 # $3 Command line variable name.
425 # $4 Default. If both the config file variable and the command line
426 # option are not present, then the config file variable is set to
427 # this default value. Optional.
429 # The order of priority of these three sources (highest first) is:
430 # Command line, which overrides
431 # Config file (/etc/genkernel.conf), which overrides
434 # Arguments $2 and $3 are variable *names*, not *values*. This function uses
435 # various forms of indirection to access the values.
437 # For switch type arguments, all forms of "True" are converted to a numeric 1
438 # and all forms of "False" (everything else, really) to a numeric 0.
442 set_config_with_override() {
450 # Syntax check the function arguments.
456 gen_die "Illegal variable type \"$VarType\" passed to set_config_with_override()."
460 if [ -n "${!OverrideVar}" ]
462 Result=${!OverrideVar}
463 if [ -n "${!CfgVar}" ]
465 print_info 5 " $CfgVar overridden on command line to \"$Result\"."
467 print_info 5 " $CfgVar set on command line to \"$Result\"."
470 if [ -n "${!CfgVar}" ]
473 # we need to set the CMD_* according to configfile...
474 eval ${OverrideVar}=\"${Result}\"
475 print_info 5 " $CfgVar set in config file to \"${Result}\"."
480 # set OverrideVar to Result, otherwise CMD_* may not be initialized...
481 eval ${OverrideVar}=\"${Result}\"
482 print_info 5 " $CfgVar defaulted to \"${Result}\"."
484 print_info 5 " $CfgVar not set."
489 if [ "$VarType" -eq "1" ]
491 if isTrue "${Result}"
499 eval ${CfgVar}=\"${Result}\"
503 for i in $BUSYBOX_SRCTAR $DEVICE_MAPPER_SRCTAR $MULTIPATH_SRCTAR $LVM_SRCTAR $DMRAID_SRCTAR $E2FSPROGS_SRCTAR $ISCSI_SRCTAR
507 small_die "Could not find source tarball ${i}. Please refetch."
512 find_kernel_binary() {
513 local kernel_binary=$*
517 for i in ${kernel_binary}
525 # if [ -z "${tmp_kernel_binary}" ]
527 # gen_die "Cannot locate kernel binary!"
530 echo "${tmp_kernel_binary}"