[csw-devel] SF.net SVN: gar:[11993] csw/mgar/pkg/cswpkgloghooks/trunk/files

bdwalton at users.sourceforge.net bdwalton at users.sourceforge.net
Sat Dec 18 05:27:23 CET 2010


Revision: 11993
          http://gar.svn.sourceforge.net/gar/?rev=11993&view=rev
Author:   bdwalton
Date:     2010-12-18 04:27:23 +0000 (Sat, 18 Dec 2010)

Log Message:
-----------
cswpkgloghooks: convert to perl to ease the name/version splitting issue correction

Modified Paths:
--------------
    csw/mgar/pkg/cswpkgloghooks/trunk/files/01-CSWcswpkgloghooks-postupgrade
    csw/mgar/pkg/cswpkgloghooks/trunk/files/01-CSWcswpkgloghooks-preupgrade

Modified: csw/mgar/pkg/cswpkgloghooks/trunk/files/01-CSWcswpkgloghooks-postupgrade
===================================================================
--- csw/mgar/pkg/cswpkgloghooks/trunk/files/01-CSWcswpkgloghooks-postupgrade	2010-12-17 22:26:17 UTC (rev 11992)
+++ csw/mgar/pkg/cswpkgloghooks/trunk/files/01-CSWcswpkgloghooks-postupgrade	2010-12-18 04:27:23 UTC (rev 11993)
@@ -1,62 +1,80 @@
-#!/usr/bin/env bash
+#!/usr/bin/env perl
 
-script=$0
+use strict;
+use warnings;
 
-set -- ${1/-/ }
-PKG=$1
-VER=$2
+my ($script, $pkg, $ver, $oldver, $sysver, $statefile);
 
-function logdie() {
-    logger -t "cswpkgloghooks" "$1"
+$script = $0;
+$ARGV[0] =~ /(.+)-(.+)/;
+$pkg = $1;
+$ver = $2;
+
+$sysver = `pkgparam $pkg VERSION`;
+$statefile = "/var/opt/csw/pkg-hooks/CSWpkgloghooks.upgrade.$pkg";
+
+open(STATEFILE, ">$statefile") or die "Couldn't open $statefile.";
+print STATEFILE "$sysver";
+close(STATEFILE)
+
+sub logdie() {
+    my $arg = shift;
+    system('logger', '-t', 'cswpkgloghooks', $arg);
     exit 0
 }
 
-function success() {
-    case ${script} in
-	*install) MSG="installed ${PKG} ${VER}";;
-	*upgrade) MSG="upgraded ${PKG} to ${VER} (from: $1)";;
-	*remove) MSG="removed ${PKG} ${VER}";;
-    esac
+sub success() {
+    my $old = shift;
+    my $msg = '';
+    if ($script =~ /install$/) {
+	$msg = "installed $pkg $ver";
+    } elsif ($script =~ /upgrade$/) {
+	$msg = "upgraded $pkg to $ver (from: $old)";
+    } elsif ($script =~ /remove$/) {
+	$msg = "removed $pkg $ver";
+    }
 
-    logdie "${MSG}"
+    logdie $msg;
 }
 
 function failure() {
-    case ${script} in
-	*install) MSG="Failed to install ${PKG} ${VER}";;
-	*upgrade) MSG="Failed to upgrade ${PKG} ${VER} (current: $1)";;
-	*remove) MSG="Failed to remove ${PKG} ${VER}";;
-    esac
+    my $old = shift;
+    my $msg = '';
+    if ($script =~ /install$/) {
+	$msg = "Failed to install $pkg $ver";
+    } elsif ($script =~ /upgrade$/) {
+	$msg = "Failed to upgrade $pkg to $ver (current: $old)";
+    } elsif ($script =~ /remove$/) {
+	$msg = "Failed to remove $pkg $ver";
+    }
 
-    logdie "${MSG}"
+    logdie $msg;
 }
 
-if [ -d /var/sadm/pkg/${PKG} ]; then
-    SYSTEMVER=$(pkgparam ${PKG} VERSION 2>/dev/null)
-    pf=/var/opt/csw/pkg-hooks/CSWcswpkgloghooks.upgrade.${PKG}
-    if [ -f ${pf} ]; then
-	PREVVER=$(cat ${pf} 2>/dev/null)
-	rm -f ${pf}
-    fi
 
-    case ${script} in
-	*remove)
-	    failure
-	    ;;
-	*install|*upgrade)
-	    case "${VER}" in
-		${SYSTEMVER}) success ${PREVVER};;
-		*) failure ${SYSTEMVER};;
-	    esac
-	    ;;
-    esac
-else
-    case ${script} in
-	*remove)
-	    success
-	    ;;
-	*install|*upgrade)
-	    failure
-	    ;;
-    esac
-fi
+if ( -d "/var/sadm/pkg/$pkg" ) {
+    $sysver = system('pkgparam', $pkg, 'VERSION');
+
+    if ( -f "$statefile" ) {
+	open (STATEFILE, "<$statefile") or die "Couldn't open $statefile.";
+	$oldver = <STATEFILE>;
+	close(STATEFILE);
+	unlink($statefile);
+    }
+
+    if ($script =~ /remove$/) {
+	failure;
+    } else {
+	if ("$ver" eq "$sysver") {
+	    success($oldver);
+	} else {
+	    failure($sysver);
+	}
+    }
+} else {
+    if ($script =~ /remove$/) {
+	success();
+    } else {
+	failure();
+    }
+}

Modified: csw/mgar/pkg/cswpkgloghooks/trunk/files/01-CSWcswpkgloghooks-preupgrade
===================================================================
--- csw/mgar/pkg/cswpkgloghooks/trunk/files/01-CSWcswpkgloghooks-preupgrade	2010-12-17 22:26:17 UTC (rev 11992)
+++ csw/mgar/pkg/cswpkgloghooks/trunk/files/01-CSWcswpkgloghooks-preupgrade	2010-12-18 04:27:23 UTC (rev 11993)
@@ -1,11 +1,17 @@
-#!/usr/bin/env bash
+#!/usr/bin/env perl
 
-set -- ${1/-/ }
+use strict;
+use warnings;
 
-PKG=$1
-VER=$2
+my ($pkg, $ver, $sysver, $statefile);
 
-SYSTEMVER=$(pkgparam ${PKG} VERSION)
+$ARGV[0] =~ /(.+)-(.+)/;
+$pkg = $1;
+$ver = $2;
 
-# store previous version so we can log smarter things if upgrade fails.
-echo ${SYSTEMVER} > /var/opt/csw/pkg-hooks/CSWcswpkgloghooks.upgrade.${PKG}
+$sysver = `pkgparam $pkg VERSION`;
+$statefile = "/var/opt/csw/pkg-hooks/CSWpkgloghooks.upgrade.$pkg";
+
+open(STATEFILE, ">$statefile") or die "Couldn't open $statefile.";
+print STATEFILE "$sysver";
+close(STATEFILE)


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list