5 # Update node package repository metadata and sign packages
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2006 The Trustees of Princeton University
9 # Thierry Parmentelat <thierry.parmentelat@inria.fr>
12 # Source function library and configuration
13 . /etc/plc.d/functions
14 . /etc/planetlab/plc_config
19 #################### hack yumgroups
20 # if we've installed for several flavours
21 # we create cross links in install-rpms like this one
22 # ./onelab-f8-i386/vserver-onelab-f12-i386-5.0-6.2011.02.03.i686.rpm
23 # -> /var/www/html/install-rpms/onelab-f12-i386/vserver-onelab-f12-i386-5.0-6.2011.02.03.i686.rpm
25 # but this won't make it to the nodes until they are insered in yumgroups.xml in the PlanetLab group
28 function hack_yumgroups () {
31 pushd $repo >& /dev/null
33 vsrpms=$(find . -name 'vserver*rpm')
34 echo found vsrpms $vsrpms
35 if [ ! -f yumgroups.xml ] ; then
36 echo "hack_yumgroups: could not find yumgroups in $(pwd)"
37 elif [ -z "$vsrpms" ] ; then
38 echo "No need to hack yumgroups, no foreign vserver package found"
40 cp yumgroups.xml yumgroups.xml.hacking
41 # remove references to package vserver-
42 grep -v '>vserver-' yumgroups.xml.hacking > yumgroups.xml
43 # build a list of lines with corresponding rpm names
45 for vsrpm in $vsrpms; do
46 rpmname=$(rpm -q --qf '%{name}' -p $vsrpm)
47 echo found file $vsrpm with name $rpmname
48 insert="$insert<packagereq type=\"mandatory\">$rpmname</packagereq>"
50 echo 'inserting' $insert
51 # insert in yumgroups at the right place -- first packages in the PlanetLab group
52 ed yumgroups.xml <<EOF
70 if [ "$PLC_BOOT_ENABLED" != "1" ] ; then
74 MESSAGE=$"Signing and indexing node packages"
81 if [[ -z "$@" ]] ; then
82 # use all subdirs in install-rpms by default
83 repositories=/var/www/html/install-rpms/*
90 # deal with the vserver packages
91 # symlink all instances of plain 'vserver-*rpm' in all repos
92 # and cleanup old links
93 vsrpms=$(find $repositories -name 'vserver*rpm' -a -type f)
94 vslinks=$(find $repositories -name 'vserver*rpm' -a -type l)
96 for vslink in $vslinks; do
97 [ ! -e $vslink ] && echo removing old $vslink
100 for repo in $repositories; do
101 for vsrpm in $vsrpms; do
102 # if in the repo we're dealing with, ignore
103 if [ "$(echo $vsrpm | sed -e s,^$repo,,)" != $vsrpm ] ; then
108 if [ ! -e $link ] ; then
109 echo "creating symlink $link towards $vsrpm"
115 # now that the symlinks are OK, we can tweak yumgroups
116 for repository in $repositories; do
117 hack_yumgroups $repository
120 ########## sign plain packages
121 for repository in $repositories ; do
122 # the rpms that need signing
124 # and the corresponding stamps
126 # is there a need to refresh yum metadata
127 # a safe approach would be to always run createrepo
128 # however this is painfully slow with multi-flavour installed
130 # however if we run this script like
131 # /etc/plc.d/packages force
132 # then we force a createrepo
133 [ "$mode" == force ] && need_createrepo=true
135 # right after installation, no package is present
136 # but we still need to create index
137 [ ! -f $repository/repodata/repomd.xml ] && need_createrepo=true
139 # it's not helpful to sign symlinks that will get signed on their own
140 for package in $(find $repository/ -name '*.rpm' -a \! -type l) ; do
141 stamp=$repository/signed-stamps/$(basename $package).signed
142 # If package is newer than signature stamp
143 if [ $package -nt $stamp ] ; then
144 new_rpms="$new_rpms $package"
145 new_stamps="$new_stamps $stamp"
147 # Or than createrepo database
148 [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
151 if [ -n "$new_rpms" ] ; then
152 # Create a stamp once the package gets signed
153 mkdir $repository/signed-stamps 2> /dev/null
155 # Sign RPMS. setsid detaches rpm from the terminal,
156 # allowing the (hopefully blank) GPG password to be
157 # entered from stdin instead of /dev/tty.
159 --define "_signature gpg" \
160 --define "_gpg_path /etc/planetlab" \
161 --define "_gpg_name $PLC_MAIL_SUPPORT_ADDRESS" \
162 --resign $new_rpms && touch $new_stamps
166 # Update repository index / yum metadata.
168 if [ -n "$need_createrepo" ] ; then
169 if [ -f $repository/yumgroups.xml ] ; then
170 createrepo --quiet -g yumgroups.xml $repository
172 createrepo --quiet $repository
182 if [[ -z "$@" ]] ; then
183 # use all subdirs in install-rpms by default
184 repositories=/var/www/html/install-rpms/*
190 for repository in $repositories ; do
191 rm -rf $repository/signed-stamps
192 rm -rf $repository/repodata
193 rm -rf $repository/headers
194 find $repository -type l | xargs rm
198 echo "Usage: $0 start|force|clean [repo ..]"