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
48 # helper for hacking yumgroups
49 # if we've installed for several flavours
50 # we create cross links in install-rpms like this one
51 # ./onelab-f8-i386/vserver-onelab-f12-i386-5.0-6.2011.02.03.i686.rpm
52 # -> /var/www/html/install-rpms/onelab-f12-i386/vserver-onelab-f12-i386-5.0-6.2011.02.03.i686.rpm
54 # but this won't make it to the nodes until they are insered in yumgroups.xml in the PlanetLab group
57 function hack_yumgroups () {
60 pushd $repo >& /dev/null
62 vsrpms=$(find . -name 'vserver*rpm')
63 echo found vsrpms $vsrpms
64 if [ ! -f yumgroups.xml ] ; then
65 echo "hack_yumgroups: could not find yumgroups in $(pwd)"
66 elif [ -z "$vsrpms" ] ; then
67 echo "No need to hack yumgroups, no foreign vserver package found"
69 cp yumgroups.xml yumgroups.xml.hacking
70 # remove references to package vserver-
71 grep -v '>vserver-' yumgroups.xml.hacking > yumgroups.xml
72 # build a list of lines with corresponding rpm names
74 for vsrpm in $vsrpms; do
75 rpmname=$(rpm -q --qf '%{name}' -p $vsrpm)
76 echo found file $vsrpm with name $rpmname
77 insert="$insert<packagereq type=\"mandatory\">$rpmname</packagereq>"
79 echo 'inserting' $insert
80 # insert in yumgroups at the right place -- first packages in the PlanetLab group
81 ed yumgroups.xml <<EOF
99 if [ "$PLC_BOOT_ENABLED" != "1" ] ; then
103 MESSAGE=$"Signing and indexing node packages"
110 if [[ -z "$@" ]] ; then
111 # use all subdirs in install-rpms by default
112 repositories=/var/www/html/install-rpms/*
119 # deal with the vserver packages
120 # symlink all instances of plain 'vserver-*rpm' in all repos
121 # and cleanup old links
122 vsrpms=$(find $repositories -name 'vserver*rpm' -a -type f)
123 vslinks=$(find $repositories -name 'vserver*rpm' -a -type l)
125 for vslink in $vslinks; do
126 [ ! -e $vslink ] && { echo removing old $vslink; rm $vslink; }
129 for repo in $repositories; do
130 for vsrpm in $vsrpms; do
131 # if in the repo we're dealing with, ignore
132 if [ "$(echo $vsrpm | sed -e s,^$repo,,)" != $vsrpm ] ; then
137 if [ ! -e $link ] ; then
138 echo "creating symlink $link towards $vsrpm"
145 # now that the symlinks are OK, we can tweak yumgroups
146 for repository in $repositories; do
147 hack_yumgroups $repository
150 ########## sign plain packages
151 for repository in $repositories ; do
152 # the rpms that need signing
154 # and the corresponding stamps
156 # is there a need to refresh yum metadata
157 # a safe approach would be to always run createrepo
158 # however this is painfully slow with multi-flavour installed
160 # however if we run this script like
161 # /etc/plc.d/packages force
162 # then we force a createrepo
163 [ "$mode" == force ] && need_createrepo=true
165 # right after installation, no package is present
166 # but we still need to create index
167 [ ! -f $repository/repodata/repomd.xml ] && need_createrepo=true
169 # it's not helpful to sign symlinks that will get signed on their own
170 for package in $(find $repository/ -name '*.rpm' -a \! -type l) ; do
171 stamp=$repository/signed-stamps/$(basename $package).signed
172 # If package is newer than signature stamp
173 if [ $package -nt $stamp ] ; then
174 new_rpms="$new_rpms $package"
175 new_stamps="$new_stamps $stamp"
177 # Or than createrepo database
178 [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
179 [ $package -nt $repository/repodata/filelists.xml.gz ] && need_createrepo=true
182 if [ -n "$new_rpms" ] ; then
183 # Create a stamp once the package gets signed
184 mkdir $repository/signed-stamps 2> /dev/null
186 # Sign RPMS. setsid detaches rpm from the terminal,
187 # allowing the (hopefully blank) GPG password to be
188 # entered from stdin instead of /dev/tty.
190 --define "_signature gpg" \
191 --define "_gpg_path /etc/planetlab" \
192 --define "_gpg_name $PLC_MAIL_SUPPORT_ADDRESS" \
193 --resign $new_rpms && touch $new_stamps
195 # if we sign at least one package then we need to reindex
199 # Update repository index / yum metadata.
201 if [ -n "$need_createrepo" ] ; then
202 if [ -f $repository/yumgroups.xml ] ; then
203 createrepo --quiet -g yumgroups.xml $repository
206 createrepo --quiet $repository
216 if [[ -z "$@" ]] ; then
217 # use all subdirs in install-rpms by default
218 repositories=/var/www/html/install-rpms/*
224 for repository in $repositories ; do
225 rm -rf $repository/signed-stamps
226 rm -rf $repository/repodata
227 find $repository -type l | xargs rm
230 # (use this only if you have noderepos installed)
233 find /var/www/html/install-rpms -name signed-stamps | xargs rm -rf
234 find /var/www/html/install-rpms -name repodata | xargs rm -rf
235 find /var/www/html/install-rpms -type l | xargs rm
236 rpm -aq | grep noderepo | xargs yum -y reinstall
239 echo "Usage: $0 start|force|clean [repo ..]"