You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.2 KiB

  1. #!/bin/bash
  2. set -e
  3. THIS_SCRIPT=`basename "$0"`
  4. function usage
  5. {
  6. echo "$THIS_SCRIPT <BZR_URL> <SRC_DIR> [<GPG_KEY>]"
  7. }
  8. function gpg_sign
  9. {
  10. FILE="$1"
  11. rm -f "$FILE".sig
  12. $GPG --batch --use-agent --detach-sign --local-user "$GPG_KEY" \
  13. "$FILE"
  14. }
  15. function maybe_gpg_sign
  16. {
  17. [[ -e "$1" ]] && gpg_sign "$1"
  18. }
  19. function command_exists
  20. {
  21. type "$1" &>/dev/null
  22. }
  23. function find_archiver
  24. {
  25. command_exists "$1" && echo "$1" || echo ':'
  26. }
  27. BZR_URL="$1"
  28. if [[ -z "$BZR_URL" ]] ; then
  29. usage
  30. exit 1
  31. fi
  32. if [[ -z "$2" ]] ; then
  33. BZR_URL=${BZR_URL%/}
  34. BZR_BASE_URL=${BZR_URL%/*}
  35. BZR_BRANCH_NAME=${BZR_URL#$BZR_BASE_URL}
  36. BZR_BRANCH_NAME=${BZR_BRANCH_NAME#/}
  37. SRC_DIR=$BZR_BRANCH_NAME
  38. else
  39. SRC_DIR="$2"
  40. fi
  41. if [[ ! -z "$3" ]] ; then
  42. GPG_KEY="$3"
  43. else
  44. GPG_KEY=
  45. fi
  46. DEST_DIR="$PWD"
  47. TMPDIR=${TMPDIR:-${TMP:-${TEMP}}}
  48. if [[ -z "${TMPDIR}" ]] ; then
  49. unset TMPDIR
  50. else
  51. export TMPDIR
  52. fi
  53. TMP_DIR=`mktemp -d -t log4cplus.XXXXXXX`
  54. pushd "$TMP_DIR"
  55. TAR=${TAR:-$(find_archiver tar)}
  56. XZ=${XZ:-$(find_archiver xz)}
  57. BZIP2=${BZIP2:-$(find_archiver bzip2)}
  58. GZIP=${GZIP:-$(find_archiver gzip)}
  59. SEVENZA=${SEVENZA:-$(find_archiver 7za)}
  60. LRZIP=${LRZIP:-$(find_archiver lrzip)}
  61. BZR=${BZR:-bzr}
  62. GPG=${GPG:-gpg}
  63. $BZR export --per-file-timestamps -v "$SRC_DIR" "$BZR_URL"
  64. $BZR version-info "$BZR_URL" >"$SRC_DIR/REVISION"
  65. pushd "$SRC_DIR"
  66. $SHELL ./scripts/fix-timestamps.sh
  67. popd
  68. $SEVENZA a -t7z "$DEST_DIR/$SRC_DIR".7z "$SRC_DIR" >/dev/null \
  69. & $SEVENZA a -tzip "$DEST_DIR/$SRC_DIR".zip "$SRC_DIR" >/dev/null
  70. TAR_FILE="$SRC_DIR".tar
  71. $TAR -cf "$TAR_FILE" "$SRC_DIR"
  72. $XZ -e -c "$TAR_FILE" >"$DEST_DIR/$TAR_FILE".xz \
  73. & $BZIP2 -9 -c "$TAR_FILE" >"$DEST_DIR/$TAR_FILE".bz2 \
  74. & $GZIP -9 -c "$TAR_FILE" >"$DEST_DIR/$TAR_FILE".gz \
  75. & $LRZIP -q -o - "$TAR_FILE" |([[ "$LRZIP" = ":" ]] && cat >/dev/null || cat >"$DEST_DIR/$TAR_FILE".lrz)
  76. echo waiting for tarballs...
  77. wait
  78. echo done waiting
  79. if [[ ! -z "$GPG_KEY" ]] ; then
  80. maybe_gpg_sign "$DEST_DIR/$SRC_DIR".7z
  81. maybe_gpg_sign "$DEST_DIR/$SRC_DIR".zip
  82. maybe_gpg_sign "$DEST_DIR/$TAR_FILE".xz
  83. maybe_gpg_sign "$DEST_DIR/$TAR_FILE".bz2
  84. maybe_gpg_sign "$DEST_DIR/$TAR_FILE".gz
  85. maybe_gpg_sign "$DEST_DIR/$TAR_FILE".lrz
  86. fi
  87. rm -rf "$SRC_DIR"
  88. rm -f "$TAR_FILE"
  89. popd
  90. rmdir "$TMP_DIR"