eosio_build_amazon.sh 20.3 KB
Newer Older
1
	OS_VER=$( grep VERSION_ID /etc/os-release | cut -d'=' -f2 | sed 's/[^0-9\.]//gI' | cut -d'.' -f1 )
2

3
	MEM_MEG=$( free -m | sed -n 2p | tr -s ' ' | cut -d\  -f2 )
4 5
	CPU_SPEED=$( lscpu | grep "MHz" | tr -s ' ' | cut -d\  -f3 | cut -d'.' -f1 )
	CPU_CORE=$( lscpu | grep "^CPU(s)" | tr -s ' ' | cut -d\  -f2 )
6
	MEM_GIG=$(( ((MEM_MEG / 1000) / 2) ))
7
	JOBS=$(( MEM_GIG > CPU_CORE ? CPU_CORE : MEM_GIG ))
8

9 10
	DISK_TOTAL=$( df -h . | grep /dev | tr -s ' ' | cut -d\  -f2 | sed 's/[^0-9]//' )
	DISK_AVAIL=$( df -h . | grep /dev | tr -s ' ' | cut -d\  -f4 | sed 's/[^0-9]//' )
11

12 13 14
	printf "\\n\\tOS name: %s\\n" "${OS_NAME}"
	printf "\\tOS Version: %s\\n" "${OS_VER}"
	printf "\\tCPU speed: %sMhz\\n" "${CPU_SPEED}"
15 16
	printf "\\tCPU cores: %s\\n" "${CPU_CORE}"
	printf "\\tPhysical Memory: %sMgb\\n" "${MEM_MEG}"
17 18
	printf "\\tDisk space total: %sGb\\n" "${DISK_TOTAL}"
	printf "\\tDisk space available: %sG\\n" "${DISK_AVAIL}"
19

20
	if [ "${MEM_MEG}" -lt 7000 ]; then
21 22
		printf "\\tYour system must have 7 or more Gigabytes of physical memory installed.\\n"
		printf "\\texiting now.\\n"
23 24 25
		exit 1
	fi

26
	if [ "${OS_VER}" -lt 2017 ]; then
27 28
		printf "\\tYou must be running Amazon Linux 2017.09 or higher to install EOSIO.\\n"
		printf "\\texiting now.\\n"
29 30 31
		exit 1
	fi

32
	if [ "${DISK_AVAIL}" -lt "${DISK_MIN}" ]; then
33 34
		printf "\\tYou must have at least %sGB of available storage to install EOSIO.\\n" "${DISK_MIN}"
		printf "\\texiting now.\\n"
35 36
		exit 1
	fi
37 38 39 40 41 42 43

	printf "\\n\\tChecking Yum installation.\\n"
	if ! YUM=$( command -v yum 2>/dev/null )
	then
		printf "\\n\\tYum must be installed to compile EOS.IO.\\n"
		printf "\\n\\tExiting now.\\n"
		exit 1
44 45
	fi
	
46 47 48 49 50 51
	printf "\\tYum installation found at %s.\\n" "${YUM}"
	printf "\\tUpdating YUM.\\n"
	if ! UPDATE=$( sudo "$YUM" -y update )
	then
		printf "\\n\\tYUM update failed.\\n"
		printf "\\n\\tExiting now.\\n"
52 53
		exit 1
	fi
54 55
	printf "\\t%s\\n" "${UPDATE}"

56
	DEP_ARRAY=( git gcc72.x86_64 gcc72-c++.x86_64 autoconf automake libtool make bzip2 \
57 58
	bzip2-devel.x86_64 openssl-devel.x86_64 gmp-devel.x86_64 libstdc++72.x86_64 \
	python27.x86_64 python36-devel.x86_64 libedit-devel.x86_64 doxygen.x86_64 graphviz.x86_64)
59 60 61 62
	COUNT=1
	DISPLAY=""
	DEP=""

63
	printf "\\n\\tChecking YUM for installed dependencies.\\n\\n"
