]> Frank Brehm's Git Trees - scripts/root-bin.git/commitdiff
Current version by helga helga
authorFrank Brehm <frank@brehm-online.com>
Thu, 5 Mar 2015 17:40:28 +0000 (18:40 +0100)
committerFrank Brehm <frank@brehm-online.com>
Thu, 5 Mar 2015 17:40:28 +0000 (18:40 +0100)
installkernel

index 581669b48b0774815c94bab4592a8b6d0a138c1e..3e603d15ba1e9fb0bab95f4decd8ac470b676103 100755 (executable)
@@ -4,16 +4,35 @@
 set -e
 
 ME=installkernel
-VERSION="2011-10-26"
+VERSION="2012-09-24"
+
+simulate=""
+#simulate="y"
 
 echo -e "\n$ME:\nFrank Brehm's installkernel script, $VERSION"
-echo "* Arguments:
+
+if [ "${KBUILD_VERBOSE}" != "0" -a "${KBUILD_VERBOSE}" != "" ] ; then
+    echo "* Arguments:
 kernel version: $1
 kernel image file: $2
 kernel map file: $3
 default install path: $4
 "
+fi
+
+if [ "${simulate}" = "y" ] ; then
+    echo "SIMULATION mode ..."
+    echo
+fi
+
+#---------------------------------------
+out() {
+    topic="$1"
+    shift
+    printf "  %-08s %s\n" "${topic}" "$*"
+}
 
+#---------------------------------------
 #B="/mnt/misc/boot"
 BOOT_DIR="/boot"
 KERNEL_VERSION=$1
@@ -24,8 +43,8 @@ DEF_INSTALL_PATH=$4
 was_mounted='y'
 
 # check we have a valid kernel target directory
-if [[ -n "$DEF_INSTALL_PATH" && "$DEF_INSTALL_PATH" != "$BOOT_DIR" ]] ; then
-    if [[ -d "$DEF_INSTALL_PATH" ]] ; then
+if [ -n "$DEF_INSTALL_PATH" ] && [ "$DEF_INSTALL_PATH" != "$BOOT_DIR" ] ; then
+    if [ -d "$DEF_INSTALL_PATH" ] ; then
         BOOT_DIR="$DEF_INSTALL_PATH"
     else
         echo -e "\n\n$ME: fatal: missing kernel target directory:" >&2
@@ -34,14 +53,24 @@ if [[ -n "$DEF_INSTALL_PATH" && "$DEF_INSTALL_PATH" != "$BOOT_DIR" ]] ; then
     fi
 fi
 
-if [[ ! -d ${BOOT_DIR}/grub ]] ; then
+if [ ! -d ${BOOT_DIR}/grub ] ; then
     was_mounted='n'
-    echo "  MOUNT   ${BOOT_DIR}"
+    out "MOUNT" "${BOOT_DIR}"
     mount ${BOOT_DIR}
 fi
 
+# Check for necessary genkernel ...
+DO_GENKERNEL="n"
+
+LINK_INITRD_CUR="${BOOT_DIR}/initrd-gentoo-cur"
+LINK_INITRD_LAST="${BOOT_DIR}/initrd-gentoo-last"
+
+if [ -e "${LINK_INITRD_CUR}" -a -x /usr/bin/genkernel ] ; then
+    DO_GENKERNEL="y"
+fi
+
 # where to find .config, based on kernel series
-if [[ -f '.config' ]] ; then
+if [ -f '.config' ] ; then
     echo "* 2.6/3.x kernel"
     DOT_CONFIG=".config"
 else
@@ -51,71 +80,83 @@ fi
 
 i=0
 TARGET_CONFIG_BOOT=$( printf "%s/config-%s-%02d" "${BOOT_DIR}" "${KERNEL_VERSION}" "${i}" )
-while [[ -f "${TARGET_CONFIG_BOOT}" ]] ; do
+while [ -f "${TARGET_CONFIG_BOOT}" ] ; do
     i=$(( i + 1 ))
     TARGET_CONFIG_BOOT=$( printf "%s/config-%s-%02d" "${BOOT_DIR}" "${KERNEL_VERSION}" "${i}" )
 done
 
-echo "  CP      ${DOT_CONFIG} -> ${TARGET_CONFIG_BOOT}"
-cp -p "${DOT_CONFIG}" "${TARGET_CONFIG_BOOT}"
+out "CP" "${DOT_CONFIG} -> ${TARGET_CONFIG_BOOT}"
+if [ "${simulate}" = "y" ] ; then
+    echo "cp -p \"${DOT_CONFIG}\" \"${TARGET_CONFIG_BOOT}\""
+else
+    cp -p "${DOT_CONFIG}" "${TARGET_CONFIG_BOOT}"
+fi
 
-if [[ ! -d /etc/kernel-config ]] ; then
-    echo "  MKDIR   /etc/kernel-config"
-    mkdir -p /etc/kernel-config
+if [ ! -d /etc/kernel-config ] ; then
+    out "MKDIR" "/etc/kernel-config"
+    if [ "${simulate}" = "y" ] ; then
+        echo "mkdir -p /etc/kernel-config"
+    else
+        mkdir -p /etc/kernel-config
+    fi
 fi
 
 i=0
 TARGET_CONFIG_ETC=$( printf "%s/config-%s-%02d" "/etc/kernel-config" "${KERNEL_VERSION}" "${i}" )
-while [[ -f "${TARGET_CONFIG_ETC}" ]] ; do
+while [ -f "${TARGET_CONFIG_ETC}" ] ; do
     i=$(( i + 1 ))
     TARGET_CONFIG_ETC=$( printf "%s/config-%s-%02d" "/etc/kernel-config" "${KERNEL_VERSION}" "${i}" )
 done
 
-echo "  CP      ${DOT_CONFIG} -> ${TARGET_CONFIG_ETC}"
-cp -p "${DOT_CONFIG}" "${TARGET_CONFIG_ETC}"
+out 'CP' "${DOT_CONFIG} -> ${TARGET_CONFIG_ETC}"
+if [ "${simulate}" = "y" ] ; then
+    echo "cp -p \"${DOT_CONFIG}\" \"${TARGET_CONFIG_ETC}\""
+else
+    cp -p "${DOT_CONFIG}" "${TARGET_CONFIG_ETC}"
+fi
 
-if [[ -n "$KBUILD_OUTPUT_PREFIX" && -d $KBUILD_OUTPUT_PREFIX/$KERNEL_VERSION ]] ; then
+if [ -n "$KBUILD_OUTPUT_PREFIX" -a -d $KBUILD_OUTPUT_PREFIX/$KERNEL_VERSION ] ; then
     LINUX_SRC_DIR=$KBUILD_OUTPUT_PREFIX/$KERNEL_VERSION
 else
     LINUX_SRC_DIR="/usr/src/linux-$KERNEL_VERSION"
 fi
 
-i=0
-image_version=$( printf "%s-%02d" "${KERNEL_VERSION}" "${i}" )
-bzimage_inst="${BOOT_DIR}/bzImage-${image_version}"
-kernel_inst="${BOOT_DIR}/kernel-${image_version}"
-mapfile_inst="${BOOT_DIR}/System.map-${image_version}"
-while [[ -f "${bzimage_inst}" ]] ; do
-    i=$(( i + 1 ))
-    image_version=$( printf "%s-%02d" "${KERNEL_VERSION}" "${i}" )
-    bzimage_inst="${BOOT_DIR}/bzImage-${image_version}"
-    kernel_inst="${BOOT_DIR}/kernel-${image_version}"
-    mapfile_inst="${BOOT_DIR}/System.map-${image_version}"
-done
+# Install bzImage ...
+out "INSTALL" "$BOOT_DIR/bzImage-$KERNEL_VERSION"
 
-echo "  INSTALL ${bzimage_inst}"
-
-if [[ ! -f $LINUX_SRC_DIR/$KERNEL_IMAGE ]] ; then
-    if [[ -f $LINUX_SRC_DIR/arch/i386/boot/$KERNEL_IMAGE ]] ; then
+if [ ! -f $LINUX_SRC_DIR/$KERNEL_IMAGE ] ; then
+    if [ -f $LINUX_SRC_DIR/arch/i386/boot/$KERNEL_IMAGE ] ; then
         EX="/arch/i386/boot"
     else
         exit 1
     fi
 fi
+if [ "${simulate}" = "y" ] ; then
+    echo "cp -p $LINUX_SRC_DIR$EX/$KERNEL_IMAGE $BOOT_DIR/bzImage-$KERNEL_VERSION"
+else
+    cp -p $LINUX_SRC_DIR$EX/$KERNEL_IMAGE $BOOT_DIR/bzImage-$KERNEL_VERSION
+fi
+
+# Hardlink kernel-X.Y -> bzImage-X.Y
+out "LN" "$BOOT_DIR/kernel-$KERNEL_VERSION -> $BOOT_DIR/bzImage-$KERNEL_VERSION"
+if [ "${simulate}" = "y" ] ; then
+    echo "ln $BOOT_DIR/bzImage-$KERNEL_VERSION $BOOT_DIR/kernel-$KERNEL_VERSION"
+else
+    ln $BOOT_DIR/bzImage-$KERNEL_VERSION $BOOT_DIR/kernel-$KERNEL_VERSION
+fi
 
-if [[ -f $LINUX_SRC_DIR/$KERNEL_MAPFILE ]] ; then
+# Install System.map ...
+if [ -f $LINUX_SRC_DIR/$KERNEL_MAPFILE ] ; then
     KERNEL_MAPFILE=$LINUX_SRC_DIR/$KERNEL_MAPFILE
 else
     test -f $KERNEL_MAPFILE || exit 1
 fi
-
-cp -p $LINUX_SRC_DIR$EX/$KERNEL_IMAGE "${bzimage_inst}"
-
-echo "  LN      ${bzimage_inst} -> ${kernel_inst}"
-ln "${bzimage_inst}" "${kernel_inst}"
-
-echo "  INSTALL ${mapfile_inst}"
-cp -p $KERNEL_MAPFILE "${mapfile_inst}"
+out "INSTALL" "$BOOT_DIR/System.map-$KERNEL_VERSION"
+if [ "${simulate}" = "y" ] ; then
+    echo "cp -p $KERNEL_MAPFILE $BOOT_DIR/System.map-$KERNEL_VERSION"
+else
+    cp -p $KERNEL_MAPFILE $BOOT_DIR/System.map-$KERNEL_VERSION
+fi
 
 case $KERNEL_VERSION in
     *-gentoo*)
@@ -129,26 +170,158 @@ esac
 TARG_CUR=${TARG}-cur
 TARG_LAST=${TARG}-last
 
