Embed singatures BEFORE generating meta.
[git-tools-moved-to-github.git] / update-archive / update-yum-archve.sh
1 #!/bin/sh
2 if [ "$(id -u)" != "0" -o $HOME != "/root" ]; then
3   echo "This script must be run as root (not sudo) to perform package singning." 1>&2
4   exit 1
5 fi
6
7 if test ! -f ~/.rpmmacros; then
8   echo "$0: Make sure ~/.rpmmacros file exsits and contains macros from git-tools/update-archive/root-rpmmacros"
9   exit 1
10 fi
11
12 if test ! -x /usr/bin/createrepo; then
13   echo "$0: /usr/bin/createrepo missing. Install createrepo"
14   exit 1
15 fi
16
17 if test ! -x /usr/bin/gpg; then
18   echo "$0: /usr/bin/gpg missing. Install gpg"
19   exit 1
20 fi
21
22 #check if root has rpm macros
23 confdir=`pwd`
24 pkgs_to_sign=""
25 architectures="i386 x86_64"
26 dirs_to_upd=""
27 for vdist in centos/5.5 rhel/5.5; do
28   dist=`basename $vdist`
29   vendor=`dirname $vdist`
30   ftpdir=/home/ftp/pub/yum/$vendor/$dist
31   if test ! -d $ftpdir; then
32     echo "$ftpdir does not exist"
33     exit 1
34   fi
35   cd $ftpdir    
36   sections=""
37   for section in main restricted; do
38     # Prepare pool
39     d=$section
40     if test ! -d $d; then mkdir -p $d; fi
41     if test ! -d $d/SRPMS; then mkdir -p $d/SRPMS; fi
42     # Remove invalid symlinks (SRPMS, i386, x86_64,..)
43     for l in $d/SRPMS/*; do
44       if test -L "$l"; then
45         if test ! -f "$l"; then
46           rm $l
47         fi
48       fi
49     done
50     for arch in $architectures; do
51       for l in $d/$arch/Packages/*; do
52         if test -L "$l"; then
53           if test ! -f "$l"; then
54             rm $l
55           fi
56         fi
57       done
58     done
59     # Make symlinks from the regular FTP archive
60     has_packages=false
61     for pdir in /home/ftp/pub/*; do
62       use=false
63       if test -f $pdir/.htaccess -a $section != "main"; then
64         use=true
65       fi
66       if test ! -f $pdir/.htaccess -a $section = "main"; then
67         use=true
68       fi
69       if $use; then
70         distdir=$pdir/redhat/$vendor/$dist
71         if test -d $distdir; then
72           if test -d $distdir/SRPMS; then
73             for f in $distdir/SRPMS/*.src.rpm; do
74               if test -f $f; then                                                               
75                 ln -sf $f $d/SRPMS/
76               fi
77             done
78           fi
79           for arch in $architectures; do
80             mkdir -p $d/${arch}/Packages
81             for f in $distdir/RPMS/${arch}/*.rpm $distdir/RPMS/noarch/*.rpm; do
82               if test -f $f; then
83                 pkgs_to_sign="${pkgs_to_sign} $f"
84                 ln -sf $f $d/${arch}/Packages/
85                 has_packages=true
86               fi
87             done
88             dirs_to_upd="${dirs_to_upd} ${ftpdir}/${d}/${arch}"
89           done
90         fi
91       fi
92     done
93   done
94 done
95 echo "Signing pakages (default ID PPH is empty):"
96 rpm --addsign $pkgs_to_sign ${pkgs_to_sign}
97 echo "Updating repository meta:"
98 echo ${dirs_to_upd}
99 for rdir in ${dirs_to_upd}; do
100   createrepo --update ${rdir}
101   if test -f ${rdir}/repodata/repomd.xml.asc; then
102     rm ${rdir}/repodata/repomd.xml.asc
103   fi
104   gpg --detach-sign -u "Index Data" --armor ${rdir}/repodata/repomd.xml
105 done
106 # Local Variables:
107 # mode:shell-script
108 # sh-indentation: 2
109 # sh-basic-offset: 8
110 # End:
111