diff --git a/.gitignore b/.gitignore index 3061650..12f8f3a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /coverage /vendor /bin -/testdata \ No newline at end of file +/testdata +/release \ No newline at end of file diff --git a/Makefile b/Makefile index eb00721..2dc8fcb 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,9 @@ test: watch: modd +release: + script/release + deps: GO111MODULE=off go get -u golang.org/x/tools/cmd/godoc GO111MODULE=off go get -u github.com/cortesi/modd/cmd/modd @@ -29,4 +32,4 @@ doc: bin/keygen: go build -o bin/keygen ./cmd/keygen -.PHONY: test lint doc sequence-diagram bin/keygen \ No newline at end of file +.PHONY: test lint doc sequence-diagram bin/keygen release \ No newline at end of file diff --git a/script/release b/script/release new file mode 100755 index 0000000..383387c --- /dev/null +++ b/script/release @@ -0,0 +1,99 @@ +#!/bin/bash + +set -eo pipefail + +OS_TARGETS=(linux) +ARCH_TARGETS=${ARCH_TARGETS:-amd64} + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" + +function build { + + local name=$1 + local srcdir=$2 + local os=$3 + local arch=$4 + + local dirname="$name-$os-$arch" + local destdir="$DIR/../release/$dirname" + + rm -rf "$destdir" + mkdir -p "$destdir" + + echo "building $dirname..." + + CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" go build \ + -ldflags="-s -w" \ + -gcflags=-trimpath="${PWD}" \ + -asmflags=-trimpath="${PWD}" \ + -o "$destdir/$name" \ + "$srcdir" + + if [ ! -z "$(which upx)" ]; then + upx --best "$destdir/$name" + fi + +} + +function copy { + + local name=$1 + local os=$2 + local arch=$3 + local src=$4 + local dest=$5 + + local dirname="$name-$os-$arch" + local destdir="$DIR/../release/$dirname" + + echo "copying '$src' to '$destdir/$dest'..." + + mkdir -p "$(dirname $destdir/$dest)" + + cp -rfL $src "$destdir/$dest" + +} + +function dump_default_conf { + # Generate and copy configuration file + local command=$1 + local os=$2 + local arch=$3 + local tmp_conf=$(mktemp) + + go run "$DIR/../cmd/$command" -dump-config > "$tmp_conf" + copy "$command" $os $arch "$tmp_conf" "$command.conf" + rm -f "$tmp_conf" +} + +function compress { + + local name=$1 + local os=$2 + local arch=$3 + + local dirname="$name-$os-$arch" + local destdir="$DIR/../release/$dirname" + + echo "compressing $dirname..." + tar -czf "$destdir.tar.gz" -C "$destdir/../" "$dirname" +} + +function release_keygen { + local os=$1 + local arch=$2 + build 'keygen' "$DIR/../cmd/keygen" $os $arch + copy 'keygen' $os $arch "$DIR/../README.md" "README.md" + compress 'keygen' $os $arch +} + + +function main { + for os in ${OS_TARGETS[@]}; do + for arch in ${ARCH_TARGETS[@]}; do + release_keygen $os $arch + done + done +} + +main \ No newline at end of file