#!/usr/bin/env bash ################################################################################# # Hive-in-a-box Quick Installer # # (C) 2020 Someguy123 # # # # GH: https://github.com/Someguy123 Blog: https://peakd.com/@someguy123 # # # # Usage: # # # # curl -fsSL https://cdn.privex.io/extras/auto_hive_setup.sh | bash # # # # (Advanced) Edit block_log source / SIAB install folder: # # # # # Download block_log/rocksdb etc. from our Finnish server # # export S_HOST="rsync://fin1.files.privex.io/" # # # # # Install steem-docker at /opt/steem instead of ${PWD}/steem-docker # # export HIVE_INSTALL="/opt/steem" # # # # # Download and use RocksDB in /mnt/rocksdb instead # # # of ${HIVE_INSTALL}/data/rocksdb # # export HIVE_RDB="/mnt/rocksdb" # # # # # Download block_log via HTTP + lz4 on-the-fly decompression instead # # # of using rsync --append # # export RSYNC_BLOCKS=0 # # # # # If RSYNC_BLOCKS is set to 0, you can set USE_LZ4 to 0 to download the # # # raw block_log over HTTP instead of the lz4 version + OTF decompression # # export USE_LZ4=0 # # # # # Download + run the script and those options will be used # # curl -fsSL https://cdn.privex.io/extras/auto_hive_setup.sh | sudo bash # # # # # ################################################################################# : ${S_HOST="rsync://files.privex.io/"} : ${S_HOST_HTTP="http://files.privex.io/"} : ${RDB_DIR="hive/rocksdb"} : ${BC_DIR="hive"} : ${HIVE_INSTALL="${PWD}/steem-docker"} : ${HIVE_RDB="${HIVE_INSTALL}/data/rocksdb"} : ${RSYNC_BLOCKS=1} : ${USE_LZ4=1} MAGENTA="" GREEN="" CYAN="" RED="" RESET="" [ -t 1 ] && { MAGENTA="$(tput setaf 5)" GREEN="$(tput setaf 2)" RED="$(tput setaf 1)" CYAN="$(tput setaf 6)" RESET="$(tput sgr0)"; } echo "$CYAN" echo " ########################################## " echo " # Hive-in-a-box Quick Installer # " echo " # (C) 2020 Someguy123 # " echo " # # " echo " # GH: https://github.com/Someguy123 # " echo " # Blog: https://peakd.com/@someguy123 # " echo " ########################################## " echo "$RESET" echo -e "\n${MAGENTA} [...] Loading / Installing Privex ShellCore™ ${RESET}\n" _sc_fail() { >&2 echo -e "\n${RED} [!!!] Failed to load or install Privex ShellCore...${RESET}" && exit 1; } # Array of Privex ShellCore modules to be loaded during ShellCore initialisation. SG_LOAD_LIBS=(gnusafe helpers trap_helper traplib) # Run ShellCore auto-install if we can't detect an existing ShellCore load.sh file. [[ -f "${HOME}/.pv-shcore/load.sh" ]] || [[ -f "/usr/local/share/pv-shcore/load.sh" ]] || \ { curl -fsS https://cdn.privex.io/github/shell-core/install.sh | bash >/dev/null; } || _sc_fail # Attempt to load the local install of ShellCore first, then fallback to global install if it's not found. [[ -d "${HOME}/.pv-shcore" ]] && source "${HOME}/.pv-shcore/load.sh" || \ source "/usr/local/share/pv-shcore/load.sh" || _sc_fail error_control 0 msg bold green "\n [+++] Successfully loaded Privex ShellCore™ \n" msg bold green "\n >>> Cloning steem-docker into ${HIVE_INSTALL}\n" git clone https://github.com/Someguy123/steem-docker.git "${HIVE_INSTALL}" cd "${HIVE_INSTALL}" if ! has_binary docker; then msg bold yellow " [???] Could not find 'docker' executable. Will auto-install Docker for you :)" sudo ./run.sh install_docker || true gpasswd -a "$(whoami)" docker || true fi # Install my docker MIRA image (required for RocksDB files to be compatible) msg bold green "\n >>> Installing someguy123/hive:latest-mira\n" sudo ./run.sh install someguy123/hive:latest-mira ####### # Configure the .env file to forward ports and use rocksdb on disk instead of /dev/shm ####### msg bold green "\n >>> Configuring .env file for RocksDB + Port forwards\n" # Set the default image source to someguy123/hive:latest-mira # This ensures an accidental './run.sh install' with no args will install the Hive MIRA image echo "DK_TAG=someguy123/hive:latest-mira" >> .env # Set the container name to 'hiveseed' - prevents conflicts with existing steem-docker # nodes with the default 'seed' name echo "DOCKER_NAME=hiveseed" >> .env # Point shared memory dir (rocksdb) to steem-docker/data/rocksdb echo "SHM_DIR=${HIVE_RDB}" >> .env # Expose port 2001 (seed port) to internet # Forward 8090 (WS) + 8091 (HTTP) RPC port to localhost for querying echo 'PORTS=2001,127.0.0.1:8091:8091,127.0.0.1:8090:8090' >> .env ####### # Download/update the Hive block_log, block_log.index, and RocksDB via rsync # If the download is interrupted, just run the command again - Rsync will safely resume ####### msg bold green "\n >>> Downloading block_log, block_log.index, and RocksDB from ${S_HOST} \n" # Use sudo if you're not already logged in as root, Docker can cause rocksdb/block_log to become owned by root and break rsync. msg bold green "\n >>> Downloading: ${S_HOST}${RDB_DIR}/ \n" sudo rsync -avh --progress --delete --inplace "${S_HOST}${RDB_DIR}/" "${HIVE_RDB}/" if (( RSYNC_BLOCKS == 1 )); then msg bold green "\n >>> Downloading: ${S_HOST}${BC_DIR}/block_log \n" sudo rsync -avh --progress --append "${S_HOST}${BC_DIR}/block_log" data/witness_node_data_dir/blockchain/block_log else if (( USE_LZ4 == 1 )); then pkg_not_found lz4 liblz4-tool msg bold green "\n >>> Downloading (on-the-fly lz4 decompression): ${S_HOST_HTTP}${BC_DIR}/block_log.lz4 \n" sudo wget -q "${S_HOST_HTTP}${BC_DIR}/block_log.lz4" -O - | sudo lz4 -v -d - data/witness_node_data_dir/blockchain/block_log else msg bold green "\n >>> Downloading: ${S_HOST_HTTP}${BC_DIR}/block_log \n" sudo wget -q --show-progress "${S_HOST_HTTP}${BC_DIR}/block_log" -O data/witness_node_data_dir/blockchain/block_log fi fi msg bold green "\n >>> Downloading: ${S_HOST}${BC_DIR}/block_log.index \n" sudo rsync -avh --progress --inplace "${S_HOST}${BC_DIR}/block_log.index" data/witness_node_data_dir/blockchain/block_log.index ####### # Start (not replay) the Hive node # After chainstate is loaded, it will begin syncing up any new blocks since the snapshot via p2p ####### msg bold green "\n >>> Starting Hive container ... \n" # Start it up. May take a few minutes to sync up with the network sudo ./run.sh start msg bold green "\n +++ FINISHED +++ \n" msg msg green "Please monitor the node startup using './run.sh logs'" msg green "To confirm it's syncing, use './run.sh wallet' and type 'info' at the wallet prompt every few minutes" msg green "You'll find the current synced up-to block under 'head_block_number'" msg green "You'll find the timestamp of the current synced block under 'time'" msg green "Example:\n" msg yellow " new >>> info" msg yellow " ..." msg yellow " \"head_block_number\": 41905671," msg yellow " \"head_block_id\": \"027f6e0781e773edb823020e4fefbbc579ec2397\"," msg yellow " \"time\": \"2020-03-23T15:43:48\"," msg yellow " ..." msg msg green "Steem-docker was installed at: ${HIVE_INSTALL}" msg