#!/bin/bash # https://github.com/mempool/mempool pinnedVersion="v2.1.2" # command info if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then echo "# small config script to switch Mempool on or off" echo "# installs the $pinnedVersion by default" echo "# bonus.mempool.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.mempool.sh status) # check if index is ready if [ "${isIndexed}" == "0" ]; then dialog --title " Blockchain Index Not Ready " --msgbox " The Blockchain Index is still getting built. ${indexInfo} This can take multiple hours. " 9 48 exit 0 fi # get network info localip=$(ip addr | grep 'state UP' -A2 | egrep -v 'docker0' | grep 'eth0\|wlan0' | tail -n1 | awk '{print $2}' | cut -f1 -d'/') toraddress=$(sudo cat /mnt/hdd/tor/mempool/hostname 2>/dev/null) fingerprint=$(openssl x509 -in /mnt/hdd/app-data/nginx/tls.cert -fingerprint -noout | cut -d"=" -f2) if [ "${runBehindTor}" = "on" ] && [ ${#toraddress} -gt 0 ]; then # TOR /home/admin/config.scripts/blitz.display.sh qr "${toraddress}" whiptail --title " Mempool " --msgbox "Open in your local web browser: http://${localip}:4080\n https://${localip}:4081 with Fingerprint: ${fingerprint}\n Hidden Service address for TOR Browser (QR see LCD): ${toraddress} " 16 67 /home/admin/config.scripts/blitz.display.sh hide else # IP + Domain whiptail --title " Mempool " --msgbox "Open in your local web browser: http://${localip}:4080\n https://${localip}:4081 with Fingerprint: ${fingerprint}\n Activate TOR to access the web block explorer from outside your local network. " 16 54 fi echo "please wait ..." exit 0 fi # add default value to raspi config if needed if ! grep -Eq "^mempoolExplorer=" /mnt/hdd/raspiblitz.conf; then echo "mempoolExplorer=off" >> /mnt/hdd/raspiblitz.conf fi # status if [ "$1" = "status" ]; then if [ "${mempoolExplorer}" = "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 mempool | grep -c 'inactive (dead)') if [ ${isDead} -eq 1 ]; then echo "error='Service Failed'" exit 1 fi else echo "configured=0" fi exit 0 fi # stop service echo "# making sure services are not running" sudo systemctl stop mempool 2>/dev/null # switch on if [ "$1" = "1" ] || [ "$1" = "on" ]; then echo "# *** INSTALL MEMPOOL ***" isInstalled=$(sudo ls /etc/systemd/system/mempool.service 2>/dev/null | grep -c 'mempool.service') if [ ${isInstalled} -eq 0 ]; then # install nodeJS /home/admin/config.scripts/bonus.nodejs.sh on # make sure that txindex of blockchain is switched on /home/admin/config.scripts/network.txindex.sh on # make sure needed os dependencies are installed sudo apt-get install -y mariadb-server mariadb-client # add mempool user sudo adduser --disabled-password --gecos "" mempool # install mempool cd /home/mempool sudo -u mempool git clone https://github.com/mempool/mempool.git cd mempool sudo -u mempool git reset --hard $pinnedVersion # modify an #echo "# try to suppress question on statistics report .." #sudo sed -i "s/^}/,\"cli\": {\"analytics\": false}}/g" /home/mempool/mempool/frontend/angular.json sudo mariadb -e "DROP DATABASE IF EXISTS mempool;" sudo mariadb -e "CREATE DATABASE mempool;" sudo mariadb -e "GRANT ALL PRIVILEGES ON mempool.* TO 'mempool' IDENTIFIED BY 'mempool';" sudo mariadb -e "FLUSH PRIVILEGES;" mariadb -umempool -pmempool mempool < mariadb-structure.sql echo "# npm install for mempool explorer (frontend)" cd frontend sudo -u mempool NG_CLI_ANALYTICS=false npm install if ! [ $? -eq 0 ]; then echo "FAIL - npm install did not run correctly, aborting" exit 1 fi sudo -u mempool NG_CLI_ANALYTICS=false npm run build if ! [ $? -eq 0 ]; then echo "FAIL - npm run build did not run correctly, aborting" exit 1 fi echo "# npm install for mempool explorer (backend)" cd ../backend/ sudo -u mempool NG_CLI_ANALYTICS=false npm install if ! [ $? -eq 0 ]; then echo "FAIL - npm install did not run correctly, aborting" exit 1 fi sudo -u mempool NG_CLI_ANALYTICS=false npm run build if ! [ $? -eq 0 ]; then echo "FAIL - npm run build did not run correctly, aborting" exit 1 fi # 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-) touch /home/admin/mempool-config.json sudo chmod 600 /home/admin/mempool-config.json || exit 1 cat > /home/admin/mempool-config.json < /home/admin/mempool.service <