go-http-peering/script/release

107 lines
2.1 KiB
Plaintext
Raw Normal View History

2019-04-09 11:20:47 +02:00
#!/bin/bash
set -eo pipefail
OS_TARGETS=(linux)
2022-09-12 17:47:09 +02:00
ARCH_TARGETS=${ARCH_TARGETS:-amd64 mipsle}
2019-04-09 11:20:47 +02:00
export GOMIPS=softfloat
2019-04-09 11:20:47 +02:00
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"
2022-09-12 18:22:49 +02:00
# Disable UPX compression for MIPS archs
# See https://github.com/upx/upx/issues/339
if [ ! -z "$(which upx)" ] && [[ ! "$arch" =~ "mips" ]]; then
2019-04-09 11:20:47 +02:00
upx --best "$destdir/$name"
fi
2023-10-19 15:08:48 +02:00
if [ ! -z "${GPG_SIGNING_KEY}" ]; then
echo "signing '$destdir/$name' with gpg key '$GPG_SIGNING_KEY'..."
gpg --sign --default-key "${GPG_SIGNING_KEY}" --output "$destdir/$name.sig" "$destdir/$name"
fi
2019-04-09 11:20:47 +02:00
}
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