comparison removeKernel @ 160:c35d56590441

add the two helper scripts for gentoo that are requied on all hosts
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 23 Dec 2019 11:41:35 +0100
parents
children 4500455b2375
comparison
equal deleted inserted replaced
159:d0cdc3f47182 160:c35d56590441
1 #!/bin/bash
2
3 if [ `whoami` != "root" ]; then
4 echo "$0 must be run as root!"
5 exit 1
6 fi
7
8 if [ $# -lt 3 ]; then
9 echo "usage: $0 <major minor micro [revision], e.g. 2 6 21 r4>"
10 exit 1
11 fi
12
13 MAJOR=$1
14 MINOR=$2
15 MICRO=$3
16 if [ $# -gt 3 ]; then
17 REVISION=$4
18 fi
19 LOGFILE=/tmp/removeKernel-$$.log
20
21 # unmerge the kernel
22 cd /usr/src
23 KERNEL_DIR="linux-${MAJOR}.${MINOR}.${MICRO}-gentoo"
24 if [ "$REVISION" != "" ]; then
25 KERNEL_DIR="${KERNEL_DIR}-${REVISION}"
26 fi
27 if [ -d $KERNEL_DIR ]; then
28 KERNEL_NAME=gentoo-sources-${MAJOR}.${MINOR}.${MICRO}
29 if [ "${REVISION}" != "" ]; then
30 KERNEL_NAME="${KERNEL_NAME}-${REVISION}"
31 fi
32
33 echo "unmerge kernel $KERNEL_NAME" >> $LOGFILE 2>&1
34 emerge --unmerge $KERNEL_NAME >> $LOGFILE 2>&1
35
36 echo "remove $KERNEL_DIR" >> $LOGFILE 2>&1
37 rm -r $KERNEL_DIR >> $LOGFILE 2>&1
38 fi
39
40 # remove modules
41 cd /lib/modules
42 LIB_DIR=${MAJOR}.${MINOR}.${MICRO}-gentoo
43 if [ "$REVISION" != "" ]; then
44 LIB_DIR="${LIB_DIR}-${REVISION}"
45 fi
46 if [ -d $LIB_DIR ]; then
47 echo "remove modules from `pwd`/$LIB_DIR" >> $LOGFILE 2>&1
48 rm -r $LIB_DIR >> $LOGFILE 2>&1
49 fi
50
51 # remove the kernel and stuff, check if /boot is mounted first
52 MOUNTED=`mount | grep /boot`
53 if [ "$MOUNTED" = "" ]; then
54 echo "mount /boot" >> $LOGFILE 2>&1
55 mount /boot >> $LOGFILE 2>&1
56 fi
57
58 cd /boot
59
60 ARCH=`uname -m`
61 if [ "$ARCH" = "i686" ]; then
62 ARCH="x86"
63 fi
64
65 SUFFIX=genkernel-${ARCH}-${MAJOR}.${MINOR}.${MICRO}-gentoo
66 if [ "$REVISION" != "" ]; then
67 SUFFIX="$SUFFIX-${REVISION}"
68 fi
69 rm System.map-${SUFFIX} >> $LOGFILE 2>&1
70 rm initramfs-${SUFFIX} >> $LOGFILE 2>&1
71
72 KERNEL="kernel-${SUFFIX}"
73 if [[ -f $KERNEL ]]; then
74 rm $KERNEL >> $LOGFILE 2>&1
75 fi
76 KERNEL="vmlinuz-${MAJOR}.${MINOR}.${MICRO}-gentoo-${ARCH}"
77 if [[ -f $KERNEL ]]; then
78 rm $KERNEL >> $LOGFILE 2>&1
79 fi
80
81 # if we got until here, just remove the logfile again
82 rm $LOGFILE