DRY
[git-tools-moved-to-github.git] / update-archive / update-archive.sh
1 #!/bin/sh
2 if test ! -f apt-ftparchive.conf.in; then
3         echo "$0: apt-ftparchive.conf.in must be located in current directory"
4         exit 1
5 fi
6
7 if test ! -x /usr/bin/apt-ftparchive; then
8         echo "$0: /usr/bin/apt-ftparchive missing. Install apt-utils"
9         exit 1
10 fi
11
12 # gpg -a -d -o Release.gpg Release
13
14 confdir=`pwd`
15
16 architectures="i386 amd64"
17
18 if [ "$1" == "" ]; then 
19         DISTRIBUTIONS="ubuntu/lucid ubuntu/natty ubuntu/oneiric ubuntu/precise ubuntu/quantal debian/wheezy debian/squeeze debian/lenny"
20 else
21         DISTRIBUTIONS=$1
22 fi
23
24 for vdist in $DISTRIBUTIONS ; do
25         dist=`basename $vdist`
26         vendor=`dirname $vdist`
27         ftpdir=/home/ftp/pub/$vendor
28         if test ! -d $ftpdir; then
29                 echo "$ftpdir does not exist"
30                 exit 1
31         fi
32         cd $ftpdir
33         test -d tmp || mkdir tmp
34         # Uncomment to clean the .db (cache)
35         # rm tmp/*
36
37         sections=""
38         for section in main restricted; do
39                 # Prepare pool
40                 d=pool/dists/$dist/$section
41                 if test ! -d $d; then mkdir -p $d; fi
42                 mkdir -p $d/source
43                 # Remove invalid symlinks (source, i386, amd64,..)
44                 for l in $d/*/*; do
45                         if test -L "$l"; then
46                                 if test ! -f "$l"; then
47                                         rm $l
48                                 fi
49                         fi
50                 done
51                 # Make symlinks from the regular FTP archive
52                 has_packages=false
53                 for pdir in /home/ftp/pub/*; do
54                         use=false
55                         if test -f $pdir/.htaccess -a $section != "main"; then
56                                 use=true
57                         fi
58                         if test ! -f $pdir/.htaccess -a $section = "main"; then
59                                 use=true
60                         fi
61                         if $use; then
62                                 distdir=$pdir/$vendor/$dist
63                                 if test -d $distdir; then
64                                         for f in $distdir/*.dsc $distdir/*.gz; do
65                                                 test -f $f && ln -sf $f $d/source
66                                         done
67                                         for arch in $architectures; do
68                                                 mkdir -p $d/${arch}
69                                                 for f in $pdir/.htaccess \
70                                                         $distdir/*_${arch}.* \
71                                                         $distdir/*_all.*; do
72                                                     if test -f $f; then
73                                                             ln -sf $f $d/${arch}
74                                                             has_packages=true
75                                                     fi
76                                                 done
77                                         done
78                                 fi
79                         fi
80                 done
81                 # ${confdir}/symclean.sh $d
82
83                 rm -f $d/Release
84                 if $has_packages; then
85                         if test -z "$sections"; then
86                                 sections="$section"
87                         else
88                                 sections="$sections $section"
89                         fi
90                         for arch in $architectures; do
91                                 d=dists/$dist/$section/binary-$arch
92                                 if test ! -d $d; then mkdir -p $d; fi
93                                 echo "Archive: $dist" >$d/Release
94                                 echo "Component: $section" >>$d/Release
95                                 echo 'Origin: Indexdata' >>$d/Release
96                                 echo "Architecture: $arch" >>$d/Release
97                         done
98                         d=dists/$dist/$section/source
99                         if test ! -d $d; then mkdir -p $d; fi
100                         echo "Archive: $dist" >$d/Release
101                         echo "Component: $section" >>$d/Release
102                         echo 'Origin: Indexdata' >>$d/Release
103                         echo 'Architecture: source' >>$d/Release
104                 fi
105         done
106         # generate
107         echo "Begin Generate $dist: $sections"
108         F=apt-ftparchive.conf
109         sed "s/@dist@/$dist/g" <${confdir}/${F}.in | \
110                 sed "s/@architectures@/${architectures}/g" | \
111                 sed "s/@sections@/${sections}/g" > $F
112         # Don't know if clean is needed!
113         # apt-ftparchive clean apt-ftparchive.conf
114         apt-ftparchive generate apt-ftparchive.conf
115         echo "Done generate $dist: $sections"
116
117         # release
118         r=dists/$dist/Release
119         F=apt-release.conf
120         sed "s/@dist@/$dist/g" <${confdir}/${F}.in | \
121                 sed "s/@architectures@/${architectures}/g" | \
122                 sed "s/@sections@/${sections}/g" > $F
123         # Move Release file away while calling using release 
124         rm $r
125         apt-ftparchive -c $F release dists/$dist >tmp_Release
126         mv tmp_Release $r
127
128         # sign
129         if true; then
130                 r=dists/$dist/Release
131                 rm -f ${r}.gpg
132                 gpg --sign -u "Index Data" -ba -o ${r}.gpg dists/$dist/Release
133         fi
134 done
135 # Local Variables:
136 # mode:shell-script
137 # sh-indentation: 2
138 # sh-basic-offset: 8
139 # End:
140