64 65 66

	for (( i=0; i<${#DEP_ARRAY[@]}; i++ ));
	do
67
		pkg=$( sudo "$YUM" info "${DEP_ARRAY[$i]}" 2>/dev/null | grep Repo | tr -s ' ' | cut -d: -f2 | sed 's/ //g' )
68 69 70

		if [ "$pkg" != "installed" ]; then
			DEP=$DEP" ${DEP_ARRAY[$i]} "
71 72 73
			DISPLAY="${DISPLAY}${COUNT}. ${DEP_ARRAY[$i]}\\n\\t"
			printf "\\tPackage %s ${bldred} NOT ${txtrst} found.\\n" "${DEP_ARRAY[$i]}"
			(( COUNT++ ))
74
		else
75
			printf "\\tPackage %s found.\\n" "${DEP_ARRAY[$i]}"
76 77 78 79
			continue
		fi
	done		

80 81
	if [ "${COUNT}" -gt 1 ]; then
		printf "\\n\\tThe following dependencies are required to install EOSIO.\\n"
82
		printf "\\n\\t${DISPLAY}\\n\\n"
83
		printf "\\tDo you wish to install these dependencies?\\n"
84 85 86
		select yn in "Yes" "No"; do
			case $yn in
				[Yy]* ) 
87
					printf "\\n\\n\\tInstalling dependencies.\\n\\n"
88
					if ! sudo "${YUM}" -y install ${DEP}
89 90 91
					then
						printf "\\n\\tYUM dependency installation failed.\\n"
						printf "\\n\\tExiting now.\\n"
92 93
						exit 1
					else
94
						printf "\\n\\tYUM dependencies installed successfully.\\n"
95 96
					fi
				break;;
97
				[Nn]* ) printf "\\nUser aborting installation of required dependencies,\\n Exiting now.\\n"; exit;;
98 99 100 101
				* ) echo "Please type 1 for yes or 2 for no.";;
			esac
		done
	else 
102
		printf "\\n\\tNo required YUM dependencies to install.\\n"
103 104
	fi

105
	if [ "${ENABLE_COVERAGE_TESTING}" = true ]; then
106
		printf "\\n\\tChecking perl installation.\\n"
107 108
		perl_bin=$( command -v perl 2>/dev/null )
		if [ -z "${perl_bin}" ]; then
109 110 111 112
			printf "\\n\\tInstalling perl.\\n"
			if ! sudo "${YUM}" -y install perl
			then
				printf "\\n\\tUnable to install perl at this time.\\n"
113 114
				printf "\\n\\tExiting now.\\n\\n"
				exit 1;
115 116
			fi
		else
117
			printf "\\tPerl installation found at %s.\\n" "${perl_bin}"
118 119 120 121 122 123 124
		fi
		printf "\\n\\tChecking LCOV installation.\\n"
		if [ ! -e "/usr/local/bin/lcov" ]; then
			printf "\\n\\tLCOV installation not found.\\n"
			printf "\\tInstalling LCOV.\\n"
			if ! cd "${TEMP_DIR}"
			then
125
				printf "\\n\\tUnable to enter %s. Exiting now.\\n" "${TEMP_DIR}"
126 127 128 129 130 131 132
				exit 1;
			fi
			if ! git clone "https://github.com/linux-test-project/lcov.git"
			then
				printf "\\n\\tUnable to clone LCOV at this time.\\n"
				printf "\\tExiting now.\\n\\n"
				exit 1;
133
			fi
134 135
			if ! cd "${TEMP_DIR}/lcov"
			then
136
				printf "\\n\\tUnable to enter %s/lcov. Exiting now.\\n" "${TEMP_DIR}"
137
				exit 1;
138
			fi
139 140 141 142 143 144 145 146
			if ! sudo make install
			then
				printf "\\n\\tUnable to install LCOV at this time.\\n"
				printf "\\tExiting now.\\n\\n"
				exit 1;
			fi
			rm -rf "${TEMP_DIR}/lcov"
			printf "\\n\\tSuccessfully installed LCOV.\\n\\n"
147
		else
148
			printf "\\n\\tLCOV installation found @ /usr/local/bin.\\n"
149 150
		fi
	fi
151

152 153 154 155 156
	printf "\\n\\tChecking CMAKE installation.\\n"
    if [ ! -e "${CMAKE}" ]; then
		printf "\\tInstalling CMAKE.\\n"
		if ! mkdir -p "${HOME}/opt/" 2>/dev/null
		then
157
			printf "\\n\\tUnable to create directory %s/opt.\\n" "${HOME}"
158 159 160 161 162
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! cd "${HOME}/opt"
		then
163
			printf "\\n\\tUnable to enter directory %s/opt.\\n" "${HOME}"
