Mercurial > hg > zsh-env
annotate removeKernel @ 162:0bd8976bd5fb
add default aliases for gk and removeKernel
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Thu, 09 Jan 2020 13:03:20 +0100 |
parents | 4500455b2375 |
children | 5da4de3d7ee1 |
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 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
19 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
|
20 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
21 # 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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 fi |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
27 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
|
28 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
|
29 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
|
30 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
|
31 fi |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
32 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
33 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
|
34 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
|
35 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
36 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
|
37 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
|
38 fi |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
39 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
40 # 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
|
41 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
|
42 LIB_DIR=${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
|
43 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
|
44 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
|
45 fi |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
46 if [ -d $LIB_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
|
47 echo "remove modules from `pwd`/$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
|
48 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
|
49 fi |
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 # 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 fi |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
57 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
58 cd /boot |
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 ARCH=`uname -m` |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
61 if [ "$ARCH" = "i686" ]; then |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
62 ARCH="x86" |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
63 fi |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
64 |
161
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
65 SUFFIX_V3="genkernel-${ARCH}-${MAJOR}.${MINOR}.${MICRO}" |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
66 if [[ "${REVISION}" != "" ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
67 SUFFIX_V3="${SUFFIX_V3}-${REVISION}" |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
68 fi |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
69 SUFFIX_V3="${SUFFIX_V3}-gentoo" |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
70 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
71 SUFFIX_V4="${MAJOR}.${MINOR}.${MICRO}" |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
72 if [ "${REVISION}" != "" ]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
73 SUFFIX_V4="${SUFFIX_V4}-${REVISION}" |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
74 fi |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
75 SUFFIX_V4="${SUFFIX_V4}-gentoo-${ARCH}" |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
76 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
77 SYSTEM_MAP="System.map-${SUFFIX_V3}" |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
78 if [[ -f $SYSTEM_MAP ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
79 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
|
80 fi |
161
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
81 SYSTEM_MAP="System.map-${SUFFIX_V4}" |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
82 if [[ -f ${SYSTEM_MAP} ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
83 rm ${SYSTEM_MAP} >> $LOGFILE 2>&1 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
84 fi |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
85 if [[ -f ${SYSTEM_MAP}.old ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
86 rm ${SYSTEM_MAP}.old >> $LOGFILE 2>&1 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
87 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
|
88 |
161
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
89 INITRAMFS="initramfs-${SUFFIX_V3}" |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
90 if [[ -f ${INITRAMFS} ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
91 rm ${INITRAMFS} >> $LOGFILE 2>&1 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
92 fi |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
93 INITRAMFS="initramfs-${SUFFIX_V4}" |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
94 if [[ -f ${INITRAMFS} ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
95 rm ${INITRAMFS} >> $LOGFILE 2>&1 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
96 fi |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
97 if [[ -f ${INITRAMFS}.old ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
98 rm ${INITRAMFS}.old >> $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 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 fi |
161
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
105 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
|
106 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
|
107 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
|
108 fi |
161
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
109 if [[ -f $KERNEL.old ]]; then |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
110 rm $KERNEL.old >> $LOGFILE 2>&1 |
4500455b2375
Adjust filenames to the old pattern
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
160
diff
changeset
|
111 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
|
112 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
113 # 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
|
114 rm $LOGFILE |