-
Notifications
You must be signed in to change notification settings - Fork 0
/
gobuild_repos
executable file
·44 lines (32 loc) · 1.25 KB
/
gobuild_repos
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
#!/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_GIT=${3}
[[ "${PACKAGE_GIT}" != "" ]] || PACKAGE_GIT=${PACKAGE_PKG}.git
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 https://${PACKAGE_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