annotate removeKernel @ 174:5da4de3d7ee1

remove files from /var/tmp/genkernel and /lib/modules, too
author Dirk Olmes <dirk.olmes@codedo.de>
date Thu, 09 Apr 2020 11:21:59 +0200
parents 4500455b2375
children 8af0a6219353
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
160
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
1 #!/bin/bash
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
2
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
3 if [ `whoami` != "root" ]; then
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
4 echo "$0 must be run as root!"
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
5 exit 1
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
6 fi
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
7
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
8 if [ $# -lt 3 ]; then
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
9 echo "usage: $0 <major minor micro [revision], e.g. 2 6 21 r4>"
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
10 exit 1
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
11 fi
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
12
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
13 MAJOR=$1
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
14 MINOR=$2
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
15 MICRO=$3
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
16 if [ $# -gt 3 ]; then
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
17 REVISION=$4
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
18 fi
174
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
19
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
20 ARCH=`uname -m`
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
21 if [ "$ARCH" = "i686" ]; then
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
22 ARCH="x86"
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
23 fi
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
24
160
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
25 LOGFILE=/tmp/removeKernel-$$.log
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
26
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
27 # unmerge the kernel
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
28 cd /usr/src
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
29 KERNEL_DIR="linux-${MAJOR}.${MINOR}.${MICRO}-gentoo"
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
30 if [ "$REVISION" != "" ]; then
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
31 KERNEL_DIR="${KERNEL_DIR}-${REVISION}"
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
32 fi
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
33 if [ -d $KERNEL_DIR ]; then
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
34 KERNEL_NAME=gentoo-sources-${MAJOR}.${MINOR}.${MICRO}
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
35 if [ "${REVISION}" != "" ]; then
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
36 KERNEL_NAME="${KERNEL_NAME}-${REVISION}"
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
37 fi
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
38
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
39 echo "unmerge kernel $KERNEL_NAME" >> $LOGFILE 2>&1
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
40 emerge --unmerge $KERNEL_NAME >> $LOGFILE 2>&1
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
41
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
42 echo "remove $KERNEL_DIR" >> $LOGFILE 2>&1
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
43 rm -r $KERNEL_DIR >> $LOGFILE 2>&1
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
44 fi
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
45
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
46 # remove modules
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
47 cd /lib/modules
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
48 LIB_DIR=${MAJOR}.${MINOR}.${MICRO}-gentoo
174
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
49 if [[ "$REVISION" != "" ]]; then
160
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
50 LIB_DIR="${LIB_DIR}-${REVISION}"
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
51 fi
174
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
52 if [[ ! -d $LIB_DIR ]]; then
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
53 LIB_DIR="${LIB_DIR}-${ARCH}"
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
54 fi
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
55 if [[ -d $LIB_DIR ]]; then
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
56 echo "remove modules from `pwd`/${LIB_DIR}" >> $LOGFILE 2>&1
160
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
57 rm -r $LIB_DIR >> $LOGFILE 2>&1
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
58 fi
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
59
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
60 # remove the kernel and stuff, check if /boot is mounted first
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
61 MOUNTED=`mount | grep /boot`
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
62 if [ "$MOUNTED" = "" ]; then
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
63 echo "mount /boot" >> $LOGFILE 2>&1
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
64 mount /boot >> $LOGFILE 2>&1
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
65 fi
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
66
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
67 cd /boot
161
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
68 SUFFIX_V3="genkernel-${ARCH}-${MAJOR}.${MINOR}.${MICRO}"
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
69 if [[ "${REVISION}" != "" ]]; then
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
70 SUFFIX_V3="${SUFFIX_V3}-${REVISION}"
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
71 fi
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
72 SUFFIX_V3="${SUFFIX_V3}-gentoo"
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
73
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
74 SUFFIX_V4="${MAJOR}.${MINOR}.${MICRO}"
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
75 if [ "${REVISION}" != "" ]; then
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
76 SUFFIX_V4="${SUFFIX_V4}-${REVISION}"
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
77 fi
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
78 SUFFIX_V4="${SUFFIX_V4}-gentoo-${ARCH}"
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
79
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
80 SYSTEM_MAP="System.map-${SUFFIX_V3}"
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
81 if [[ -f $SYSTEM_MAP ]]; then
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
82 rm ${SYSTEM_MAP} >> $LOGFILE 2>&1
160
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
83 fi
161
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
84 SYSTEM_MAP="System.map-${SUFFIX_V4}"
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
85 if [[ -f ${SYSTEM_MAP} ]]; then
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
86 rm ${SYSTEM_MAP} >> $LOGFILE 2>&1
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
87 fi
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
88 if [[ -f ${SYSTEM_MAP}.old ]]; then
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
89 rm ${SYSTEM_MAP}.old >> $LOGFILE 2>&1
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
90 fi
160
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
91
161
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
92 INITRAMFS="initramfs-${SUFFIX_V3}"
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
93 if [[ -f ${INITRAMFS} ]]; then
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
94 rm ${INITRAMFS} >> $LOGFILE 2>&1
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
95 fi
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
96 INITRAMFS="initramfs-${SUFFIX_V4}"
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
97 if [[ -f ${INITRAMFS} ]]; then
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
98 rm ${INITRAMFS} >> $LOGFILE 2>&1
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
99 fi
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
100 if [[ -f ${INITRAMFS}.old ]]; then
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
101 rm ${INITRAMFS}.old >> $LOGFILE 2>&1
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
102 fi
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
103
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
104 KERNEL="kernel-${SUFFIX_V3}"
160
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
105 if [[ -f $KERNEL ]]; then
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
106 rm $KERNEL >> $LOGFILE 2>&1
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
107 fi
161
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
108 KERNEL="vmlinuz-${SUFFIX_V4}"
160
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
109 if [[ -f $KERNEL ]]; then
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
110 rm $KERNEL >> $LOGFILE 2>&1
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
111 fi
161
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
112 if [[ -f $KERNEL.old ]]; then
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
113 rm $KERNEL.old >> $LOGFILE 2>&1
4500455b2375 Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 160
diff changeset
114 fi
160
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
115
174
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
116 cd /var/tmp/genkernel
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
117 INITRAMFS="initramfs-${ARCH}-${SUFFIX_V4}"
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
118 if [[ -f ${INITRAMFS} ]]; then
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
119 rm ${INITRAMFS} >> $LOGFILE 2>&1
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
120 fi
5da4de3d7ee1 remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents: 161
diff changeset
121
160
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
122 # if we got until here, just remove the logfile again
c35d56590441 add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
123 rm $LOGFILE