164 165 166 167
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		STATUS=$( curl -LO -w '%{http_code}' --connect-timeout 30 "https://cmake.org/files/v3.10/cmake-3.10.2.tar.gz" )
168
		if [ "${STATUS}" -ne 200 ]; then
169
			printf "\\tUnable to clone CMAKE repo.\\n"
170 171
			printf "\\tExiting now.\\n\\n"
			exit 1;
172
		fi
173
		if ! tar xf "${HOME}/opt/cmake-3.10.2.tar.gz"
174
		then
175
			printf "\\tUnable to unarchive file %s/opt/cmake-3.10.2.tar.gz at this time.\\n" "${HOME}"
176 177
			printf "\\tExiting now.\\n\\n"
			exit 1;
178
		fi
179
		if ! rm -f "${HOME}/opt/cmake-3.10.2.tar.gz"
180
		then
181
			printf "\\tUnable to remove file %s/opt/cmake-3.10.2.tar.gz.\\n" "${HOME}"
182 183 184 185 186
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! ln -s "${HOME}/opt/cmake-3.10.2/" "${HOME}/opt/cmake"
		then
187
			printf "\\tUnable to symlink directory %s/opt/cmake-3.10.2/ to %s/opt/cmake at this time.\\n" "${HOME}" "${HOME}"
188 189 190 191 192
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! cd "${HOME}/opt/cmake/"
		then
193
			printf "\\n\\tUnable to change directory into %s/opt/cmake.\\n" "${HOME}"
194 195 196 197 198
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! ./bootstrap
		then
199
			printf "\\tRunning bootstrap for CMAKE exited with the above error.\\n"
200 201 202
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
203
		if ! make -j"${JOBS}"
204 205 206 207
		then
			printf "\\tError compiling CMAKE.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
208
		fi
209
		printf "\\tCMAKE successfully installed @ %s.\\n" "${CMAKE}"
210
	else
211
		printf "\\tCMAKE found @ %s.\\n" "${CMAKE}"
212 213
	fi

214 215 216
	if [ -d "${HOME}/opt/boost_1_67_0" ]; then
		if ! mv "${HOME}/opt/boost_1_67_0" "$BOOST_ROOT"
		then
217
			printf "\\n\\tUnable to move directory %s/opt/boost_1_67_0 to %s.\\n" "${HOME}" "${BOOST_ROOT}"
218 219 220 221 222 223 224 225 226 227 228 229 230
			printf "\\n\\tExiting now.\\n"
			exit 1
		fi
		if [ -d "$BUILD_DIR" ]; then
			if ! rm -rf "$BUILD_DIR"
			then
			printf "\\tUnable to remove directory %s. Please remove this directory and run this script %s again. 0\\n" "$BUILD_DIR" "${BASH_SOURCE[0]}"
			printf "\\tExiting now.\\n\\n"
			exit 1;
			fi
		fi
	fi
	
231 232 233
	printf "\\n\\tChecking boost library installation.\\n"
	BVERSION=$( grep "BOOST_LIB_VERSION" "${BOOST_ROOT}/include/boost/version.hpp" 2>/dev/null \
	| tail -1 | tr -s ' ' | cut -d\  -f3 | sed 's/[^0-9\._]//gI' )
234
	if [ "${BVERSION}" != "1_67" ]; then
235
		printf "\\tRemoving existing boost libraries in %s/opt/boost*.\\n" "${HOME}"
236
		if ! rm -rf "${HOME}"/opt/boost*
237 238 239
		then
			printf "\\n\\tUnable to remove deprecated boost libraries at this time.\\n"
			printf "\\n\\tExiting now.\\n"
240 241
			exit 1
		fi
242 243 244 245 246 247 248 249
		printf "\\tInstalling boost libraries.\\n"
		if ! cd "${TEMP_DIR}"
		then
			printf "\\n\\tUnable to cd into directory %s at this time.\\n" "${TEMP_DIR}"
			printf "\\n\\tExiting now.\\n"
			exit 1
		fi
		STATUS=$(curl -LO -w '%{http_code}' --connect-timeout 30 \
250
		"https://dl.bintray.com/boostorg/release/1.67.0/source/boost_1_67_0.tar.bz2" )
251
		if [ "${STATUS}" -ne 200 ]; then
252 253 254 255
			printf "\\tUnable to download Boost libraries at this time.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
