-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc7040d
commit aeb0dfc
Showing
1 changed file
with
62 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,82 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Description: Build script for nettica-client | ||
|
||
ARCH=$(uname -m) | ||
|
||
if [[ ! -v VERSION ]]; then | ||
VERSION=development | ||
fi | ||
|
||
|
||
# Check arguments | ||
if [ $# -eq 0 ]; then | ||
echo "Usage: build.sh [version] [arch] (eg. build.sh 2.0.0 amd64|arm64|armhf))" | ||
echo "Usage: build.sh version [arch] (eg. build.sh 2.0.0 amd64|arm64|armhf))" | ||
echo " not specifying the arch will build all three" | ||
exit 1 | ||
fi | ||
|
||
# Set version to arg 1 | ||
export VERSION=$1 | ||
export ARCH=$2 | ||
if [ $# -ge 1 ]; then | ||
VERSION=$1 | ||
fi | ||
|
||
echo $2 | ||
if [ $# -eq 2 ]; then | ||
ARCH=$2 | ||
ARCHS=($2) | ||
fi | ||
|
||
if [ $ARCH == 'x86_64' ]; then | ||
ARCH=amd64 | ||
fi | ||
|
||
if [ $ARCH == 'aarch64' ]; then | ||
ARCH=arm64 | ||
fi | ||
|
||
echo "Building version $VERSION for $ARCH" | ||
if [ $ARCH == 'arm/v7' ]; then | ||
ARCH=armhf | ||
fi | ||
|
||
export GOOS=linux | ||
export GOARCH=$ARCH | ||
export CGO_ENABLED=0 | ||
|
||
if [ $GOARCH == "armhf" ]; then | ||
export GOARCH=arm | ||
export GOARM=7 | ||
if [ -z $ARCHS ]; then | ||
ARCHS=("armhf" "arm64" "amd64") | ||
fi | ||
|
||
if go build -ldflags "-X main.Version=$VERSION" ; then | ||
echo "Build success" | ||
else | ||
echo "Build failed" | ||
exit 1 | ||
fi | ||
for ARCH in ${ARCHS[@]}; do | ||
export GOARCH=$ARCH | ||
|
||
|
||
if [ $GOARCH == "armhf" ]; then | ||
export GOARCH=arm | ||
export GOARM=7 | ||
fi | ||
|
||
|
||
echo "Building version $VERSION for $ARCH/$GOARCH" | ||
|
||
|
||
if go build -ldflags "-X main.Version=$VERSION" ; then | ||
echo "Build success" | ||
else | ||
echo "Build failed" | ||
exit 1 | ||
fi | ||
|
||
cp -r nettica-client_2.X.X_${ARCH}/ nettica-client_${VERSION}_${ARCH}/ | ||
sed -i "s/2.X.X/$VERSION/g" nettica-client_${VERSION}_${ARCH}/DEBIAN/control | ||
mkdir -p nettica-client_${VERSION}_${ARCH}/usr/bin/ | ||
cp nettica-client nettica-client_${VERSION}_${ARCH}/usr/bin/nettica-client | ||
dpkg-deb -Zxz --build --root-owner-group nettica-client_${VERSION}_${ARCH}/ | ||
rm -rf nettica-client_${VERSION}_${ARCH}/ | ||
|
||
cp -r nettica-client_2.X.X_${ARCH}/ nettica-client_${VERSION}_${ARCH}/ | ||
sed -i "s/2.X.X/$VERSION/g" nettica-client_${VERSION}_${ARCH}/DEBIAN/control | ||
mkdir -p nettica-client_${VERSION}_${ARCH}/usr/bin/ | ||
cp nettica-client nettica-client_${VERSION}_${ARCH}/usr/bin/nettica-client | ||
dpkg-deb -Zxz --build --root-owner-group nettica-client_${VERSION}_${ARCH}/ | ||
rm -rf nettica-client_${VERSION}_${ARCH}/ | ||
echo "Build complete" | ||
|
||
echo "Build complete" | ||
done | ||
|
||
exit 0 | ||
|