| 1 | #!/bin/bash |
| 2 | |
| 3 | set -eu |
| 4 | set -o pipefail |
| 5 | |
| 6 | # invoke with do-release 2.N.M, or 2.N.M-rcXX |
| 7 | |
| 8 | # Default maintainer values |
| 9 | SRCDIR="${HOME}/git/lttng-modules" |
| 10 | # The output files are created in ${HOME}/stable/ |
| 11 | OUTPUTDIR="${HOME}/stable" |
| 12 | SIGN="yes" |
| 13 | VERBOSE="" |
| 14 | |
| 15 | usage() { |
| 16 | echo "Usage: do-release.sh [OPTION]... RELEASE" |
| 17 | echo |
| 18 | echo "Mandatory arguments to long options are mandatory for short options too." |
| 19 | echo " -s, --srcdir DIR source directory" |
| 20 | echo " -o, --outputdir DIR output directory, must exist" |
| 21 | echo " -n, --no-sign don't GPG sign the output archive" |
| 22 | echo " -v, --verbose verbose command output" |
| 23 | } |
| 24 | |
| 25 | POS_ARGS=() |
| 26 | while [[ $# -gt 0 ]] |
| 27 | do |
| 28 | arg="$1" |
| 29 | |
| 30 | case $arg in |
| 31 | -n|--no-sign) |
| 32 | SIGN="no" |
| 33 | shift 1 |
| 34 | ;; |
| 35 | |
| 36 | -s|--srcdir) |
| 37 | SRCDIR="$2" |
| 38 | shift 2 |
| 39 | ;; |
| 40 | |
| 41 | -o|--outputdir) |
| 42 | OUTPUTDIR="$2" |
| 43 | shift 2 |
| 44 | ;; |
| 45 | |
| 46 | -v|--verbose) |
| 47 | VERBOSE="-v" |
| 48 | shift 1 |
| 49 | ;; |
| 50 | |
| 51 | # Catch unknown arguments |
| 52 | -*) |
| 53 | usage |
| 54 | exit 1 |
| 55 | ;; |
| 56 | |
| 57 | *) |
| 58 | POS_ARGS+=("$1") |
| 59 | shift |
| 60 | ;; |
| 61 | esac |
| 62 | done |
| 63 | set -- "${POS_ARGS[@]}" |
| 64 | |
| 65 | REL=${1:-} |
| 66 | |
| 67 | if [ x"${REL}" = x"" ]; then |
| 68 | usage |
| 69 | exit 1; |
| 70 | fi |
| 71 | |
| 72 | echo "Doing LTTng modules release ${REL}" |
| 73 | echo " Source dir: ${SRCDIR}" |
| 74 | echo " Output dir: ${OUTPUTDIR}" |
| 75 | echo " GPG sign: ${SIGN}" |
| 76 | |
| 77 | # Make sure the output directory exists |
| 78 | if [ ! -d "${OUTPUTDIR}" ]; then |
| 79 | echo "Output directory '${OUTPUTDIR}' doesn't exist." |
| 80 | exit 1 |
| 81 | fi |
| 82 | |
| 83 | # Make sure the source directory is a git repository |
| 84 | if [ ! -r "${SRCDIR}/.git/config" ]; then |
| 85 | echo "Source directory '${SRCDIR}' isn't a git repository." |
| 86 | exit 1 |
| 87 | fi |
| 88 | |
| 89 | # Set the git repo directory for all further git commands |
| 90 | export GIT_DIR="${SRCDIR}/.git/" |
| 91 | |
| 92 | # Check if the release tag exists |
| 93 | if ! git rev-parse "refs/tags/v${REL}" >/dev/null 2>&1; then |
| 94 | echo "Release tag 'v${REL}' doesn't exist." |
| 95 | exit 1 |
| 96 | fi |
| 97 | |
| 98 | # Generate the compressed tar archive, the git attributes from the tag will be used. |
| 99 | git archive $VERBOSE --format=tar --prefix="lttng-modules-${REL}/" "v${REL}" | bzip2 > "${OUTPUTDIR}/lttng-modules-${REL}.tar.bz2" |
| 100 | |
| 101 | pushd "${OUTPUTDIR}" >/dev/null |
| 102 | # Generate the hashes |
| 103 | md5sum "lttng-modules-${REL}.tar.bz2" > "lttng-modules-${REL}.tar.bz2.md5" |
| 104 | sha256sum "lttng-modules-${REL}.tar.bz2" > "lttng-modules-${REL}.tar.bz2.sha256" |
| 105 | |
| 106 | if [ "x${SIGN}" = "xyes" ]; then |
| 107 | # Sign with the default key |
| 108 | gpg --armor -b "lttng-modules-${REL}.tar.bz2" |
| 109 | fi |
| 110 | popd >/dev/null |