256
		if ! tar xf "${TEMP_DIR}/boost_1_67_0.tar.bz2"
257
		then
258
			printf "\\tUnable to decompress Boost libraries @ %s/boost_1_67_0.tar.bz2 at this time.\\n" "${TEMP_DIR}"
259 260 261
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
262
		if ! rm -f  "${TEMP_DIR}/boost_1_67_0.tar.bz2"
263
		then
264
			printf "\\tUnable to remove Boost libraries @ %s/boost_1_67_0.tar.bz2 at this time.\\n" "${TEMP_DIR}"
265 266 267
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
268
		if ! cd "${TEMP_DIR}/boost_1_67_0/"
269
		then
270
			printf "\\tUnable to change directory into %s/boost_1_67_0/ at this time.\\n" "${TEMP_DIR}"
271 272
			printf "\\tExiting now.\\n\\n"
			exit 1;
273
		fi
274
		if ! ./bootstrap.sh "--prefix=${BOOST_ROOT}"
275 276 277
		then
			printf "\\n\\tInstallation of boost libraries failed. 0\\n"
			printf "\\n\\tExiting now.\\n"
278 279
			exit 1
		fi
280
		if ! "${TEMP_DIR}"/boost_1_67_0/b2 install
281 282 283 284 285
		then
			printf "\\n\\tInstallation of boost libraries failed. 1\\n"
			printf "\\n\\tExiting now.\\n"
			exit 1
		fi
286
		if ! rm -rf "${TEMP_DIR}/boost_1_67_0/"
287
		then
288
			printf "\\n\\tUnable to remove boost libraries directory @ %s/boost_1_67_0/.\\n" "${TEMP_DIR}"
289
			printf "\\n\\tExiting now.\\n"
290 291
			exit 1
		fi
292 293 294 295 296 297 298 299
		if [ -d "$BUILD_DIR" ]; then
			if ! rm -rf "$BUILD_DIR"
			then
			printf "\\tUnable to remove directory %s. Please remove this directory and run this script %s again. 0\\n" "$BUILD_DIR" "${BASH_SOURCE[0]}"
			printf "\\tExiting now.\\n\\n"
			exit 1;
			fi
		fi
300
		printf "\\tBoost successfully installed @ %s.\\n" "${BOOST_ROOT}"
301
	else
302
		printf "\\tBoost found at %s.\\n" "${BOOST_ROOT}"
303 304
	fi

305 306 307 308 309
	printf "\\n\\tChecking MongoDB installation.\\n"
	if [ ! -e "${MONGOD_CONF}" ]; then
		printf "\\tInstalling MongoDB 3.6.3.\\n"
		if ! cd "${HOME}/opt"
		then
310
			printf "\\n\\tUnable to cd into directory %s/opt.\\n" "${HOME}"
311 312 313 314 315
			printf "\\n\\tExiting now.\\n"
			exit 1;
		fi
		STATUS=$( curl -LO -w '%{http_code}' --connect-timeout 30 \
		"https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-3.6.3.tgz" )
316
		if [ "${STATUS}" -ne 200 ]; then
317 318 319 320 321 322 323 324 325 326 327 328 329
			printf "\\tUnable to download MongoDB at this time.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! tar xf "${HOME}/opt/mongodb-linux-x86_64-amazon-3.6.3.tgz"
		then
			printf "\\tUnable to decompress file %s at this time.\\n" \
			"${HOME}/opt/mongodb-linux-x86_64-amazon-3.6.3.tgz"
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! rm -f "${HOME}/opt/mongodb-linux-x86_64-amazon-3.6.3.tgz"
		then
330
			printf "\\tUnable to remove file %s/opt/mongodb-linux-x86_64-amazon-3.6.3.tgz at this time.\\n" "${HOME}"
331 332 333 334 335
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! ln -s "${HOME}/opt/mongodb-linux-x86_64-amazon-3.6.3/" "${HOME}/opt/mongodb"
		then
336 337
			printf "\\tUnable to symlink directory %s/opt/mongodb-linux-x86_64-amazon-3.6.3/ to directory %s/opt/mongodb at this time.\\n" \
			"${HOME}" "${HOME}"
338 339 340 341 342
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! mkdir "${HOME}/opt/mongodb/data"
		then
343
			printf "\\tUnable to create directory %s/opt/mongodb/data at this time.\\n" "${HOME}"
