Skip to content

Instantly share code, notes, and snippets.

@mentrelli
Forked from mmstick/Ubuntu Kernel Upgrader Script
Last active September 3, 2017 15:48
Show Gist options
  • Save mentrelli/30413cec295a9d13cd2c30bcb28f10f7 to your computer and use it in GitHub Desktop.
Save mentrelli/30413cec295a9d13cd2c30bcb28f10f7 to your computer and use it in GitHub Desktop.
Asks the user whether they want to install the latest RC or stable, then downloads the correct kernel and installs it.
#!/bin/bash
# Ubuntu_Kernel_Upgrader_Script
# Forked from https://gist.github.com/mmstick/8493727
#set -x
rc=n # release candidate
lowlatency=n # low latency
verbose=n # be verbose
# Help
function show_help {
echo "NAME"
echo " $0 - detect and download the latest available kernel in Ubuntu's repository"
echo
echo "SYNOPSIS"
echo " $0 [-r] [-l] [-c] [-h]"
echo
echo "DESCRIPTION"
echo " -r"
echo " look for RC (release candidate) version [default: $rc]"
echo
echo " -l"
echo " look for low-latency version [default: $lowlatency]"
echo
echo " -h"
echo " print this help"
echo
echo "AUTHOR"
echo " Undy / Febraury 26, 2016"
}
# Parse command line options
OPTIND=1
while getopts "rlcvh?" opt; do
case "$opt" in
r) rc=y
;;
l) lowlatency=y
;;
c) check=y
;;
v) verbose=y
;;
h|\?)
show_help
exit 0
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
[ "$verbose" = "y" ] &&
echo -e "\n rc: $rc\n low latency: $lowlatency\n check: $check\n verbose: $verbose"
# Do the job
if ! which lynx > /dev/null; then sudo apt-get install lynx -y; fi
if [ "$(getconf LONG_BIT)" == "64" ]; then arch="amd64"; else arch="i386.deb"; fi
function getfileurl() {
local fileURL=$(lynx -dump -listonly -dont-wrap-pre -nonumbers $kernelURL | grep "$1" | grep "$2" | grep $arch.deb | cut -d ' ' -f 4 | sort -u)
echo $fileURL
}
function getfileurlshared() {
local fileURL=$(lynx -dump -listonly -dont-wrap-pre -nonumbers $kernelURL | grep "all.deb" | cut -d ' ' -f 4 | sort -u)
echo $fileURL
}
# Kernel URL
#read -p "Do you want the latest RC? " rc
case "$rc" in
y* | Y* | s* | S*) kernelURL=$(lynx -dump -nonumbers http://kernel.ubuntu.com/~kernel-ppa/mainline/ | tail -1) ;;
n* | N*) kernelURL=$(lynx -dump -nonumbers http://kernel.ubuntu.com/~kernel-ppa/mainline/ | grep -v rc[[:digit:]] | grep v[[:digit:]] | sort | tail -1) ;;
*) exit ;;
esac
#read -p "Do you want the lowlatency kernel? " lowlatency
case "$lowlatency" in
y* | Y* | s* | S*) kerneltype=lowlatency ;;
n* | n*) kerneltype=generic ;;
*) exit ;;
esac
# Get file URLs
echo ""
echo "Getting URLs of the latest "$kerneltype" kernel..."
filename_header=$(getfileurl $kerneltype header)
filename_image=$(getfileurl $kerneltype image)
filename_shared=$(getfileurlshared)
echo "...file to download: "$filename_header
echo "...file to download: "$filename_image
echo "...file to download: "$filename_shared
echo ""
read -p "Do you want to download the files now? " yesno
case "$yesno" in
y* | Y*)
wget $filename_header
wget $filename_image
wget $filename_shared
echo "" ;;
n* | n*)
echo "" ;;
*) exit ;;
esac
read -p "Do you want to install this kernel now? " yesno
case "$yesno" in
y* | Y*)
echo "...Installing Linux Kernel"
sudo dpkg -i linux*.deb
echo "...Done. You may now reboot." ;;
n* | n*)
echo "Goodbye." ;;
*) exit ;;
esac
@ronnocnave
Copy link

This version is great! Thank you for publishing.

@numericOverflow
Copy link

numericOverflow commented Sep 3, 2017

Thanks @mentrelli - This version is much better, but I had to tweak it slightly to intelligently handle kernel sorting so v4.12.10 is higher than v4.9.9. See my fork, which seems to do this better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment