46 echo "${DEBUGCACHE}" >> ${LOGFILE}
49 # print_info(loglevel, print [, newline [, prefixline [, forcefile ] ] ])
58 if [ "$#" -lt '2' ] ; then return 1; fi
60 # IF 3 OR MORE ARGS, CHECK IF WE WANT A NEWLINE AFTER PRINT
71 # IF 4 OR MORE ARGS, CHECK IF WE WANT TO PREFIX WITH A *
82 # IF 5 OR MORE ARGS, CHECK IF WE WANT TO FORCE OUTPUT TO DEBUG
83 # FILE EVEN IF IT DOESN'T MEET THE MINIMUM DEBUG REQS
94 # PRINT TO SCREEN ONLY IF PASSED LOGLEVEL IS HIGHER THAN
95 # OR EQUAL TO SET DEBUG LEVEL
96 if [ "$1" -lt "${LOGLEVEL}" -o "$1" -eq "${LOGLEVEL}" ]
101 # RETURN IF NOT OUTPUTTING ANYWHERE
102 if [ "${SCRPRINT}" != '1' -a "${FORCEFILE}" != '1' ]
107 # STRUCTURE DATA TO BE OUTPUT TO SCREEN, AND OUTPUT IT
108 if [ "${SCRPRINT}" -eq '1' ]
110 if [ "${PREFIXLINE}" = '1' ]
112 STR="${GOOD}*${NORMAL} ${2}"
117 if [ "${NEWLINE}" = '0' ]
125 # STRUCTURE DATA TO BE OUTPUT TO FILE, AND OUTPUT IT
126 if [ "${SCRPRINT}" -eq '1' -o "${FORCEFILE}" -eq '1' ]
129 STRR=${STRR//${BAD}/}
130 STRR=${STRR//${BOLD}/}
131 STRR=${STRR//${NORMAL}/}
133 if [ "${PREFIXLINE}" = '1' ]
140 if [ "${NEWLINE}" = '0' ]
142 if [ "${TODEBUGCACHE}" -eq '1' ]; then
143 DEBUGCACHE="${DEBUGCACHE}${STR}"
145 echo -ne "${STR}" >> ${LOGFILE}
148 if [ "${TODEBUGCACHE}" -eq '1' ]; then
149 DEBUGCACHE="${DEBUGCACHE}${STR}"$'\n'
151 echo "${STR}" >> ${LOGFILE}
161 GOOD=${BAD} print_info "$@"
166 GOOD=${WARN} print_info "$@"
169 # var_replace(var_name, var_value, string)
171 # $2 = variable value
176 # Escape '\' and '.' in $2 to make it safe to use
177 # in the later sed expression
179 SAFE_VAR=`echo "${2}" | sed -e 's/\([\/\.]\)/\\\\\\1/g'`
181 echo "${3}" | sed -e "s/%%${1}%%/${SAFE_VAR}/g" -
185 var_replace "ARCH" "${ARCH}" "${1}"
189 var_replace "KV" "${KV}" "${1}"
193 var_replace "CACHE" "${CACHE_DIR}" "${1}"
197 if [ -f "${LOGFILE}" ]
199 (echo > "${LOGFILE}") 2>/dev/null || small_die "Genkernel: Could not write to ${LOGFILE}."
208 print_error 1 "ERROR: ${1}"
211 print_info 1 "-- Grepping log... --"
214 if isTrue ${USECOLOR}
216 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}
218 grep -B5 -E "([Ww][Aa][Rr][Nn][Ii][Nn][Gg]|[Ee][Rr][Rr][Oo][Rr][ :,!]|[Ff][Aa][Ii][Ll][Ee]?[Dd]?)" ${LOGFILE}
221 print_info 1 "-- End log... --"
223 print_info 1 "Please consult ${LOGFILE} for more information and any"
224 print_info 1 "errors that were reported above."
226 print_info 1 "Report any genkernel bugs to bugs.gentoo.org and"
227 print_info 1 "assign your bug to genkernel@gentoo.org. Please include"
228 print_info 1 "as much information as you can in your bug report; attaching"
229 print_info 1 "${LOGFILE} so that your issue can be dealt with effectively."
231 print_info 1 'Please do *not* report compilation failures as genkernel bugs!'
234 # Cleanup temp dirs and caches if requested
240 if [ -e /var/log/dmesg ]
242 cat /var/log/dmesg | egrep -q '^loop:'
244 dmesg | egrep -q '^loop:'
246 if [ -e '/dev/loop0' -o -e '/dev/loop/0' -a ${PIPESTATUS[1]} ]
248 # We found devfs or standard dev loop device, assume
249 # loop is compiled into the kernel or the module is loaded
258 return $(awk '( $2 == "'${BOOTDIR}'" && $4 ~ /(^|,)ro(,|$)/){ I=1; exit }END{print !I }' /proc/mounts);
264 [ ! -d "${CACHE_DIR}" ] && mkdir -p "${CACHE_DIR}"
266 if [ "${CLEAR_CACHE_DIR}" == 'yes' ]
268 print_info 1 "Clearing cache dir contents from ${CACHE_DIR}"
269 CACHE_DIR_CONTENTS=`ls ${CACHE_DIR}|grep -v CVS|grep -v cpio|grep -v README`
271 for i in ${CACHE_DIR_CONTENTS}
273 print_info 1 " >> removing ${i}"
282 if ! isTrue ${CMD_NOINSTALL}
284 TMPDIR_CONTENTS=`ls ${TMPDIR}`
285 print_info 1 "Removing tmp dir contents"
286 for i in ${TMPDIR_CONTENTS}
288 print_info 1 " >> removing ${i}"
295 # Function to copy various kernel boot image products to the boot directory,
296 # preserve a generation of old images (just like the manual kernel build's
297 # "make install" does), and maintain the symlinks (if enabled).
300 # $1 Symlink name. Symlink on the boot directory. Path not included.
301 # $2 Source image. Fully qualified path name of the source image.
302 # $3 Dest image. Name of the destination image in the boot directory,
303 # no path included. This script pushd's into ${BOOTDIR} in order to
304 # create relative symlinks just like the manual kernel build.
308 copy_image_with_preserve() {
310 local newSrceImage=$2
311 local fullDestName=$3
315 local currDestImageExists=0
316 local prevDestImageExists=0
318 print_info 4 "Copying new ${symlinkName} image, " 0
320 # Old product might be a different version. If so, we need to read
321 # the symlink to see what it's name is, if there are symlinks.
322 if [ "${SYMLINK}" -eq '1' ]
324 print_info 4 "automatically managing symlinks and old images." 1 0
325 if [ -e "${BOOTDIR}/${symlinkName}" ]
327 # JRG: Do I need a special case here for when the standard symlink
328 # name is, in fact, not a symlink?
329 currDestImage=`readlink --no-newline ${BOOTDIR}/${symlinkName}`
330 print_info 5 " Current ${symlinkName} symlink exists:"
331 print_info 5 " ${currDestImage}"
333 currDestImage="${fullDestName}"
334 print_info 5 " Current ${symlinkName} symlink did not exist."
335 print_info 5 " Defaulted to: ${currDestImage}"
337 if [ -e "${BOOTDIR}/${currDestImage}" ]
339 currDestImageExists=1
340 print_info 5 " Actual image file exists."
343 if [ -e "${BOOTDIR}/${symlinkName}.old" ]
345 # JRG: Do I need a special case here for when the standard symlink
346 # name is, in fact, not a symlink?
347 prevDestImage=`readlink --no-newline ${BOOTDIR}/${symlinkName}.old`
348 print_info 5 " Old ${symlinkName} symlink exists:"
349 print_info 5 " ${prevDestImage}"
351 prevDestImage="${fullDestName}.old"
352 print_info 5 " Old ${symlinkName} symlink did not exist."
353 print_info 5 " Defaulted to: ${prevDestImage}"
355 if [ -e "${BOOTDIR}/${prevDestImage}" ]
357 prevDestImageExists=1
358 print_info 5 " Actual old image file exists."
361 print_info 4 "symlinks not being handled by genkernel." 1 0
362 currDestImage="${fullDestName}"
363 prevDestImage="${fullDestName}.old"
366 # When symlinks are not being managed by genkernel, old symlinks might
367 # still be useful. Leave 'em alone unless managed.
368 if [ "${SYMLINK}" -eq '1' ]
370 print_info 5 " Deleting old symlinks, if any."
371 rm -f "${BOOTDIR}/${symlinkName}"
372 rm -f "${BOOTDIR}/${symlinkName}.old"
375 # We only erase the .old image when it is the exact same version as the
376 # current and new images. Different version .old (and current) images are
377 # left behind. This is consistent with how "make install" of the manual
378 # kernel build works.
379 if [ "${currDestImage}" == "${fullDestName}" ]
382 # Case for new and currrent of the same base version.
384 print_info 5 " Same base version. May have to delete old image to make room."
386 if [ "${currDestImageExists}" -eq '1' ]
388 if [ -e "${BOOTDIR}/${currDestImage}.old" ]
390 print_info 5 " Deleting old identical version ${symlinkName}."
391 rm -f "${BOOTDIR}/${currDestImage}.old"
393 print_info 5 " Moving ${BOOTDIR}/${currDestImage}"
394 print_info 5 " to ${BOOTDIR}/${currDestImage}.old"
395 mv "${BOOTDIR}/${currDestImage}" "${BOOTDIR}/${currDestImage}.old" ||
396 gen_die "Could not rename the old ${symlinkName} image!"
397 prevDestImage="${currDestImage}.old"
398 prevDestImageExists=1
402 # Case for new / current not of the same base version.
404 print_info 5 " Different base version. Do not delete old images."
405 prevDestImage="${currDestImage}"
406 currDestImage="${fullDestName}"
409 print_info 5 " Copying ${symlinkName}: ${newSrceImage}"
410 print_info 5 " to ${BOOTDIR}/${currDestImage}"
411 cp "${newSrceImage}" "${BOOTDIR}/${currDestImage}" ||
412 gen_die "Could not copy the ${symlinkName} image to ${BOOTDIR}!"
414 if [ "${SYMLINK}" -eq '1' ]
416 print_info 5 " Make new symlink(s) (from ${BOOTDIR}):"
417 print_info 5 " ${symlinkName} -> ${currDestImage}"
418 pushd ${BOOTDIR} >/dev/null
419 ln -s "${currDestImage}" "${symlinkName}" ||
420 gen_die "Could not create the ${symlinkName} symlink!"
421 if [ "${prevDestImageExists}" -eq '1' ]
423 print_info 5 " ${symlinkName}.old -> ${prevDestImage}"
424 ln -s "${prevDestImage}" "${symlinkName}.old" ||
425 gen_die "Could not create the ${symlinkName}.old symlink!"
432 # Helper function to allow command line arguments to override configuration
433 # file specified values and to apply defaults.
437 # 1 Switch type arguments (e.g., --color / --no-color).
438 # 2 Value type arguments (e.g., --debuglevel=5).
439 # $2 Config file variable name.
440 # $3 Command line variable name.
441 # $4 Default. If both the config file variable and the command line
442 # option are not present, then the config file variable is set to
443 # this default value. Optional.
445 # The order of priority of these three sources (highest first) is:
446 # Command line, which overrides
447 # Config file (/etc/genkernel.conf), which overrides
450 # Arguments $2 and $3 are variable *names*, not *values*. This function uses
451 # various forms of indirection to access the values.
453 # For switch type arguments, all forms of "True" are converted to a numeric 1
454 # and all forms of "False" (everything else, really) to a numeric 0.
458 set_config_with_override() {
466 # Syntax check the function arguments.
472 gen_die "Illegal variable type \"$VarType\" passed to set_config_with_override()."
476 if [ -n "${!OverrideVar}" ]
478 Result=${!OverrideVar}
479 if [ -n "${!CfgVar}" ]
481 print_info 5 " $CfgVar overridden on command line to \"$Result\"."
483 print_info 5 " $CfgVar set on command line to \"$Result\"."
486 if [ -n "${!CfgVar}" ]
489 print_info 5 " $CfgVar set in config file to \"${Result}\"."
494 print_info 5 " $CfgVar defaulted to \"${Result}\"."
496 print_info 5 " $CfgVar not set."
501 if [ "$VarType" -eq "1" ]
503 if isTrue "${Result}"
511 eval ${CfgVar}=${Result}