#!/bin/bash set -euo pipefail init_system() { ARCH=$(uname -m) local out out=$(uname) case "$out" in Linux) OS_NAME=linux EXE_NAME=$APP_NAME ;; Darwin) OS_NAME=macos EXE_NAME=$APP_NAME ;; MINGW*|MSYS*) OS_NAME=windows EXE_NAME=$APP_NAME.exe ;; *) echo "error: unknown OS. uname printed '$out'" exit 1 ;; esac } init_checksum_cmd() { CHECKSUM_CMD=$(which sha512sum 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 sha512 -r" return fi die "Neither sha512sum nor openssl are installed, can't compute sha512 sum" } cd $(dirname $0)/.. APP_NAME=git-bonsai DATA_FILES="README.md CHANGELOG.md LICENSE" init_system init_checksum_cmd echo "Checksum command: $CHECKSUM_CMD" 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" } define_version ARTIFACTS_DIR=$PWD/artifacts ARCHIVE_DIR=$APP_NAME-$VERSION ARCHIVE_NAME=$APP_NAME-$VERSION-$ARCH-$OS_NAME.tar.bz2 rm -rf $ARTIFACTS_DIR mkdir -p $ARTIFACTS_DIR/$ARCHIVE_DIR echo "Copying and stripping binary" cp target/release/$EXE_NAME $ARTIFACTS_DIR/$ARCHIVE_DIR strip $ARTIFACTS_DIR/$ARCHIVE_DIR/$EXE_NAME echo "Copying data files" cp $DATA_FILES $ARTIFACTS_DIR/$ARCHIVE_DIR echo "Creating archive $ARTIFACTS_DIR/$ARCHIVE_NAME" cd $ARTIFACTS_DIR tar -cjvf $ARCHIVE_NAME $ARCHIVE_DIR echo "Computing checksum" $CHECKSUM_CMD $ARCHIVE_NAME