Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save numericOverflow/27f3c51e3e972c6ba65e86ad5f479202 to your computer and use it in GitHub Desktop.
Save numericOverflow/27f3c51e3e972c6ba65e86ad5f479202 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 --version-sort)
echo $fileURL
}
function getfileurlshared() {
local fileURL=$(lynx -dump -listonly -dont-wrap-pre -nonumbers $kernelURL | grep "all.deb" | cut -d ' ' -f 4 | sort -u --version-sort)
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/ | grep -v [DIR] | grep -P 'v([[:digit:]]+\.)+[[:digit:]]+' | sort --version-sort | tail -2 | sort | tail -1) ;;
n* | N*) kernelURL=$(lynx -dump -nonumbers http://kernel.ubuntu.com/~kernel-ppa/mainline/ | grep -v [DIR] | grep -v rc[[:digit:]] | grep -P 'v([[:digit:]]+\.)+[[:digit:]]+' | sort --version-sort | tail -2 | 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment