forked from palark/ovpn-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·82 lines (73 loc) · 2.57 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
set -eo pipefail
APP_VERSION=$(grep '"version":' frontend/package.json)
APP_VERSION=${APP_VERSION##*\": \"}
APP_VERSION=${APP_VERSION%%\"*}
case "$APP_VERSION" in
*.*.*) ;;
*) echo "Bad version in package.json '$APP_VERSION'"; exit 1;;
esac
PATH=$PATH:~/go/bin
SKIP_FRONT=0
SKIP_BACK=0
BUILD_DEV=0
ARCH=amd64
while [ $# -ge 1 ]; do
case $1 in
--dev)
BUILD_DEV=1
;;
--skip-front)
SKIP_FRONT=1
;;
--skip-back)
SKIP_BACK=1
;;
--arch)
shift
ARCH=$1
;;
*)
echo "Unsupported option: $1"
exit 1
esac
shift
done
PACKAGE_BUILD_SCRIPT=build
[ "$BUILD_DEV" = 1 ] && PACKAGE_BUILD_SCRIPT=build-dev
if [ $SKIP_FRONT = 0 ]; then
rsync --progress --times --recursive --delete-after ~/bus-ui/src/content/app/openvpn/ ./frontend/src/content/app/openvpn/
rsync --progress --times --recursive --delete-after ~/bus-ui/src/content/app/shared/services/ble/ ./frontend/src/content/app/shared/services/ble/
export APP_VERSION
cd frontend && npm install && npm run $PACKAGE_BUILD_SCRIPT && cd .. || (echo "Build front failed"; exit 1)
fi
if [ $SKIP_BACK = 0 ]; then
echo "Compile Go backend for arch '$ARCH' at version '$APP_VERSION'"
# CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags "-X main.version=$APP_VERSION -linkmode external -extldflags -static -s -w"
# apt install gcc-arm-linux-gnueabi
# apt install gcc-arm-linux-gnueabihf
# apt install aarch64-linux-gnu-gcc
rm -f ./rpiadm
case $ARCH in
arm)
CC=arm-linux-gnueabi-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 go build -a -tags netgo -ldflags "-X main.version=$APP_VERSION -linkmode external -extldflags -static -s -w"
;;
armhf)
CC=arm-linux-gnueabi-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=6 go build -a -tags netgo -ldflags "-X main.version=$APP_VERSION -linkmode external -extldflags -static -s -w"
;;
arm64)
CC=arm-linux-gnueabi-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -a -tags netgo -ldflags "-X main.version=$APP_VERSION -linkmode external -extldflags -static -s -w"
;;
aarch64)
CC=arm-linux-gnueabi-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -a -tags netgo -ldflags "-X main.version=$APP_VERSION -linkmode external -extldflags -static -s -w"
;;
*)
CGO_ENABLED=1 GOOS=linux GOARCH=${ARCH} go build -a -tags netgo -ldflags "-X main.version=$APP_VERSION -linkmode external -extldflags -static -s -w"
;;
esac
if [ ! -f ./rpiadm ]; then
echo "Build failed" 1>&2
exit 1
fi
mv ./rpiadm ./rpiadm-$ARCH
fi