-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoenv
68 lines (55 loc) · 1.33 KB
/
goenv
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
#!/bin/bash
# source goenv
GOLIB=$(pwd)/go
GOVENDOR=$(pwd)/go/vendor
[[ ! -e go/src ]] && mkdir -p go/src
[[ ! -e go/pkg ]] && mkdir -p go/pkg
[[ ! -e go/doc ]] && mkdir -p go/doc
[[ ! -e go/bin ]] && mkdir -p go/bin
echo "Adding $GOLIB to GOPATH..."
# export GOPATH=$GOVENDOR:$GOLIB
export GOPATH=$GOLIB
export PATH=$GOLIB/bin:$PATH
[[ -e golang ]] && export PATH=$(pwd)/golang/go/bin:$PATH
echo "Done"
function clean() {
echo "Cleaning..."
rm -rf go/pkg/
go clean -i drshine
}
function build_all() {
go build -a -x drshine
}
function remote_install() {
repo=$1
go get -u $repo
}
function git_install() {
installdir=$(echo $GOPATH | cut -d: -f1)
repo=$1
target=$installdir/src/$2
branch=$3
currentdir=$(pwd)
if [[ -z $branch ]] ; then
branch=master
fi
mkdir -p $(dirname $target)
echo "===> Sync $repo => $target..."
if [[ ! -e $target ]] ; then
echo "Cloning..."
git clone --branch $branch $repo $target
else
echo "Fetching..."
GITCMD="git --work-tree $target --git-dir $target/.git"
if [[ -z `$GITCMD diff` ]] ; then
$GITCMD pull -q --rebase origin HEAD
else
$GITCMD fetch -q
fi
if [[ -n `$GITCMD log @{u}..` ]] ; then
echo "Pushing commits..."
$GITCMD push origin HEAD
fi
cd $target && go install && cd $currentdir
fi
}