byhand-di 3.1 KB

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