-if [[ -L $BOOT_DIR/bzImage${TARG_CUR} ]] ; then
-    IMG_LAST=$(readlink $BOOT_DIR/bzImage${TARG_CUR})
-    echo "  LN      $BOOT_DIR/bzImage${TARG_LAST}"
-    ln -sf ${IMG_LAST} $BOOT_DIR/bzImage${TARG_LAST}
+do_bzimage_cur="y"
+do_bzimage_last="n"
+
+bzimage_link_cur="$BOOT_DIR/bzImage${TARG_CUR}"
+bzimage_link_last="$BOOT_DIR/bzImage${TARG_LAST}"
+IMG_CUR=""
+IMG_CUR_NEW="bzImage-$KERNEL_VERSION"
+IMG_LAST=""
+
+# Create bzimage_link_last ...
+if [ -L "${bzimage_link_cur}" ] ; then
+
+    do_bzimage_cur="n"
+    IMG_CUR=$(readlink "${bzimage_link_cur}")
+    if [ -L "${bzimage_link_last}" ] ; then
+        IMG_LAST=$(readlink "${bzimage_link_last}")
+    fi
+
+    if [ -z "${IMG_LAST}" ] ; then
+        do_bzimage_last="y"
+    elif [ "${IMG_LAST}" != "${IMG_CUR}" ] ; then
+        do_bzimage_last="y"
+    fi
+
+    if [ "${IMG_CUR}" = "${IMG_CUR_NEW}" ] ; then
+        do_bzimage_cur="n"
+        if [ -n "${IMG_LAST}" ] ; then
+            do_bzimage_last="n"
+        fi
+    fi
+
+fi
+
+if [ "${do_bzimage_last}" = "y" ] ; then
+    out "LN" "${bzimage_link_last}"
+    if [ "${simulate}" = "y" ] ; then
+        echo "ln -sf ${IMG_LAST} ${bzimage_link_last}"
+    else
+        ln -sf ${IMG_LAST} "${bzimage_link_last}"
+    fi
+fi
+
+if [ "${do_bzimage_cur}" = "y" ] ; then
+    out "LN" "${bzimage_link_cur}"
+    if [ "${simulate}" = "y" ] ; then
+        echo "ln -sf ${IMG_CUR_NEW} ${bzimage_link_cur}"
+    else
+        ln -sf ${IMG_CUR_NEW} "${bzimage_link_cur}"
+    fi
+fi
+
+#----------------------------------------------------------------------
+INITRD_LINK_CUR="$BOOT_DIR/initrd${TARG_CUR}"
+INITRD_LINK_LAST="$BOOT_DIR/initrd${TARG_LAST}"
+
+INITRD_CUR_NEW="initramfs-genkernel-${KBUILD_BUILDHOST}-${KERNEL_VERSION}"
+INITRD_CUR=""
+INITRD_LAST=""
+
+if [ -L "${INITRD_LINK_CUR}" ] ; then
+    INITRD_CUR=$(readlink "${INITRD_LINK_CUR}")
+fi
+if [ -L "${INITRD_LINK_LAST}" ] ; then
+    INITRD_LAST=$(readlink "${INITRD_LINK_LAST}")
+fi
+
+do_ln_initrd_cur="n"
+if [ "${DO_GENKERNEL}" = "y" -a "${INITRD_CUR}" != "${INITRD_CUR_NEW}" ] ; then
+    do_ln_initrd_cur="y"
+fi
+
+do_ln_initrd_last="n"
+if [ "${DO_GENKERNEL}" = "y" -a "${do_ln_initrd_cur}" = "y" -a "${INITRD_LAST}" != "${INITRD_CUR}" ] ; then
+    do_ln_initrd_cur="y"
+fi
+
+if [ "${do_ln_initrd_last}" = "y" ] ; then
+    out "LN" "${INITRD_LINK_LAST} -> ${INITRD_CUR}"
+    if [ "${simulate}" = "y" ] ; then
+        echo "ln -sf ${INITRD_CUR} ${INITRD_LINK_LAST}"
+    else
+        ln -sf ${INITRD_CUR} "${INITRD_LINK_LAST}"
+    fi
+fi
+
+if [ "${do_ln_initrd_cur}" = "y" ] ; then
+    out "LN" "${INITRD_LINK_CUR} -> ${INITRD_CUR_NEW}"
+    if [ "${simulate}" = "y" ] ; then
+        echo "ln -sf ${INITRD_CUR_NEW} ${INITRD_LINK_CUR}"
+    else
+        ln -sf ${INITRD_CUR_NEW} "${INITRD_LINK_CUR}"
+    fi
+fi
+
+if [ "${DO_GENKERNEL}" = "y" ] ; then
+
+    out "CREATE" "${INITRD_CUR_NEW}"
+
+    if [ "${simulate}" = "y" ] ; then
+        echo "genkernel --kerneldir=\".\" --install --no-ramdisk-modules --lvm --mdadm initramfs"
+    else
+        genkernel --kerneldir="." --install --no-ramdisk-modules --lvm --mdadm initramfs
+    fi
+
 fi
 
