72b1b81b304af0f7350bdfc7fe5786e1f54cfb98
[git-tools-moved-to-github.git] / update-archive / update-yum-archive.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       dirs_to_upd="${dirs_to_upd} ${ftpdir}/${d}/${arch}"
52       for l in $d/$arch/Packages/*; do
53         if test -L "$l"; then
54           if test ! -f "$l"; then
55             rm $l
56           fi
57         fi
58       done
59     done
60     # Make symlinks from the regular FTP archive
61     has_packages=false
62     for pdir in /home/ftp/pub/*; do
63       use=false
64       if test -f $pdir/.htaccess -a $section != "main"; then
65         use=true
66       fi
67       if test ! -f $pdir/.htaccess -a $section = "main"; then
68         use=true
69       fi
70       if $use; then
71         distdir=$pdir/redhat/$vendor/$dist
72         if test -d $distdir; then
73           if test -d $distdir/SRPMS; then
74             for f in $distdir/SRPMS/*.src.rpm; do
75               if test -f $f; then                                                               
76                 ln -sf $f $d/SRPMS/
77               fi
78             done
79           fi
80           for arch in $architectures; do
81             mkdir -p $d/${arch}/Packages
82             for f in $distdir/RPMS/${arch}/*.rpm $distdir/RPMS/noarch/*.rpm; do
83               if test -f $f; then
84                 pkgs_to_sign="${pkgs_to_sign} $f"
85                 ln -sf $f $d/${arch}/Packages/
86                 has_packages=true
87               fi
88             done
89           done
90         fi
91       fi
92     done
93   done
94 done
95 echo "Signing packages (default ID PPH is empty):"
96 rpm --addsign ${pkgs_to_sign}
97 chgrp staff ${pkgs_to_sign}
98 chmod g+w ${pkgs_to_sign}
99 echo "Updating repository meta:"
100 for rdir in ${dirs_to_upd}; do
101   echo "Section ${rdir}"
102   if test -d $rdir && ls -A $rdir; then
103         createrepo --update ${rdir}
104         if test -f ${rdir}/repodata/repomd.xml.asc; then
105                 rm ${rdir}/repodata/repomd.xml.asc
106         fi
107         gpg --detach-sign -u "Index Data" --armor ${rdir}/repodata/repomd.xml
108   else
109         echo "Empty."
110   fi
111 done
112 # Local Variables:
113 # mode:shell-script
114 # sh-indentation: 2
115 # sh-basic-offset: 8
116 # End: