#!/bin/bash # https://github.com/janoside/btc-rpc-explorer # ~/.config/btc-rpc-explorer.env # https://github.com/janoside/btc-rpc-explorer/blob/master/.env-sample # command info if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then echo "small config script to switch BTC-RPC-explorer on or off" echo "bonus.btc-rpc-explorer.sh [status|on|off]" exit 1 fi source /mnt/hdd/raspiblitz.conf # show info menu if [ "$1" = "menu" ]; then # get status echo "# collecting status info ... (please wait)" source <(sudo /home/admin/config.scripts/bonus.btc-rpc-explorer.sh status) # check if index is ready if [ ${isIndexed} -eq 0 ]; then dialog --title " Blockchain Index Not Ready " --msgbox " The Blockchain Index is still getting build. Please wait and try again later. This can take multiple hours. " 9 48 exit 0 fi # get network info localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') toraddress=$(sudo cat /mnt/hdd/tor/btc-rpc-explorer/hostname 2>/dev/null) if [ "${runBehindTor}" = "on" ] && [ ${#toraddress} -gt 0 ]; then # TOR /home/admin/config.scripts/blitz.lcd.sh qr "${toraddress}" whiptail --title " BTC-RPC-Explorer " --msgbox "Open the following URL in your local web browser: http://${localip}:3002 Login is 'admin' with your Password B\n Hidden Service address for TOR Browser (QR see LCD): ${toraddress} " 12 67 /home/admin/config.scripts/blitz.lcd.sh hide else # IP + Domain whiptail --title " BTC-RPC-Explorer " --msgbox "Open the following URL in your local web browser: http://${localip}:3002 Login is 'admin' with your Password B\n Activate TOR to access the web block explorer from outside your local network. " 12 54 fi echo "please wait ..." exit 0 fi # add default value to raspi config if needed if ! grep -Eq "^BTCRPCexplorer=" /mnt/hdd/raspiblitz.conf; then echo "BTCRPCexplorer=off" >> /mnt/hdd/raspiblitz.conf fi # status if [ "$1" = "status" ]; then if [ "${BTCRPCexplorer}" = "on" ]; then echo "configured=1" # check indexing source <(sudo /home/admin/config.scripts/network.txindex.sh status) echo "isIndexed=${isIndexed}" echo "indexInfo='${indexInfo}'" # check for error isDead=$(sudo systemctl status btc-rpc-explorer | grep -c 'inactive (dead)') if [ ${isDead} -eq 1 ]; then echo "error='Service Failed'" exit 1 fi else echo "configured=0" fi exit 0 fi # determine nodeJS DISTRO isARM=$(uname -m | grep -c 'arm') isAARCH64=$(uname -m | grep -c 'aarch64') isX86_64=$(uname -m | grep -c 'x86_64') isX86_32=$(uname -m | grep -c 'i386\|i486\|i586\|i686\|i786') # get checksums from -> https://nodejs.org/dist/vx.y.z/SHASUMS256.txt if [ ${isARM} -eq 1 ] ; then DISTRO="linux-armv7l" fi if [ ${isAARCH64} -eq 1 ] ; then DISTRO="linux-arm64" fi if [ ${isX86_64} -eq 1 ] ; then DISTRO="linux-x64" fi if [ ${isX86_32} -eq 1 ] ; then echo "FAIL: No X86 32bit build available - will abort setup" exit 1 fi if [ ${#DISTRO} -eq 0 ]; then echo "FAIL: Was not able to determine architecture" exit 1 fi # stop service echo "making sure services are not running" sudo systemctl stop btc-rpc-explorer 2>/dev/null # switch on if [ "$1" = "1" ] || [ "$1" = "on" ]; then echo "*** INSTALL BTC-RPC-EXPLORER ***" isInstalled=$(sudo ls /etc/systemd/system/btc-rpc-explorer.service 2>/dev/null | grep -c 'btc-rpc-explorer.service') if [ ${isInstalled} -eq 0 ]; then # install nodeJS /home/admin/config.scripts/bonus.nodejs.sh # make sure that txindex of blockchain is switched on /home/admin/config.scripts/network.txindex.sh on npm install -g btc-rpc-explorer@1.1.8 # prepare .env file echo "getting RPC credentials from the ${network}.conf" RPC_USER=$(sudo cat /mnt/hdd/${network}/${network}.conf | grep rpcuser | cut -c 9-) PASSWORD_B=$(sudo cat /mnt/hdd/${network}/${network}.conf | grep rpcpassword | cut -c 13-) sudo -u bitcoin mkdir /home/bitcoin/.config/ 2>/dev/null touch /home/admin/btc-rpc-explorer.env chmod 600 /home/admin/btc-rpc-explorer.env || exit 1 cat > /home/admin/btc-rpc-explorer.env < /home/admin/btc-rpc-explorer.service <