Mercurial > hg > zsh-env
annotate removeKernel @ 183:249b37a8c917
Fix fuer Kernel Versionen mit Revision
author | Dirk Olmes <dirk.olmes@codedo.de> |
---|---|
date | Tue, 22 Dec 2020 12:03:22 +0100 |
parents | 8af0a6219353 |
children |
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 |
175
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
20 FULL_VERSION="${MAJOR}.${MINOR}.${MICRO}" |
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
21 if [[ "${REVISION}" != "" ]]; then |
183
249b37a8c917
Fix fuer Kernel Versionen mit Revision
Dirk Olmes <dirk.olmes@codedo.de>
parents:
175
diff
changeset
|
22 FULL_VERSION="${FULL_VERSION}-${REVISION}" |
175
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
23 fi |
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
24 |
174
5da4de3d7ee1
remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents:
161
diff
changeset
|
25 ARCH=`uname -m` |
5da4de3d7ee1
remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents:
161
diff
changeset
|
26 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
|
27 ARCH="x86" |
5da4de3d7ee1
remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents:
161
diff
changeset
|
28 fi |
5da4de3d7ee1
remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents:
161
diff
changeset
|
29 |
175
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
30 KERNEL_FLAVOR="" |
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
31 KERNEL_EBUILD="vanilla-sources" |
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
32 if [[ "$(grep gentoo-sources /var/lib/portage/world)" != "" ]]; then |
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
33 KERNEL_FLAVOR="-gentoo" |
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
34 KERNEL_EBUILD="gentoo-sources" |
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
35 fi |
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
36 |
160
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
37 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
|
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 # 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
|
40 cd /usr/src |
183
249b37a8c917
Fix fuer Kernel Versionen mit Revision
Dirk Olmes <dirk.olmes@codedo.de>
parents:
175
diff
changeset
|
41 KERNEL_DIR="linux-${MAJOR}.${MINOR}.${MICRO}${KERNEL_FLAVOR}" |
249b37a8c917
Fix fuer Kernel Versionen mit Revision
Dirk Olmes <dirk.olmes@codedo.de>
parents:
175
diff
changeset
|
42 if [[ "${REVISION}" != "" ]]; then |
249b37a8c917
Fix fuer Kernel Versionen mit Revision
Dirk Olmes <dirk.olmes@codedo.de>
parents:
175
diff
changeset
|
43 KERNEL_DIR="${KERNEL_DIR}-${REVISION}" |
249b37a8c917
Fix fuer Kernel Versionen mit Revision
Dirk Olmes <dirk.olmes@codedo.de>
parents:
175
diff
changeset
|
44 fi |
249b37a8c917
Fix fuer Kernel Versionen mit Revision
Dirk Olmes <dirk.olmes@codedo.de>
parents:
175
diff
changeset
|
45 if [[ -d $KERNEL_DIR ]]; then |
175
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
46 KERNEL_NAME="${KERNEL_EBUILD}-${FULL_VERSION}" |
160
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
47 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
48 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
|
49 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
|
50 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
51 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
|
52 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
|
53 fi |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
54 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
55 # 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
|
56 cd /lib/modules |
175
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
57 LIB_DIR="${FULL_VERSION}${KERNEL_FLAVOR}-${ARCH}" |
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
58 if [[ -d ${LIB_DIR} ]]; then |
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
59 echo "remove modules from $(pwd)/${LIB_DIR}" >> $LOGFILE 2>&1 |
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
60 rm -r ${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
|
61 fi |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
62 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
63 # 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 fi |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
69 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
70 cd /boot |
161
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
71 |
175
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
72 SYSTEM_MAP="System.map-${FULL_VERSION}${KERNEL_FLAVOR}-${ARCH}" |
161
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
73 if [[ -f ${SYSTEM_MAP} ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
74 rm ${SYSTEM_MAP} >> $LOGFILE 2>&1 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
75 fi |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
76 if [[ -f ${SYSTEM_MAP}.old ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
77 rm ${SYSTEM_MAP}.old >> $LOGFILE 2>&1 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
78 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
|
79 |
175
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
80 INITRAMFS="initramfs-${FULL_VERSION}${KERNEL_FLAVOR}-${ARCH}.img" |
161
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
81 if [[ -f ${INITRAMFS} ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
82 rm ${INITRAMFS} >> $LOGFILE 2>&1 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
83 fi |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
84 if [[ -f ${INITRAMFS}.old ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
85 rm ${INITRAMFS}.old >> $LOGFILE 2>&1 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
86 fi |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
87 |
175
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
88 KERNEL="vmlinuz-${FULL_VERSION}${KERNEL_FLAVOR}-${ARCH}" |
160
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
89 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
|
90 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
|
91 fi |
161
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
92 if [[ -f $KERNEL.old ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
93 rm $KERNEL.old >> $LOGFILE 2>&1 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
94 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
|
95 |
174
5da4de3d7ee1
remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents:
161
diff
changeset
|
96 cd /var/tmp/genkernel |
175
8af0a6219353
Remove the support for genkernel 3, add support for distinguishing between gentoo/vanilla sources
Dirk Olmes <dirk.olmes@codedo.de>
parents:
174
diff
changeset
|
97 INITRAMFS="initramfs-${ARCH}-${FULL_VERSION}${KERNEL_FLAVOR}-${ARCH}" |
174
5da4de3d7ee1
remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents:
161
diff
changeset
|
98 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
|
99 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
|
100 fi |
5da4de3d7ee1
remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents:
161
diff
changeset
|
101 |
160
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
102 # 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
|
103 rm $LOGFILE |