byhand-di 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. set -u
  3. set -e
  4. set -o pipefail
  5. if [ $# -lt 5 ]; then
  6. echo "Usage: $0 filename version arch changes_file suite"
  7. exit 1
  8. fi
  9. TARBALL="$1" # Tarball to read, compressed with gzip
  10. VERSION="$2"
  11. ARCH="$3"
  12. CHANGES="$4" # Changes file for the upload
  13. SUITE="$5"
  14. error() {
  15. echo "$*"
  16. exit 1
  17. }
  18. # Check validity of version number
  19. # Expected are: YYYYMMDD, YYYYMMDD.x, YYYYMMDD<suite>x, YYYYMMDD+<suite>x,
  20. # YYYYMMDD+debXuZ and the +b[0-9] on the end
  21. if ! echo "$VERSION" | grep -Eq "^[0-9]{8}((\.|\+?[a-z]+|\+deb[0-9]+u|\+kbsd[0-9]+u)[0-9]+)?(\+b[0-9])?$"; then
  22. error "Invalid version: '$VERSION'"
  23. fi
  24. case $SUITE in
  25. unstable|sid|*proposed-updates)
  26. : # nothing to do
  27. ;;
  28. *)
  29. SUITE="${SUITE}-proposed-updates"
  30. ;;
  31. esac
  32. # This must end with /
  33. TARGET="/srv/ftp-master.debian.org/ftp/dists/$SUITE/main/installer-$ARCH/"
  34. # Check validity of the target directory
  35. # This could fail, for example for new architectures; doing
  36. # a regular BYHAND is safer in that case
  37. if [ ! -d "$TARGET" ]; then
  38. mkdir -p "$TARGET"
  39. fi
  40. # Check that there isn't already a directory for this version
  41. if [ -d "$TARGET/$VERSION" ]; then
  42. error "Directory already exists: $TARGET/$VERSION"
  43. fi
  44. # We know the VERSION is sane by here, we just need to make sure we escape the + in +b1 (if any)
  45. # It needs 'g' as well as we may have +$DIST+b[0-9] or +debXuZ+bY
  46. VERSIONREGEXP="$(echo $VERSION | sed 's@+@\\\+@g')"
  47. # We know all data to be in ./installer-<arch>/<version>; see if there's
  48. # anything else in the tarball except that and the 'current' symlink
  49. if tar tzf "$TARBALL" | \
  50. grep -Eqv "^\./(installer-$ARCH/($VERSIONREGEXP/.*|current|)|)$"; then
  51. error "Tarball contains unexpected contents"
  52. fi
  53. # Create a temporary directory where to store the images
  54. umask 002
  55. TMPDIR="$(mktemp -td byhand-di.XXXXXX)"
  56. # If we fail somewhere, cleanup the temporary directory
  57. cleanup() {
  58. rm -rf "$TMPDIR"
  59. }
  60. trap cleanup EXIT
  61. # Extract the data into the temporary directory
  62. tar xzf "$TARBALL" --directory="$TMPDIR" "./installer-$ARCH/"
  63. # Check the 'current' symlink
  64. if [ ! -L $TMPDIR/installer-$ARCH/current ]; then
  65. error "Missing 'current' symlink"
  66. elif [ X"$(readlink "$TMPDIR/installer-$ARCH/current")" != X"$VERSION" ]; then
  67. error "Incorrect 'current' symlink"
  68. fi
  69. # We should have an MD5SUMS file; use that for a final check
  70. if [ -r "$TMPDIR/installer-$ARCH/$VERSION/images/MD5SUMS" ]; then
  71. (
  72. cd "$TMPDIR/installer-$ARCH/$VERSION/images"
  73. md5sum -c --status MD5SUMS || error "Error while checking MD5SUMS"
  74. )
  75. else
  76. error "Missing MD5SUMS file"
  77. fi
  78. # Move the data to the final location
  79. mv "$TMPDIR/installer-$ARCH/$VERSION" "$TARGET"
  80. mv "$TMPDIR/installer-$ARCH/current" "$TARGET"
  81. # Fixup permissions
  82. find "$TARGET/$VERSION" -type d -exec chmod 755 {} +
  83. find "$TARGET/$VERSION" -type f -exec chmod 644 {} +
  84. # Make sure nothing symlinks outside of the ftpdir
  85. # Shouldnt happen, but better be sure.
  86. symlinks -d -r /srv/ftp-master.debian.org/ftp
  87. trap - EXIT
  88. cleanup
  89. exit 0