Last active
October 4, 2015 03:37
-
-
Save danielrichman/2570742 to your computer and use it in GitHub Desktop.
Linode: check that the currently running kernel is up to date.
This file contains hidden or 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/python | |
# Copyright 2012 Daniel Richman. | |
# Protip: need not be run as root. | |
import sys | |
import os | |
import urllib2 | |
import xml.dom.minidom | |
import traceback | |
def expect(): | |
f = urllib2.urlopen("http://www.linode.com/kernels/rss.xml") | |
d = xml.dom.minidom.parse(f) | |
f.close() | |
items = d.getElementsByTagName("item") | |
latest = None | |
for i in items: | |
x = i.getElementsByTagName("title") | |
assert len(x) == 1 | |
t = x[0] | |
assert t.firstChild == t.lastChild | |
s = t.firstChild | |
kernel = s.nodeValue | |
if "Latest" not in kernel or "x86_64" not in kernel: | |
continue | |
(_, p, kernel) = kernel.partition('(') | |
assert p == '(' | |
(kernel, p, _) = kernel.partition(')') | |
assert p == ')' | |
kernel = str(kernel) | |
assert not latest and kernel | |
latest = kernel | |
return latest | |
def current(): | |
(_, _, kernel, _, _) = os.uname() | |
assert kernel | |
return kernel | |
def main(): | |
e = expect() | |
c = current() | |
if e != c: | |
print "Kernel is not up to date!" | |
print "Latest: ", e | |
print "Current:", c | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment