-
Notifications
You must be signed in to change notification settings - Fork 32
/
build.sh
executable file
·160 lines (134 loc) · 3.64 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
#!/bin/bash
# Check root
if [[ `whoami` != "root" ]]; then
echo "Not root"
exit -1
fi
# Build grpc
if [[ $# -ge 1 && "$1" = "grpc" ]]; then
release_tag="latest"
if [[ $# -ge 2 ]]; then
release_tag=$2
fi
/bin/bash /opt/cloudland/build_grpc.sh "$release_tag"
fi
# Install tools
yum groupinstall -y "Development Tools"
yum install -y git golang
cland_root_dir=/opt/cloudland
# folders used by cloudland
mkdir -p $cland_root_dir/{etc,log,run,cache} $cland_root_dir/cache/{image,instance,dnsmasq,meta,router,volume,xml}
# download cloudland from github
function get_commitid()
{
cd $cland_root_dir
commitID=$(git rev-parse --short HEAD 2>/dev/null)
if [ "$commitID" = "" ]; then
commitID="not available"
fi
echo "$commitID" > commitID
}
# Build sci and Install it to /opt/sci
function inst_sci()
{
cd $cland_root_dir/sci
source /opt/rh/devtoolset-9/enable
./configure
make
make install
}
# Build and install cloudland
function inst_cland()
{
# Setup grpc env
export PATH=$PATH:/usr/local/bin
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig
source /opt/rh/devtoolset-9/enable
# Build and install cland to /opt/cloudland/bin and /opt/cloudland/lib64
cd $cland_root_dir/src
make clean
make
make install
# update cloudland.j2, the default SCI libraray path is sci/lib64
if [ -d "/opt/sci/lib" ]; then
echo "Update sci lib ..."
sed -i "s/\/sci\/lib64/\/sci\/lib/g" $cland_root_dir/deploy/roles/cland/templates/cloudland.j2
sed -i "s/\/sci\/lib64/\/sci\/lib/g" $cland_root_dir/deploy/roles/hyper/templates/cloudlet.j2
fi
}
# Build web/clui
function build_clui()
{
chown -R cland:cland $cland_root_dir
su cland << EOF
# Prepare GO mod
cd $cland_root_dir
rm -f go.mod
go mod init web
go mod tidy
echo 'replace github.com/IBM/cloudland => /opt/cloudland' >> go.mod
# Build
cd $cland_root_dir/web/clui
CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"'
EOF
}
# Build libvirt-console-proxy
function inst_console_proxy()
{
cd /opt
rm -rf libvirt-console-proxy
git clone https://github.com/libvirt/libvirt-console-proxy.git
chown -R cland:cland libvirt-console-proxy
su cland << EOF
cd /opt/libvirt-console-proxy
go build -o build/virtconsoleproxyd cmd/virtconsoleproxyd/virtconsoleproxyd.go
EOF
}
# Download noVNC
function get_noVNC()
{
rm -rf "$cland_root_dir/web/clui/public/novnc"
git clone https://github.com/novnc/noVNC.git $cland_root_dir/web/clui/public/novnc
rm -rf $cland_root_dir/web/clui/public/novnc/.git*
chown -R cland:cland $cland_root_dir
}
# create user cland if it is necessary
grep cland /etc/passwd
if [ $? -ne 0 ]; then
useradd cland
echo 'cland ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/cland
else
echo "User cland already exists."
fi
# configure golang for cland
su cland << EOF
# Prepare GO env
sed -i '/export GO/d' ~/.bashrc
echo 'export GOPROXY=https://goproxy.io' >> ~/.bashrc
echo 'export GO111MODULE=on' >> ~/.bashrc
source ~/.bashrc
EOF
get_commitid
inst_sci
if [[ ! -d "/opt/sci" ]]; then
echo "Error: SCI build failed."
exit -1
fi
inst_cland
pushd "$cland_root_dir/bin/"
if [[ ! -e "cloudland" || ! -e "cloudlet" || ! -e "grpcfile" || ! -e "grpcmsg" ]]; then
echo "Error: CloudLand build failed."
exit -1
fi
popd
build_clui
pushd "$cland_root_dir/web/clui"
if [[ ! -e "clui" ]]; then
echo "Error: CloudLand clui build failed."
exit -1
fi
popd
inst_console_proxy
get_noVNC
cd $cland_root_dir
echo Build completes, you can build rpm package with build_rpm.sh now""