# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: packages,v 1.2 2006/05/18 22:58:20 mlhuang Exp $
+# $Id: packages,v 1.7 2007/02/04 01:05:28 mlhuang Exp $
#
# Source function library and configuration
case "$1" in
start)
- MESSAGE=$"Signing node packages"
+ if [ "$PLC_BOOT_ENABLED" != "1" ] ; then
+ exit 0
+ fi
+
+ MESSAGE=$"Signing and indexing node packages"
dialog "$MESSAGE"
shopt -s nullglob
- for repository in /var/www/html/install-rpms/* ; 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.
+
+ 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
packages=
+ stamps=
+ yum_arch=0
+ createrepo=0
+
+ # 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
+ # If package is newer than signature stamp
+ if [ $package -nt $stamp ] ; then
+ packages="$packages $package"
+ stamps="$stamps $stamp"
+ fi
+ # Or yum-arch headers
+ if [ $package -nt $repository/headers/header.info ] ; then
+ yum_arch=1
+ fi
+ # Or createrepo database
+ if [ $package -nt $repository/repodata/repomd.xml ] ; then
+ createrepo=1
+ fi
done
+
if [ -n "$packages" ] ; then
+ # Sign RPMS. setsid detaches rpm from the terminal,
+ # allowing the (hopefully blank) GPG password to be
+ # entered from stdin instead of /dev/tty.
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
+
+ # Update yum metadata. yum-arch createrepo sometimes leaves behind
+ # .oldheaders and .olddata directories accidentally.
+ rm -rf $repository/{.oldheaders,.olddata}
+
+ # Old command is yum-arch
+ if [ $yum_arch -eq 1 ] ; then
+ yum-arch $repository
check
fi
- # Update yum metadata. createrepo sometimes leaves behind
- # an .olddata file accidentally.
- rm -rf $repository/.olddata
- yum-arch $repository
- check
- createrepo -g yumgroups.xml $repository
- check
+ # New command is createrepo
+ if [ $createrepo -eq 1 ] ; then
+ if [ -f $repository/yumgroups.xml ] ; then
+ createrepo -g yumgroups.xml $repository
+ else
+ createrepo $repository
+ fi
+ check
+ fi
done
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
+ rm -rf $repository/repodata
+ rm -rf $repository/headers
+ done
+ ;;
+ *)
+ echo "Usage: $0 start|clean [repo ..]"
+ ;;
esac
exit $ERRORS