Add Ubuntu Xenial to update-archive.sh
[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 ! -x /usr/bin/apt-ftparchive; then
60         echo "$0: /usr/bin/apt-ftparchive missing. Install apt-utils"
61         exit 1
62 fi
63
64 # gpg -a -d -o Release.gpg Release
65
66 architectures="i386 amd64"
67
68 if test "$DEBIAN_DIST"; then
69         for d in $DEBIAN_DIST; do
70                 DISTRIBUTIONS="$DISTRIBUTIONS debian/$d"
71         done
72 fi
73 if test "$UBUNTU_DIST"; then
74         for d in $UBUNTU_DIST; do
75                 DISTRIBUTIONS="$DISTRIBUTIONS ubuntu/$d"
76         done
77 fi
78
79 # All distributions we know of
80 ALLD="ubuntu/lucid ubuntu/natty ubuntu/oneiric ubuntu/precise ubuntu/quantal ubuntu/raring ubuntu/saucy ubuntu/trusty ubuntu/utopic ubuntu/vivid ubuntu/wily ubuntu/xenial debian/jessie debian/wheezy debian/squeeze debian/lenny"
81
82 if test -z "$DISTRIBUTIONS"; then
83         DISTRIBUTIONS=$ALLD
84 else
85         for d in $DISTRIBUTIONS; do
86                 bad=true
87                 for y in $ALLD; do
88                         if test "$d" = "$y"; then
89                                 bad=false
90                         fi
91                 done
92                 if $bad; then
93                         echo "No such distro $d"
94                         exit 1
95                 fi
96         done
97 fi
98
99 echo "DISTRIBUTIONS=$DISTRIBUTIONS"
100 for vdist in $DISTRIBUTIONS ; do
101         dist=`basename $vdist`
102         fdist=${dist}
103         if test -n "${suffix}"; then
104                 fdist="${fdist}-${suffix}"
105         fi
106         vendor=`dirname $vdist`
107         ftpdir=/home/ftp/pub/$vendor
108         if test ! -d $ftpdir; then
109                 echo "$ftpdir does not exist"
110                 exit 1
111         fi
112         cd $ftpdir
113         mkdir -p tmp
114         # Uncomment to clean the .db (cache)
115         if $clear; then
116                 rm tmp/*
117         fi
118
119         sections=""
120         for section in main restricted; do
121                 # Prepare pool
122                 d=pool/dists/$fdist/$section
123                 mkdir -p $d
124                 mkdir -p $d/source
125                 # Remove invalid symlinks (source, i386, amd64,..)
126                 for l in $d/*/*; do
127                         if test -L "$l"; then
128                                 if test ! -f "$l"; then
129                                         rm $l
130                                 fi
131                         fi
132                 done
133                 # Make symlinks from the regular FTP archive
134                 has_packages=false
135                 for pdir in /home/ftp/pub/*; do
136                         use=false
137                         if test -f $pdir/.htaccess -a $section != "main"; then
138                                 use=true
139                         fi
140                         if test ! -f $pdir/.htaccess -a $section = "main"; then
141                                 use=true
142                         fi
143                         if $use; then
144                                 distdir=$pdir/$vendor/$dist
145                                 if test -d $distdir; then
146                                         for f in $distdir/*.dsc $distdir/*.gz; do
147                                                 test -f $f && ln -sf $f $d/source
148                                         done
149                                         for arch in $architectures; do
150                                                 mkdir -p $d/${arch}
151                                                 for f in $pdir/.htaccess \
152                                                         $distdir/*_${arch}.* \
153                                                         $distdir/*_all.*; do
154                                                     if test -f $f; then
155                                                             ln -sf $f $d/${arch}
156                                                             has_packages=true
157                                                     fi
158                                                 done
159                                         done
160                                 fi
161                         fi
162                 done
163
164                 rm -f $d/Release
165                 if $has_packages; then
166                         if test -z "$sections"; then
167                                 sections="$section"
168                         else
169                                 sections="$sections $section"
170                         fi
171                         for arch in $architectures; do
172                                 d=dists/$fdist/$section/binary-$arch
173                                 mkdir -p $d
174                                 echo "Archive: $fdist" >$d/Release
175                                 echo "Component: $section" >>$d/Release
176                                 echo 'Origin: Index Data' >>$d/Release
177                                 echo "Architecture: $arch" >>$d/Release
178                         done
179                         d=dists/$fdist/$section/source
180                         mkdir -p $d
181                         echo "Archive: $fdist" >$d/Release
182                         echo "Component: $section" >>$d/Release
183                         echo 'Origin: Index Data' >>$d/Release
184                         echo 'Architecture: source' >>$d/Release
185                 fi
186         done
187         if test -n "$sections"; then
188                 F=apt-ftparchive.conf
189                 sed "s/@dist@/$fdist/g" <${confdir}/${F}.in | \
190                         sed "s/@architectures@/${architectures}/g" | \
191                         sed "s/@sections@/${sections}/g" > $F
192                 apt-ftparchive generate apt-ftparchive.conf 2>&1
193                 r=dists/$fdist/Release
194                 rm -f $r # Move Release file away while calling using release
195                 apt-ftparchive -c $F release dists/$fdist >tmp_Release
196                 if $noauto; then
197                         sed -e 's/^Suite:/NotAutomatic: yes\nButAutomaticUpgrades: yes\nSuite:/g' <tmp_Release >$r
198                 else
199                         mv tmp_Release $r
200                 fi
201                 rm -f ${r}.gpg
202                 gpg --sign -u "Index Data" -ba -o ${r}.gpg $r
203         fi
204 done
205 # Local Variables:
206 # mode:shell-script
207 # sh-indentation: 8
208 # sh-basic-offset: 8
209 # End:
210