Introduction to Linux - A Hands on Guide | Linux Bible | Linux From Scratch | A Newbie's Getting Started Guide to Linux | Linux Command Line Cheat Sheet | More Linux eBooks



Sunday, 11 January 2015

A Bash Script to Install/Upgrade to Linux Kernel 3.17.8 in Ubuntu/Linux Mint

The Linux Kernel 3.17.8 is now available for the users, announced Linus Torvalds. This Linux Kernel version comes with plenty of fixes and improvements. The following BASH script, when executed, despite of the system architecture (valid only for i386, i686 and x86_64 based systems), installs Linux kernel 3.17.8 in your Linux systems.



Note: Make sure that you execute this script as a ROOT user.

Usage:

./script_name.sh
Script:

#!/bin/sh

# Check if the user is ROOT
if [ $(id -u) -ne 0 ]
then
    echo "You are not ROOT! Please login as ROOT."
    exit
fi

# Latest Available Kernel version
LatestKernel="3.17.8-031708-generic"

# Required Packages
Headers_All="http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.17.8-vivid/linux-headers-3.17.8-031708_3.17.8-031708.201501081837_all.deb"
Headers_i386="http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.17.8-vivid/linux-headers-3.17.8-031708-generic_3.17.8-031708.201501081837_i386.deb"
Image_i386="http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.17.8-vivid/linux-image-3.17.8-031708-generic_3.17.8-031708.201501081837_i386.deb"
Headers_amd64="http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.17.8-vivid/linux-headers-3.17.8-031708-generic_3.17.8-031708.201501081837_amd64.deb"
Image_amd64="http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.17.8-vivid/linux-image-3.17.8-031708-generic_3.17.8-031708.201501081837_amd64.deb"

# Debian Packages
DEB="linux-headers-3.17.8*.deb linux-image-3.17.8*.deb"

# Currently Installed Kernel Version
CurrentKernel_release=$(uname -r) 

# System Architecture
SystemArch=$(uname -i)

# Check if System already has latest kernel installed
if [ "$CurrentKernel" = "$LatestKernel" ]
then
    echo "Wow! Your System is Already Updated to Latest Available Kernel Version!"
    echo "Program will now exit..."
    sleep 2s
    exit
fi

# If latest kernel is not available, then check the system architecture and download necessary packages

# For 32-bit Systems

if [ $SystemArch = "i386" ] || [ $SystemArch = "i686" ]
then

    echo "Kernel upgrade process for 32-bit systems will now start..."
    sleep 2s
    echo "Downloading required packages.."
    sleep 2s

    wget $Headers_All
    wget $Headers_i386
    wget $Image_i386

    echo "Download process completed. Packages are present in $(pwd) directory"
    sleep 2s

    echo "Installing the packages..."
    dpkg -i $DEB

# For 64-bit Systems
elif [ $SystemArch = "x86_64" ]
then
    echo "Kernel upgrade process for 64-bit systems will now start..." 
    sleep 2s

    wget $Headers_All
    wget $Headers_amd64
    wget $Image_amd64

    echo "Download process completed. Packages are present in $(pwd) directory"
    sleep 2s

    echo "Installing the packages..."
    dpkg -i $DEB

# If system architecture is not compatible
else
    echo "Packages for following system architecture not found :  $SystemArch"
    echo "Program will now exit..."
    sleep 2s
exit
fi

    echo "Your system has been successfully upgraded to latest kernel version $(LatestKernel)."
    echo "System will now reboot."
    sleep 5s
    shutdown -r now
NOTE: Above script worked perfectly on my i386 system. I need confirmation from i686 and x86_64 users, if it works fine for them. Please suggest any changes to be incorporated.

0 comments:

Post a Comment