diff removeKernel @ 175:8af0a6219353

Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
author Dirk Olmes <dirk.olmes@codedo.de>
date Wed, 15 Apr 2020 09:02:04 +0200
parents 5da4de3d7ee1
children 249b37a8c917
line wrap: on
line diff
--- a/removeKernel	Thu Apr 09 11:21:59 2020 +0200
+++ b/removeKernel	Wed Apr 15 09:02:04 2020 +0200
@@ -17,24 +17,30 @@
     REVISION=$4
 fi
 
+FULL_VERSION="${MAJOR}.${MINOR}.${MICRO}"
+if [[ "${REVISION}" != "" ]]; then
+	FULL_VERSION=$"{FULL_VERSION}-${REVISION}"
+fi
+
 ARCH=`uname -m`
 if [ "$ARCH" = "i686" ]; then
     ARCH="x86"
 fi
 
+KERNEL_FLAVOR=""
+KERNEL_EBUILD="vanilla-sources"
+if [[ "$(grep gentoo-sources /var/lib/portage/world)" != "" ]]; then
+	KERNEL_FLAVOR="-gentoo"
+	KERNEL_EBUILD="gentoo-sources"
+fi
+
 LOGFILE=/tmp/removeKernel-$$.log
 
 # unmerge the kernel
 cd /usr/src
-KERNEL_DIR="linux-${MAJOR}.${MINOR}.${MICRO}-gentoo"
-if [ "$REVISION" != "" ]; then
-    KERNEL_DIR="${KERNEL_DIR}-${REVISION}"
-fi
+KERNEL_DIR="linux-${FULL_VERSION}${KERNEL_FLAVOR}"
 if [ -d $KERNEL_DIR ]; then
-    KERNEL_NAME=gentoo-sources-${MAJOR}.${MINOR}.${MICRO}
-    if [ "${REVISION}" != "" ]; then
-        KERNEL_NAME="${KERNEL_NAME}-${REVISION}"
-    fi
+	KERNEL_NAME="${KERNEL_EBUILD}-${FULL_VERSION}"
 
     echo "unmerge kernel $KERNEL_NAME" >> $LOGFILE 2>&1
     emerge --unmerge $KERNEL_NAME >> $LOGFILE 2>&1
@@ -45,16 +51,10 @@
 
 # remove modules
 cd /lib/modules
-LIB_DIR=${MAJOR}.${MINOR}.${MICRO}-gentoo
-if [[ "$REVISION" != "" ]]; then
-    LIB_DIR="${LIB_DIR}-${REVISION}"
-fi
-if [[ ! -d $LIB_DIR ]]; then
-	LIB_DIR="${LIB_DIR}-${ARCH}"
-fi
-if [[ -d $LIB_DIR ]]; then
-    echo "remove modules from `pwd`/${LIB_DIR}" >> $LOGFILE 2>&1
-    rm -r $LIB_DIR >> $LOGFILE 2>&1
+LIB_DIR="${FULL_VERSION}${KERNEL_FLAVOR}-${ARCH}"
+if [[ -d ${LIB_DIR} ]]; then
+    echo "remove modules from $(pwd)/${LIB_DIR}" >> $LOGFILE 2>&1
+    rm -r ${LIB_DIR} >> $LOGFILE 2>&1
 fi
 
 # remove the kernel and stuff, check if /boot is mounted first
@@ -65,23 +65,8 @@
 fi
 
 cd /boot
-SUFFIX_V3="genkernel-${ARCH}-${MAJOR}.${MINOR}.${MICRO}"
-if [[ "${REVISION}" != "" ]]; then
-	SUFFIX_V3="${SUFFIX_V3}-${REVISION}"
-fi
-SUFFIX_V3="${SUFFIX_V3}-gentoo"
 
-SUFFIX_V4="${MAJOR}.${MINOR}.${MICRO}"
-if [ "${REVISION}" != "" ]; then
-    SUFFIX_V4="${SUFFIX_V4}-${REVISION}"
-fi
-SUFFIX_V4="${SUFFIX_V4}-gentoo-${ARCH}"
-
-SYSTEM_MAP="System.map-${SUFFIX_V3}"
-if [[ -f $SYSTEM_MAP ]]; then
-	rm ${SYSTEM_MAP} >> $LOGFILE 2>&1
-fi
-SYSTEM_MAP="System.map-${SUFFIX_V4}"
+SYSTEM_MAP="System.map-${FULL_VERSION}${KERNEL_FLAVOR}-${ARCH}"
 if [[ -f ${SYSTEM_MAP} ]]; then
 	rm ${SYSTEM_MAP} >> $LOGFILE 2>&1
 fi
@@ -89,11 +74,7 @@
 	rm ${SYSTEM_MAP}.old >> $LOGFILE 2>&1
 fi
 
-INITRAMFS="initramfs-${SUFFIX_V3}"
-if [[ -f ${INITRAMFS} ]]; then
-	rm ${INITRAMFS} >> $LOGFILE 2>&1
-fi
-INITRAMFS="initramfs-${SUFFIX_V4}"
+INITRAMFS="initramfs-${FULL_VERSION}${KERNEL_FLAVOR}-${ARCH}.img"
 if [[ -f ${INITRAMFS} ]]; then
 	rm ${INITRAMFS} >> $LOGFILE 2>&1
 fi
@@ -101,11 +82,7 @@
 	rm ${INITRAMFS}.old >> $LOGFILE 2>&1
 fi
 
-KERNEL="kernel-${SUFFIX_V3}"
-if [[ -f $KERNEL ]]; then
-	rm $KERNEL >> $LOGFILE 2>&1
-fi
-KERNEL="vmlinuz-${SUFFIX_V4}"
+KERNEL="vmlinuz-${FULL_VERSION}${KERNEL_FLAVOR}-${ARCH}"
 if [[ -f $KERNEL ]]; then
 	rm $KERNEL >> $LOGFILE 2>&1
 fi
@@ -114,7 +91,7 @@
 fi
 
 cd /var/tmp/genkernel
-INITRAMFS="initramfs-${ARCH}-${SUFFIX_V4}"
+INITRAMFS="initramfs-${ARCH}-${FULL_VERSION}${KERNEL_FLAVOR}-${ARCH}"
 if [[ -f ${INITRAMFS} ]]; then
     rm ${INITRAMFS} >> $LOGFILE 2>&1
 fi