#!/usr/bin/perl use Socket; $proto=getprotobyname('tcp'); if (!$proto) { die "getprotobyname failed: $!"; } socket(FINGER, PF_INET, SOCK_STREAM, $proto) || die "socket failed: $!"; select((select(FINGER), $|=1)[0]); $port=getservbyname('finger', 'tcp'); if (!$port) { die "getservbyname failed: $!"; } $host=inet_aton("finger.kernel.org"); if (!$host) { die "inet_aton failed: $!"; } $sin=sockaddr_in($port, $host); if (!$sin) { die "sockaddr_in failed: $!"; } connect(FINGER, $sin) || die "connect failed: $!"; print FINGER "\n"; while () { chomp; if (/^\s*The latest \*?(stable|beta)\*? version of the Linux kernel is:\s*(\d+\.\d+\.\d+\w*)\s*$/o) { $version{$1}=$2; } } close(FINGER); if (!defined($version{'stable'})) { print STDERR "failed to determine latest kernel version!\n"; exit 1; } if (-f "/proc/sys/kernel/osrelease") { open(RELEASE, "; close(RELEASE); } else # I don't know what to do, so fall back to uname. { $version{'local'}=`uname -r`; } chomp $version{'local'}; if ($version{'local'} gt $version{'stable'}) { if (defined($version{'beta'})) { if ($version{'local'} lt $version{'beta'}) { print "kernel version $version{'beta'} is available\n"; } elsif ($version{'local'} eq $version{'beta'}) { print "running latest beta kernel\n"; } else { print "running newer beta kernel than the latest?!?\n"; } } else { print "running newer stable kernel than the latest?!?\n"; } } elsif ($version{'local'} eq $version{'stable'}) { print "running latest stable kernel\n"; } else { print "kernel version $version{'stable'} is available\n"; }