Add some root/sudo checks and pkg singing (disabled)
[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
24 confdir=`pwd`
25 architectures="i386 x86_64"
26 for vdist in centos/5.5 rhel/5.5; do
27         dist=`basename $vdist`
28         vendor=`dirname $vdist`
29         ftpdir=/home/ftp/pub/yum/$vendor/$dist
30         if test ! -d $ftpdir; then
31                 echo "$ftpdir does not exist"
32                 exit 1
33         fi
34         cd $ftpdir      
35         sections=""
36         for section in main restricted; do
37                 # Prepare pool
38                 d=$section
39                 if test ! -d $d; then mkdir -p $d; fi
40                 if test ! -d $d/SRPMS; then mkdir -p $d/SRPMS; fi
41                 # Remove invalid symlinks (SRPMS, i386, x86_64,..)
42                 for l in $d/SRPMS/*; do
43                         if test -L "$l"; then
44                                 if test ! -f "$l"; then
45                                         rm $l
46                                 fi
47                         fi
48                 done
49                 for arch in $architectures; do
50                         for l in $d/$arch/Packages/*; do
51                                 if test -L "$l"; then
52                                         if test ! -f "$l"; then
53                                                 rm $l
54                                         fi
55                                 fi
56                         done
57                 done
58                 # Make symlinks from the regular FTP archive
59                 has_packages=false
60                 for pdir in /home/ftp/pub/*; do
61                         use=false
62                         if test -f $pdir/.htaccess -a $section != "main"; then
63                                 use=true
64                         fi
65                         if test ! -f $pdir/.htaccess -a $section = "main"; then
66                                 use=true
67                         fi
68                         if $use; then
69                                 distdir=$pdir/redhat/$vendor/$dist
70                                 if test -d $distdir; then
71                                         if test -d $distdir/SRPMS; then
72                                                 for f in $distdir/SRPMS/*.src.rpm; do
73                                                         if test -f $f; then                                                             
74                                                                 ln -sf $f $d/SRPMS/
75                                                         fi
76                                                 done
77                                         fi
78                                         for arch in $architectures; do
79                                                 mkdir -p $d/${arch}/Packages
80                                                 for f in $distdir/RPMS/${arch}/*.rpm $distdir/RPMS/noarch/*.rpm; do
81                                                     if test -f $f; then
82                   #rpm --addsign $f
83                                                             ln -sf $f $d/${arch}/Packages/
84                                                         has_packages=true
85                                                     fi
86                                                 done
87             createrepo --update $d/${arch}
88             if test -f $d/${arch}/repodata/repomd.xml.asc; then
89               rm $d/${arch}/repodata/repomd.xml.asc
90             fi
91             gpg --detach-sign -u "Index Data" --armor $d/${arch}/repodata/repomd.xml
92                                         done
93                                 fi
94                         fi
95                 done
96         done
97 done
98 # Local Variables:
99 # mode:shell-script
100 # sh-indentation: 2
101 # sh-basic-offset: 8
102 # End:
103