Mercurial > hg > zsh-env
annotate removeKernel @ 180:bfc94ec31b2b
allow a local include in .gitconfig
author | Dirk Olmes <dirk.olmes@codedo.de> |
---|---|
date | Tue, 04 Aug 2020 11:20:15 +0200 |
parents | 8af0a6219353 |
children | 249b37a8c917 |
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 |
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
|
22 FULL_VERSION=$"{FULL_VERSION}-${REVISION}" |
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 |
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
|
41 KERNEL_DIR="linux-${FULL_VERSION}${KERNEL_FLAVOR}" |
160
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
42 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
|
43 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
|
44 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
45 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
|
46 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
|
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 "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
|
49 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
|
50 fi |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
51 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
52 # 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
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 |
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
|
69 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
|
70 if [[ -f ${SYSTEM_MAP} ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
71 rm ${SYSTEM_MAP} >> $LOGFILE 2>&1 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
72 fi |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
73 if [[ -f ${SYSTEM_MAP}.old ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
74 rm ${SYSTEM_MAP}.old >> $LOGFILE 2>&1 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
75 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
|
76 |
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
|
77 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
|
78 if [[ -f ${INITRAMFS} ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
79 rm ${INITRAMFS} >> $LOGFILE 2>&1 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
80 fi |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
81 if [[ -f ${INITRAMFS}.old ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
82 rm ${INITRAMFS}.old >> $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 |
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
|
85 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
|
86 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
|
87 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
|
88 fi |
161
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
89 if [[ -f $KERNEL.old ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
90 rm $KERNEL.old >> $LOGFILE 2>&1 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
91 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
|
92 |
174
5da4de3d7ee1
remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents:
161
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 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
|
97 fi |
5da4de3d7ee1
remove files from /var/tmp/genkernel and /lib/modules, too
Dirk Olmes <dirk.olmes@codedo.de>
parents:
161
diff
changeset
|
98 |
160
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
99 # 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
|
100 rm $LOGFILE |