Added a patch by John R. Graham <john_r_graham@mindspring.com> from bug #169383 to...
authorChris Gianelloni <wolf31o2@gentoo.org>
Fri, 9 Mar 2007 20:24:09 +0000 (20:24 +0000)
committerChris Gianelloni <wolf31o2@gentoo.org>
Fri, 9 Mar 2007 20:24:09 +0000 (20:24 +0000)
git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/genkernel/trunk@494 67a159dc-881f-0410-a524-ba9dfbe2cb84

ChangeLog
gen_compile.sh
gen_determineargs.sh
gen_funcs.sh
gen_initramfs.sh
gen_initrd.sh
gen_package.sh
genkernel

index b9018ee0050fda4fb6fd02a4c4045c58d2e074a5..ba10a4856c3e8be32573ca9a1f48a8f92024731f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,13 @@
 # Copyright 2006-2007 Gentoo Foundation; Distributed under the GPL v2
 # $Header: $
 
+  09 Mar 2007; Chris Gianelloni <wolf31o2@gentoo.org> gen_compile.sh,
+  gen_determineargs.sh, gen_funcs.sh, gen_initramfs.sh, gen_initrd.sh,
+  gen_package.sh, genkernel:
+  Added a patch by John R. Graham <john_r_graham@mindspring.com> from bug
+  #169383 to improve the --symlink option fairly significantly. This is going
+  to be 3.4.7_pre4 and while I haven't tested this yet, it looks good.
+
   09 Mar 2007; Chris Gianelloni <wolf31o2@gentoo.org> gen_initramfs.sh:
   Fixed lib64 link for bug #168664.
 
index 4dabc1465940a3fddae1572724b57820a1ce1e3e..0b5b5031d89fd02c0539b644892ba8f5a37c6268 100644 (file)
@@ -183,6 +183,7 @@ reset_args()
        fi
 }
 
