Skip to content

Commit

Permalink
Adding script for creating release tarballs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Whissi committed Jun 2, 2014
1 parent 26d008d commit 9d755a9
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions mkrelease.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash

# From <sysexits.h>
declare -r EX_OK=0 # Everything is fine. No error.
declare -r EX_ERROR=1 # General error.
declare -r EX_USAGE=64 # Command line error, e.g. invalid argument
declare -r EX_IOERR=74 # An error occurred while doing I/O on some file
declare -r EX_CONFIG=78 # Something was found in an unconfigured or misconfigured state.

cleanup() {
if [[ -n "${D}" && -d "${D}" ]] ; then
echo ">>> Cleaning working directory ‘${D}"
rm -rf "${D}"
fi

return 0
}

##
# Die.
#
# Usage: die <exit_code> <message>
die() {
local status=$1
shift

cleanup

print_error ""
print_error "${@}"

exit $status
}

##
# Prints an error message to stderr.
print_error() {
echo >&2 -e "$@"
}

if [ $# != 1 ] ; then
die ${EX_USAGE} "Need version argument"
fi

if [[ -n ${1/[0-9]*} ]] ; then
die ${EX_USAGE} "Invalid version argument"
fi

VERSION=$1
NAME="realpath_turbo"
GITREF="HEAD"
DISTPREFIX="${NAME}-${VERSION}"
DISTFILE="${DISTPREFIX}.tar.bz2"

trap "die $? 'Terminated!'" SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM


D=$(mktemp -d)
if [[ $? -ne 0 ]] ; then
die ${EX_IOERR} "Couldn't create temporary folder!"
fi

WORKING_DIR="${D}/${DISTPREFIX}"
mkdir "${WORKING_DIR}"
if [[ $? -ne 0 ]] ; then
die ${EX_IOERR} "Failed to create ‘${WORKING_DIR}’!"
fi

echo ">>> Building release tree"
git checkout-index --force --all --prefix="${WORKING_DIR}/"
if [[ $? -ne 0 ]] ; then
die ${EX_ERROR} "Failed to copy files from the git repository index to the working dir ‘${WORKING_DIR}’!"
fi

if [[ -f "${WORKING_DIR}/${0##*/}" ]] ; then
echo ">>> Removing myself from release tree"
rm "${WORKING_DIR}/${0##*/}"
fi

echo ">>> Creating Changelog"
git log >"${WORKING_DIR}/ChangeLog"
if [[ $? -ne 0 ]] ; then
die ${EX_ERROR} "Failed to create ChangeLog from git!"
fi

echo ">>> Creating release tarball ‘${DISTFILE}"
tar -caf "${DISTFILE}" --owner=0 --group=0 --format=posix --mode=a+rX -C "$D" "${DISTPREFIX}"
if [[ $? -ne 0 ]] ; then
die ${EX_ERROR} "Failed to create tarball!"
fi

cleanup

du -h "$PWD/${DISTFILE}"


exit 0

0 comments on commit 9d755a9

Please sign in to comment.