]> git.decadent.org.uk Git - dak.git/blob - scripts/debian/update-buildd-archive
update-buildd-archive: Also copy zzz-dists
[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}/pool exists
47 if [ ! -e "${dest}/pool" ]; then
48   # Files are only removed from the build queues once they are no longer
49   # referenced. Having a symlink should thus not cause problems.
50   ln -s "${source}/pool" "${dest}/pool"
51 fi
52
53 for subdir in dists zzz-dists; do
54   if [ ! -d "${source}/${subdir}" ]; then
55     continue
56   fi
57
58   # Make sure ${dest}/${subdir} exists to avoid a special case later
59   if [ ! -d "${dest}/${subdir}" ]; then
60     mkdir "${dest}/${subdir}"
61   fi
62   for olddir in ${subdir}.new ${subdir}.old; do
63     if [ -e "${dest}/${olddir}" ]; then
64       echo "Removing old ${olddir}..."
65       rm -r "${dest}/${olddir}"
66     fi
67   done
68
69   # Finally copy ${subdir}/ to ${subdir}.new/, rename it and remove old version
70   cp -a "${source}/${subdir}" "${dest}/${subdir}.new"
71   mv "${dest}/${subdir}" "${dest}/${subdir}.old"
72   mv "${dest}/${subdir}.new" "${dest}/${subdir}"
73   rm -r "${dest}/${subdir}.old"
74 done