yum-arch is not supported on recent fedoras
[myplc.git] / plc.d / packages
1 #!/bin/bash
2 #
3 # priority: 1200
4 #
5 # Update node package repository metadata and sign packages
6 #
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2006 The Trustees of Princeton University
9 #
10 # $Id$
11 #
12
13 # Source function library and configuration
14 . /etc/plc.d/functions
15 . /etc/planetlab/plc_config
16
17 # Be verbose
18 set -x
19
20 case "$1" in
21     start)
22         if [ "$PLC_BOOT_ENABLED" != "1" ] ; then
23             exit 0
24         fi
25
26         MESSAGE=$"Signing and indexing node packages"
27         dialog "$MESSAGE"
28
29         shopt -s nullglob
30
31         shift
32         if [[ -z "$@" ]] ; then
33             # use all subdirs in install-rpms by default
34             repositories=/var/www/html/install-rpms/*
35         else
36             # else use argv
37             repositories=$@
38         fi
39
40         for repository in $repositories ; do
41             packages=
42             stamps=
43             yum_arch=0
44             createrepo=0
45
46             # Create a stamp once the package gets signed
47             mkdir $repository/signed-stamps 2> /dev/null
48
49             for package in $(find $repository/ -name '*.rpm') ; do
50                 stamp=$repository/signed-stamps/$(basename $package).signed
51                 # If package is newer than signature stamp
52                 if [ $package -nt $stamp ] ; then
53                     packages="$packages $package"
54                     stamps="$stamps $stamp"
55                 fi
56                 # Or yum-arch headers
57                 if [ $package -nt $repository/headers/header.info ] ; then
58                     yum_arch=1
59                 fi
60                 # Or createrepo database
61                 if [ $package -nt $repository/repodata/repomd.xml ] ; then
62                     createrepo=1
63                 fi
64             done
65
66             if [ -n "$packages" ] ; then
67                 # Sign RPMS. setsid detaches rpm from the terminal,
68                 # allowing the (hopefully blank) GPG password to be
69                 # entered from stdin instead of /dev/tty.
70                 echo | setsid rpm \
71                     --define "_signature gpg" \
72                     --define "_gpg_path /etc/planetlab" \
73                     --define "_gpg_name $PLC_MAIL_SUPPORT_ADDRESS" \
74                     --resign $packages && touch $stamps
75                 check
76             fi
77
78             # Update yum metadata. yum-arch createrepo sometimes leaves behind
79             # .oldheaders and .olddata directories accidentally.
80             rm -rf $repository/{.oldheaders,.olddata}
81
82             type -p yum-arch > /dev/null && have_yum_arch="true"
83
84             # Old command is yum-arch
85             if [ -n "$have_yum_arch" -a $yum_arch -eq 1 ] ; then
86                 yum-arch $repository 
87                 check
88             fi
89
90             type -p createrepo > /dev/null && have_createrepo="true"
91
92             # New command is createrepo
93             if [ -n "$have_createrepo" -a $createrepo -eq 1 ] ; then
94                 if [ -f $repository/yumgroups.xml ] ; then
95                     createrepo --quiet -g yumgroups.xml $repository 
96                 else
97                     createrepo --quiet $repository
98                 fi
99                 check
100             fi
101         done
102
103         result "$MESSAGE"
104         ;;
105     clean)
106         shift
107         if [[ -z "$@" ]] ; then
108             # use all subdirs in install-rpms by default
109             repositories=/var/www/html/install-rpms/*
110         else
111             # else use argv
112             repositories=$@
113         fi
114
115         for repository in $repositories ; do
116             rm -rf $repository/signed-stamps
117             rm -rf $repository/repodata
118             rm -rf $repository/headers
119         done
120         ;;
121     *)
122         echo "Usage: $0 start|clean [repo ..]"
123         ;;
124 esac
125
126 exit $ERRORS