]> git.decadent.org.uk Git - dak.git/blob - scripts/debian/update-buildd-archive
a11b009af0eca76723b027da9fc020edc7bd9cca
[dak.git] / scripts / debian / update-buildd-archive
1 #! /bin/bash
2 #
3 # Copyright 2012, Ansgar Burchardt <ansgar@debian.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 set -e
20 set -u
21
22 usage() {
23   echo "usage: $0 <source> <target>"
24   echo
25   echo "Update a minimalistic mirror for buildd archives."
26   exit ${1:-0}
27 }
28
29 if [ $# -ne 2 ]; then
30   usage 1
31 fi
32
33 source="${1}"
34 dest="${2}"
35
36 if [ ! -d "${source}/dists" -o ! -d "${source}/pool" ]; then
37   echo "${source}: does not look like a Debian archive" >&2
38   exit 1
39 fi
40
41 if [ ! -d "${dest}" ]; then
42   echo "${dest}: destination does not exist or is not a directory" >&2
43   exit 1
44 fi
45
46 # Make sure ${dest}/dists exists to avoid a special case later
47 if [ ! -d "${dest}/dists" ]; then
48   mkdir "${dest}/dists"
49 fi
50 for olddir in dists.new dists.old; do
51   if [ -e "${dest}/${olddir}" ]; then
52     echo "Removing old ${olddir}..."
53     rm -r "${dest}/${olddir}"
54   fi
55 done
56
57 # Make sure ${dest}/pool exists
58 if [ ! -e "${dest}/pool" ]; then
59   # Files are only removed from the build queues once they are no longer
60   # referenced. Having a symlink should thus not cause problems.
61   ln -s "${source}/pool" "${dest}/pool"
62 fi
63
64 # Finally copy dists/ to dists.new/, rename it and remove old version
65 cp -a "${source}/dists" "${dest}/dists.new"
66 mv "${dest}/dists" "${dest}/dists.old"
67 mv "${dest}/dists.new" "${dest}/dists"
68 rm -r "${dest}/dists.old"