update-buildd-archive 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. set -e
  19. set -u
  20. usage() {
  21. echo "usage: $0 <source> <target>"
  22. echo
  23. echo "Update a minimalistic mirror for buildd archives."
  24. exit ${1:-0}
  25. }
  26. if [ $# -ne 2 ]; then
  27. usage 1
  28. fi
  29. source="${1}"
  30. dest="${2}"
  31. if [ ! -d "${source}/dists" -o ! -d "${source}/pool" ]; then
  32. echo "${source}: does not look like a Debian archive" >&2
  33. exit 1
  34. fi
  35. if [ ! -d "${dest}" ]; then
  36. echo "${dest}: destination does not exist or is not a directory" >&2
  37. exit 1
  38. fi
  39. # Make sure ${dest}/pool exists
  40. if [ ! -e "${dest}/pool" ]; then
  41. # Files are only removed from the build queues once they are no longer
  42. # referenced. Having a symlink should thus not cause problems.
  43. ln -s "${source}/pool" "${dest}/pool"
  44. fi
  45. for subdir in dists zzz-dists project/external-signatures; do
  46. if [ ! -d "${source}/${subdir}" ]; then
  47. continue
  48. fi
  49. # Make sure ${dest}/${subdir} exists to avoid a special case later
  50. if [ ! -d "${dest}/${subdir}" ]; then
  51. mkdir -p "${dest}/${subdir}"
  52. fi
  53. for olddir in ${subdir}.new ${subdir}.old; do
  54. if [ -e "${dest}/${olddir}" ]; then
  55. echo "Removing old ${olddir}..."
  56. rm -r "${dest}/${olddir}"
  57. fi
  58. done
  59. # Finally copy ${subdir}/ to ${subdir}.new/, rename it and remove old version
  60. cp -a "${source}/${subdir}" "${dest}/${subdir}.new"
  61. mv "${dest}/${subdir}" "${dest}/${subdir}.old"
  62. mv "${dest}/${subdir}.new" "${dest}/${subdir}"
  63. rm -r "${dest}/${subdir}.old"
  64. done