-
Notifications
You must be signed in to change notification settings - Fork 0
/
gobuild_version
executable file
·47 lines (34 loc) · 1.43 KB
/
gobuild_version
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
#!/usr/bin/env bash
export PACKAGE_BIN=$(echo ${PACKAGE_BIN})
export SUDOCMD=$(echo ${SUDOCMD})
export CURDIR=$(echo ${CURDIR})
export RUNDIR=$(echo ${RUNDIR})
export GOROOT=$(echo ${GOROOT})
export GOPATH=$(echo ${GOPATH})
PACKAGE_PKG=${1}
[[ "${PACKAGE_PKG}" != "" ]] || exit 1
PACKAGE_CMD=${2}
[[ "${PACKAGE_CMD}" != "." ]] || PACKAGE_CMD=""
[[ "${PACKAGE_CMD}" = "" ]] || PACKAGE_CMD=$(echo "./${PACKAGE_CMD}")
PACKAGE_VER=$(mktemp)
wget --output-document=${PACKAGE_VER} https://api.github.com/repos/${PACKAGE_PKG}/releases/latest
PACKAGE_TAG=$(cat ${PACKAGE_VER} | grep -i '"tag_name"' | grep -oP '(v[^"]*)')
PACKAGE_PKG=github.com/${PACKAGE_PKG}
go version || exit 1
[[ ! -e ${GOPATH}/src/${PACKAGE_PKG} ]] || rm -rf ${GOPATH}/src/${PACKAGE_PKG} || ${SUDOCMD} rm -rf ${GOPATH}/src/${PACKAGE_PKG} || exit 1
[[ -e $( dirname ${GOPATH}/src/${PACKAGE_PKG}) ]] || mkdir -vp $(dirname ${GOPATH}/src/${PACKAGE_PKG}) || ${SUDOCMD} mkdir -vp $(dirname ${GOPATH}/src/${PACKAGE_PKG}) || exit 1
git clone --recursive --branch ${PACKAGE_TAG} https://${PACKAGE_PKG}.git ${GOPATH}/src/${PACKAGE_PKG} || exit 1
cd ${GOPATH}/src/${PACKAGE_PKG} || exit 1
if [[ -e "go.mod" ]]
then
export GO111MODULE=on
go mod download
go mod vendor
else
export GO111MODULE=off
go get ./...
fi
echo -e "\n\n\n\t >>> build : "
go install -a ${PACKAGE_CMD} || exit 1
echo -e "\n\n\n\t >>> Moving package : "
${SUDOCMD} mv -vf ${GOPATH}/bin/* ${PACKAGE_BIN}/ || exit 1