#!/bin/bash # Confirm root. If not error and exit. if [ "$EUID" -ne 0 ] then echo "You are not root. Come back when you are." exit fi # Show kernel installed and newest for download: echo -e "The current running kernel is $(uname -r).\nVersion $(sudo -u nobody curl -sL https://www.kernel.org/ | awk -F'/' '/latest_link/{getline; sub(/.*linux-/, ""); sub(/\.tar\.xz.*/, ""); print}') is the latest stable kernel." # Ask to confirm new kernel build: while true; do read -p "Would you like to proceed? [Y\\n]" yn case $yn in [Yy]* ) echo "Go make some coffee."; break;; [Nn]* ) exit;; * ) echo "Please answer yes or no.";; esac done # Get current stable: VERSION=$(sudo -u nobody curl -sL https://www.kernel.org/ | awk -F'/' '/latest_link/{getline; sub(/.*kernel.org\//, ""); sub(/".*/, ""); print}') # Get current dir and cd to /usr/src CWD=$PWD cd /usr/src # Rsync kernel source if [ ! -z $VERSION ]; then sudo -u nobody rsync -avPz rsync://rsync.kernel.org/$VERSION /tmp/ else echo "Unable to reach kernel.org via rsync. Check Interent connection or any firewall rules that may prevent this." exit fi # Remove URL from version VERSION=$(echo "./$VERSION" | cut -d'/' -f6) # Copy file, change its permissions and delete the old. rsync -avP /tmp/$VERSION /usr/src/ && chown root: /usr/src/$VERSION && rm -vf /tmp/$VERSION # Extract downloaded kernel if tar -xvf "/usr/src/$VERSION"; then echo "Extraction Complete." else echo "Tar file failed to extract. Check connection to kernel.org" exit fi # Remove tar file rm -v "/usr/src/$VERSION" # Remove .tar.xz from $VERSION VERSION=$(echo $VERSION | sed -e 's/\.tar\.xz//g') # Move into directory cd "/usr/src/$VERSION" # Copy old config cp /boot/config-`uname -r` /usr/src/$VERSION/.config ## Uncomment if on an non-EFI system. # If using EFI, break if [ -d /sys/firmware/efi ]; then break 2>/dev/null else # Else comment out EFI settings in config. More may be needed in the future. sed -i 's/CONFIG_SYSTEM_TRUSTED_KEYS/#CONFIG_SYSTEM_TRUSTED_KEYS/g;s/CONFIG_MODULE_SIG_KEY/#CONFIG_MODULE_SIG_KEY/g;' .config fi # Build with config with defaults yes "" | make oldconfig # Finish building nice make -j $(nproc) bindeb-pkg # Make for BTF export BTF_VERSION=$(echo $VERSION | awk -F- '{ print $2 }') cd tools/bpf/resolve_btfids/ make cp -a resolve_btfids /usr/src/linux-headers-$BTF_VERSION/tools/bpf/resolve_btfids/ cd - # Make modules make modules # Install modules su -c "make modules_install install" # Get version again. Seems to get lost without this. VERSION=$(sudo -u nobody curl -sL https://www.kernel.org/ | awk -F'/' '/latest_link/{getline; sub(/.*linux-/, ""); sub(/\.tar\.xz.*/, ""); print}'); # Install debs for i in $(ls /usr/src | awk '$0 !~ /dbg/ && $0 ~ /'"$VERSION"'/ && $0 ~ /deb/'); do dpkg -i /usr/src/$i; done # Remove debs for i in $(ls /usr/src | awk "/$VERSION/ && /changes$|buildinfo$|.deb$/"); do rm -vf /usr/src/$i; done # Clean unneeded files make clean make distclean # Change back to original dir. cd $CWD DPKG=$(dpkg -l | grep "linux-image-$VERSION") # Link some modules rsync -avP /sys/kernel/btf/vmlinux /usr/lib/modules/$VERSION*/build/ ln -sf /usr/lib/modules/linux-$VERSION/vmlinux.xz /boot/ rsync -avP /usr/src/linux-$VERSION/tools/ /usr/src/linux-headers-$VERSION*/tools/ # If package for new kernel installed, print to user or a message to trouble-shoot errors: if [ ! -z "$DPKG" ]; then echo -e "Kernel $VERSION is now installed.\nReboot to load this kernel into memory.\n"; else "It appears this kernel did not install successfully. You will want to re-run this program with 'kernup 2> log_name' to diagnose any problems."; fi