* accept the repositories to manage as arguments
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 30 Jan 2007 15:09:22 +0000 (15:09 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 30 Jan 2007 15:09:22 +0000 (15:09 +0000)
* performs gpg-signing only once, stores stamps in repository/signed-stamps/
  (still runs yum-arch and createrepo unconditionnally)
* can also cleanup these stamps with packages clean [repo]

plc.d/packages

index 002bebd..fd24a06 100755 (executable)
@@ -7,7 +7,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: packages,v 1.3 2006/06/23 20:29:22 mlhuang Exp $
+# $Id: packages,v 1.4 2006/07/19 14:15:15 mlhuang Exp $
 #
 
 # Source function library and configuration
@@ -23,20 +23,41 @@ case "$1" in
        dialog "$MESSAGE"
 
        shopt -s nullglob
-       for repository in /var/www/html/install-rpms/* ; do
+
+       shift
+       if [[ -z "$@" ]] ; then
+           # use all subdirs in install-rpms by default
+           repositories=/var/www/html/install-rpms/*
+       else
+           # else use argv
+           repositories=$@
+       fi
+
+       for repository in $repositories ; do
             # Sign all RPMS. setsid detaches rpm from the terminal,
             # allowing the (hopefully blank) GPG password to be
             # entered from stdin instead of /dev/tty.
            packages=
+           stamps=
+           # create a stamp once the package gets signed
+           mkdir $repository/signed-stamps
+
            for package in $repository/*.rpm ; do
-               packages="$packages $package"
+               stamp=$repository/signed-stamps/$(basename $package).signed
+               # is package newer than stamp ?
+               if [ $package -nt $stamp ] ; then
+                   packages="$packages $package"
+                   stamps="$stamps $stamp"
+               else
+                   echo "Package $package already signed - skipped"
+               fi
            done
            if [ -n "$packages" ] ; then
                echo | setsid rpm \
                    --define "_signature gpg" \
                    --define "_gpg_path /etc/planetlab" \
                    --define "_gpg_name $PLC_MAIL_SUPPORT_ADDRESS" \
-                   --resign $packages
+                   --resign $packages && touch $stamps
                check
            fi
 
@@ -51,6 +72,23 @@ case "$1" in
 
        result "$MESSAGE"
        ;;
+    clean)
+       shift
+       if [[ -z "$@" ]] ; then
+           # use all subdirs in install-rpms by default
+           repositories=/var/www/html/install-rpms/*
+       else
+           # else use argv
+           repositories=$@
+       fi
+
+       for repository in $repositories ; do
+           rm -rf $repository/signed-stamps
+       done
+       ;;
+    *)
+        echo "Usage: $0 start|clean [repo ..]"
+       ;;
 esac
 
 exit $ERRORS