-echo "  LN      $BOOT_DIR/bzImage${TARG_CUR}"
-ln -sf "bzImage-${image_version}" $BOOT_DIR/bzImage${TARG_CUR}
+#----------------------------------------------------------------------
+SYSTEM_MAP_LINK_CUR="$BOOT_DIR/System${TARG_CUR}.map"
+SYSTEM_MAP_LINK_LAST="$BOOT_DIR/System${TARG_LAST}.map"
+
+SYSTEM_MAP_CUR_NEW="System.map-${KERNEL_VERSION}"
+SYSTEM_MAP_CUR=""
+SYSTEM_MAP_LAST=""
 
-if [[ -L $BOOT_DIR/System${TARG_CUR}.map ]] ; then
-    IMG_LAST=$(readlink $BOOT_DIR/System${TARG_CUR}.map)
-    echo "  LN      $BOOT_DIR/System${TARG_LAST}.map"
-    ln -sf $IMG_LAST $BOOT_DIR/System${TARG_LAST}.map
+if [ -L "${SYSTEM_MAP_LINK_CUR}" ] ; then
+    SYSTEM_MAP_CUR=$(readlink "${SYSTEM_MAP_LINK_CUR}")
+fi
+if [ -L "${SYSTEM_MAP_LINK_LAST}" ] ; then
+    SYSTEM_MAP_LAST=$(readlink "${SYSTEM_MAP_LINK_LAST}")
 fi
 
-echo "  LN      $BOOT_DIR/System${TARG_CUR}.map"
-ln -sf "System.map-${image_version}" $BOOT_DIR/System${TARG_CUR}.map
+do_ln_system_map_cur="n"
+if [ "${SYSTEM_MAP_CUR}" != "${SYSTEM_MAP_CUR_NEW}" ] ; then
+    do_ln_system_map_cur="y"
+fi
+
+do_ln_system_map_last="n"
+if [ -n "${SYSTEM_MAP_CUR}" -a "${do_ln_system_map_cur}" = "y" -a "${SYSTEM_MAP_LAST}" != "${SYSTEM_MAP_CUR}" ] ; then
+    do_ln_system_map_cur="y"
+fi
+
+if [ "${do_ln_system_map_last}" = "y" ] ; then
+    out "LN" "${SYSTEM_MAP_LINK_LAST} -> ${SYSTEM_MAP_CUR}"
+    if [ "${simulate}" = "y" ] ; then
+        echo "ln -sf ${SYSTEM_MAP_CUR} ${SYSTEM_MAP_LINK_LAST}"
+    else
+        ln -sf ${SYSTEM_MAP_CUR} "${SYSTEM_MAP_LINK_LAST}"
+    fi
+fi
+
+if [ "${do_ln_system_map_cur}" = "y" ] ; then
+    out "LN" "${SYSTEM_MAP_LINK_LAST} -> ${SYSTEM_MAP_CUR_NEW}"
+    if [ "${simulate}" = "y" ] ; then
+        echo "ln -sf ${SYSTEM_MAP_CUR_NEW} ${SYSTEM_MAP_LINK_LAST}"
+    else
+        ln -sf ${SYSTEM_MAP_CUR_NEW} "${SYSTEM_MAP_LINK_LAST}"
+    fi
+fi
 
+#----------------------------------------------------------------------
 if [ "${was_mounted}" = "n" ] ; then
-    echo "  UMOUNT  ${BOOT_DIR}"
+    out "UMOUNT" "${BOOT_DIR}"
     umount ${BOOT_DIR}
 fi