changeset 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 d0cdc3f47182
children 4500455b2375
files gk.sh removeKernel
diffstat 2 files changed, 132 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gk.sh	Mon Dec 23 11:41:35 2019 +0100
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+if [ `whoami` != "root" ]; then
+    echo "must be root"
+    exit 1
+fi
+
+# for xconfig
+export DISPLAY=localhost:0.0
+
+# make sure gk.sh always uses the same ccache cache
+export CCACHE_DIR=/var/tmp/ccache
+
+# use CCACHE when compiling the kernel
+COMPILER=/usr/lib/ccache/bin/gcc
+
+# source make.conf for MAKEOPTS
+GK_OPTS=""
+
+if [ -f /etc/make.conf ]; then
+    . /etc/make.conf
+elif [ -f /etc/portage/make.conf ]; then
+    . /etc/portage/make.conf
+else
+    echo "cannot find make.conf"
+    exit 1
+fi
+
+if [ "$MAKEOPTS" != "" ]; then
+    GK_OPTS="--makeopts=$MAKEOPTS "
+fi
+
+if [ -d /etc/kernels ]; then
+    kernel=`ls -rt /etc/kernels | tail -n 1`
+    if [ $kernel != "" ]; then
+        GK_OPTS="$GK_OPTS --kernel-config=/etc/kernels/$kernel"
+    fi
+fi
+
+genkernel $* \
+    --install \
+    --no-color \
+    --kernel-cc=$COMPILER \
+    --utils-cc=$COMPILER \
+    $GK_OPTS \
+    all
+
+# TODO check --bootloader
+# update the bootloader
+#grub-mkconfig -o /boot/grub/grub.cfg
--- /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