[LON-CAPA-cvs] cvs: loncom /build CHECKRPMS
raeburn
raeburn@source.lon-capa.org
Tue, 14 Jul 2009 14:36:06 -0000
raeburn Tue Jul 14 14:36:06 2009 EDT
Modified files:
/loncom/build CHECKRPMS
Log:
- &check_with_apt() added to report if installed .deb packages need updating for
Debian/Ubuntu.
- &check_with_zypper() used for SuSE 11.1.
Index: loncom/build/CHECKRPMS
diff -u loncom/build/CHECKRPMS:1.10 loncom/build/CHECKRPMS:1.11
--- loncom/build/CHECKRPMS:1.10 Tue Dec 4 04:43:24 2007
+++ loncom/build/CHECKRPMS Tue Jul 14 14:36:06 2009
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl
#
# The LearningOnline Network with CAPA
# Checks status of RPM packages on system.
@@ -30,7 +30,8 @@
=head1 NAME
-B<CHECKRPMS> - automated status report about RPMs on a system.
+B<CHECKRPMS> - automated status report about RPMs (RHEL/Fedora/CentOS/SuSE)
+ or debs (Debian/Ubuntu) on a system.
=head1 DESCRIPTION
@@ -41,9 +42,10 @@
fedora, rhel 5/5+, centos, scientific - yum
suse 9.X and sles9 - you
-suse 10.2,10.3 - zypper
+suse 10.2,10.3,11.1 - zypper
sles10,suse10.1 - rug
rhel 4 - up2date
+debian, ubuntu - apt-get
others - check-rpms
Created by amalgamating previous distribution-specific CHECKRPMS.dist files (where dist was one of: fedora, rhel, suse, sles10, default).
@@ -89,9 +91,10 @@
$cmd = 'you';
&prepare_msg($tmpfile,$cmd);
($send,$addsubj) = &check_with_you($tmpfile);
-} elsif ($distro =~ /^suse10\.(\d)$/) {
+} elsif ($distro =~ /^suse(\d{2,})\.(\d+)$/) {
my $version =$1;
- if ($version > 1) {
+ my $subversion = $2;
+ if (($version > 10) || (($version == 10) && ($subversion > 1))) {
$cmd = 'zypper up';
&prepare_msg($tmpfile,$cmd);
($send,$addsubj) = &check_with_zypper($tmpfile);
@@ -123,6 +126,10 @@
$cmd = 'yum update';
&prepare_msg($tmpfile,$cmd);
($send,$addsubj) = &check_with_yum($tmpfile);
+} elsif ($distro =~ /^(debian|ubuntu)\d+/) {
+ $cmd = 'apt-get upgrade';
+ &prepare_msg($tmpfile,$cmd);
+ ($send,$addsubj) = &check_with_apt($tmpfile);
} else {
$cmd = '/usr/local/bin/check-rpms --update';
($send,$addsubj) = &check_with_checkrpms($tmpfile);
@@ -356,6 +363,51 @@
return ($sendflag,$append_to_subj);
}
+sub check_with_apt {
+ my ($tmpfile) = @_;
+ my $apt = '/usr/bin/apt-get';
+ my $sendflag = 0;
+ my $append_to_subj;
+ my $header;
+ my @chg_package;
+ #
+ # Execute apt-get command to update distributions
+ system ("$apt update > /dev/null");
+ my $returnvalue = $?>>8;
+ if ($returnvalue == 0) {
+ # Execute apt-get commands to check for upgrades
+ if (open (PIPE, "$apt -y --dry-run upgrade 2>&1 |")) {
+ my @output=<PIPE>;
+ close(PIPE);
+ chomp(@output);
+ foreach my $line (@output) {
+ $line =~ s/^\s+//;
+ my @items = split(/\s+/,$line);
+ if ($items[0] eq "Inst") {
+ push(@chg_package,$items[1]);
+ }
+ }
+ if (@chg_package > 0) {
+ $header = 'apt-get upgrade found the following packages need updating:'.
+ "\n\n";
+ open(TMPFILE,">>$tmpfile");
+ my $message = join("\n",@output);
+ print TMPFILE $header.$message;
+ close(TMPFILE);
+ $append_to_subj= ' deb packages to upgrade';
+ $sendflag = 1;
+ }
+ } else {
+ $append_to_subj = ' Error running deb upgrade check';
+ $sendflag = 1;
+ }
+ } else {
+ $append_to_subj = ' Error running deb update check';
+ $sendflag = 1;
+ }
+ return ($sendflag,$append_to_subj);
+}
+
sub check_with_checkrpms {
my ($tmpfile,$perlvar) = @_;
my $checkrpms = '/usr/local/bin/check-rpms';