From 57c88207c488d0579cb475a248e53b6cadcc737c Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 28 Dec 2016 14:41:15 +0100 Subject: [PATCH] Improved installkernel --- installkernel | 121 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 106 insertions(+), 15 deletions(-) diff --git a/installkernel b/installkernel index 581669b..198f0f3 100755 --- a/installkernel +++ b/installkernel @@ -8,10 +8,12 @@ VERSION="2011-10-26" echo -e "\n$ME:\nFrank Brehm's installkernel script, $VERSION" echo "* Arguments: -kernel version: $1 -kernel image file: $2 -kernel map file: $3 -default install path: $4 +kernel version: $1 +kernel image file: $2 +kernel map file: $3 +default install path: $4 + +current path: $( pwd ) " #B="/mnt/misc/boot" @@ -21,6 +23,8 @@ KERNEL_IMAGE=$2 KERNEL_MAPFILE=$3 DEF_INSTALL_PATH=$4 +SIMULATE='n' + was_mounted='y' # check we have a valid kernel target directory @@ -50,6 +54,16 @@ else fi i=0 +for f in $( ls -1 -tr "${BOOT_DIR}/config-${KERNEL_VERSION}"* 2>/dev/null || true ) ; do + if [[ ! -f "${f}" ]] ; then + break + fi + j=$( echo "${f}" | sed -e "s|${BOOT_DIR}/config-${KERNEL_VERSION}-||" ) + if [[ -z "${j}" ]] ; then + continue + fi + i=$(( $j + 0 )) +done TARGET_CONFIG_BOOT=$( printf "%s/config-%s-%02d" "${BOOT_DIR}" "${KERNEL_VERSION}" "${i}" ) while [[ -f "${TARGET_CONFIG_BOOT}" ]] ; do i=$(( i + 1 )) @@ -57,7 +71,11 @@ while [[ -f "${TARGET_CONFIG_BOOT}" ]] ; do done echo " CP ${DOT_CONFIG} -> ${TARGET_CONFIG_BOOT}" -cp -p "${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" @@ -65,6 +83,16 @@ if [[ ! -d /etc/kernel-config ]] ; then fi i=0 +for f in $( ls -1 -tr "/etc/kernel-config/config-${KERNEL_VERSION}"* 2>/dev/null || true ) ; do + if [[ ! -f "${f}" ]] ; then + break + fi + j=$( echo "${f}" | sed -e "s|/etc/kernel-config/config-${KERNEL_VERSION}-||" ) + if [[ -z "${j}" ]] ; then + continue + fi + i=$(( $j + 0 )) +done TARGET_CONFIG_ETC=$( printf "%s/config-%s-%02d" "/etc/kernel-config" "${KERNEL_VERSION}" "${i}" ) while [[ -f "${TARGET_CONFIG_ETC}" ]] ; do i=$(( i + 1 )) @@ -72,7 +100,11 @@ while [[ -f "${TARGET_CONFIG_ETC}" ]] ; do done echo " CP ${DOT_CONFIG} -> ${TARGET_CONFIG_ETC}" -cp -p "${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 LINUX_SRC_DIR=$KBUILD_OUTPUT_PREFIX/$KERNEL_VERSION @@ -81,6 +113,16 @@ else fi i=0 +for f in $( ls -1 -tr "${BOOT_DIR}/bzImage-${KERNEL_VERSION}"* 2>/dev/null || true ) ; do + if [[ ! -f "${f}" ]] ; then + break + fi + j=$( echo "${f}" | sed -e "s|${BOOT_DIR}/bzImage-${KERNEL_VERSION}-||" ) + if [[ -z "${j}" ]] ; then + continue + fi + i=$(( $j + 0 )) +done image_version=$( printf "%s-%02d" "${KERNEL_VERSION}" "${i}" ) bzimage_inst="${BOOT_DIR}/bzImage-${image_version}" kernel_inst="${BOOT_DIR}/kernel-${image_version}" @@ -109,13 +151,25 @@ else test -f $KERNEL_MAPFILE || exit 1 fi -cp -p $LINUX_SRC_DIR$EX/$KERNEL_IMAGE "${bzimage_inst}" +if [[ "${SIMULATE}" == "y" ]] ; then + echo " cp -p \"${LINUX_SRC_DIR}${EX}/${KERNEL_IMAGE}\" \"${bzimage_inst}\"" +else + cp -p "${LINUX_SRC_DIR}${EX}/${KERNEL_IMAGE}" "${bzimage_inst}" +fi echo " LN ${bzimage_inst} -> ${kernel_inst}" -ln "${bzimage_inst}" "${kernel_inst}" +if [[ "${SIMULATE}" == "y" ]] ; then + echo " ln \"${bzimage_inst}\" \"${kernel_inst}\"" +else + ln "${bzimage_inst}" "${kernel_inst}" +fi echo " INSTALL ${mapfile_inst}" -cp -p $KERNEL_MAPFILE "${mapfile_inst}" +if [[ "${SIMULATE}" == "y" ]] ; then + echo " cp -p \"${KERNEL_MAPFILE}\" \"${mapfile_inst}\"" +else + cp -p "${KERNEL_MAPFILE}" "${mapfile_inst}" +fi case $KERNEL_VERSION in *-gentoo*) @@ -132,24 +186,61 @@ 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} + if [[ "${SIMULATE}" == "y" ]] ; then + echo " ln -sf ${IMG_LAST} $BOOT_DIR/bzImage${TARG_LAST}" + else + ln -sf ${IMG_LAST} $BOOT_DIR/bzImage${TARG_LAST} + fi fi echo " LN $BOOT_DIR/bzImage${TARG_CUR}" -ln -sf "bzImage-${image_version}" $BOOT_DIR/bzImage${TARG_CUR} +if [[ "${SIMULATE}" == "y" ]] ; then + echo " ln -sf \"bzImage-${image_version}\" $BOOT_DIR/bzImage${TARG_CUR}" +else + ln -sf "bzImage-${image_version}" $BOOT_DIR/bzImage${TARG_CUR} +fi if [[ -L $BOOT_DIR/System${TARG_CUR}.map ]] ; then - IMG_LAST=$(readlink $BOOT_DIR/System${TARG_CUR}.map) + SYSTEM_MAP_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 [[ "${SIMULATE}" == "y" ]] ; then + echo " ln -sf ${SYSTEM_MAP_LAST} $BOOT_DIR/System${TARG_LAST}.map" + else + ln -sf $SYSTEM_MAP_LAST $BOOT_DIR/System${TARG_LAST}.map + fi fi echo " LN $BOOT_DIR/System${TARG_CUR}.map" -ln -sf "System.map-${image_version}" $BOOT_DIR/System${TARG_CUR}.map +if [[ "${SIMULATE}" == "y" ]] ; then + echo " ln -sf \"System.map-${image_version}\" $BOOT_DIR/Sytem${TARG_CUR}.map" +else + ln -sf "System.map-${image_version}" $BOOT_DIR/System${TARG_CUR}.map +fi + +if [[ -x "/usr/bin/genkernel" && -f "/etc/kernel-config/do-genkernel" ]] ; then + initrd_src=$( printf "initramfs-genkernel-x86_64-%s" "${KERNEL_VERSION}" ) + initrd_tgt="initramfs-genkernel-x86_64-${image_version}" + echo " INITRD ${initrd_src}" + if [[ "${SIMULATE}" == "y" ]] ; then + echo " /usr/bin/genkernel --kerneldir=. --install initramfs" + else + /usr/bin/genkernel --kerneldir=. --install initramfs || exit $? + fi + if [[ "${SIMULATE}" != "y" && ! -f "$BOOT_DIR/${initrd_src}" ]] ; then + echo "File '$BOOT_DIR/${initrd_src}' not found." >&2 + exit 6 + fi + echo " MV ${initrd_src} -> ${initrd_tgt}" + if [[ "${SIMULATE}" == "y" ]] ; then + echo " mv -i \"$BOOT_DIR/${initrd_src}\" \"$BOOT_DIR/${initrd_tgt}\"" + else + mv -i "$BOOT_DIR/${initrd_src}" "$BOOT_DIR/${initrd_tgt}"