+
 compile_generic() {
        local RET
        [ "$#" -lt '2' ] &&
@@ -298,14 +299,19 @@ compile_kernel() {
        fi
        if ! isTrue "${CMD_NOINSTALL}"
        then
-               cp "${KERNEL_BINARY}" "${BOOTDIR}/kernel-${KNAME}-${ARCH}-${KV}" ||
-                       gen_die 'Could not copy the kernel binary to ${BOOTDIR}!'
-               cp "System.map" "${BOOTDIR}/System.map-${KNAME}-${ARCH}-${KV}" ||
-                       gen_die 'Could not copy System.map to ${BOOTDIR}!'
+               copy_image_with_preserve "kernel" \
+                       "${KERNEL_BINARY}" \
+                       "kernel-${KNAME}-${ARCH}-${KV}"
+
+               copy_image_with_preserve "System.map" \
+                       "System.map" \
+                       "System.map-${KNAME}-${ARCH}-${KV}"
+
                if [ "${KERNEL_BINARY_2}" != '' -a "${GENERATE_Z_IMAGE}" = '1' ]
                then
-                       cp "${KERNEL_BINARY_2}" "${BOOTDIR}/kernelz-${KV}" ||
-                               gen_die 'Could not copy the kernelz binary to ${BOOTDIR}!'
+                       copy_image_with_preserve "kernelz" \
+                               "${KERNEL_BINARY_2}" \
+                               "kernelz-${KV}"
                fi
        else
                cp "${KERNEL_BINARY}" "${TMPDIR}/kernel-${KNAME}-${ARCH}-${KV}" ||
index 206724564b84ed5c1e1333ebc6527a665a1624e1..072ec2b7ade0e2ba4b45bcb35f6073c0e8aa6a58 100644 (file)
@@ -363,7 +363,12 @@ determine_real_args() {
                SAVE_CONFIG=0
        fi
   
-       if isTrue "${CMD_SYMLINK}"
+       if [ "${CMD_SYMLINK}" != '' ]
+       then
+               SYMLINK="${CMD_SYMLINK}"
+       fi
+
+       if isTrue "${SYMLINK}"
        then
                SYMLINK=1
        else
index e0245abfb353fe43ff0758d25c675724fb2ad7e2..f869a786d01ef1e2a746c41fc0c8ee3c9499b156 100755 (executable)
@@ -290,3 +290,141 @@ then
     done
 fi
 }      
+
+#
+# Function to copy various kernel boot image products to the boot directory,
+# preserve a generation of old images (just like the manual kernel build's
+# "make install" does), and maintain the symlinks (if enabled).
+#
+# Arguments:
+#     $1  Symlink name.  Symlink on the boot directory. Path not included.
+#     $2  Source image.  Fully qualified path name of the source image.
+#     $3  Dest image.    Name of the destination image in the boot directory,
+#         no path included.  This script pushd's into ${BOOTDIR} in order to
+#         create relative symlinks just like the manual kernel build.
+#
+# - JRG
+#
+copy_image_with_preserve() {
+       local symlinkName=$1
+       local newSrceImage=$2
+       local fullDestName=$3
+
+       local currDestImage
+       local prevDestImage
+       local currDestImageExists=0
+       local prevDestImageExists=0
+
+       print_info 4 "Copying new ${symlinkName} image, " 0
+
+       # Old product might be a different version.  If so, we need to read
+       # the symlink to see what it's name is, if there are symlinks.
+       if [ "${SYMLINK}" -eq '1' ]
+       then
+               print_info 4 "automatically managing symlinks and old images." 1 0
+               if [ -e "${BOOTDIR}/${symlinkName}" ]
+               then
+                       # JRG: Do I need a special case here for when the standard symlink
+                       # name is, in fact, not a symlink?
+                       currDestImage=`readlink --no-newline ${BOOTDIR}/${symlinkName}`
+                       print_info 5 "  Current ${symlinkName} symlink exists:"
+                       print_info 5 "    ${currDestImage}"
+               else
+                       currDestImage="${fullDestName}"
+                       print_info 5 "  Current ${symlinkName} symlink did not exist."
+                       print_info 5 "    Defaulted to: ${currDestImage}"
+               fi
+               if [ -e "${BOOTDIR}/${currDestImage}" ]
+               then
+                       currDestImageExists=1
+                       print_info 5 "  Actual image file exists."
+               fi
+
+               if [ -e "${BOOTDIR}/${symlinkName}.old" ]
+               then
+                       # JRG: Do I need a special case here for when the standard symlink
+                       # name is, in fact, not a symlink?
+                       prevDestImage=`readlink --no-newline ${BOOTDIR}/${symlinkName}.old`
+                       print_info 5 "  Old ${symlinkName} symlink exists:"
+                       print_info 5 "    ${prevDestImage}"
+               else
+                       prevDestImage="${fullDestName}.old"
+                       print_info 5 "  Old ${symlinkName} symlink did not exist."
+                       print_info 5 "    Defaulted to: ${prevDestImage}"
+               fi
+               if [ -e "${BOOTDIR}/${prevDestImage}" ]
+               then
+                       prevDestImageExists=1
+                       print_info 5 "  Actual old image file exists."
+               fi
+       else
+               print_info 4 "symlinks not being handled by genkernel." 1 0
+               currDestImage="${fullDestName}"
+               prevDestImage="${fullDestName}.old"
+       fi
+
+       # When symlinks are not being managed by genkernel, old symlinks might
+    # still be useful.  Leave 'em alone unless managed.
+       if [ "${SYMLINK}" -eq '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 image.  Different version old images are left behind.  This is
+       # consistent with how "make install" of the manual kernel build works.
+       if [ "${currDestImage}.old" == "${prevDestImage}" ]
+       then
+               #
+               # Case for current / old of the same base version.
+               #
+               print_info 5 "  Same base version.  May have to delete old image to make room."
+               if [  "${prevDestImageExists}" -eq '1' ]
+               then
+                       print_info 5 "  Deleting old identical version ${symlinkName}."
+                       rm -f "${BOOTDIR}/${prevDestImage}"
+               fi
+
+               if [  "${currDestImageExists}" -eq '1' ]
+               then
+                       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!"
+               fi
+       else
+               #
+               # Case for current / old not of the same base version.
+               #
+               print_info 5 "  Different base version.  Do not delete old iamges."
+               if [ "${currDestImageExists}" -eq 1 ]
+               then
+                       prevDestImage="${currDestImage}"
+                       currDestImage="${fullDestName}"
+               fi
+       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}" -eq '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 [ "${currDestImageExists}" -eq '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
+}
+
index 322644dab318708eb61372861e02d9b0a3c9bda7..6889fe9316f9ce8e0ea0bfc8d5b1b8148f0ec134 100644 (file)
@@ -527,8 +527,9 @@ create_initramfs() {
        then
                if [ "${GENERATE_Z_IMAGE}" != '1' ]
                then
-                       cp ${TMPDIR}/initramfs-${KV} ${BOOTDIR}/initramfs-${KNAME}-${ARCH}-${KV} ||
-                               gen_die 'Could not copy the initramfs to ${BOOTDIR}!'
+                       copy_image_with_preserve "initramfs" \
+                               "${TMPDIR}/initramfs-${KV}" \
+                               "initramfs-${KNAME}-${ARCH}-${KV}"
                fi
        fi
 }
index b31be8a08b18e0f52d8a28332db1a919550a0127..011ef587d4fbb64afa8c6609be1943325e30aaf5 100644 (file)
@@ -437,8 +437,9 @@ create_initrd() {
        fi
        if ! isTrue "${CMD_NOINSTALL}"
        then
-               cp ${TMPDIR}/initrd-${KV} ${BOOTDIR}/initrd-${KNAME}-${ARCH}-${KV} ||
-                       gen_die 'Could not copy the initrd to ${BOOTDIR}!'
+               copy_image_with_preserve "initrd" \
+                       "${TMPDIR}/initrd-${KV}" \
+                       "initrd-${KNAME}-${ARCH}-${KV}"
        fi
 
        # Pegasos hack for merging the initrd into the kernel at compile time
index d696b722c7433767c36304d94c346b6f1f46c818..c8c807d9d6869801040f224b54503b23cf5740c1 100644 (file)
@@ -88,13 +88,21 @@ gen_kerncache()
 
 gen_kerncache_extract_kernel()
 {
-               /bin/tar -f ${KERNCACHE} -C ${TEMP} -xj 
-       cp "${TEMP}/kernel-${ARCH}-${KV}" "${BOOTDIR}/kernel-${KNAME}-${ARCH}-${KV}" || gen_die "Could not copy the kernel binary to ${BOOTDIR}!"
+    /bin/tar -f ${KERNCACHE} -C ${TEMP} -xj 
+       copy_image_with_preserve "kernel" \
+               "${TEMP}/kernel-${ARCH}-${KV}" \
+               "kernel-${KNAME}-${ARCH}-${KV}"
+
        if [ "${KERNEL_BINARY_2}" != '' -a "${GENERATE_Z_IMAGE}" = '1' ]
-        then
-               cp "${TEMP}/kernelz-${ARCH}-${KV}" "${BOOTDIR}/kernelz-${KNAME}-${ARCH}-${KV}" || gen_die "Could not copy the kernel binary to ${BOOTDIR}!"
-        fi
-        cp "${TEMP}/System.map-${ARCH}-${KV}" "${BOOTDIR}/System.map-${KNAME}-${ARCH}-${KV}" || gen_die "Could not copy System.map to ${BOOTDIR}!"
+    then
+               copy_image_with_preserve "kernelz" \
+                       "${TEMP}/kernelz-${ARCH}-${KV}" \
+                       "kernelz-${KNAME}-${ARCH}-${KV}"
+    fi
+    
+       copy_image_with_preserve "System.map" \
+               "${TEMP}/System.map-${ARCH}-${KV}" \
+               "System.map-${KNAME}-${ARCH}-${KV}"
 }
 
 gen_kerncache_extract_modules()
index 3a238763f28f5a3dbdabd89d395e9f849bcc7d05..e8b76b61a53ef8ed51c6dda035ce6958fe0aba50 100755 (executable)
--- a/genkernel
+++ b/genkernel
@@ -2,7 +2,7 @@
 # Genkernel v3
 
 PATH="/bin:/usr/bin:/sbin:/usr/sbin"
-GK_V='3.4.7_pre3'
+GK_V='3.4.7_pre4'
 
 TMPDIR='/var/tmp/genkernel'
 TEMP=${TMPDIR}/$RANDOM.$RANDOM.$RANDOM.$$
@@ -398,60 +398,6 @@ then
        [ "${UNIONFS}" -eq '1' ] && print_info 1 '      or "unionfs=<block_device>"'
 fi
 
-
-symlinker() {
-       local base=$1
-       local fullVer=${KNAME}-${ARCH}-${KV}
-
-       local newThing=${BOOTDIR}/${base}-${fullVer}
-       local newSym=${BOOTDIR}/${base}
-       local oldSym=${newSym}.old
-
-       local prevLink
-       local ret=0
-
-       print_info 1 "      creating ${base} name symlink!"
-       if [ -e ${newThing} ] ; then
-               if [ -L ${newSym} ] ; then
-                       prevLink=`readlink --no-newline ${newSym}`
-                       if [ ${prevLink} != ${newThing} ] ; then
-                               if [ -L ${oldSym} ] ; then
-                                       rm ${oldSym}
-                               fi
-                               ln -s ${prevLink} ${oldSym}
-                               [ $((ret += $?)) ]
-                       fi
-                       rm ${newSym}
-               fi
-               ln -s ${newThing} ${newSym}
-               [ $((ret += $?)) ]
-       fi
-       
-       if [[ ${ret} > 0 ]] ; then
-               print_error 1 "     $base link failed: ${ret}"
-       fi
-
-       return ${ret}
-}
-
-
-if [ "${CMD_NOINSTALL}" != '1' -a "${SYMLINK}" = '1' ]
-then 
-    echo
-    print_info 1 'Creating symlinks'
-    
-    
-       symlinker kernel
-       symlinker System.map 
-
-       if [ "${KERN_24}" != '1' -a  "${CMD_BOOTSPLASH}" != '1' ] ; then
-               symlinker initramfs
-       else
-               symlinker initrd
-    fi
-fi
-
-
 [ "${BOOTRW}" != '' ] && mount -o remount,ro ${BOOTDIR}
 
 echo