From e664a075b3523098b63ad6b64dc010c51ddba39b Mon Sep 17 00:00:00 2001 From: Bill Hamilton Date: Wed, 9 May 2018 08:27:19 -0700 Subject: [PATCH] darwin: added check for cmake cache file in eos/ doc root --- eosio_build.sh | 4 + scripts/eosio_build_darwin.sh | 611 +++++++++++++++++++++------------- 2 files changed, 377 insertions(+), 238 deletions(-) diff --git a/eosio_build.sh b/eosio_build.sh index 6ab290a57..66e4f3195 100755 --- a/eosio_build.sh +++ b/eosio_build.sh @@ -35,6 +35,10 @@ printf "\\n\\tPlease cd into directory %s to run this script.\\n \\tExiting now.\\n\\n" "${CWD}" exit 1 fi + if [ -f "${PWD}/CMakeCache.txt" ]; then + printf "\\n\\tPlease remove file %s/CMakeCache.txt before building EOS.IO.\\n \\tExiting now.\\n\\n" "${PWD}" + exit 1 + fi function usage() { diff --git a/scripts/eosio_build_darwin.sh b/scripts/eosio_build_darwin.sh index 7339dc362..e4cba0fa9 100644 --- a/scripts/eosio_build_darwin.sh +++ b/scripts/eosio_build_darwin.sh @@ -1,77 +1,81 @@ - OS_VER=`sw_vers -productVersion` - OS_MAJ=`echo "${OS_VER}" | cut -d'.' -f1` - OS_MIN=`echo "${OS_VER}" | cut -d'.' -f2` - OS_PATCH=`echo "${OS_VER}" | cut -d'.' -f3` + OS_VER=$(sw_vers -productVersion) + OS_MAJ=$(echo "${OS_VER}" | cut -d'.' -f1) + OS_MIN=$(echo "${OS_VER}" | cut -d'.' -f2) + OS_PATCH=$(echo "${OS_VER}" | cut -d'.' -f3) - MEM_GIG=`bc <<< "($(sysctl -in hw.memsize) / 1024000000)"` + MEM_GIG=$(bc <<< "($(sysctl -in hw.memsize) / 1024000000)") - CPU_SPEED=`bc <<< "scale=2; ($(sysctl -in hw.cpufrequency) / 10^6) / 10"` + CPU_SPEED=$(bc <<< "scale=2; ($(sysctl -in hw.cpufrequency) / 10^6) / 10") CPU_CORE=$( sysctl -in machdep.cpu.core_count ) - blksize=`df . | head -1 | awk '{print $2}' | cut -d- -f1` - gbfactor=$(( 1073741824 / $blksize )) - total_blks=`df . | tail -1 | awk '{print $2}'` - avail_blks=`df . | tail -1 | awk '{print $4}'` - DISK_TOTAL=$(($total_blks / $gbfactor )) - DISK_AVAIL=$(($avail_blks / $gbfactor )) + DISK_INSTALL=$(df -h . | tail -1 | tr -s ' ' | cut -d\ -f1 || cut -d' ' -f1) + blksize=$(df . | head -1 | awk '{print $2}' | cut -d- -f1) + gbfactor=$(( 1073741824 / blksize )) + total_blks=$(df . | tail -1 | awk '{print $2}') + avail_blks=$(df . | tail -1 | awk '{print $4}') + DISK_TOTAL=$((total_blks / gbfactor )) + DISK_AVAIL=$((avail_blks / gbfactor )) - printf "\n\tOS name: $ARCH\n" - printf "\tOS Version: ${OS_VER}\n" - printf "\tCPU speed: ${CPU_SPEED}Ghz\n" - printf "\tCPU cores: $CPU_CORE\n" - printf "\tPhysical Memory: $MEM_GIG Gbytes\n" - printf "\tDisk space total: ${DISK_TOTAL}G\n" - printf "\tDisk space available: ${DISK_AVAIL}G\n\n" + printf "\\n\\tOS name: %s\\n" "${ARCH}" + printf "\\tOS Version: %s\\n" "${OS_VER}" + printf "\\tCPU speed: %sGhz\\n" "${CPU_SPEED}" + printf "\\tCPU cores: %s\\n" "${CPU_CORE}" + printf "\\tPhysical Memory: %s Gbytes\\n" "${MEM_GIG}" + printf "\\tDisk install: %s\\n" "${DISK_INSTALL}" + printf "\\tDisk space total: %sG\\n" "${DISK_TOTAL}" + printf "\\tDisk space available: %sG\\n\\n" "${DISK_AVAIL}" - if [ $MEM_GIG -lt 7 ]; then + if [ "${MEM_GIG}" -lt 7 ]; then echo "Your system must have 7 or more Gigabytes of physical memory installed." echo "Exiting now." exit 1 fi - if [ $OS_MIN -lt 12 ]; then + if [ "${OS_MIN}" -lt 12 ]; then echo "You must be running Mac OS 10.12.x or higher to install EOSIO." echo "Exiting now." exit 1 fi - if [ $DISK_AVAIL -lt $DISK_MIN ]; then + if [ "${DISK_AVAIL}" -lt "$DISK_MIN" ]; then echo "You must have at least ${DISK_MIN}GB of available storage to install EOSIO." echo "Exiting now." exit 1 fi - printf "\tChecking XCode installation\n" - XCODESELECT=$(which xcode-select) - if [ $? -ne 0 ]; then - printf "\n\tXCode must be installed in order to proceed.\n\n" - printf "\texiting now.\n" + printf "\\tChecking xcode-select installation\\n" + if ! XCODESELECT=$( command -v xcode-select) + then + printf "\\n\\tXCode must be installed in order to proceed.\\n\\n" + printf "\\tExiting now.\\n" exit 1 fi - printf "\tXCode installation found.\n\n" + printf "\\txcode-select installation found @ \\n" + printf "\\t%s \\n\\n" "${XCODESELECT}" - printf "\tChecking Ruby installation\n" - RUBY=$(which ruby) - if [ $? -ne 0 ]; then - printf "\nRuby must be installed in order to proceed.\n\n" - printf "\texiting now.\n" + printf "\\tChecking Ruby installation.\\n" + if ! RUBY=$( command -v ruby) + then + printf "\\nRuby must be installed in order to proceed.\\n\\n" + printf "\\tExiting now.\\n" exit 1 fi - printf "\tRuby installation found.\n\n" - - printf "\tChecking Home Brew installation\n" - BREW=$(which brew) - if [ $? -ne 0 ]; then - printf "\tHomebrew must be installed to compile EOS.IO\n\n" - printf "\tDo you wish to install Home Brew?\n" + printf "\\tRuby installation found @ \\n" + printf "\\t%s \\n\\n" "${RUBY}" + + printf "\\tChecking Home Brew installation\\n" + if ! BREW=$( command -v brew ) + then + printf "\\tHomebrew must be installed to compile EOS.IO\\n\\n" + printf "\\tDo you wish to install Home Brew?\\n" select yn in "Yes" "No"; do - case $yn in + case "${yn}" in [Yy]* ) - $XCODESELECT --install 2>/dev/null; - $RUBY -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - if [ $? -ne 0 ]; then + "${XCODESELECT}" --install 2>/dev/null; + if ! "${RUBY}" -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + then echo "Unable to install homebrew at this time. Exiting now." exit 1; fi @@ -83,82 +87,80 @@ done fi - printf "\tHome Brew installation found.\n\n" + printf "\\tHome Brew installation found @\\n" + printf "\\t%s\\n\\n" "${BREW}" + COUNT=1 PERMISSION_GETTEXT=0 - BOOST_CHECK=0 DISPLAY="" DEP="" - printf "\tChecking dependencies.\n" - var_ifs=${IFS} - IFS=',' + printf "\\tChecking dependencies.\\n" + var_ifs="${IFS}" + IFS="," while read -r name tester testee brewname uri do - printf "\tChecking $name ... " - if [ ${tester} ${testee} ]; then - printf '\t\t %s found\n' "$name" + printf "\\tChecking %s ... " "${name}" + if [ "${tester}" "${testee}" ]; then + printf "\\t\\t %s found\\n" "${name}" continue fi # resolve conflict with homebrew glibtool and apple/gnu installs of libtool - if [ ${testee} == "/usr/local/bin/glibtool" ]; then - if [ ${tester} "/usr/local/bin/libtool" ]; then - printf '\t\t %s found\n' "$name" + if [ "${testee}" == "/usr/local/bin/glibtool" ]; then + if [ "${tester}" "/usr/local/bin/libtool" ]; then + printf "\\t\\t %s found\\n" "${name}" continue fi fi - if [ $brewname = "gettext" ]; then + if [ "${brewname}" = "gettext" ]; then PERMISSION_GETTEXT=1 fi DEP=$DEP"${brewname} " - DISPLAY="${DISPLAY}${COUNT}. ${name}\n\t" - printf "\t\t ${name} ${bldred}NOT${txtrst} found.\n" - let COUNT++ + DISPLAY="${DISPLAY}${COUNT}. ${name}\\n\\t" + printf "\\t\\t %s ${bldred}NOT${txtrst} found.\\n" "${name}" + (( COUNT++ )) done < scripts/eosio_build_dep - IFS=${var_ifs} + IFS="${var_ifs}" - printf "\tChecking Python3 ... " - if [ -z `python3 -c 'import sys; print(sys.version_info.major)' 2>/dev/null` ]; then + printf "\\tChecking Python3 ... " + if [ -z "$( python3 -c 'import sys; print(sys.version_info.major)' 2>/dev/null )" ]; then DEP=$DEP"python@3 " - DISPLAY="${DISPLAY}${COUNT}. Python 3\n\t" - printf "\t\t python3 ${bldred}NOT${txtrst} found.\n" - let DCOUNT++ + DISPLAY="${DISPLAY}${COUNT}. Python 3\\n\\t" + printf "\\t\\t python3 ${bldred}NOT${txtrst} found.\\n" + (( DCOUNT++ )) else - printf "\t\t Python3 found\n" + printf "\\t\\t Python3 found\\n" fi if [ $COUNT -gt 1 ]; then - printf "\n\tThe following dependencies are required to install EOSIO.\n" - printf "\n\t$DISPLAY\n\n" + printf "\\n\\tThe following dependencies are required to install EOSIO.\\n" + printf "\\n\\t%s\\n\\n" "${DISPLAY}" echo "Do you wish to install these packages?" select yn in "Yes" "No"; do case $yn in [Yy]* ) if [ $PERMISSION_GETTEXT -eq 1 ]; then - sudo chown -R $(whoami) /usr/local/share + sudo chown -R "$(whoami)" /usr/local/share fi - $XCODESELECT --install 2>/dev/null; - printf "\tUpdating Home Brew.\n" - brew update - if [ $? -ne 0 ]; then - printf "\tUnable to update Home Brew at this time.\n" - printf "\tExiting now.\n\n" + "${XCODESELECT}" --install 2>/dev/null; + printf "\\tUpdating Home Brew.\\n" + if ! brew update + then + printf "\\tUnable to update Home Brew at this time.\\n" + printf "\\tExiting now.\\n\\n" exit 1; fi - printf "\tInstalling Dependencies.\n" - if [ "${BOOST_CHECK}" = 1 ]; then - brew remove boost - fi - brew install --force $DEP - if [ $? -ne 0 ]; then - printf "\tHomebrew exited with the above errors.\n" - printf "\tExiting now.\n\n" + printf "\\tInstalling Dependencies.\\n" + if ! "${BREW}" install --force "${DEP}" + then + printf "\\tHomebrew exited with the above errors.\\n" + printf "\\tExiting now.\\n\\n" exit 1; fi - brew unlink $DEP && brew link --force $DEP - if [ $? -ne 0 ]; then - printf "\tHomebrew exited with the above errors.\n" - printf "\tExiting now.\n\n" + if ! "${BREW}" unlink "{DEP}" && "${BREW}" link --force "${DEP}" + then + printf "\\tHomebrew exited with the above errors.\\n" + printf "\\tExiting now.\\n\\n" exit 1; fi break;; @@ -167,41 +169,42 @@ esac done else - printf "\n\tNo required Home Brew dependencies to install.\n" + printf "\\n\\tNo required Home Brew dependencies to install.\\n" fi + - printf "\n\tChecking boost library installation.\n" - BVERSION=`cat "/usr/local/include/boost/version.hpp" 2>/dev/null | grep "#define BOOST_VERSION" | tail -1 | tr -s ' ' | cut -d\ -f3` + printf "\\n\\tChecking boost library installation.\\n" + BVERSION=$( grep "#define BOOST_VERSION" "/usr/local/include/boost/version.hpp" 2>/dev/null | tail -1 | tr -s ' ' | cut -d\ -f3 ) if [ "${BVERSION}" != "106600" ]; then if [ ! -z "${BVERSION}" ]; then - printf "\tFound Boost Version ${BVERSION}.\n" - printf "\tEOS.IO requires Boost version 1.66.\n" - printf "\tWould you like to uninstall version ${BVERSION} and install Boost version 1.66.\n" + printf "\\tFound Boost Version %s.\\n" "${BVERSION}" + printf "\\tEOS.IO requires Boost version 1.66.\\n" + printf "\\tWould you like to uninstall version %s and install Boost version 1.66.\\n" "${BVERSION}" select yn in "Yes" "No"; do case $yn in [Yy]* ) if brew list | grep "boost" then - printf "\tUnlinking Boost Version ${BVERSION}.\n" - echo unlinking boost "${BVERSION}" - if ! brew unlink boost + printf "\\tUnlinking Boost Version %s.\\n" "${BVERSION}" + printff "\\tunlinking boost %s\\n" "${BVERSION}" + if ! "${BREW}" unlink boost then - printf "\tUnable to remove boost libraries at this time. 0\n" - printf "\tExiting now.\n\n" + printf "\\tUnable to remove boost libraries at this time. 0\\n" + printf "\\tExiting now.\\n\\n" exit 1; fi else - printf "\tRemoving Boost Version ${BVERSION}.\n" - sudo rm -rf "${BOOST_ROOT}/include/boost" - if [ $? -ne 0 ]; then - printf "\tUnable to remove boost libraries at this time. 1\n" - printf "\tExiting now.\n\n" + printf "\\tRemoving Boost Version %s.\\n" "${BVERSION}" + if ! sudo rm -rf "${BOOST_ROOT}/include/boost" + then + printf "\\tUnable to remove boost libraries at this time. 1\\n" + printf "\\tExiting now.\\n\\n" exit 1; fi - sudo rm -rf "${BOOST_ROOT}/lib/libboost*" - if [ $? -ne 0 ]; then - printf "\tUnable to remove boost libraries at this time. 2\n" - printf "\tExiting now.\n\n" + if ! sudo rm -rf "${BOOST_ROOT}/lib/libboost*" + then + printf "\\tUnable to remove boost libraries at this time. 2\\n" + printf "\\tExiting now.\\n\\n" exit 1; fi fi @@ -211,170 +214,302 @@ esac done fi - printf "\tInstalling boost libraries.\n" + printf "\\tInstalling boost libraries.\\n" if [ ! -d "/usr/local/Cellar/boost/1.66.0" ]; then if ! brew install "https://raw.githubusercontent.com/Homebrew/homebrew-core/76a83d798d76aa43459ceb145b721ba4a16a54a6/Formula/boost.rb" then - printf "\tUnable to install boost 1.66 libraries at this time. 0\n" - printf "\tExiting now.\n\n" - exit; + printf "\\tUnable to install boost 1.66 libraries at this time. 0\\n" + printf "\\tExiting now.\\n\\n" + exit 1; fi - printf "\tPinning boost libraries.\n" + printf "\\tPinning boost libraries.\\n" if ! brew pin boost then - printf "\tUnable to pin boost libraries at this time. 2\n" - printf "\tExiting now.\n\n" - exit; + printf "\\tUnable to pin boost libraries at this time. 2\\n" + printf "\\tExiting now.\\n\\n" + exit 1; fi else if ! brew switch boost 1.66.0 then - printf "\tUnable to swtich boost libraries to 1.66.0 at this time. 1\n" - printf "\tExiting now.\n\n" + printf "\\tUnable to swtich boost libraries to 1.66.0 at this time. 1\\n" + printf "\\tExiting now.\\n\\n" exit; fi fi - printf "\tBoost 1.66.0 successfully installed @ /usr/local.\n" + printf "\\tBoost 1.66.0 successfully installed @ /usr/local.\\n" else - printf "\tBoost 1.66.0 found at /usr/local.\n" + printf "\\tBoost 1.66.0 found at /usr/local.\\n" fi - printf "\n\tChecking MongoDB C++ driver installation.\n" - if [ ! -e /usr/local/lib/libmongocxx-static.a ]; then - cd ${TEMP_DIR} - brew install --force pkgconfig - brew unlink pkgconfig && brew link --force pkgconfig + printf "\\n\\tChecking MongoDB C++ driver installation.\\n" + if [ ! -e "/usr/local/lib/libmongocxx-static.a" ]; then + if ! cd "${TEMP_DIR}" + then + printf "\\tUnable to enter directory %s.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! pkgconfig=$( "${BREW}" list | grep pkg-config ) + then + if ! "${BREW}" install --force pkg-config + then + printf "\\tHomebrew returned an error installing pkg-config.\\n" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! "${BREW}" unlink pkg-config && "${BREW}" link --force pkg-config + then + printf "\\tHomebrew returned an error linking pkgconfig.\\n" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + 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) if [ "${STATUS}" -ne 200 ]; then - 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; - fi - tar xf mongo-c-driver-1.9.3.tar.gz - rm -f ${TEMP_DIR}/mongo-c-driver-1.9.3.tar.gz - cd mongo-c-driver-1.9.3 - ./configure --enable-static --with-libbson=bundled --enable-ssl=darwin --disable-automatic-init-and-cleanup --prefix=/usr/local - if [ $? -ne 0 ]; then - printf "\tConfiguring MongoDB C driver has encountered the errors above.\n" - printf "\tExiting now.\n\n" - exit; - fi - make -j${CPU_CORE} - if [ $? -ne 0 ]; then - printf "\tError compiling MongoDB C driver.\n" - printf "\tExiting now.\n\n" - exit; - fi - sudo make install - if [ $? -ne 0 ]; then - printf "\tError installing MongoDB C driver.\nMake sure you have sudo privileges.\n" - printf "\tExiting now.\n\n" - exit; - fi - cd .. - rm -rf ${TEMP_DIR}/mongo-c-driver-1.9.3 - cd ${TEMP_DIR} - rm -rf ${TEMP_DIR}/mongo-cxx-driver - git clone https://github.com/mongodb/mongo-cxx-driver.git --branch releases/stable --depth 1 - if [ $? -ne 0 ]; then - printf "\tUnable to clone MongoDB C++ driver at this time.\n" - printf "\tExiting now.\n\n" - exit; - fi - cd mongo-cxx-driver/build - cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local .. - if [ $? -ne 0 ]; then - printf "\tCmake has encountered the above errors building the MongoDB C++ driver.\n" - printf "\tExiting now.\n\n" - exit; - fi - make -j${CPU_CORE} - if [ $? -ne 0 ]; then - printf "\tError compiling MongoDB C++ driver.\n" - printf "\tExiting now.\n\n" - exit; - fi - sudo make install - if [ $? -ne 0 ]; then - printf "\tError installing MongoDB C++ driver.\nMake sure you have sudo privileges.\n" - printf "\tExiting now.\n\n" - exit; - fi - cd - rm -rf ${TEMP_DIR}/mongo-cxx-driver + if ! rm -f "${TEMP_DIR}/mongo-c-driver-1.9.3.tar.gz" + then + printf "\\tUnable to remove file %s/mongo-c-driver-1.9.3.tar.gz.\\n" "${TEMP_DIR}" + fi + printf "\\tUnable to download MongoDB C driver at this time.\\n" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! tar xf mongo-c-driver-1.9.3.tar.gz + then + printf "\\tUnable to unarchive file mongo-c-driver-1.9.3.tar.gz.\\n" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! rm -f "${TEMP_DIR}/mongo-c-driver-1.9.3.tar.gz" + then + printf "\\tUnable to remove file mongo-c-driver-1.9.3.tar.gz.\\n" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! cd mongo-c-driver-1.9.3 + then + printf "\\tUnable to cd into directory %s/mongo-c-driver-1.9.3.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! ./configure --enable-static --with-libbson=bundled --enable-ssl=darwin --disable-automatic-init-and-cleanup --prefix=/usr/local + then + printf "\\tConfiguring MongoDB C driver has encountered the errors above.\\n" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! make -j"${CPU_CORE}" + 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 "\\tUnable to enter directory %s.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! rm -rf "${TEMP_DIR}/mongo-c-driver-1.9.3" + then + printf "\\tUnable to remove directory %s/mongo-c-driver-1.9.3.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! git clone https://github.com/mongodb/mongo-cxx-driver.git --branch releases/stable --depth 1 + then + printf "\\tUnable to clone MongoDB C++ driver at this time.\\n" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! cd "${TEMP_DIR}/mongo-cxx-driver/build" + then + printf "\\tUnable to enter directory %s/mongo-cxx-driver/build.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local .. + then + printf "\\tCmake has encountered the above errors building the MongoDB C++ driver.\\n" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! make -j"${CPU_CORE}" + 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 "\\tUnable to enter directory %s.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! rm -rf "${TEMP_DIR}/mongo-cxx-driver" + then + printf "\\tUnable to remove directory %s/mongo-cxx-driver.\\n" "${TEMP_DIR}" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + printf "\\tMongo C++ driver installed at /usr/local/lib/libmongocxx-static.a.\\n" else - printf "\tMongo C++ driver found at /usr/local/lib/libmongocxx-static.a.\n" + printf "\\tMongo C++ driver found at /usr/local/lib/libmongocxx-static.a.\\n" fi - printf "\n\tChecking secp256k1-zkp installation.\n" + printf "\\n\\tChecking secp256k1-zkp installation.\\n" # install secp256k1-zkp (Cryptonomex branch) - if [ ! -e /usr/local/lib/libsecp256k1.a ]; then - cd ${TEMP_DIR} - git clone https://github.com/cryptonomex/secp256k1-zkp.git - if [ $? -ne 0 ]; then - printf "\tUnable to clone repo secp256k1-zkp @ https://github.com/cryptonomex/secp256k1-zkp.git.\n" - printf "\tExiting now.\n\n" - exit; - fi - cd secp256k1-zkp - ./autogen.sh - if [ $? -ne 0 ]; then - printf "\tError running autogen\n" - printf "\tExiting now.\n\n" - exit; - fi - ./configure - make -j${CPU_CORE} - if [ $? -ne 0 ]; then - printf "\tError compiling secp256k1-zkp.\n" - printf "\tExiting now.\n\n" - exit; - fi - sudo make install - rm -rf ${TEMP_DIR}/secp256k1-zkp + if [ ! -e "/usr/local/lib/libsecp256k1.a" ]; then + if ! cd "${TEMP_DIR}" + then + printf "\\tUnable to enter directory %s.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + 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; + fi + if ! cd "${TEMP_DIR}/secp256k1-zkp" + then + printf "\\tUnable to enter directory %s/secp256k1-zkp.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! ./autogen.sh + then + printf "\\tError running autogen.\\n" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! ./configure + then + printf "\\tConfiguring secp256k1-zkp has returned the above error.\\n" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! make -j"${CPU_CORE}" + then + printf "\\tError compiling secp256k1-zkp.\\n" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! sudo make install + then + printf "\\tInstalling secp256k1-zkp has returned the above error.\\n" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! rm -rf "${TEMP_DIR}/secp256k1-zkp" + then + printf "\\tUnable to remove directory %s/secp256k1-zkp56k1-zkp.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + printf "\\n\\n\\tSuccessffully installed secp256k1 @ /usr/local/lib/.\\n\\n" else - printf "\tsecp256k1 found at /usr/local/lib/\n" + printf "\\tsecp256k1 found at /usr/local/lib/.\\n" fi - printf "\n\tChecking LLVM with WASM support.\n" + printf "\\n\\tChecking LLVM with WASM support.\\n" if [ ! -d /usr/local/wasm/bin ]; then - cd ${TEMP_DIR} - mkdir wasm-compiler - cd wasm-compiler - git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/llvm.git - if [ $? -ne 0 ]; then - printf "\tUnable to clone llvm repo @ https://github.com/llvm-mirror/llvm.git.\n" - printf "\tExiting now.\n\n" - exit; - fi - cd llvm/tools - git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/clang.git - if [ $? -ne 0 ]; then - printf "\tUnable to clone clang repo @ https://github.com/llvm-mirror/clang.git.\n" - printf "\tExiting now.\n\n" - exit; - fi - cd .. - mkdir build - cd build - sudo cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr/local/wasm \ + if ! cd "${TEMP_DIR}" + then + printf "\\tUnable to enter directory %s.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! mkdir "${TEMP_DIR}/wasm-compiler" + then + printf "\\tUnable to create directory %s/wasm-compiler.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! cd "${TEMP_DIR}/wasm-compiler" + then + printf "\\tUnable to enter directory %s/wasm-compiler.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + 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" + exit 1; + fi + if ! cd "${TEMP_DIR}/wasm-compiler/llvm/tools" + then + printf "\\tUnable to enter directory %s/wasm-compiler/llvm/tools.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\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}/wasm-compiler/llvm" + then + printf "\\tUnable to enter directory %s/wasm-compiler/llvm.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! mkdir "${TEMP_DIR}/wasm-compiler/llvm/build" + then + printf "\\tUnable to create directory %s/wasm-compiler/llvm/build.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! cd "${TEMP_DIR}/wasm-compiler/llvm/build" + then + printf "\\tUnable to enter directory %s/wasm-compiler/llvm/build.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr/local/wasm \ -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly \ -DCMAKE_BUILD_TYPE=Release ../ - if [ $? -ne 0 ]; then - printf "\tError compiling WASM.\n" - printf "\tExiting now.\n\n" - exit; + then + printf "\\tError compiling LLVM/Clang with WASM support.\\n" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! sudo make -j"${CPU_CORE}" install + then + printf "\\tCompiling LLVM/Clang with WASM support has exited with the error above.\\n" + printf "\\tExiting now.\\n\\n" + exit 1; + fi + if ! sudo rm -rf "${TEMP_DIR}/wasm-compiler" + then + printf "\\tUnable to remove directory %s/wasm-compiler.\\n" "${TEMP_DIR}" + printf "\\tExiting now.\\n\\n" + exit 1; fi - sudo make -j${CPU_CORE} install - sudo rm -rf ${TEMP_DIR}/wasm-compiler + printf "\\tSuccessfully installed LLVM/Clang with WASM support @ /usr/local/wasm/bin/.\\n" else - printf "\tWASM found at /usr/local/wasm/bin/\n" + printf "\\tWASM found at /usr/local/wasm/bin/.\\n" fi function print_instructions() { - printf "\n\t$( which mongod ) -f ${MONGOD_CONF} &\n" - printf "\tcd ${BUILD_DIR}; make test\n\n" + printf "\\n\\t%s -f %s &\\n" "$( command -v mongod )" "${MONGOD_CONF}" + printf "\\tcd %s; make test\\n\\n" "${BUILD_DIR}" return 0 } -- GitLab