-
Notifications
You must be signed in to change notification settings - Fork 45
/
configure
executable file
·169 lines (143 loc) · 4.13 KB
/
configure
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
showhelp()
{
cat << ENDHELP
usage: configure [options]
Configure p2p
Options:
--dht=<url>
Default DHT url
--branch=<branch_ name>
Specify a branch name. By default configure script will try to determine branch name
using command line. Setting this option will modify version output and target DHT
--os=<operating_system>
Specify operating system handle: linux, darwin, windows
--help
Display this help screen
ENDHELP
}
name_prefix=p2p
gopath=
branch=
dht=""
argOS=""
targetURL="subutai.io"
while [ $# -ge 1 ]; do
case "$1" in
--branch=*)
branch="`echo ${1} | awk '{print substr($0,10)}'`" ;;
--dht=*)
dht="`echo ${1} | awk '{print substr($0,7)}'`" ;;
--os=*)
argOS="`echo ${1} | awk '{print substr($0,6)}'`" ;;
--help)
showhelp
exit 0
;;
*)
echo "ERROR: Unknown argument: $1"
showhelp
exit 1
;;
esac
shift
done
if [ "$argOS" != "linux" ] && [ "$argOS" != "darwin" ] && [ "$argOS" != "windows" ]; then
argOS=""
fi
if [ -z "$argOS" ]; then
argOS=$(uname -s | tr '[:upper:]' '[:lower:]')
fi
# Workaround for AppVeyor
if [ "$argOS" == "windows" ]; then
location="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $location
fi
if [ -z "$branch" ]; then
echo "Branch was not specified. Trying to determine"
branch=`git rev-parse --abbrev-ref HEAD`
if [ $? -ne 0 ]; then
echo "Failed to determine branch using git command. Exiting"
exit 25
fi
fi
echo "Preparing \"${branch}\" build for ${argOS}"
version=`cat VERSION`
build=`git describe`
source_list=`ls | grep .go`
source_files="${source_list//$'\n'/ }"
name_base="$name_prefix"
if [ "$branch" != "HEAD" ]; then
name_base=$name_prefix-$branch
fi
echo "Building $name_base"
if [ "$dht" == "" ]; then
echo "Determining DHT address"
if [ "$branch" == "dev" ]; then
dht="devdht"
elif [ "$branch" == "master" ]; then
dht="masterdht"
elif [ "$branch" == "sysnet" ]; then
dht="sysnetdht"
else
dht="dht"
fi
echo "DHT is set to $dht"
else
echo "DHT is set to $dht"
fi
log_level="INFO"
if [ "$branch" == "HEAD" ]; then
log_level="WARNING"
elif [ "$branch" == "master" ]; then
log_level="DEBUG"
elif [ "$branch" == "dev" ]; then
log_level="DEBUG"
elif [ "$branch" == "sysnet" ]; then
log_level="TRACE"
fi
if [ "$argOS" != "windows" ]; then
echo "Checking go environment"
if [ "$GOPATH" == "" ]; then
echo "GOPATH is not set. Setting to /tmp/go-path-tmp directory"
gopath=/tmp/go-path-tmp
fi
echo "Downloading necessary packages"
if [ ! -z $gopath ]; then
export GOPATH=$HOME
export GOBIN=$HOME/go-bin
fi
go get
go get -u github.com/golang/protobuf/proto
fi
if [ "$argOS" == "windows" ]; then
output_file="build.bat"
echo ":: ${output_file} generated by configure script" > $output_file
echo "go get" >> $output_file
echo "go build -ldflags=\"-w -s -X main.AppVersion=${version}-${branch} -X main.DefaultDHT=${dht} -X main.BuildID=${build} -X main.DefaultLog=${log_level}\" -o p2p.exe github.com/subutai-io/p2p" >> $output_file
else
# generating config.make file
echo "# config.make generated by configure script" > config.make
echo "NAME_BASE = $name_base" >> config.make
echo "NAME_PREFIX = $name_prefix" >> config.make
echo "DHT_ENDPOINTS = $dht" >> config.make
echo "LOG_LEVEL = $log_level" >> config.make
if [ "$dht" != "" ]; then
echo "DHT = $dht" >> config.make
fi
if [ "$branch" != "HEAD" ]; then
echo "BRANCH_POSTFIX = -$branch" >> config.make
fi
#
echo "export NAME_BASE" >> config.make
echo "export NAME_PREFIX" >> config.make
echo "export DHT_ENDPOINTS" >> config.make
echo "export LOG_LEVEL" >> config.make
if [ ! -z "$gopath" ]; then
echo "GOPATH = $HOME" >> config.make
echo "export GOPATH" >> config.make
fi
if [ "$branch" != "HEAD" ]; then
echo "export BRANCH_POSTFIX" >> config.make
fi
fi