-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sh
executable file
·73 lines (55 loc) · 1.65 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
#!/bin/bash
#set -e
BEAT="${1:-filebeat}"
ARCH="${2:-armv7l}"
BRANCH="${3:-master}"
TYPE="${4:-branch}"
if [[ -n ${GITHUB_REF_NAME} ]] ; then
BRANCH=${GITHUB_REF_NAME}
echo "Using BRANCH(${BRANCH})"
fi
if [[ -n ${GITHUB_REF_TYPE} ]] ; then
TYPE=${GITHUB_REF_TYPE}
echo "Using GITHUB_REF_TYPE(${TYPE})"
fi
if [[ $TYPE != "tag" ]] ; then
BRANCH="master"
echo "Using default branch(${BRANCH})"
fi
echo "Branch(${BRANCH}) Type(${TYPE})"
VERSION="${BRANCH:1}"
SRC=$(pwd)
echo "Setup"
unset GOROOT
export GOPATH=$(pwd)/go/project
export PATH="/usr/local/go/bin:${GOPATH}/bin:${PATH}"
mkdir -p "${GOPATH}"
go version
go tool dist list | grep linux
if [[ ! -d beats ]] ; then
echo "Cloning elastic/beats git branch(${BRANCH})"
git clone --quiet --single-branch --branch="${BRANCH}" --depth=1 "https://github.com/elastic/beats.git"
cd "${SRC}/beats"
git checkout --quiet --detach "${BRANCH}"
git describe --tags
fi
set -e
echo "Building(${BEAT})"
rm -rf "${GOPATH}/bin"
cd "${SRC}/beats/${BEAT}"
env GOOS=linux GOARCH=arm go install -v -a -ldflags "-s -w" ./...
if [[ $TYPE != "tag" ]] ; then
#do not packe if not a tag
ls -al ${GOPATH}/bin/linux_arm/${BEAT}
exit 0
fi
echo "Patching package version(${VERSION})"
SRC_ARCHIVE="${BEAT}-${VERSION}-linux-arm64"
DEST_ARCHIVE="${BEAT}-${VERSION}-linux-${ARCH}"
echo "${SRC_ARCHIVE} --> ${DEST_ARCHIVE}"
cd "${SRC}"
wget "https://artifacts.elastic.co/downloads/beats/${BEAT}/${SRC_ARCHIVE}.tar.gz"
tar -xf "${SRC_ARCHIVE}.tar.gz"
mv "${SRC_ARCHIVE}" "${DEST_ARCHIVE}"
cp -f "${GOPATH}/bin/linux_arm/${BEAT}" "${DEST_ARCHIVE}/${BEAT}"
tar -czf "${DEST_ARCHIVE}.tar.gz" "${DEST_ARCHIVE}"