1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#!/usr/bin/env bash
#
# Creates source tarballs for giada in the form of
# 'giada-x.x.x-src.tar.gz' and optionally detached PGP signatures
# for the created file of the form 'giada-x.x.x-src.tar.gz.asc'.
# If the environment variable BUILD_DIR is provided, the files will be moved to
# $BUILD_DIR/, else to the location of this script (the repository folder).
#
# Requirements:
# - git
# - tar
# - a writable (user) /tmp folder for mktemp
# - gnupg >= 2.0.0 (if source tarball signing is requested)
# - a valid PGP signing key in the keyring (if source tarball signing is
# requested)
set -euo pipefail
get_absolute_path() {
cd "$(dirname "$1")" && pwd -P
}
validate_project_tag() {
if ! git ls-remote -t "${upstream}"| grep -e "${version}$" > /dev/null; then
echo "The tag '$version' could not be found in upstream repository (${upstream})."
exit 1
fi
}
checkout_project() {
echo "Cloning project below working directory ${working_dir}"
cd "$working_dir"
git clone "$upstream" --branch "$version" \
--single-branch \
--depth=1 \
--recurse-submodules \
--shallow-submodules \
"${output_name}"
}
clean_sources() {
cd "${working_dir}/${output_name}"
echo "Removing unneeded files and folders..."
rm -rfv .git* \
.travis* \
create_source_tarball.sh
}
compress_sources() {
cd "${working_dir}"
tar cfz "${output_name}.tar.gz" "${output_name}"
}
move_sources() {
cd "${working_dir}"
mv -v "${output_name}.tar.gz" "${output_dir}/"
}
sign_sources() {
cd "${output_dir}"
gpg --detach-sign \
-u "${signer}" \
-o "${output_name}.tar.gz.asc" \
"${output_name}.tar.gz"
}
cleanup_working_dir() {
echo "Removing working directory: ${working_dir}"
rm -rf "${working_dir}"
}
print_help() {
echo "Usage: $0 -v <version tag> -s <signature email or key ID>"
exit 1
}
if [ -n "${BUILD_DIR:-}" ]; then
echo "Build dir provided: ${BUILD_DIR}"
output_dir="${BUILD_DIR}/"
mkdir -p "${output_dir}"
else
output_dir="$(get_absolute_path "$0")"
fi
upstream="https://github.com/monocasual/giada"
package_name="giada"
working_dir="$(mktemp -d)"
version="$(date '+%Y-%m-%d')"
output_version=""
output_name=""
signer=""
signature=0
# remove the working directory, no matter what
trap cleanup_working_dir EXIT
if [ ${#@} -gt 0 ]; then
while getopts 'hv:s:' flag; do
case "${flag}" in
h) print_help
;;
s) signer=$OPTARG
signature=1
;;
v) version=$OPTARG
output_version="${version}"
;;
*)
echo "Error! Try '${0} -h'."
exit 1
;;
esac
done
else
print_help
fi
output_name="${package_name}-${output_version}-src"
validate_project_tag
checkout_project
clean_sources
compress_sources
move_sources
if [ $signature -eq 1 ]; then
sign_sources
fi
exit 0
# vim:set ts=4 sw=4 et:
|