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" = "${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}" = '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}" = '1' -o "${FORCEFILE}" = '1' ]
130 STRR=${STRR//${BAD}/}
131 STRR=${STRR//${BOLD}/}
132 STRR=${STRR//${NORMAL}/}
134 if [ "${PREFIXLINE}" = '1' ]
141 if [ "${NEWLINE}" = '0' ]
143 if [ "${TODEBUGCACHE}" = '1' ]; then
144 DEBUGCACHE="${DEBUGCACHE}${STR}"
146 echo -ne "${STR}" >> ${LOGFILE}
149 if [ "${TODEBUGCACHE}" = '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 "CACHE" "${CACHE_DIR}" "${1}"
194 if [ -f "${LOGFILE}" ]
196 (echo > "${LOGFILE}") 2>/dev/null || small_die "Genkernel: Could not write to ${LOGFILE}."
205 print_error 1 "ERROR: ${1}"
208 print_error 1 "-- Grepping log... --"
211 if isTrue ${USECOLOR}
213 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} \
214 | sed -s "s|^\(*\)\?|${BAD}*${NORMAL}|"
216 grep -B5 -E "([Ww][Aa][Rr][Nn][Ii][Nn][Gg]|[Ee][Rr][Rr][Oo][Rr][ :,!]|[Ff][Aa][Ii][Ll][Ee]?[Dd]?)" ${LOGFILE}
219 print_error 1 "-- End log... --"
221 print_error 1 "Please consult ${LOGFILE} for more information and any"
222 print_error 1 "errors that were reported above."
224 print_error 1 "Report any genkernel bugs to bugs.gentoo.org and"
225 print_error 1 "assign your bug to genkernel@gentoo.org. Please include"
226 print_error 1 "as much information as you can in your bug report; attaching"
227 print_error 1 "${LOGFILE} so that your issue can be dealt with effectively."
229 print_error 1 'Please do *not* report compilation failures as genkernel bugs!'
232 # Cleanup temp dirs and caches if requested
239 return $(awk '( $2 == "'${BOOTDIR}'" && $4 ~ /(^|,)ro(,|$)/){ I=1; exit }END{print !I }' /proc/mounts);
245 [ ! -d "${CACHE_DIR}" ] && mkdir -p "${CACHE_DIR}"
247 if [ "${CLEAR_CACHE_DIR}" == 'yes' ]
249 print_info 1 "Clearing cache dir contents from ${CACHE_DIR}"
252 print_info 1 " >> removing ${i}"
254 done < <(find "${CACHE_DIR}" -maxdepth 1 -type f -name '*.tar.*' -o -name '*.bz2')
261 if isTrue ${CMD_INSTALL}
263 TMPDIR_CONTENTS=`ls ${TMPDIR}`
264 print_info 1 "Removing tmp dir contents"
265 for i in ${TMPDIR_CONTENTS}
267 print_info 1 " >> removing ${i}"
274 # Function to copy various kernel boot image products to the boot directory,
275 # preserve a generation of old images (just like the manual kernel build's
276 # "make install" does), and maintain the symlinks (if enabled).
279 # $1 Symlink name. Symlink on the boot directory. Path not included.
280 # $2 Source image. Fully qualified path name of the source image.
281 # $3 Dest image. Name of the destination image in the boot directory,
282 # no path included. This script pushd's into ${BOOTDIR} in order to
283 # create relative symlinks just like the manual kernel build.
287 copy_image_with_preserve() {
289 local newSrceImage=$2
290 local fullDestName=$3
294 local currDestImageExists=0
295 local prevDestImageExists=0
297 print_info 4 "Copying new ${symlinkName} image, " 0
299 # Old product might be a different version. If so, we need to read
300 # the symlink to see what it's name is, if there are symlinks.
301 if [ "${SYMLINK}" = '1' ]
303 print_info 4 "automatically managing symlinks and old images." 1 0
304 if [ -e "${BOOTDIR}/${symlinkName}" ]
306 # JRG: Do I need a special case here for when the standard symlink
307 # name is, in fact, not a symlink?
308 currDestImage=`readlink --no-newline ${BOOTDIR}/${symlinkName}`
309 print_info 5 " Current ${symlinkName} symlink exists:"
310 print_info 5 " ${currDestImage}"
312 currDestImage="${fullDestName}"
313 print_info 5 " Current ${symlinkName} symlink did not exist."
314 print_info 5 " Defaulted to: ${currDestImage}"
316 if [ -e "${BOOTDIR}/${currDestImage}" ]
318 currDestImageExists=1
319 print_info 5 " Actual image file exists."
322 if [ -e "${BOOTDIR}/${symlinkName}.old" ]
324 # JRG: Do I need a special case here for when the standard symlink
325 # name is, in fact, not a symlink?
326 prevDestImage=`readlink --no-newline ${BOOTDIR}/${symlinkName}.old`
327 print_info 5 " Old ${symlinkName} symlink exists:"
328 print_info 5 " ${prevDestImage}"
330 prevDestImage="${fullDestName}.old"
331 print_info 5 " Old ${symlinkName} symlink did not exist."
332 print_info 5 " Defaulted to: ${prevDestImage}"
334 if [ -e "${BOOTDIR}/${prevDestImage}" ]
336 prevDestImageExists=1
337 print_info 5 " Actual old image file exists."
340 print_info 4 "symlinks not being handled by genkernel." 1 0
341 currDestImage="${fullDestName}"
342 prevDestImage="${fullDestName}.old"
345 # When symlinks are not being managed by genkernel, old symlinks might
346 # still be useful. Leave 'em alone unless managed.
347 if [ "${SYMLINK}" = '1' ]
349 print_info 5 " Deleting old symlinks, if any."
350 rm -f "${BOOTDIR}/${symlinkName}"
351 rm -f "${BOOTDIR}/${symlinkName}.old"
354 # We only erase the .old image when it is the exact same version as the
355 # current and new images. Different version .old (and current) images are
356 # left behind. This is consistent with how "make install" of the manual
357 # kernel build works.
358 if [ "${currDestImage}" == "${fullDestName}" ]
361 # Case for new and currrent of the same base version.
363 print_info 5 " Same base version. May have to delete old image to make room."
365 if [ "${currDestImageExists}" = '1' ]
367 if [ -e "${BOOTDIR}/${currDestImage}.old" ]
369 print_info 5 " Deleting old identical version ${symlinkName}."
370 rm -f "${BOOTDIR}/${currDestImage}.old"
372 print_info 5 " Moving ${BOOTDIR}/${currDestImage}"
373 print_info 5 " to ${BOOTDIR}/${currDestImage}.old"
374 mv "${BOOTDIR}/${currDestImage}" "${BOOTDIR}/${currDestImage}.old" ||
375 gen_die "Could not rename the old ${symlinkName} image!"
376 prevDestImage="${currDestImage}.old"
377 prevDestImageExists=1
381 # Case for new / current not of the same base version.
383 print_info 5 " Different base version. Do not delete old images."
384 prevDestImage="${currDestImage}"
385 currDestImage="${fullDestName}"
388 print_info 5 " Copying ${symlinkName}: ${newSrceImage}"
389 print_info 5 " to ${BOOTDIR}/${currDestImage}"
390 cp "${newSrceImage}" "${BOOTDIR}/${currDestImage}" ||
391 gen_die "Could not copy the ${symlinkName} image to ${BOOTDIR}!"
393 if [ "${SYMLINK}" = '1' ]
395 print_info 5 " Make new symlink(s) (from ${BOOTDIR}):"
396 print_info 5 " ${symlinkName} -> ${currDestImage}"
397 pushd ${BOOTDIR} >/dev/null
398 ln -s "${currDestImage}" "${symlinkName}" ||
399 gen_die "Could not create the ${symlinkName} symlink!"
400 if [ "${prevDestImageExists}" = '1' ]
402 print_info 5 " ${symlinkName}.old -> ${prevDestImage}"
403 ln -s "${prevDestImage}" "${symlinkName}.old" ||
404 gen_die "Could not create the ${symlinkName}.old symlink!"
411 # Helper function to allow command line arguments to override configuration
412 # file specified values and to apply defaults.
416 # 1 Switch type arguments (e.g., --color / --no-color).
417 # 2 Value type arguments (e.g., --debuglevel=5).
418 # $2 Config file variable name.
419 # $3 Command line variable name.
420 # $4 Default. If both the config file variable and the command line
421 # option are not present, then the config file variable is set to
422 # this default value. Optional.
424 # The order of priority of these three sources (highest first) is:
425 # Command line, which overrides
426 # Config file (/etc/genkernel.conf), which overrides
429 # Arguments $2 and $3 are variable *names*, not *values*. This function uses
430 # various forms of indirection to access the values.
432 # For switch type arguments, all forms of "True" are converted to a numeric 1
433 # and all forms of "False" (everything else, really) to a numeric 0.
437 set_config_with_override() {
445 # Syntax check the function arguments.
451 gen_die "Illegal variable type \"$VarType\" passed to set_config_with_override()."
455 if [ -n "${!OverrideVar}" ]
457 Result=${!OverrideVar}
458 if [ -n "${!CfgVar}" ]
460 print_info 5 " $CfgVar overridden on command line to \"$Result\"."
462 print_info 5 " $CfgVar set on command line to \"$Result\"."
465 if [ -n "${!CfgVar}" ]
468 # we need to set the CMD_* according to configfile...
469 eval ${OverrideVar}=\"${Result}\"
470 print_info 5 " $CfgVar set in config file to \"${Result}\"."
475 # set OverrideVar to Result, otherwise CMD_* may not be initialized...
476 eval ${OverrideVar}=\"${Result}\"
477 print_info 5 " $CfgVar defaulted to \"${Result}\"."
479 print_info 5 " $CfgVar not set."
484 if [ "${VarType}" = BOOL ]
486 if isTrue "${Result}"
494 eval ${CfgVar}=\"${Result}\"
498 for i in $BUSYBOX_SRCTAR $MULTIPATH_SRCTAR $LVM_SRCTAR $DMRAID_SRCTAR $ISCSI_SRCTAR $GPG_SRCTAR
502 small_die "Could not find source tarball ${i}. Please refetch."
507 find_kernel_binary() {
508 local kernel_binary=$*
512 for i in ${kernel_binary}
520 # if [ -z "${tmp_kernel_binary}" ]
522 # gen_die "Cannot locate kernel binary!"
525 echo "${tmp_kernel_binary}"