Fix spelling of clear option
[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 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                 # ${confdir}/symclean.sh $d
155
156                 rm -f $d/Release
157                 if $has_packages; then
158                         if test -z "$sections"; then
159                                 sections="$section"
160                         else
161                                 sections="$sections $section"
162                         fi
163                         for arch in $architectures; do
164                                 d=dists/$dist/$section/binary-$arch
165                                 if test ! -d $d; then mkdir -p $d; fi
166                                 echo "Archive: $dist" >$d/Release
167                                 echo "Component: $section" >>$d/Release
168                                 echo 'Origin: Indexdata' >>$d/Release
169                                 echo "Architecture: $arch" >>$d/Release
170                         done
171                         d=dists/$dist/$section/source
172                         if test ! -d $d; then mkdir -p $d; fi
173                         echo "Archive: $dist" >$d/Release
174                         echo "Component: $section" >>$d/Release
175                         echo 'Origin: Indexdata' >>$d/Release
176                         echo 'Architecture: source' >>$d/Release
177                 fi
178         done
179         # generate
180         echo "Begin Generate $dist: $sections"
181         F=apt-ftparchive.conf
182         sed "s/@dist@/$dist/g" <${confdir}/${F}.in | \
183                 sed "s/@architectures@/${architectures}/g" | \
184                 sed "s/@sections@/${sections}/g" > $F
185         # Don't know if clean is needed!
186         # apt-ftparchive clean apt-ftparchive.conf
187         apt-ftparchive generate apt-ftparchive.conf 2>&1
188         echo "Done generate $dist: $sections"
189
190         # release
191         r=dists/$dist/Release
192         F=apt-release.conf
193         sed "s/@dist@/$dist/g" <${confdir}/${F}.in | \
194                 sed "s/@architectures@/${architectures}/g" | \
195                 sed "s/@sections@/${sections}/g" > $F
196         # Move Release file away while calling using release 
197         rm $r
198         apt-ftparchive -c $F release dists/$dist >tmp_Release
199         mv tmp_Release $r
200
201         # sign
202         if true; then
203                 r=dists/$dist/Release
204                 rm -f ${r}.gpg
205                 gpg --sign -u "Index Data" -ba -o ${r}.gpg dists/$dist/Release
206         fi
207 done
208 # Local Variables:
209 # mode:shell-script
210 # sh-indentation: 2
211 # sh-basic-offset: 8
212 # End:
213