|
| 1 | +#!/bin/bash |
| 2 | +## User local: source/bash/sh |
| 3 | +## If remote: source/bash/sh <(curl -s https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/scripts/setup_fullnode.sh) |
| 4 | + |
| 5 | +# Colour codes |
| 6 | +YELLOW='\033[0;33m' |
| 7 | +RED='\033[0;31m' |
| 8 | +NC='\033[0m' # No Color |
| 9 | + |
| 10 | +pushd () { |
| 11 | + command pushd "$@" > /dev/null |
| 12 | +} |
| 13 | + |
| 14 | +popd () { |
| 15 | + command popd "$@" > /dev/null |
| 16 | +} |
| 17 | + |
| 18 | +function sedCheck() { |
| 19 | + sed --version > /dev/null 2>&1 |
| 20 | + if [ $? -eq 0 ];then |
| 21 | + sed --version|grep 'GNU sed' > /dev/null 2>&1 |
| 22 | + if [ $? -eq 0 ];then |
| 23 | + SED_IS_GNU=1 |
| 24 | + fi |
| 25 | + fi |
| 26 | +} |
| 27 | + |
| 28 | +function checkDockerPermissions() { |
| 29 | + docker ps > /dev/null 2>&1 |
| 30 | + if [ $? = 1 ];then |
| 31 | + echo -e "your $RED [$USER] $NC not privilege docker" |
| 32 | + echo -e "please run $RED [sudo bash] $NC first" |
| 33 | + echo -e "Or docker not install " |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | +} |
| 37 | + |
| 38 | +function checkDockerCompose() { |
| 39 | + docker-compose --version > /dev/null 2>&1 |
| 40 | + if [ $? -eq 127 ];then |
| 41 | + echo -e "$RED docker-compose command not found $NC" |
| 42 | + echo -e "Please install it first" |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | +} |
| 46 | + |
| 47 | +function setVar() { |
| 48 | + producerPrivKey="" |
| 49 | + externalHost="" |
| 50 | + defaultdatadir="$HOME/iotex-var" |
| 51 | + IOTEX_IMAGE=363205959602.dkr.ecr.us-east-1.amazonaws.com/iotex-core:latest |
| 52 | +} |
| 53 | + |
| 54 | +function determinIotexHome() { |
| 55 | + ##Input Data Dir |
| 56 | + echo "The current user of the input directory must have write permission!!!" |
| 57 | + echo -e "${RED} If Upgrade ; input your old directory \$IOTEX_HOME !!! ${NC}" |
| 58 | + |
| 59 | + #while True: do |
| 60 | + read -p "Input your \$IOTEX_HOME [e.g., $defaultdatadir]: " inputdir |
| 61 | + IOTEX_HOME=${inputdir:-"$defaultdatadir"} |
| 62 | + IOTEX_MONITOR_HOME=$IOTEX_HOME/monitor |
| 63 | +} |
| 64 | + |
| 65 | +function preDockerCompose() { |
| 66 | + # set monitor home |
| 67 | + mkdir -p $IOTEX_MONITOR_HOME |
| 68 | + |
| 69 | + export IOTEX_HOME IOTEX_MONITOR_HOME IOTEX_IMAGE |
| 70 | + |
| 71 | + curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/docker-compose.yml.marketplace > $IOTEX_MONITOR_HOME/docker-compose.yml |
| 72 | + curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/.env > $IOTEX_MONITOR_HOME/.env |
| 73 | +} |
| 74 | + |
| 75 | +function determineExtIp() { |
| 76 | + findip=$(curl -Ss ip.sb) |
| 77 | + read -p "SET YOUR EXTERNAL IP HERE [$findip]: " inputip |
| 78 | + ip=${inputip:-$findip} |
| 79 | + externalHost="externalHost: $ip" |
| 80 | +} |
| 81 | + |
| 82 | +function determinPrivKey() { |
| 83 | + echo "If you are a delegate, make sure producerPrivKey is the key for the operator address you have registered." |
| 84 | + echo "SET YOUR PRIVATE KEY HERE(e.g., 96f0aa5e8523d6a28dc35c927274be4e931e74eaa720b418735debfcbfe712b8)" |
| 85 | + read -p ": " inputkey |
| 86 | + privKey=${inputkey:-"96f0aa5e8523d6a28dc35c927274be4e931e74eaa720b418735debfcbfe712b8"} |
| 87 | + producerPrivKey="producerPrivKey: $privKey" |
| 88 | +} |
| 89 | + |
| 90 | +function downloadConfig() { |
| 91 | + echo "download new config" |
| 92 | + curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/v1.1.1/config_mainnet.yaml > $IOTEX_HOME/etc/config.yaml |
| 93 | + curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/v1.1.1/genesis_mainnet.yaml > $IOTEX_HOME/etc/genesis.yaml |
| 94 | + # https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/v0.9.2/config_mainnet.yaml |
| 95 | + |
| 96 | + SED_IS_GNU=0 |
| 97 | + sedCheck |
| 98 | + echo "Update your externalHost,producerPrivKey to config.yaml" |
| 99 | + if [ $SED_IS_GNU -eq 1 ];then |
| 100 | + sed -i "/^network:/a\ \ $externalHost" $IOTEX_HOME/etc/config.yaml |
| 101 | + sed -i "/^chain:/a\ \ $producerPrivKey" $IOTEX_HOME/etc/config.yaml |
| 102 | + else |
| 103 | + sed -i '' "/^network:/a\ |
| 104 | +\ \ $externalHost |
| 105 | +" $IOTEX_HOME/etc/config.yaml |
| 106 | + sed -i '' "/^chain:/a\ |
| 107 | +\ \ $producerPrivKey |
| 108 | +" $IOTEX_HOME/etc/config.yaml |
| 109 | + fi |
| 110 | +} |
| 111 | + |
| 112 | +function donwloadBlockDataFile() { |
| 113 | + NODE_GATEWAY_MAINNET_DATA_URL=https://t.iotex.me/mainnet-data-with-idx-latest |
| 114 | + |
| 115 | + SAVE_DIR=$IOTEX_HOME/tmp |
| 116 | + mkdir -p $SAVE_DIR |
| 117 | + DATA_FILE_PATH=$SAVE_DIR/data.tar.gz |
| 118 | + |
| 119 | + UNZIP_FILE_CMD="tar xvf $SAVE_DIR/data.tar.gz -C $IOTEX_HOME" |
| 120 | + |
| 121 | + echo -e "${YELLOW} Downloading the db file from a snapshot...${NC}" |
| 122 | + curl -sSL $NODE_GATEWAY_MAINNET_DATA_URL > $DATA_FILE_PATH |
| 123 | + echo -e "${YELLOW} Unzipping...${NC}" |
| 124 | + $UNZIP_FILE_CMD |
| 125 | + echo -e "${YELLOW} Done.${NC}" |
| 126 | +} |
| 127 | + |
| 128 | +function startup() { |
| 129 | + echo -e "Start iotex-server." |
| 130 | + pushd $IOTEX_MONITOR_HOME |
| 131 | + docker-compose up -d iotex |
| 132 | + popd |
| 133 | +} |
| 134 | + |
| 135 | +function startupNode() { |
| 136 | + startup |
| 137 | + #check node running |
| 138 | + sleep 5 |
| 139 | + pushd $IOTEX_MONITOR_HOME |
| 140 | + docker-compose ps iotex |
| 141 | + popd |
| 142 | +} |
| 143 | + |
| 144 | +function main() { |
| 145 | + # Check and clean |
| 146 | + checkDockerPermissions # Determine the current user can run docker |
| 147 | + checkDockerCompose # Determin the docker-compose is installed |
| 148 | + setVar # Set global variable |
| 149 | + |
| 150 | + determinIotexHome # Determine the $IOTEX_HOME |
| 151 | + determineExtIp |
| 152 | + determinPrivKey |
| 153 | + |
| 154 | + echo -e "${YELLOW} ****** Install Iotex Node ***** ${NC}" |
| 155 | + echo -e "${YELLOW} if installed, Confirm Input IOTEX_HOME directory $IOTEX_HOME True ${NC};" |
| 156 | + read -p "[Ctrl + c exit!]; else Enter anykey ..." anykey |
| 157 | + |
| 158 | + mkdir -p ${IOTEX_HOME} |
| 159 | + pushd ${IOTEX_HOME} |
| 160 | + mkdir data log etc > /dev/null 2>&1 |
| 161 | + popd |
| 162 | + |
| 163 | + wantdownload=N |
| 164 | + read -p "Do you prefer to start from a snapshot, Download the db file. [Y/N] (Default: N)? " wantdownload |
| 165 | + if [ "${wantdownload}X" = "YX" ] || [ "${wantdownload}X" = "yX" ];then |
| 166 | + # Download db file |
| 167 | + donwloadBlockDataFile |
| 168 | + fi |
| 169 | + |
| 170 | + echo -e "Confirm your externalHost: ${YELLOW} $ip ${NC}" |
| 171 | + echo -e "Confirm your producerPrivKey: ${RED} $privKey ${NC}" |
| 172 | + read -p "Press any key to continue ... [Ctrl + c exit!] " key2 |
| 173 | + |
| 174 | + echo "docker pull iotex-core" |
| 175 | + docker pull $IOTEX_IMAGE |
| 176 | + # or use gcr.io/iotex-servers/iotex-core:${version} |
| 177 | + #Set the environment with the following commands: |
| 178 | + |
| 179 | + downloadConfig |
| 180 | + preDockerCompose |
| 181 | + |
| 182 | + startupNode |
| 183 | +} |
| 184 | + |
| 185 | +main $@ |
0 commit comments