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
21 # (*) sometimes we have yum issuing errors like 'package does not match intended content'
22 # this means that the sha256 checksum of the downloaded pkg does not match
23 # the sha256 checksum advertised in filelists.xml
24 # if you did run 'yum clean all' on the node,
25 # this means that the repodata/ dir. on the server side is out of date
26 # forcing a createrepo should solve this
28 # (*) also sometimes the node complains that a package is not signed
30 # so there quite obviously are some corner cases that are not well handled
31 # hopefully the following subforms may be helpful to recover in these cases
33 # /etc/plc.d/packages clean
34 # performs cleanup of the yum repositories and signed-stamps
35 # thus forcing the next 'start' command to re-sign and re-index everything
36 # /etc/plc.d/packages superclean
37 # like 'clean', plus this will reinstall the noderepo rpms that you have,
38 # that is to say restart from unsigned rpms
39 # /etc/plc.d/packages start
40 # this is the usual form, it should be smart enough to only sign the packages that need to,
41 # and to rerun createrepo when useful
42 # /etc/plc.d/packages force
43 # same as 'start' but createrepo is run unconditionnally
45 # PS. I suspect sometimes the signing fails and the script does not notice properly
49 # helper for hacking yumgroups
50 # if we've installed for several flavours
51 # we create cross links in install-rpms like this one
52 # ./onelab-f8-i386/sliceimage-onelab-f12-i386-5.0-6.2011.02.03.i686.rpm
53 # -> /var/www/html/install-rpms/onelab-f12-i386/sliceimage-onelab-f12-i386-5.0-6.2011.02.03.i686.rpm
55 # but this won't make it to the nodes until they are insered in yumgroups.xml in the PlanetLab group
58 function hack_yumgroups () {
61 pushd $repo >& /dev/null
63 sirpms=$(find . -name 'sliceimage*rpm')
64 echo found sirpms $sirpms
65 if [ ! -f yumgroups.xml ] ; then
66 echo "hack_yumgroups: could not find yumgroups in $(pwd)"
67 elif [ -z "$sirpms" ] ; then
68 echo "No need to hack yumgroups, no foreign sliceimage package found"
70 cp yumgroups.xml yumgroups.xml.hacking
71 # remove references to package sliceimage-
72 grep -v '>sliceimage-' yumgroups.xml.hacking > yumgroups.xml
73 # build a list of lines with corresponding rpm names
75 for sirpm in $sirpms; do
76 rpmname=$(rpm -q --qf '%{name}' -p $sirpm)
77 echo found file $sirpm with name $rpmname
78 insert="$insert<packagereq type=\"mandatory\">$rpmname</packagereq>"
80 echo 'inserting' $insert
81 # insert in yumgroups at the right place -- first packages in the PlanetLab group
82 ed yumgroups.xml <<EOF
100 if [ "$PLC_BOOT_ENABLED" != "1" ] ; then
104 MESSAGE=$"Signing and indexing node packages"
111 # on PLC there is a need to select the repos as there are quite a few in there
112 # would contain names or patterns relative to install-rpms
113 explicit_list=/var/www/html/install-rpms/PACKAGES
115 # use argv if provided
116 if [[ -n "$@" ]] ; then
118 elif [ -f $explicit_list ] ; then
120 for name in $(grep -v '#' $explicit_list); do
121 repositories="$repositories /var/www/html/install-rpms/$name"
124 # use all subdirs in install-rpms by default
125 repositories=/var/www/html/install-rpms/*
129 # deal with the sliceimage packages
130 # symlink all instances of plain 'sliceimage-*rpm' in all repos
131 # and cleanup old links
132 sirpms=$(find $repositories -name 'sliceimage*rpm' -a -type f)
133 # for nicer upgrades, also remove symlinks from 5.0
134 silinks=$(find $repositories '(' -name 'sliceimage*rpm' -o -name 'vserver*rpm' ')' -a -type l)
136 for silink in $silinks; do
137 [ ! -e $silink ] && { echo removing old $silink; rm $silink; }
140 for repo in $repositories; do
141 for sirpm in $sirpms; do
142 # if in the repo we're dealing with, ignore
143 if [ "$(echo $sirpm | sed -e s,^$repo,,)" != $sirpm ] ; then
148 if [ ! -e $link ] ; then
149 echo "creating symlink $link towards $sirpm"
156 # now that the symlinks are OK, we can tweak yumgroups
157 for repository in $repositories; do
158 hack_yumgroups $repository
161 ########## sign plain packages
162 for repository in $repositories ; do
163 # the rpms that need signing
165 # and the corresponding stamps
167 # is there a need to refresh yum metadata
168 # a safe approach would be to always run createrepo
169 # however this is painfully slow with multi-flavour installed
171 # however if we run this script like
172 # /etc/plc.d/packages force
173 # then we force a createrepo
174 [ "$mode" == force ] && need_createrepo=true
176 # right after installation, no package is present
177 # but we still need to create index
178 [ ! -f $repository/repodata/repomd.xml ] && need_createrepo=true
180 # it's not helpful to sign symlinks that will get signed on their own
181 for package in $(find $repository/ -name '*.rpm' -a \! -type l) ; do
182 stamp=$repository/signed-stamps/$(basename $package).signed
183 # If package is newer than signature stamp
184 if [ $package -nt $stamp ] ; then
185 new_rpms="$new_rpms $package"
186 new_stamps="$new_stamps $stamp"
188 # Or than createrepo database
189 [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
190 [ $package -nt $repository/repodata/filelists.xml.gz ] && need_createrepo=true
193 if [ -n "$new_rpms" ] ; then
194 # Create a stamp once the package gets signed
195 mkdir $repository/signed-stamps 2> /dev/null
197 # Sign RPMS. setsid detaches rpm from the terminal,
198 # allowing the (hopefully blank) GPG password to be
199 # entered from stdin instead of /dev/tty.
201 --define "_signature gpg" \
202 --define "_gpg_path /etc/planetlab" \
203 --define "_gpg_name $PLC_MAIL_SUPPORT_ADDRESS" \
204 --resign $new_rpms && touch $new_stamps
206 # if we sign at least one package then we need to reindex
210 # Update repository index / yum metadata.
212 if [ -n "$need_createrepo" ] ; then
213 if [ -f $repository/yumgroups.xml ] ; then
214 createrepo --quiet -g yumgroups.xml $repository
217 createrepo --quiet $repository
227 if [[ -z "$@" ]] ; then
228 # use all subdirs in install-rpms by default
229 repositories=/var/www/html/install-rpms/*
235 for repository in $repositories ; do
236 rm -rf $repository/signed-stamps
237 rm -rf $repository/repodata
238 find $repository -type l | xargs rm
241 # (use this only if you have noderepos installed)
244 find /var/www/html/install-rpms -name signed-stamps | xargs rm -rf
245 find /var/www/html/install-rpms -name repodata | xargs rm -rf
246 find /var/www/html/install-rpms -type l | xargs rm
247 rpm -aq | grep noderepo | xargs yum -y reinstall
250 echo "Usage: $0 start|force|clean [repo ..]"