This repository has been archived on 2024-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
orion/scripts/release

118 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
set -eo pipefail
export GO111MODULE=on
OS_TARGETS=(windows linux)
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"
local ext=
[ "$os" == "windows" ] && ext=.exe
rm -rf "$destdir"
mkdir -p "$destdir"
echo "building $dirname..."
CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" go build \
-v \
-mod=vendor \
-ldflags="-s -w" \
-gcflags=-trimpath="${PWD}" \
-asmflags=-trimpath="${PWD}" \
-o "$destdir/$name$ext" \
"$srcdir"
if [ ! -z "$(which upx)" ]; then
upx --best "$destdir/$name$ext"
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 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_updater {
local os=$1
local arch=$2
build 'updater' "$DIR/../cmd/updater" $os $arch
compress 'updater' $os $arch
}
function release_discovery {
local os=$1
local arch=$2
build 'discovery' "$DIR/../cmd/discovery" $os $arch
compress 'discovery' $os $arch
}
function release_configurator {
local os=$1
local arch=$2
build 'configurator' "$DIR/../cmd/configurator" $os $arch
compress 'configurator' $os $arch
}
function main {
for os in ${OS_TARGETS[@]}; do
for arch in ${ARCH_TARGETS[@]}; do
release_configurator $os $arch
release_updater $os $arch
release_discovery $os $arch
done
done
}
main