#!/usr/bin/env bash baseUrl="https://kernel.ubuntu.com/~kernel-ppa/mainline/" # read the current kernel version currentVersion=$(uname -r | grep -oP [0-9.]+-[0-9]+) echo "The currently used kernel version is $currentVersion." # get all version folders, remove the duplicates and move the latest to top versions="$(curl -s $baseUrl | grep -E v[0-9]+\\.[0-9]+\(\\.[0-9]+\)?\/ -o | sort -u -t . -k1.2,1nr -k2,2nr -k3,3nr)" # store the first item in a variable read latest <<< $versions # find all .deb files for amd64 or all and filter out the ones which contain the current version amd64Packages="$(curl -s $baseUrl$latest | grep -P linux.+?_\(amd64\|all\).deb -o | sort -u | grep -P \(generic\|all\) | grep -v $currentVersion)" # create a temp folder, download the deb files and install them if [ ! -z "$amd64Packages" ]; then # let the user confirm the installation shouldInstall="y" read -p "New kernel found: ${latest/v/}. Shall I install it? (Y/n)? " shouldInstall if [ "$shouldInstall" = "n" ]; then echo "New kernel $latest was not installed." exit fi targetDir="/tmp/updateKernel/$latest" mkdir -p $targetDir cd $targetDir for package in $amd64Packages; do wget $baseUrl$latest$package done; sudo dpkg -i *.deb else echo "No new kernel version found." fi