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