[LON-CAPA-cvs] cvs: loncom /build CHECKRPMS

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Thu, 13 Sep 2007 21:50:39 -0000


raeburn		Thu Sep 13 17:50:39 2007 EDT

  Modified files:              
    /loncom/build	CHECKRPMS 
  Log:
  Use zypper to check for updates for SuSE 10.2 and later.
  Continue using rug for SLES10 and SuSE 10.1.
  
  
Index: loncom/build/CHECKRPMS
diff -u loncom/build/CHECKRPMS:1.8 loncom/build/CHECKRPMS:1.9
--- loncom/build/CHECKRPMS:1.8	Thu Jun 28 09:30:06 2007
+++ loncom/build/CHECKRPMS	Thu Sep 13 17:50:37 2007
@@ -41,7 +41,8 @@
 
 fedora, rhel 5/5+, centos, scientific - yum
 suse 9.X and sles9 - you
-suse 10.X and sles10 - rug
+suse 10.2,10.3 - zypper 
+sles10,suse10.1 - rug
 rhel 4 - up2date
 others - check-rpms
 
@@ -84,7 +85,18 @@
     $cmd = 'you';
     &prepare_msg($tmpfile,$cmd);
     ($send,$addsubj) = &check_with_you($tmpfile);
-} elsif ($distro =~ /^(suse|sles)10\.?\d?$/) {
+} elsif ($distro =~ /^suse10\.(\d)$/) {
+    my $version =$1;
+    if ($version > 1) { 
+        $cmd = 'zypper up';
+        &prepare_msg($tmpfile,$cmd);
+        ($send,$addsubj) = &check_with_zypper($tmpfile);
+    } else {
+        $cmd = 'rug up';
+        &prepare_msg($tmpfile,$cmd);
+        ($send,$addsubj) = &check_with_rug($tmpfile);
+    }
+} elsif ($distro =~ /^sles10$/) {
     $cmd = 'rug up';
     &prepare_msg($tmpfile,$cmd);
     ($send,$addsubj) = &check_with_rug($tmpfile);
@@ -291,6 +303,55 @@
     return ($sendflag,$append_to_subj);
 }
 
+sub check_with_zypper {
+    my ($tmpfile) = @_;
+    my $zypper = '/usr/bin/zypper';
+    my $sendflag = 0;
+    my $append_to_subj;
+    my $header;
+    #
+    # Execute zypper command to check for updates
+    if (open (PIPE, "$zypper lu 2>&1 |")) {
+        my @output=<PIPE>;
+        close(PIPE);
+        chomp(@output);
+        my @clean_output;
+        foreach my $line (@output) {
+            if ($line eq 'Restoring system sources...') {
+                next;
+            } elsif ($line =~ /^Parsing\smetadata\sfor\s/) {
+                next;
+            } elsif ($line eq 'Parsing RPM database...') {
+                next;
+            } elsif ($line  =~ /^Catalog\s+\|\s+Name\s+\|\s+Version\s+\|\s+Category\s+\|\s+Status$/) {
+                $header = $line."\n";
+                next;
+            } elsif ($line =~ /^[-+]+$/) {
+                $header .= $line."\n";
+                next;
+            } elsif ($line eq 'WARNING: These are only the updates affecting the updater itself.') {
+                next;
+            } elsif ($line eq 'There are others available too.') {
+                next;
+            } else {
+                push(@clean_output,$line);
+            }
+        }
+        if (@clean_output > 0) {
+            open(TMPFILE,">>$tmpfile");
+            my $message = join("\n",@clean_output);
+            print TMPFILE $header.$message;
+            close(TMPFILE);
+            $append_to_subj= ' RPMS to upgrade';
+            $sendflag = 1;
+        }
+    } else {
+        $append_to_subj = ' Error running RPM update check';
+        $sendflag = 1;
+    }
+    return ($sendflag,$append_to_subj);
+}
+
 sub check_with_checkrpms {
     my ($tmpfile,$perlvar) = @_;
     my $checkrpms = '/usr/local/bin/check-rpms';