|
| 1 | +#!/bin/sh |
| 2 | +# Install script for Binance Chain |
| 3 | +# Note: this is based on current structure of `node-binary` repo, which is not optimal |
| 4 | +# Future improvement: version binaries using git, instead of folder structure |
| 5 | + |
| 6 | +# Detect operating system |
| 7 | +# Future Improvement: Refactor into helper function |
| 8 | +if [[ "$OSTYPE" == "linux-gnu" ]]; then |
| 9 | + DETECTED_OS="linux" |
| 10 | +elif [[ "$OSTYPE" == "darwin"* ]]; then |
| 11 | + DETECTED_OS="mac" |
| 12 | +elif [[ "$OSTYPE" == "cygwin" ]]; then |
| 13 | + DETECTED_OS="linux" |
| 14 | +elif [[ "$OSTYPE" == "msys" ]]; then |
| 15 | + DETECTED_OS="windows" |
| 16 | +elif [[ "$OSTYPE" == "win32" ]]; then |
| 17 | + DETECTED_OS="windows" # TODO(Dan): can you run shell on windows? |
| 18 | +elif [[ "$OSTYPE" == "freebsd"* ]]; then |
| 19 | + DETECTED_OS="linux" |
| 20 | +else |
| 21 | + FULLNODE_echo "Error: unable to detect operating system. Please install manually by referring to $DOCS_WEB_LINK" |
| 22 | + LIGHTNODE_DOCS_WEB_LINK="" |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +# Check for existence of wget |
| 27 | +if [ ! -x /usr/bin/wget ]; then |
| 28 | + # some extra check if wget is not installed at the usual place |
| 29 | + command -v wget >/dev/null 2>&1 || { |
| 30 | + echo >&2 "Error: you need to have wget installed and in your path. Use brew (mac) or apt (unix) to install wget" |
| 31 | + exit 1 |
| 32 | + } |
| 33 | +fi |
| 34 | + |
| 35 | +echo "@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@" |
| 36 | +echo "@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@" |
| 37 | +echo "@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@" |
| 38 | +echo "@@@@@@@@@@@@@ @@@@@@@@@@@@@" |
| 39 | +echo "@@@@@@@@@@@ @@@@@@@@@@@" |
| 40 | +echo "@@@@@@@@@ @@@ @@@@@@@@@" |
| 41 | +echo "@@@@@@@@ @@@@@@@ @@@@@@@@" |
| 42 | +echo "@@@@@@@@@@ @@@@@@@@@@@ @@@@@@@@@@" |
| 43 | +echo "@@@ @@@@@@@@@@@@ @@@@@@@@@@@@ @@@" |
| 44 | +echo "@ @@@@@@@@ @@@@@@@@ @" |
| 45 | +echo "@ @@@@@@@@ @@@@@@@@ @" |
| 46 | +echo "@@@ @@@@@@@@@@@@ @@@@@@@@@@@@ @@@" |
| 47 | +echo "@@@@@@@@@@ @@@@@@@@@@@ @@@@@@@@@@" |
| 48 | +echo "@@@@@@@@ @@@@@@@ @@@@@@@@" |
| 49 | +echo "@@@@@@@@@ @@@ @@@@@@@@@" |
| 50 | +echo "@@@@@@@@@@@ @@@@@@@@@@@" |
| 51 | +echo "@@@@@@@@@@@@@ @@@@@@@@@@@@@" |
| 52 | +echo "@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@" |
| 53 | +echo "@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@" |
| 54 | +echo "" |
| 55 | + |
| 56 | +echo "========== Binance Chain Node Installation ==========" |
| 57 | +echo "Installer Version: 0.1.beta" |
| 58 | +echo "Detected OS: $DETECTED_OS" |
| 59 | +echo "=====================================================" |
| 60 | + |
| 61 | +# Variables |
| 62 | +BNC_HOME_CONFIG_DIR=$BNC_HOME_DIR"/config" |
| 63 | +FULLNODE_DOCS_WEB_LINK="https://docs.binance.org/fullnode.html" |
| 64 | +LIGHTNODE_DOCS_WEB_LINK="https://docs.binance.org/light-client.html" |
| 65 | +GH_REPO_URL="https://github.com/binance-chain/node-binary" |
| 66 | +GH_RAW_PREFIX="raw/master" |
| 67 | +GH_REPO_DL_URL="$GH_REPO_URL/$GH_RAW_PREFIX" |
| 68 | + |
| 69 | +# Install location |
| 70 | +USR_LOCAL_BIN="/usr/local/bin" |
| 71 | +# Note: /usr/local/bin choice from https://unix.stackexchange.com/questions/259231/difference-between-usr-bin-and-usr-local-bin |
| 72 | +# Future improvement: needs uninstall script (brew uninstall) that removes executable from bin |
| 73 | + |
| 74 | +# Choose Home Directory |
| 75 | +BNC_HOME_DIR=${BNC_HOME_DIR:-"$HOME/.bnbchaind"} |
| 76 | +read -e -p "Choose home directory [default: ~/.bnbchaind]:" BNC_HOME_DIR |
| 77 | + |
| 78 | +# Choose network option |
| 79 | +echo "... Choose Network Version" |
| 80 | +OPTION_NETWORK=("Mainnet" "Testnet") |
| 81 | +PS3='Choose Network Type: ' |
| 82 | +select opt in "${OPTION_NETWORK[@]}"; do |
| 83 | + case $opt in |
| 84 | + "Mainnet") |
| 85 | + NETWORK="prod" |
| 86 | + break |
| 87 | + ;; |
| 88 | + "Testnet") |
| 89 | + NETWORK="testnet" |
| 90 | + break |
| 91 | + ;; |
| 92 | + esac |
| 93 | +done |
| 94 | + |
| 95 | +# Version selection options |
| 96 | +# Future improvement: pull dynamically from version list |
| 97 | +OPTION_VERSION_NUMBER=("0.5.8" "0.5.9" "0.5.10" "0.6.0" "0.6.1" "0.6.2" "0.6.3") |
| 98 | +OPTION_NODE_TYPE=("Full Node" "Light Node") |
| 99 | + |
| 100 | +echo "... Choose version of Binance Chain node to install" |
| 101 | +PS3='Choose Version Number: ' |
| 102 | +select opt in "${OPTION_VERSION_NUMBER[@]}"; do |
| 103 | + VERSION_NUMBER="$opt" |
| 104 | + break |
| 105 | +done |
| 106 | + |
| 107 | +echo "... Choose node type to install" |
| 108 | +PS3='Choose Node Type: ' |
| 109 | +select opt in "${OPTION_NODE_TYPE[@]}"; do |
| 110 | + case $opt in |
| 111 | + "Full Node") |
| 112 | + NODE_TYPE="fullnode" |
| 113 | + break |
| 114 | + ;; |
| 115 | + "Light Node") |
| 116 | + NODE_TYPE="lightnode" |
| 117 | + break |
| 118 | + ;; |
| 119 | + esac |
| 120 | +done |
| 121 | + |
| 122 | +# Download the selected binary |
| 123 | +# Future improvement: versions should just be a single .zip payload (e.g. 0.6.2) |
| 124 | +# Future improvement: should not use folder structure as addressing method |
| 125 | +VERSION_PATH="$NODE_TYPE/$NETWORK/$VERSION_NUMBER" |
| 126 | +GH_BASE_URL="$GH_REPO_URL/$GH_RAW_PREFIX/$VERSION_PATH" |
| 127 | +CONFIG_DOWNLOAD_URL="$GH_BASE_URL/config" |
| 128 | +NODE_BINARY_DOWNLOAD_URL="$GH_BASE_URL/$DETECTED_OS" |
| 129 | + |
| 130 | +# wget the binary, config files |
| 131 | +# Future improvement: should refactor in the future with releases in a single .zip or .tar.gz file |
| 132 | +if [ $NODE_TYPE == "fullnode" ]; then |
| 133 | + |
| 134 | + # Detect previous installation and create .bnbchaind |
| 135 | + echo "... creating $BNC_HOME_DIR" |
| 136 | + if [ -d "$BNC_HOME_DIR" ]; then |
| 137 | + echo "... Error: Binance Chain Fullnode has already been installed" |
| 138 | + echo "... Error: Please remove contents of ${BNC_HOME_DIR} before reinstalling." |
| 139 | + exit 1 |
| 140 | + else |
| 141 | + mkdir -p $BNC_HOME_CONFIG_DIR |
| 142 | + cd $BNC_HOME_DIR |
| 143 | + fi |
| 144 | + if [ -f "$USR_LOCAL_BIN/bnbchaind" ]; then |
| 145 | + echo "... Error: Binance Chain Fullnode has already been installed" |
| 146 | + echo "... Error: Please remove bnbchaind from /usr/local/bin before reinstalling." |
| 147 | + exit 1 |
| 148 | + fi |
| 149 | + |
| 150 | + # Future improvement: should be refactored into helper function |
| 151 | + cd $USR_LOCAL_BIN |
| 152 | + echo "... Downloading bnbchaind executable" |
| 153 | + wget -q --show-progress "$NODE_BINARY_DOWNLOAD_URL/bnbchaind" |
| 154 | + chmod 755 "./bnbchaind" |
| 155 | + |
| 156 | + cd $BNC_HOME_CONFIG_DIR |
| 157 | + echo "... Downloading config files for version" |
| 158 | + wget -q --show-progress "$CONFIG_DOWNLOAD_URL/app.toml" |
| 159 | + wget -q --show-progress "$CONFIG_DOWNLOAD_URL/config.toml" |
| 160 | + wget -q --show-progress "$CONFIG_DOWNLOAD_URL/genesis.json" |
| 161 | + |
| 162 | + # Add installed version of Binance Chain to path |
| 163 | + echo "... Installation successful!" |
| 164 | + echo "... \`bnbchaind\` added to $USR_LOCAL_BIN" |
| 165 | + echo "... Visit full node documentation at $DOCS_WEB_LINK" |
| 166 | + echo "... Run \`bnbchaind\` to see list of available commands" |
| 167 | + |
| 168 | +elif [ $NODE_TYPE == "lightnode" ]; then |
| 169 | + cd $USR_LOCAL_BIN |
| 170 | + echo "... Downloading lightd executable" |
| 171 | + wget -q --show-progress "$NODE_BINARY_DOWNLOAD_URL/lightd" |
| 172 | + chmod 755 "./lightd" |
| 173 | + |
| 174 | + echo "... Installation successful!" |
| 175 | + echo "... \`lightd\` added to $USR_LOCAL_BIN" |
| 176 | + echo "... Visit full node documentation at $DOCS_WEB_LINK" |
| 177 | + echo "... Run \`lightd\` to see list of available commands" |
| 178 | +fi |
0 commit comments