344 345 346 347 348
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! mkdir "${HOME}/opt/mongodb/log"
		then
349
			printf "\\tUnable to make directory %s/opt/mongodb/log at this time.\\n" "${HOME}"
350 351 352 353 354
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! touch "${HOME}/opt/mongodb/log/mongodb.log"
		then
355
			printf "\\tUnable to create log file @ %s/opt/mongodb/log/mongodb.log at this time.\\n" "${HOME}"
356 357
			printf "\\tExiting now.\\n\\n"
			exit 1;
358 359
		fi
		
360
if ! tee > "/dev/null" "${MONGOD_CONF}" <<mongodconf
361 362
systemLog:
 destination: file
363
 path: ${HOME}/opt/mongodb/log/mongodb.log
364 365 366 367 368 369 370 371
 logAppend: true
 logRotate: reopen
net:
 bindIp: 127.0.0.1,::1
 ipv6: true
storage:
 dbPath: ${HOME}/opt/mongodb/data
mongodconf
372
then
373
	printf "\\tUnable to create mongodb config file @ %s/opt/mongodb/log/mongodb.log at this time.\\n" "${HOME}"
374 375 376 377
	printf "\\tExiting now.\\n\\n"
	exit 1;
fi
		printf "\\n\\n\\tMongoDB successfully installed.\\n\\tConfiguration file @ %s.\\n\\n" "${MONGOD_CONF}"
378 379

	else
380
		printf "\\tMongoDB configuration found at %s.\\n" "${MONGOD_CONF}"
381
	fi
382 383

	printf "\\n\\tChecking MongoDB C++ driver installation.\\n"
384
	if [ ! -e "/usr/local/lib/libmongocxx-static.a" ]; then
385 386 387 388 389 390 391 392
		if ! cd "${TEMP_DIR}"
		then
			printf "\\n\\tUnable to cd into directory %s.\\n" "${TEMP_DIR}"
			printf "\\n\\tExiting now.\\n"
			exit 1;
		fi
		STATUS=$(curl -LO -w '%{http_code}' --connect-timeout 30 \
		"https://github.com/mongodb/mongo-c-driver/releases/download/1.9.3/mongo-c-driver-1.9.3.tar.gz" )
393
		if [ "${STATUS}" -ne 200 ]; then
394 395 396 397
			rm -f "${TEMP_DIR}/mongo-c-driver-1.9.3.tar.gz"
			printf "\\tUnable to download MongoDB C driver at this time.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
398
		fi
399 400
		if ! tar xf "${TEMP_DIR}/mongo-c-driver-1.9.3.tar.gz"
		then
401
			printf "\\n\\tUnable to decompress file  %s/mongo-c-driver-1.9.3.tar.gz.\\n" "${TEMP_DIR}"
402 403
			printf "\\n\\tExiting now.\\n"
			exit 1;
404
		fi
405 406
		if ! rm -f "${TEMP_DIR}/mongo-c-driver-1.9.3.tar.gz"
		then
407
			printf "\\n\\tUnable to remove file  %s/mongo-c-driver-1.9.3.tar.gz.\\n" "${TEMP_DIR}"
408 409
			printf "\\n\\tExiting now.\\n"
			exit 1;
410
		fi
411 412
		if ! cd "${TEMP_DIR}/mongo-c-driver-1.9.3"
		then
413
			printf "\\n\\tUnable to change directory info  %s/mongo-c-driver-1.9.3.\\n" "${TEMP_DIR}"
414 415
			printf "\\n\\tExiting now.\\n"
			exit 1;
416
		fi
417 418
		if ! ./configure --enable-static --with-libbson=bundled --enable-ssl=openssl --disable-automatic-init-and-cleanup --prefix=/usr/local
		then
419
			printf "\\tConfiguring MongoDB C driver has encountered the above errors.\\n"
420 421
			printf "\\tExiting now.\\n\\n"
			exit 1;
422
		fi
423
		if ! make -j"${JOBS}"
424 425 426 427
		then
			printf "\\tError compiling MongoDB C driver.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
428
		fi
429 430 431 432 433 434 435 436 437 438 439 440 441 442
		if ! sudo make install
		then
			printf "\\tError installing MongoDB C driver.\\nMake sure you have sudo privileges.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! cd "${TEMP_DIR}"
		then
			printf "\\n\\tUnable to cd into directory %s.\\n" "${TEMP_DIR}"
			printf "\\n\\tExiting now.\\n"
			exit 1;
		fi
		if ! rm -rf "${TEMP_DIR}/mongo-c-driver-1.9.3"
		then
