johnsonjh/gfcptun

View on GitHub
compile

Summary

Maintainability
Test Coverage
#!/usr/bin/env sh
if [ ! -f "./.gfcp_root" ] || [ ! -f "./.gfcptun_root" ]; then
printf '%s\n' 'Error: You must execute "build" from the project root.'
exit 1
fi
export BUILD_DIR="./build" || {
printf '%s\n' "Error: export failure."
exit 1
}
if [ ! -d "${BUILD_DIR:?Error: BUILD_DIR undefined.}" ]; then
mkdir -p "${BUILD_DIR:?Error: BUILD_DIR undefined.}" ||
{
printf '%s\n' "Error: mkdir failed."
exit 1
}
fi
cd "${BUILD_DIR:?Error: BUILD_DIR undefined.}" || {
printf '%s\n' "Error: unable to set cwd to BUILD_DIR."
exit 1
}
export GO111MODULE="on" ||
{
printf '%s\n' "Error: export failure."
exit 1
}
VERSION=$(date -u +%Y%m%d-gridfinity ||
{ printf '%s\n' "Error: failed to set VERSION."; }) ||
{
printf '%s\n' "Error: export failure."
exit 1
}
export VERSION ||
{
printf '%s\n' "Error: export failure."
exit 1
}
export LDFLAGS='-X main.VERSION='${VERSION:?Error: VERSION undefined.}' -s -w -linkmode "internal" -buildid=' ||
{
printf '%s\n' "Error: export failure."
exit 1
}
CGO_ENABLED=0 go build -tags="osnetgo,osusergo" -v -a -ldflags "${LDFLAGS:?Error: LDFLAGS undefined.}" -o "client_gfcp_${VERSION:?Error: VERSION undefined.}" ../client ||
{
printf '%s\n' "Error: Client build failed."
exit 1
}
CGO_ENABLED=0 go build -tags="osnetgo,osusergo" -v -a -ldflags "${LDFLAGS:?Error: LDFLAGS undefined.}" -o "server_gfcp_${VERSION:?Error: VERSION undefined.}" ../server ||
{
printf '%s\n' "Error: Server build failed."
exit 1
}
UPXC=$(env command -v upx 2>/dev/null || printf '%s' "true") || true :
# shellcheck disable=SC2236,SC2154
if [ ! -z "${UPXC:-}" ] || [ -n "${UPXC:-}" ]; then
printf '%s\n' "Compressing output with UPX, please wait ..."
# shellcheck disable=SC2015
strip --strip-all ./*_gfcp_*-gridfinity &&
"${UPXC:-}" "--ultra-brute" "-qq" ./*_gfcp_*-gridfinity &&
printf '%s\n' "UPX compression completed successfully." ||
{ printf '%s\n' "Error: UPX compression failure."; }
else
printf '%s\n' "UPX not available, skipping binary compression."
fi
printf '%s\n' "Build completed."