Last active
August 1, 2019 07:51
-
-
Save 1271/6ed614b17e56b21ca7e9a90510bc3abc to your computer and use it in GitHub Desktop.
ubuntu linux kernel autoupdater
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [[ $# -eq 0 ]]; then | |
echo "Version not recieve" 2>&1 | |
echo "Example: $0 v3.11.2 l" 2>&1 | |
echo "Example: $0 v3.11.2" 2>&1 | |
exit 1 | |
fi | |
if [[ $EUID -ne 0 ]]; then | |
echo "You must be a root user" 2>&1 | |
exit 1 | |
fi | |
if [[ $1 == 'l' ]]; then | |
PWD=`dirname $0` | |
version=`python3 $PWD/latest_kernel.py` | |
if [[ "$version" == "" ]]; then | |
echo 'Update is not required.' | |
exit | |
fi | |
v__v=${version:1} | |
echo "Latest version: $v__v" | |
version_exist=`ls /boot | grep "vmlinuz-$v__v.0-" | wc -l` | |
if [ $version_exist -ge 1 ]; then | |
echo 'Kernel downloaded now' | |
exit | |
fi | |
version_exist=`ls /boot | grep "vmlinuz-$v__v-" | wc -l` | |
if [ $version_exist -ge 1 ]; then | |
echo 'Kernel downloaded now' | |
exit | |
fi | |
else | |
version=$1 | |
fi | |
root_url='http://kernel.ubuntu.com/~kernel-ppa/mainline/' | |
install_dir="/tmp/_root_install_$$" | |
html=$(wget "$root_url$version/" -O- 2>/dev/null) | |
all=$(echo $html | sed -r 's/.*"(linux-headers[^"]+?_all\.deb)".*/\1/') | |
if [[ $2 = 'l' ]]; then | |
headers=$(echo $html | sed -r 's/.*"(linux-headers[^"]+lowlatency[^"]+?\_amd64.deb)".*/\1/') | |
image=$(echo $html | sed -r 's/.*"(linux-image[^"]+lowlatency[^"]+?\_amd64.deb)".*/\1/') | |
modules=$(echo $html | sed -r 's/.*"(linux-modules[^"]+lowlatency[^"]+?\_amd64.deb)".*/\1/') | |
else | |
headers=$(echo $html | sed -r 's/.*"(linux-headers[^"]+generic[^"]+?\_amd64.deb)".*/\1/') | |
image=$(echo $html | sed -r 's/.*"(linux-image[^"]+generic[^"]+?\_amd64.deb)".*/\1/') | |
modules=$(echo $html | sed -r 's/.*"(linux-modules[^"]+generic[^"]+?\_amd64.deb)".*/\1/') | |
fi | |
mkdir "$install_dir" ; cd "$install_dir" | |
echo "$modules" | |
echo "$root_url$version/$modules" | |
echo 'Please, wait...' | |
echo 'Downloading files.' | |
wget "$root_url$version/$headers" "$root_url$version/$modules" "$root_url$version/$image" "$root_url$version/$all" -t 0 -c 2>/dev/null && | |
echo | |
ls -alF | |
sleep 15 | |
echo 'Downloading done. Checksum check' | |
wget "$root_url$version/CHECKSUMS" | |
SUM_ALL=(`sha1sum "$all"`) | |
SUM_HEADERS=(`sha1sum "$headers"`) | |
SUM_IMAGE=(`sha1sum "$image"`) | |
SUM_MODULES=(`sha1sum "$modules"`) | |
ALL_OK=`cat CHECKSUMS | grep ${SUM_ALL[0]} | wc -l` | |
HEADERS_OK=`cat CHECKSUMS | grep ${SUM_HEADERS[0]} | wc -l` | |
IMAGE_OK=`cat CHECKSUMS | grep ${SUM_IMAGE[0]} | wc -l` | |
MODULES_OK=`cat CHECKSUMS | grep ${SUM_MODULES[0]} | wc -l` | |
if [ $ALL_OK -ge 1 ]; then | |
echo '_all - checked' 2>&1 | |
else | |
echo '_all - error' 2>&1 | |
exit | |
fi | |
if [ $HEADERS_OK -ge 1 ]; then | |
echo '_headers - checked' 2>&1 | |
else | |
echo '_headers - error' 2>&1 | |
exit | |
fi | |
if [ $IMAGE_OK -ge 1 ]; then | |
echo '_image - checked' 2>&1 | |
else | |
echo '_image - error' 2>&1 | |
exit | |
fi | |
if [ $MODULES_OK -ge 1 ]; then | |
echo '_modules - checked' 2>&1 | |
else | |
echo '_modules - error' 2>&1 | |
exit | |
fi | |
echo 'Done. Installing' | |
sleep 1 | |
sudo dpkg -i "$all" "$headers" "$image" "$modules" && echo 'OK!' > /tmp/kernel || echo 'ERROR!' > /tmp/kernel | |
sleep 1 | |
cd /tmp; rm -rf "$install_dir" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import platform | |
from re import search | |
from requests import get | |
from sys import stderr | |
try: | |
from lxml.html import document_fromstring | |
import cssselect | |
except ImportError: | |
print('Please, run: python -mpip install lxml cssselect', file=stderr) | |
exit(1) | |
uri = 'http://kernel.ubuntu.com/~kernel-ppa/mainline/' | |
html = document_fromstring(get(uri).text) | |
versions = html.cssselect('tr > td[valign="top"] + td > a') | |
versions = [i.get('href') for i in versions] | |
_version = '0' | |
for i in versions: | |
v = search('v(\\d+\\.\\d+(?:\\.\\d+)?)(.*)', i) | |
if v and v.group(2).find('rc') == -1: | |
v3 = v.group(1) | |
if tuple(_version.split('.')) < tuple(v3.split('.')): | |
_version = v3 | |
release = platform.release().split('-')[0] | |
if _version != '0' and tuple(release.split('.')) < tuple(_version.split('.')): | |
print('v%s' % _version) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment