forked from CPqD/RouteFlow
-
Notifications
You must be signed in to change notification settings - Fork 25
/
build.sh
executable file
·192 lines (166 loc) · 5.24 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/sh
INSTALL_VMS=0
FETCH_ONLY=0
UPDATE=0
QUIET=1
OVS_VERSION="deb"
MONGO_VERSION="deb"
RFDIR=`pwd`
CONTROLLERS=""
DO="echo"
SUPER="$DO sudo"
APT_OPTS="-y"
PIP_OPTS=""
ROUTEFLOW_GIT="https://github.com/routeflow/RouteFlow.git"
DEPENDENCIES="build-essential git-core libboost-dev libboost-dev \
libboost-program-options-dev libboost-thread-dev \
libboost-filesystem-dev libboost-system-dev iproute-dev python-dev \
python-pip"
usage() {
echo "usage:$0 [-hcqvdsgiu] [-m MONGO_VERSION] [-o OVS_VERSION]" \
"[controllers]"
echo "Build RouteFlow and all of its dependencies."
echo;
echo "General options:"
echo " -h Print this usage message"
echo " -c Carry out the build (default: only echo commands)"
echo " -f Only fetch the dependencies"
echo " -i Install RouteFlow VMs"
echo " -p Path to RouteFlow source directory"
echo " -v Verbose output"
echo;
echo "Build options:"
echo " -d Install binary versions of dependencies (default)"
echo " -s Build release versions of dependencies"
echo " -g Build git versions of dependencies"
echo " -u Update (rebuild) dependencies even if they have been built"
echo;
echo "Dependency version options:"
echo " Versions can be specified as \"deb\", \"X.Y.Z\" or \"git\""
echo " -m Specify the MongoDB version to fetch" \
"(default: $MONGO_VERSION)"
echo " -o Specify the Open vSwitch version to fetch" \
"(default: $OVS_VERSION)"
echo;
echo "Valid controllers: pox (default), nox, ryu. Multiple may be" \
"specified at once."
echo "Controllers must be specified at the end of the command."
echo;
echo "Report bugs to: https://github.com/routeflow/RouteFlow/issues"
}
verlte() {
local result=`echo "$1 < $2" | bc`
[ "$result" = "1" ]
}
verlt() {
[ "$1" = "$2" ] && return 1 || verlte $1 $2
}
get_versions() {
text=`lsb_release -a 2>/dev/null`
if [ $? -ne 0 ]; then
return;
fi
# We need particular versions of our dependencies. If Ubuntu does not have
# them in the repositories, then we need to fetch/build them.
if (echo "$text" | grep -q "Ubuntu"); then
version=`lsb_release -a 2>/dev/null | grep "Release" | cut -f2`
# Versions prior to Ubuntu 12.04 don't supply MongoDB-2.0 and OVS.
if (verlt $version "12.04"); then
MONGO_VERSION="2.0.9"
OVS_VERSION="1.10.0"
fi
if (echo "$*" | grep -q "ryu"); then
OVS_VERSION="1.10.0";
fi
if (verlt $version "12.04"); then
return
elif (echo "$*" | grep -q "nox"); then
echo "Cannot install NOX-Classic on Ubuntu 12.04+." && exit 1
fi
fi
}
parse_opts() {
while getopts hcfqip:vdsgum:o: option; do
case "${option}" in
c) DO="";
SUPER="sudo";;
f) FETCH_ONLY=1;
APT_OPTS="${APT_OPTS} -d";;
i) INSTALL_VMS=1;;
p) RFDIR=${OPTARG};;
v) QUIET=0;;
d) MONGO_VERSION="deb";
OVS_VERSION="deb";;
g) MONGO_VERSION="git";
OVS_VERSION="git";;
u) UPDATE=1;;
m) MONGO_VERSION=${OPTARG};;
o) OVS_VERSION=${OPTARG};;
*) usage;
exit 1;;
esac
done
if [ $QUIET -eq 1 ]; then
APT_OPTS="${APT_OPTS} -qq"
PIP_OPTS="-q"
fi
}
##
# Builds RouteFlow and all specified controllers.
#
# $@ - Commandline args to parse for controller names
##
build_routeflow() {
print_status "Building RouteFlow"
cd $RFDIR
for arg in $@; do
case $arg in
nox) . $RFDIR/dist/build_nox.sh; get_nox;;
ryu) . $RFDIR/dist/build_ryu.sh; get_ryu;;
esac
done
if [ $FETCH_ONLY -ne 1 ]; then
$DO make rfclient || fail "Couldn't build RouteFlow"
if [ $INSTALL_VMS -eq 1 ]; then
$DO cd rftest
$SUPER mkdir -p /cgroup
if [ grep -q "cgroup" "/etc/fstab" ]; then
$DO echo "none /cgroup cgroup defaults 0 0" >> /etc/fstab
fi
$SUPER mount none -t cgroup /cgroup
$SUPER ./create
$DO cd -
fi
fi
print_status "Finishing up"
}
main() {
get_versions $@
parse_opts $@
if [ `basename $RFDIR` != "RouteFlow" ]; then
RFDIR="${RFDIR}/RouteFlow"
if [ ! -d "$RFDIR" ]; then
echo "Cannot find RouteFlow directory; Fetching it."
git clone "$ROUTEFLOW_GIT" || exit 1;
fi
fi
# Import scripts from dist/
. $RFDIR/dist/common.sh
. $RFDIR/dist/build_ovs.sh
. $RFDIR/dist/build_mongo.sh
if [ "$DO" = "echo" ]; then
print_status "Warning user" $YELLOW
echo "This script may perform invasive changes to your system. By" \
"default, we only"
echo "print the changes that will be made. To confirm the build" \
"process, add the"
echo "\"-c\" option to the commandline arguments."
fi
print_status "Fetching dependencies"
pkg_install "$DEPENDENCIES"
$SUPER pip install "pymongo"
get_ovs "$OVS_VERSION"
get_mongo "$MONGO_VERSION"
build_routeflow $@
}
main $@