#!/bin/bash # update-kernel.sh - automatically compile and install new kernel sources # Licensed under the terms of the GNU GPLv3 or later # Proprietary Software Must Perish! # AUTHOR: Johannes Truschnigg ( johannes.truschnigg@gmx.at || http://johannes.truschnigg.info ) SCRIPTNAME="${0##*/}"; die() { printf "${SCRIPTNAME}: Fatal: %s\n" "${1:-reason undefined.}" 2>&1; exit ${2:-1}; } goon() { read -sp "${1:-Continue executing ${SCRIPTNAME}?} (^C->no || [ENTER]->yes)" DUMMY; echo; } [[ "${UID}" > 0 ]] && die "must be run as root."; fgrep -q /boot /etc/fstab && (mount | fgrep -q /boot || mount /boot); unset ESELECT; ESELECT=$(which eselect 2>/dev/null); if [[ -n "${ESELECT}" ]]; then # Gentoo specific way "${ESELECT}" kernel set \ "$(${ESELECT} --no-colour kernel list | tail -n1 | grep -o [0-9] | head -n1)"; else # hopefully works anywhere cd /usr/src/; unset KERNELS; declare -a KERNELS; KERNELS=(linux-*); [[ -z "${KERNELS}" ]] && die "no kernel-source-dir candidates found."; unset TARGET; for candidate in ${KERNELS[*]}; do [[ -d "${candidate}" && -f "${candidate}/Kbuild" ]] && TARGET="${candidate}"; done [[ -z "${TARGET}" ]] && die "no suitable kernel-source-dir found."; rm -f /usr/src/linux; ln -s "${TARGET}" linux; fi printf "Selected kernel-source-dir: %s\n" "$(readlink /usr/src/linux)"; goon "Continue configuring kernel-source?"; cd /usr/src/linux; #TODO: make this more clever/reliable unset CONFIG_FOUND; [[ -e "/usr/src/linux-$(uname -r)/.config" ]] && cp "/usr/src/linux-$(uname -r)/.config" .config && CONFIG_FOUND=1; [[ -e "/proc/config.gz" ]] && zcat /proc/config.gz > .config && CONFIG_FOUND=1; [[ "${CONFIG_FOUND}" != 1 ]] && die "could not find a suitable .config."; make oldconfig; goon "Continue compiling kernel?"; unset JOBS_IN_PARALLEL; JOBS_IN_PARALLEL=$(($(fgrep -c vendor_id /proc/cpuinfo) + 1) 2>/dev/null); make -j${JOBS_IN_PARALLEL:-2}; goon "Continue installing kernel-image and modules (if any)?"; make install &&\ make modules_install &&\ exit 0;