|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | + |
| 4 | +# locate the script to be able to call related scripts |
| 5 | +SCRIPT=$(readlink -e "$0") |
| 6 | +SCRIPTDIR=$(dirname "$SCRIPT") |
| 7 | + |
| 8 | +declare -r START_DIR="$PWD" |
| 9 | + |
| 10 | +# fail on error |
| 11 | +set -e |
| 12 | + |
| 13 | +# get work directory |
| 14 | +trap '[ -d "$WORKDIR" ] && rm -rf "$WORKDIR"' EXIT |
| 15 | +WORKDIR=$(mktemp -d) |
| 16 | + |
| 17 | +# create code dir |
| 18 | +CODE_DIR="$WORKDIR"/code |
| 19 | +mkdir -p "$CODE_DIR" |
| 20 | + |
| 21 | +# copy full content into code directory |
| 22 | +git clone "$SCRIPTDIR"/../.. "$CODE_DIR"/mergesat |
| 23 | + |
| 24 | +# get dependencies, if not there already: Caution: this can drop state |
| 25 | +pushd "$CODE_DIR"/mergesat |
| 26 | +git submodule update --init --recursive |
| 27 | +git clean -xfd || true |
| 28 | +git submodule foreach --recursive git clean -xfd || true |
| 29 | +popd |
| 30 | + |
| 31 | +# create required links in root directory |
| 32 | +pushd "$WORKDIR" |
| 33 | +ln -s code/mergesat/license.txt license.txt |
| 34 | +ln -s code/mergesat/README readme.txt |
| 35 | +cp -r "$SCRIPTDIR"/build.sh . |
| 36 | +popd |
| 37 | + |
| 38 | +# log git version |
| 39 | +pushd "$SCRIPTDIR" |
| 40 | +echo "Package git version:" > "$WORKDIR"/VERSION |
| 41 | +git describe || git show -s --pretty=oneline >> "$WORKDIR"/VERSION |
| 42 | +GIT_VERSION="$(git describe 6> /dev/null || true)" |
| 43 | +[ -n "$GIT_VERSION" ] && GIT_VERSION="-$GIT_VERSION" |
| 44 | +[ -z "$GIT_VERSION" ] && GIT_VERSION="-unknown" |
| 45 | +echo "Submodules:" >> "$WORKDIR"/VERSION |
| 46 | +git submodule status >> "$WORKDIR"/VERSION |
| 47 | +echo "Git remotes:" >> "$WORKDIR"/VERSION |
| 48 | +git remote -v | grep origin || true >> "$WORKDIR"/VERSION |
| 49 | +popd |
| 50 | + |
| 51 | +declare -r ZIP_NAME="mergesat${GIT_VERSION}.zip" |
| 52 | + |
| 53 | +# remove git history, as it will be large, and other files |
| 54 | +pushd "$CODE_DIR" |
| 55 | +rm -rf mergesat/.git |
| 56 | +rm -f "$ZIP_NAME" |
| 57 | +rm -rf binary/* |
| 58 | +rm -rf doc/description |
| 59 | +popd |
| 60 | + |
| 61 | +# zip to overall package |
| 62 | +pushd "$WORKDIR" |
| 63 | +zip -r -y -9 "$ZIP_NAME" * |
| 64 | + |
| 65 | +# copy archive back to workdir |
| 66 | +cp "$ZIP_NAME" "$START_DIR" |
| 67 | + |
| 68 | +# leave work directory |
| 69 | +popd |
0 commit comments