Skip to content

Instantly share code, notes, and snippets.

@pdelteil
Last active March 31, 2022 15:33
Show Gist options
  • Save pdelteil/ab1060cd8fb4da3bd8cf66caaf80d2ad to your computer and use it in GitHub Desktop.
Save pdelteil/ab1060cd8fb4da3bd8cf66caaf80d2ad to your computer and use it in GitHub Desktop.
How to update your kernel
#!/bin/bash
# [email protected]
# Oct 2017
KERNEL=$(uname -a |awk '{print $3}'|awk -F"-" '{print $1}')
echo "Current kernel version" $KERNEL
MAIN_VER_CUR_KERNEL=$(echo "$KERNEL" |awk -F"." '{print $1}')
MIN_VER_CUR_KERNEL=$(echo "$KERNEL" |awk -F"." '{print $2}')
URL="http://kernel.ubuntu.com/~kernel-ppa/mainline/"
echo "Fetching list of kernels..."
VERSIONS="$(curl --progress-bar $URL|grep "href"|grep -v "\-rc"|awk -F"</td><td" '{print $2}'|grep -o -P '(?<=">v).*(?=/<)'|grep -v -i "unstable"|sort)"
count=0
LINK=()
for i in ${VERSIONS[@]}
do
VER=$(echo $i |awk -F"." '{print $1}')
VER_MIN=$(echo $i |awk -F"." '{print $2}'|awk -F"-" '{print $1}')
if [ "$VER" -gt "$MAIN_VER_CUR_KERNEL" ] || [ "$VER" -eq "$MAIN_VER_CUR_KERNEL" ]
then
if [ "$VER_MIN" -eq "$MIN_VER_CUR_KERNEL" ] || [ "$VER_MIN" -gt "$MIN_VER_CUR_KERNEL" ]
then
echo "[$count] "$i
LINK[$count]="$i"
count=$((count +1))
fi
fi
done
echo "What kernel would you like to install? Number + [ENTER]:"
read kernel
echo "You selected " ${LINK[$kernel]}
LINK=$(echo $URL"v"${LINK[$kernel]}"/")
RES="$(curl -s $LINK |grep -A 7 "Build for amd64 succeeded"|grep -v "lowlatency" |grep -v "succeeded"|awk -F"\"" '{print $2}')"
FILES=($RES)
echo "Downloading ${FILES[0]}..."
curl --progress-bar $LINK${FILES[0]} -o ${FILES[0]} &
wait
echo "Downloading ${FILES[1]}..."
curl --progress-bar $LINK${FILES[1]} -o ${FILES[1]} &
wait
echo "Downloading ${FILES[2]}..."
curl --progress-bar $LINK${FILES[2]} -o ${FILES[2]} &
wait
echo "Downloading ${FILES[3]}..."
curl --progress-bar $LINK${FILES[3]} -o ${FILES[3]} &
wait
echo "Confirm instalation of these ${#FILES[@]} files?"
echo "[y/n]?"
read answer
if [ "$answer" == "y" ]
then
sudo dpkg -i ${FILES[0]} ${FILES[1]} ${FILES[2]} ${FILES[3]}
rm ${FILES[0]} ${FILES[1]} ${FILES[2]} ${FILES[3]}
else echo "Exit..."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment