Mercurial > hg > zsh-env
annotate 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 |
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 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
65 SUFFIX=genkernel-${ARCH}-${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
|
66 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
|
67 SUFFIX="$SUFFIX-${REVISION}" |
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 rm System.map-${SUFFIX} >> $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
|
70 rm initramfs-${SUFFIX} >> $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
|
71 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
72 KERNEL="kernel-${SUFFIX}" |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
73 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
|
74 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
|
75 fi |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
76 KERNEL="vmlinuz-${MAJOR}.${MINOR}.${MICRO}-gentoo-${ARCH}" |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
77 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
|
78 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
|
79 fi |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
80 |
c35d56590441
add the two helper scripts for gentoo that are requied on all hosts
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
81 # 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
|
82 rm $LOGFILE |