443
			printf "\\n\\tUnable to remove  directory %s/mongo-c-driver-1.9.3.\\n" "${TEMP_DIR}"
444 445
			printf "\\n\\tExiting now.\\n"
			exit 1;
446
		fi
447
		if ! git clone https://github.com/mongodb/mongo-cxx-driver.git --branch releases/v3.2 --depth 1
448 449 450
		then
			printf "\\tUnable to clone MongoDB C++ driver at this time.\\n"
			printf "\\tExiting now.\\n\\n"
451 452
			exit;
		fi
453 454
		if ! cd "${TEMP_DIR}/mongo-cxx-driver/build"
		then
455
			printf "\\n\\tUnable to enter directory %s/mongo-cxx-driver/build.\\n" "${TEMP_DIR}"
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
			printf "\\n\\tExiting now.\\n"
			exit 1;
		fi
		
		if ! "${CMAKE}" -DBUILD_SHARED_LIBS="OFF" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_INSTALL_PREFIX="/usr/local" "${TEMP_DIR}/mongo-cxx-driver"
		then
			printf "\\tCmake has encountered the above errors building the MongoDB C++ driver.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! sudo make -j"${JOBS}"
		then
			printf "\\tError compiling MongoDB C++ driver.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! sudo make install
		then
			printf "\\tError installing MongoDB C++ driver.\\nMake sure you have sudo privileges.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! cd "${TEMP_DIR}"
		then
			printf "\\n\\tUnable to cd into directory %s.\\n" "${TEMP_DIR}"
			printf "\\n\\tExiting now.\\n"
			exit 1;
		fi
		if ! sudo rm -rf "${TEMP_DIR}/mongo-cxx-driver"
		then
486
			printf "\\n\\tUnable to remove directory %s/mongo-cxx-driver.\\n" "${TEMP_DIR}"
487 488 489
			printf "\\n\\tExiting now.\\n"
			exit 1;
		fi
490
		printf "\\tSuccessfully installed Mongo C/C++ drivers found at /usr/local/lib.\\n"
491
	else
492
		printf "\\tMongo C++ driver found at /usr/local/lib.\\n"
493 494
	fi

495
	printf "\\n\\tChecking secp256k1-zkp installation.\\n"
496
    # install secp256k1-zkp (Cryptonomex branch)
497 498 499 500
    if [ ! -e "/usr/local/lib/libsecp256k1.a" ]; then
		printf "\\tInstalling secp256k1-zkp (Cryptonomex branch).\\n"
		if ! cd "${TEMP_DIR}"
		then
501
			printf "\\n\\tUnable to enter directory %s.\\n" "${TEMP_DIR}"
502 503
			printf "\\n\\tExiting now.\\n"
			exit 1;
504
		fi
505 506 507 508 509
		if ! git clone https://github.com/cryptonomex/secp256k1-zkp.git
		then
			printf "\\tUnable to clone repo secp256k1-zkp @ https://github.com/cryptonomex/secp256k1-zkp.git.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
510
		fi
511 512
		if ! cd "${TEMP_DIR}/secp256k1-zkp"
		then
513
			printf "\\n\\tUnable to cd into directory %s/secp256k1-zkp.\\n" "${TEMP_DIR}"
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
			printf "\\n\\tExiting now.\\n"
			exit 1;
		fi
		if ! ./autogen.sh
		then
			printf "\\tError running autogen for secp256k1-zkp.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! ./configure
		then
			printf "\\tError running configure for secp256k1-zkp.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! make -j"${JOBS}"
		then
			printf "\\tError compiling secp256k1-zkp.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! sudo make install
		then
			printf "\\tError installing secp256k1-zkp.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
540
		fi
541 542
		if ! rm -rf "${TEMP_DIR}/secp256k1-zkp"
		then
543
			printf "\\tError removing directory %s/secp256k1-zkp.\\n" "${TEMP_DIR}"
544 545 546 547
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		printf "\\tsecp256k1 successfully installed @ /usr/local/lib/libsecp256k1.a.\\n"
548
	else
549
		printf "\\tsecp256k1 found @ /usr/local/lib/libsecp256k1.a.\\n"
550
	fi
551

