1e3f6339925c5189136e45a86886a67ba6f2f0d2
[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 if test ! -x /usr/bin/expect; then
23   echo "$0: /usr/bin/expect missing. Install expect"
24   exit 1
25 fi
26
27 now=`date +%s`
28 # sign if newer than signage (86400=24 hrs)
29 signage=8000
30 #check if root has rpm macros
31 confdir=`pwd`
32 architectures="i386 x86_64"
33 dirs_to_upd=""
34 for vdist in centos/5.5 rhel/5.5 centos/6; do
35   dist=`basename $vdist`
36   vendor=`dirname $vdist`
37   ftpdir=/home/ftp/pub/yum/$vendor/$dist
38   if test ! -d $ftpdir; then
39     echo "$ftpdir does not exist"
40     exit 1
41   fi
42   cd $ftpdir    
43   sections=""
44   for section in main restricted; do
45     # Prepare pool
46     d=$section
47     if test ! -d $d; then mkdir -p $d; fi
48     if test ! -d $d/SRPMS; then mkdir -p $d/SRPMS; fi
49     # Remove invalid symlinks (SRPMS, i386, x86_64,..)
50     for l in $d/SRPMS/*; do
51       if test -L "$l"; then
52         if test ! -f "$l"; then
53           rm $l
54         fi
55       fi
56     done
57     for arch in $architectures; do
58       dirs_to_upd="${dirs_to_upd} ${ftpdir}/${d}/${arch}"
59       for l in $d/$arch/Packages/*; do
60         if test -L "$l"; then
61           if test ! -f "$l"; then
62             rm $l
63           fi
64         fi
65       done
66     done
67     # Make symlinks from the regular FTP archive
68     for pdir in /home/ftp/pub/*; do
69       use=false
70       if test -f $pdir/.htaccess -a $section != "main"; then
71         use=true
72       fi
73       if test ! -f $pdir/.htaccess -a $section = "main"; then
74         use=true
75       fi
76       if $use; then
77         distdir=$pdir/redhat/$vendor/$dist
78         if test -d $distdir; then
79           if test -d $distdir/SRPMS; then
80             for f in $distdir/SRPMS/*.src.rpm; do
81               if test -f $f; then
82                 ln -sf $f $d/SRPMS/
83               fi
84             done
85           fi
86           for arch in $architectures; do
87             mkdir -p $d/${arch}/Packages
88             for f in $distdir/RPMS/${arch}/*.rpm $distdir/RPMS/noarch/*.rpm; do
89               if test -f $f; then
90                 age=`stat --printf='%Y' $f`
91                 if expr $now - $age \< $signage >/dev/null; then
92                   ln -sf $f $d/${arch}/Packages/
93                   if rpm -K $f|grep -q ' gpg' >/dev/null; then
94                     echo "Already signed $f"
95                   else
96                     expect << __EOF
97                     spawn rpm --addsign $f
98 expect -exact "Enter pass phrase: "
99 send -- "\r"
100 expect eof
101 __EOF
102                     chgrp staff $f
103                     chmod g+w $f
104                   fi
105                 fi
106               fi
107             done
108           done
109         fi
110       fi
111     done
112   done
113 done
114 echo "Updating repository meta:"
115 for rdir in ${dirs_to_upd}; do
116   echo "Section ${rdir}"
117   if test -d $rdir && ls -A $rdir; then
118         createrepo --update ${rdir}
119         if test -f ${rdir}/repodata/repomd.xml.asc; then
120                 rm ${rdir}/repodata/repomd.xml.asc
121         fi
122         gpg --detach-sign -u "Index Data" --armor ${rdir}/repodata/repomd.xml
123   else
124         echo "Empty."
125   fi
126 done
127 # Local Variables:
128 # mode:shell-script
129 # sh-indentation: 2
130 # sh-basic-offset: 8
131 # End: