Mercurial > hg > zsh-env
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/removeKernel Mon Dec 23 11:41:35 2019 +0100 @@ -0,0 +1,82 @@ +#!/bin/bash + +if [ `whoami` != "root" ]; then + echo "$0 must be run as root!" + exit 1 +fi + +if [ $# -lt 3 ]; then + echo "usage: $0 <major minor micro [revision], e.g. 2 6 21 r4>" + exit 1 +fi + +MAJOR=$1 +MINOR=$2 +MICRO=$3 +if [ $# -gt 3 ]; then + REVISION=$4 +fi +LOGFILE=/tmp/removeKernel-$$.log + +# unmerge the kernel +cd /usr/src +KERNEL_DIR="linux-${MAJOR}.${MINOR}.${MICRO}-gentoo" +if [ "$REVISION" != "" ]; then + KERNEL_DIR="${KERNEL_DIR}-${REVISION}" +fi +if [ -d $KERNEL_DIR ]; then + KERNEL_NAME=gentoo-sources-${MAJOR}.${MINOR}.${MICRO} + if [ "${REVISION}" != "" ]; then + KERNEL_NAME="${KERNEL_NAME}-${REVISION}" + fi + + echo "unmerge kernel $KERNEL_NAME" >> $LOGFILE 2>&1 + emerge --unmerge $KERNEL_NAME >> $LOGFILE 2>&1 + + echo "remove $KERNEL_DIR" >> $LOGFILE 2>&1 + rm -r $KERNEL_DIR >> $LOGFILE 2>&1 +fi + +# remove modules +cd /lib/modules +LIB_DIR=${MAJOR}.${MINOR}.${MICRO}-gentoo +if [ "$REVISION" != "" ]; then + LIB_DIR="${LIB_DIR}-${REVISION}" +fi +if [ -d $LIB_DIR ]; then + echo "remove modules from `pwd`/$LIB_DIR" >> $LOGFILE 2>&1 + rm -r $LIB_DIR >> $LOGFILE 2>&1 +fi + +# remove the kernel and stuff, check if /boot is mounted first +MOUNTED=`mount | grep /boot` +if [ "$MOUNTED" = "" ]; then + echo "mount /boot" >> $LOGFILE 2>&1 + mount /boot >> $LOGFILE 2>&1 +fi + +cd /boot + +ARCH=`uname -m` +if [ "$ARCH" = "i686" ]; then + ARCH="x86" +fi + +SUFFIX=genkernel-${ARCH}-${MAJOR}.${MINOR}.${MICRO}-gentoo +if [ "$REVISION" != "" ]; then + SUFFIX="$SUFFIX-${REVISION}" +fi +rm System.map-${SUFFIX} >> $LOGFILE 2>&1 +rm initramfs-${SUFFIX} >> $LOGFILE 2>&1 + +KERNEL="kernel-${SUFFIX}" +if [[ -f $KERNEL ]]; then + rm $KERNEL >> $LOGFILE 2>&1 +fi +KERNEL="vmlinuz-${MAJOR}.${MINOR}.${MICRO}-gentoo-${ARCH}" +if [[ -f $KERNEL ]]; then + rm $KERNEL >> $LOGFILE 2>&1 +fi + +# if we got until here, just remove the logfile again +rm $LOGFILE