552 553 554 555 556 557 558 559
	printf "\\n\\tChecking LLVM with WASM support.\\n"
	if [ ! -d "${HOME}/opt/wasm/bin" ]; then
		printf "\\tInstalling LLVM & WASM.\\n"
		if ! cd "${TEMP_DIR}"
		then
			printf "\\n\\tUnable to cd into directory %s.\\n" "${TEMP_DIR}"
			printf "\\n\\tExiting now.\\n"
			exit 1;
560
		fi
561 562
		if ! mkdir "${TEMP_DIR}/llvm-compiler"  2>/dev/null
		then
563
			printf "\\n\\tUnable to make directory %s/llvm-compiler.\\n" "${TEMP_DIR}"
564 565
			printf "\\n\\tExiting now.\\n"
			exit 1;
566
		fi
567 568
		if ! cd "${TEMP_DIR}/llvm-compiler"
		then
569
			printf "\\n\\tUnable to change directory into %s/llvm-compiler.\\n" "${TEMP_DIR}"
570 571
			printf "\\n\\tExiting now.\\n"
			exit 1;
572
		fi
573 574 575 576
		if ! git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/llvm.git
		then
			printf "\\tUnable to clone llvm repo @ https://github.com/llvm-mirror/llvm.git.\\n"
			printf "\\tExiting now.\\n\\n"
577 578
			exit;
		fi
579 580
		if ! cd "${TEMP_DIR}/llvm-compiler/llvm/tools"
		then
581
			printf "\\n\\tUnable to change directory into %s/llvm-compiler/llvm/tools.\\n" "${TEMP_DIR}"
582 583 584 585 586 587 588 589 590 591 592
			printf "\\n\\tExiting now.\\n"
			exit 1;
		fi
		if ! git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/clang.git
		then
			printf "\\tUnable to clone clang repo @ https://github.com/llvm-mirror/clang.git.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! cd "${TEMP_DIR}/llvm-compiler/llvm"
		then
593
			printf "\\n\\tUnable to change directory into %s/llvm-compiler/llvm.\\n" "${TEMP_DIR}"
594 595 596 597 598
			printf "\\n\\tExiting now.\\n"
			exit 1;
		fi
		if ! mkdir "${TEMP_DIR}/llvm-compiler/llvm/build" 2>/dev/null
		then
599
			printf "\\n\\tUnable to create directory %s/llvm-compiler/llvm/build.\\n" "${TEMP_DIR}"
600 601 602 603 604
			printf "\\n\\tExiting now.\\n"
			exit 1;
		fi
		if ! cd "${TEMP_DIR}/llvm-compiler/llvm/build"
		then
605
			printf "\\n\\tUnable to change directory into %s/llvm-compiler/llvm/build.\\n" "${TEMP_DIR}"
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
			printf "\\n\\tExiting now.\\n"
			exit 1;
		fi
		if ! "$CMAKE" -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="${HOME}/opt/wasm" \
		-DLLVM_ENABLE_RTTI=1 -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" \
		-DCMAKE_BUILD_TYPE="Release" ..
		then
			printf "\\tError compiling LLVM and clang with EXPERIMENTAL WASM support.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! make -j"${JOBS}"
		then
			printf "\\tError compiling LLVM and clang with EXPERIMENTAL WASM support.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! make install
		then
			printf "\\tError installing LLVM and clang with EXPERIMENTAL WASM support.\\n"
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
		if ! rm -rf "${TEMP_DIR}/llvm-compiler" 2>/dev/null
		then
631
			printf "\\tError removing directory %s/llvm-compiler.\\n" "${TEMP_DIR}"
632 633 634
			printf "\\tExiting now.\\n\\n"
			exit 1;
		fi
635
		printf "\\tWASM successfully installed at %s/opt/wasm.\\n" "${HOME}"
636
	else
637
		printf "\\tWASM found at %s/opt/wasm.\\n" "${HOME}"
638
	fi
B
Bill Hamilton 已提交
639 640 641

	function print_instructions()
	{
642 643 644
		printf "\\n\\t%s -f %s &\\n" "$( command -v mongod )" "${MONGOD_CONF}"
		printf '\texport PATH=${HOME}/opt/mongodb/bin:$PATH \n'
		printf "\\tcd %s; make test\\n\\n" "${BUILD_DIR}"
B
Bill Hamilton 已提交
645 646
	return 0
	}