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; rm $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"
116 # now that the symlinks are OK, we can tweak yumgroups
117 for repository in $repositories; do
118 hack_yumgroups $repository
121 ########## sign plain packages
122 for repository in $repositories ; do
123 # the rpms that need signing
125 # and the corresponding stamps
127 # is there a need to refresh yum metadata
128 # a safe approach would be to always run createrepo
129 # however this is painfully slow with multi-flavour installed
131 # however if we run this script like
132 # /etc/plc.d/packages force
133 # then we force a createrepo
134 [ "$mode" == force ] && need_createrepo=true
136 # right after installation, no package is present
137 # but we still need to create index
138 [ ! -f $repository/repodata/repomd.xml ] && need_createrepo=true
140 # it's not helpful to sign symlinks that will get signed on their own
141 for package in $(find $repository/ -name '*.rpm' -a \! -type l) ; do
142 stamp=$repository/signed-stamps/$(basename $package).signed
143 # If package is newer than signature stamp
144 if [ $package -nt $stamp ] ; then
145 new_rpms="$new_rpms $package"
146 new_stamps="$new_stamps $stamp"
148 # Or than createrepo database
149 [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
152 if [ -n "$new_rpms" ] ; then
153 # Create a stamp once the package gets signed
154 mkdir $repository/signed-stamps 2> /dev/null
156 # Sign RPMS. setsid detaches rpm from the terminal,
157 # allowing the (hopefully blank) GPG password to be
158 # entered from stdin instead of /dev/tty.
160 --define "_signature gpg" \
161 --define "_gpg_path /etc/planetlab" \
162 --define "_gpg_name $PLC_MAIL_SUPPORT_ADDRESS" \
163 --resign $new_rpms && touch $new_stamps
167 # Update repository index / yum metadata.
169 if [ -n "$need_createrepo" ] ; then
170 if [ -f $repository/yumgroups.xml ] ; then
171 createrepo --quiet -g yumgroups.xml $repository
174 createrepo --quiet $repository
184 if [[ -z "$@" ]] ; then
185 # use all subdirs in install-rpms by default
186 repositories=/var/www/html/install-rpms/*
192 for repository in $repositories ; do
193 rm -rf $repository/signed-stamps
194 rm -rf $repository/repodata
195 rm -rf $repository/headers
196 find $repository -type l | xargs rm
200 echo "Usage: $0 start|force|clean [repo ..]"