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