byhand-tag 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/bash
  2. set -u
  3. set -e
  4. set -o pipefail
  5. export SCRIPTVARS=/srv/ftp-master.debian.org/dak/config/debian/vars
  6. . $SCRIPTVARS
  7. # Tarball to read, compressed with gzip
  8. INPUT="${1:?"Usage: $0 filename"}"
  9. # Regular expression used to validate tag lines
  10. CHECKRE='^([a-z0-9A-Z.+-]+[[:space:]]+Tag)?[[:space:]]+[A-Za-z0-9:. ,{}+-]+$'
  11. # This must end with /
  12. TARGET=/srv/ftp-master.debian.org/scripts/external-overrides/
  13. # Read the main directory from the tarball
  14. DIR="`tar ztf \"$INPUT\" | tail -n 1 | cut -d/ -f1`"
  15. # Create temporary files where to store the validated data
  16. umask 002
  17. OUTMAIN="`mktemp \"$TARGET\"tag.new.XXXXXX`"
  18. OUTCONTRIB="`mktemp \"$TARGET\"tag.contrib.new.XXXXXX`"
  19. OUTNONFREE="`mktemp \"$TARGET\"tag.non-free.new.XXXXXX`"
  20. # If we fail somewhere, cleanup the temporary files
  21. cleanup() {
  22. rm -f "$OUTMAIN"
  23. rm -f "$OUTCONTRIB"
  24. rm -f "$OUTNONFREE"
  25. }
  26. trap cleanup EXIT
  27. # Extract the data into the temporary files
  28. tar -O -zxf "$INPUT" "$DIR"/tag > "$OUTMAIN"
  29. tar -O -zxf "$INPUT" "$DIR"/tag.contrib > "$OUTCONTRIB"
  30. tar -O -zxf "$INPUT" "$DIR"/tag.non-free > "$OUTNONFREE"
  31. # check temporary files for invalid contents
  32. status=0
  33. grep -vq -E "$CHECKRE" "$OUTMAIN" "$OUTCONTRIB" "$OUTNONFREE" || status=$?
  34. # checking just $? != 0 is not enough. grep can return 2 on other errors.
  35. if [ $status != 1 ]; then
  36. echo "Aborting automatic import (invalid data found)." >&2
  37. exit 1
  38. fi
  39. # Move the data to the final location
  40. mv "$OUTMAIN" "$TARGET"tag
  41. mv "$OUTCONTRIB" "$TARGET"tag.contrib
  42. mv "$OUTNONFREE" "$TARGET"tag.non-free
  43. chmod 644 "$TARGET"tag "$TARGET"tag.contrib "$TARGET"tag.non-free
  44. (cd "$TARGET" \
  45. && dak external-overrides import unstable main Tag <tag \
  46. && dak external-overrides import unstable contrib Tag <tag.contrib \
  47. && dak external-overrides import unstable non-free Tag <tag.non-free)
  48. dak external-overrides copy unstable testing
  49. trap - EXIT
  50. exit 0