#!/bin/bash set -euo pipefail . $(dirname $0)/functions.sh init_archive_vars() { if [ "$OS_NAME" = "windows" ] ; then ARCHIVE_EXT=.zip ARCHIVE_CMD=7z ARCHIVE_CMD_ARGS=a else ARCHIVE_EXT=.tar.gz ARCHIVE_CMD=tar ARCHIVE_CMD_ARGS=czf fi } init_checksum_cmd() { CHECKSUM_CMD=$(which sha256sum 2> /dev/null || true) if [ -n "$CHECKSUM_CMD" ] ; then return fi local openssl_cmd=$(which openssl 2> /dev/null || true) if [ -n "$openssl_cmd" ] ; then CHECKSUM_CMD="$openssl_cmd sha256 -r" return fi die "Neither sha256sum nor openssl are installed, can't compute sha256 sum" } define_version() { local describe=$(git describe) echo "git describe: $describe" case "$describe" in *-*-g*) echo "Building a snapshot" VERSION=${describe//-*/}+$(git show --no-patch --format=%cd-%h --date=format:%Y%m%dT%H%M%S) ;; *) echo "Building from a tag" VERSION=$describe ;; esac echo "VERSION=$VERSION" } cd $(dirname $0)/.. init_system_vars init_archive_vars init_checksum_cmd echo "Checksum command: $CHECKSUM_CMD" APP_NAME=regexnight DATA_FILES="README.md CHANGELOG.md LICENSE" define_version ARTIFACTS_DIR=$PWD/artifacts ARCHIVE_DIR=$APP_NAME-$VERSION ARCHIVE_NAME=$APP_NAME-$VERSION-$ARCH-$OS_NAME$ARCHIVE_EXT rm -rf $ARTIFACTS_DIR mkdir -p $ARTIFACTS_DIR/$ARCHIVE_DIR echo "Copying and stripping binaries" cp $EXE_DIR/regexnight${EXE_EXT} $ARTIFACTS_DIR/$ARCHIVE_DIR strip $ARTIFACTS_DIR/$ARCHIVE_DIR/regexnight${EXE_EXT} echo "Copying data files" cp -a $DATA_FILES $ARTIFACTS_DIR/$ARCHIVE_DIR echo "Creating archive $ARTIFACTS_DIR/$ARCHIVE_NAME" cd $ARTIFACTS_DIR $ARCHIVE_CMD $ARCHIVE_CMD_ARGS $ARCHIVE_NAME $ARCHIVE_DIR echo "Computing checksum" $CHECKSUM_CMD $ARCHIVE_NAME