#!/bin/sh
# generic_kernel.sh
# 2022-08-14

# Switches to Slackware's generic kernel.
# This kernel boots faster and needs less RAM.
# http://docs.slackware.com/slackware:beginners_guide

CWD=$(pwd)
TMP=$(mktemp -d)

set -e

CMD=$(/usr/share/mkinitrd/mkinitrd_command_generator.sh | tail -n 1)
echo "$CMD"
$CMD

cd /boot || exit 1
LNKS="System.map config vmlinuz"
for LNK in $LNKS; do
  TARGET=$(readlink "$LNK" | sed 's/huge/generic/')
  rm "$LNK"
  ln -s "$TARGET" "$LNK"
done

cd "$TMP" || exit 1
cat > lilo.conf.hints <<EOF
#...
compact
#...
# Linux bootable partition config begins
image = /boot/vmlinuz
  initrd = /boot/initrd.gz
#...
EOF
emacs lilo.conf.hints /etc/lilo.conf

lilo

echo ""
echo "Reboot your system to load the new kernel."
echo ""

cd "$CWD"
rm -rf "$TMP"