740fefb0326e8c02d9bada2d8b796af314f8551b
[git-tools-moved-to-github.git] / update-archive / update-archive.sh
1 #!/bin/sh
2 D0=`dirname $0`
3 confdir=`cd $D0; pwd`
4
5 usage()
6 {
7     cat <<EOF
8 Usage: update-archive.sh [OPTIONS]
9 Options:
10         [--debian=distros]
11         [--ubuntu=distros]
12         [--suffix=dist-suffix]
13         [--noauto]
14         [--clear]
15 EOF
16     exit $1
17 }
18
19 do_help=false
20 clear=false
21 noauto=false
22 suffix=""
23 while test $# -gt 0; do
24     case "$1" in
25         -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
26         *) optarg= ;;
27     esac
28     case $1 in
29         --clear)
30             clear=true
31             ;;
32         --debian=*)
33             DEBIAN_DIST=$optarg
34             ;;
35         --ubuntu=*)
36             UBUNTU_DIST=$optarg
37             ;;
38         --suffix=*)
39             suffix="$optarg"
40             ;;
41         --noauto)
42             noauto=true
43             ;;
44         -*)
45             do_help=true
46             ;;
47     esac
48     shift
49 done
50
51 if $do_help; then
52         usage 1>&1
53 fi
54
55 if test ! -f ${confdir}/apt-ftparchive.conf.in; then
56         echo "$0: ${condir}/apt-ftparchive.conf.in not found"
57         exit 1
58 fi
59 if test ! -f ${confdir}/apt-release.conf.in; then
60         echo "$0: ${condir}/apt-release.conf.in not found"
61         exit 1
62 fi
63
64 if test ! -x /usr/bin/apt-ftparchive; then
65         echo "$0: /usr/bin/apt-ftparchive missing. Install apt-utils"
66         exit 1
67 fi
68
69 # gpg -a -d -o Release.gpg Release
70         
71 architectures="i386 amd64"
72
73 if test "$DEBIAN_DIST"; then
74         for d in $DEBIAN_DIST; do
75                 DISTRIBUTIONS="$DISTRIBUTIONS debian/$d"
76         done
77 fi
78 if test "$UBUNTU_DIST"; then
79         for d in $UBUNTU_DIST; do
80                 DISTRIBUTIONS="$DISTRIBUTIONS ubuntu/$d"
81         done
82 fi
83
84 # All distributions we know of
85 ALLD="ubuntu/lucid ubuntu/natty ubuntu/oneiric ubuntu/precise ubuntu/quantal ubuntu/raring ubuntu/saucy ubuntu/trusty ubuntu/utopic debian/jessie debian/wheezy debian/squeeze debian/lenny"
86
87 if test -z "$DISTRIBUTIONS"; then
88         DISTRIBUTIONS=$ALLD
89 else
90         for d in $DISTRIBUTIONS; do
91                 bad=true
92                 for y in $ALLD; do
93                         if test "$d" = "$y"; then
94                                 bad=false
95                         fi
96                 done
97                 if $bad; then
98                         echo "No such distro $d"
99                         exit 1
100                 fi
101         done
102 fi
103
104 echo "DISTRIBUTIONS=$DISTRIBUTIONS"
105 for vdist in $DISTRIBUTIONS ; do
106         dist=`basename $vdist`
107         fdist=${dist}
108         if test -n "${suffix}"; then
109                 fdist="${fdist}-${suffix}"
110         fi
111         vendor=`dirname $vdist`
112         ftpdir=/home/ftp/pub/$vendor
113         if test ! -d $ftpdir; then
114                 echo "$ftpdir does not exist"
115                 exit 1
116         fi
117         cd $ftpdir
118         test -d tmp || mkdir tmp
119         # Uncomment to clean the .db (cache)
120         if $clear; then
121                 rm tmp/*
122         fi
123
124         sections=""
125         for section in main restricted; do
126                 # Prepare pool
127                 d=pool/dists/$fdist/$section
128                 if test ! -d $d; then mkdir -p $d; fi
129                 mkdir -p $d/source
130                 # Remove invalid symlinks (source, i386, amd64,..)
131                 for l in $d/*/*; do
132                         if test -L "$l"; then
133                                 if test ! -f "$l"; then
134                                         rm $l
135                                 fi
136                         fi
137                 done
138                 # Make symlinks from the regular FTP archive
139                 has_packages=false
140                 for pdir in /home/ftp/pub/*; do
141                         use=false
142                         if test -f $pdir/.htaccess -a $section != "main"; then
143                                 use=true
144                         fi
145                         if test ! -f $pdir/.htaccess -a $section = "main"; then
146                                 use=true
147                         fi
148                         if $use; then
149                                 distdir=$pdir/$vendor/$dist
150                                 if test -d $distdir; then
151                                         for f in $distdir/*.dsc $distdir/*.gz; do
152                                                 test -f $f && ln -sf $f $d/source
153                                         done
154                                         for arch in $architectures; do
155                                                 mkdir -p $d/${arch}
156                                                 for f in $pdir/.htaccess \
157                                                         $distdir/*_${arch}.* \
158                                                         $distdir/*_all.*; do
159                                                     if test -f $f; then
160                                                             ln -sf $f $d/${arch}
161                                                             has_packages=true
162                                                     fi
163                                                 done
164                                         done
165                                 fi
166                         fi
167                 done
168
169                 rm -f $d/Release
170                 if $has_packages; then
171                         if test -z "$sections"; then
172                                 sections="$section"
173                         else
174                                 sections="$sections $section"
175                         fi
176                         for arch in $architectures; do
177                                 d=dists/$fdist/$section/binary-$arch
178                                 if test ! -d $d; then mkdir -p $d; fi
179                                 echo "Archive: $fdist" >$d/Release
180                                 echo "Component: $section" >>$d/Release
181                                 echo 'Origin: Indexdata' >>$d/Release
182                                 echo "Architecture: $arch" >>$d/Release
183                         done
184                         d=dists/$fdist/$section/source
185                         if test ! -d $d; then mkdir -p $d; fi
186                         echo "Archive: $fdist" >$d/Release
187                         echo "Component: $section" >>$d/Release
188                         echo 'Origin: Indexdata' >>$d/Release
189                         echo 'Architecture: source' >>$d/Release
190                 fi
191         done
192         # generate
193         echo "Begin Generate $fdist: $sections"
194         F=apt-ftparchive.conf
195         sed "s/@dist@/$fdist/g" <${confdir}/${F}.in | \
196                 sed "s/@architectures@/${architectures}/g" | \
197                 sed "s/@sections@/${sections}/g" > $F
198         # Don't know if clean is needed!
199         # apt-ftparchive clean apt-ftparchive.conf
200         apt-ftparchive generate apt-ftparchive.conf 2>&1
201         echo "Done generate $fdist: $sections"
202
203         # release
204         r=dists/$fdist/Release
205         F=apt-release.conf
206         sed "s/@dist@/$fdist/g" <${confdir}/${F}.in | \
207                 sed "s/@architectures@/${architectures}/g" | \
208                 sed "s/@sections@/${sections}/g" > $F
209         # Move Release file away while calling using release 
210         rm -f $r
211         apt-ftparchive -c $F release dists/$fdist >tmp_Release
212         if $noauto; then
213                 sed -e 's/^Suite:/NotAutomatic: yes\nButAutomaticUpgrades: yes\nSuite:/g' <tmp_Release >$r
214         else
215                 mv tmp_Release $r
216         fi
217
218         # sign
219         if true; then
220                 rm -f ${r}.gpg
221                 gpg --sign -u "Index Data" -ba -o ${r}.gpg $r
222         fi
223 done
224 # Local Variables:
225 # mode:shell-script
226 # sh-indentation: 2
227 # sh-basic-offset: 8
228 # End:
229