HOME


sh-3ll 1.0
DIR:/proc/self/root/usr/local/lp/apps/kernelupdate/
Upload File :
Current File : //proc/self/root/usr/local/lp/apps/kernelupdate/lp-kernelupdate.pl
#!/usr/bin/perl -w

# Based off lp-autoupdate.pl..

my $txtdomain = "kernelupdates.sourcedns.com";
my $serialfile = "/usr/local/lp/var/kernelupdate/serial";
my $logfile = "/usr/local/lp/logs/lp-kernelupdate.log";
my $yum_conf_file = '/usr/local/lp/configs/lp-kernelupdate/yum.conf';
my $updatecommand = "/usr/bin/yum -c $yum_conf_file -y update kernel* kmod*";
my $cleancommand = "/usr/bin/yum -c $yum_conf_file clean all";

my $filetimestamp = 9999999999;
my $dnstimestamp = 0000000000;
my $writednstimestamp = 0;
my $doupdate = 0;
my $linecount = 0;

die "$0: ERROR [$yum_conf_file] doesn't exist!\n" unless ( -e $yum_conf_file );

if ( `dig txt $txtdomain` =~ /$txtdomain\.\s+\d+\s+IN\s+TXT\s+"last update: (\d{10})"/i )
{
	# we have a match.

	##print "found the txt record!  $1\n";
	
	$dnstimestamp = $1;	

	if (open(INPUT, "< $serialfile"))
	{
		while (<INPUT>)
		{
			next if /^(\s)*$/;
			chomp;

			$linecount++;

			if ($_ =~ /^LastUpdate: (\d{10})$/)
			{
				##print "found the last update in the timestamp file\n";
				$filetimestamp = $1;

				if ($dnstimestamp > $filetimestamp)
				{
					# DNS timestamp is newer than our local timestamp. Update!
					# ##print "DNS timestamp is newer than our local timestamp. Update!\n";

					$writednstimestamp = 1;
					$doupdate = 1;
				}
				else
				{
					# DNS timestamp is same or older (?) than file timestamp, nothing to do.
					##print "DNS timestamp is same or older (?) than file timestamp, nothing to do.\n";
	
					$writednstimestamp = 0;
					$doupdate = 0;
				}			

			}
			else
			{
				##print "did not find the last update in the timestamp file\n";
				$writednstimestamp = 1;
				$doupdate = 0;			
		
			}		



		}
		close INPUT;
		if ($linecount == 0)
		{
			#print "no lines in the timestamp file, write a new one.\n";

			$writednstimestamp = 1;
			$doupdate = 0;
		}


	}
	else
	{
		# couldn't find the old timestamp.
		$writednstimestamp = 1;
		$doupdate = 0;
	}




	if ($writednstimestamp == 1)
	{
		##print "we would be writing stuff here to the timestamp file!\n";

		if (open($outfile, ">$serialfile"))
		{
			print $outfile ("LastUpdate: $dnstimestamp\n");
			close($outfile);
		}

	}



	if ($doupdate == 1)
	{
		##print "we would up running a yum upgrade here!\n";
		my $yumoutput1 = `$cleancommand`;
		my $yumoutput2 = `$updatecommand`;

                if (open($outfile, ">>$logfile"))
                {       
                        print $outfile ("### Start yum output from $filetimestamp -> $dnstimestamp ###\n");
								print $outfile ($yumoutput1);
								print $outfile ($yumoutput2);
								print $outfile ("###   End yum output from $filetimestamp -> $dnstimestamp ###\n\n");
								close($outfile);
                }

		# Radar stuff
		my $rpmexport_script = "/usr/local/lp/apps/rpmexport.sh";
		system("$rpmexport_script") if ( -x $rpmexport_script );
		my $sonar_helpers = "/usr/local/lp/apps/sonarpush-helpers/sonarpush-helpers.sh";	
		system("$sonar_helpers all") if ( -x $sonar_helpers );
	}




}
else
{
	# No match on the txt record. Exit quietly.
	exit;
}






exit;