#!/bin/bash # https://github.com/mempool/mempool pinnedVersion="v2.4.0" # 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 [install|uninstall]" echo "# bonus.mempool.sh [status|on|off]" exit 1 fi PGPsigner="wiz" PGPpubkeyLink="https://github.com/wiz.gpg" PGPpubkeyFingerprint="A394E332255A6173" 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 if [ "${runBehindTor}" = "on" ] && [ ${#toraddress} -gt 0 ]; then # Tor sudo /home/admin/config.scripts/blitz.display.sh qr "${toraddress}" whiptail --title " Mempool " --msgbox "Open in your local web browser: http://${localIP}:${httpPort}\n https://${localIP}:${httpsPort} with Fingerprint: ${fingerprint}\n Hidden Service address for Tor Browser (QR see LCD): ${toraddress} " 16 67 sudo /home/admin/config.scripts/blitz.display.sh hide else # IP + Domain whiptail --title " Mempool " --msgbox "Open in your local web browser: http://${localIP}:${httpPort}\n https://${localIP}:${httpsPort} 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 # status if [ "$1" = "status" ]; then echo "version='${pinnedVersion}'" isInstalled=$(compgen -u | grep -c mempool) echo "codebase=${isInstalled}" if [ "${mempoolExplorer}" = "on" ]; then echo "configured=1" # get network info localIP=$(hostname -I | awk '{print $1}') 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) echo "installed=1" echo "localIP='${localIP}'" echo "httpPort='4080'" echo "httpsPort='4081'" echo "httpsForced='0'" echo "httpsSelfsigned='1'" echo "authMethod='none'" echo "fingerprint='${fingerprint}'" echo "toraddress='${toraddress}'" # 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 "installed=0" echo "active=0" echo "configured=0" fi exit 0 fi # stop service echo "# making sure services are not running" sudo systemctl stop mempool 2>/dev/null # install (code & compile) if [ "$1" = "install" ]; then # check if already installed isInstalled=$(compgen -u | grep -c mempool) if [ "${isInstalled}" != "0" ]; then echo "result='already installed'" exit 0 fi echo "# *** INSTALL MEMPOOL ***" # install nodeJS /home/admin/config.scripts/bonus.nodejs.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 sudo -u mempool /home/admin/config.scripts/blitz.git-verify.sh "${PGPsigner}" "${PGPpubkeyLink}" "${PGPpubkeyFingerprint}" || exit 1 echo "# npm install for mempool explorer (frontend)" cd frontend sudo -u mempool NG_CLI_ANALYTICS=false npm install --no-optional 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 (1)" exit 1 fi echo "# npm install for mempool explorer (backend)" cd ../backend/ sudo -u mempool NG_CLI_ANALYTICS=false npm install --no-optional if ! [ $? -eq 0 ]; then echo "# FAIL - npm install did not run correctly, aborting" echo "result='failed npm install'" 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 (2)" echo "result='failed npm run build'" exit 1 fi exit 0 fi # remove from system if [ "$1" = "uninstall" ]; then # check if still active isActive=$(sudo ls /etc/systemd/system/mempool.service 2>/dev/null | grep -c 'mempool.service') if [ "${isActive}" != "0" ]; then echo "result='still in use'" exit 1 fi echo "# *** UNINSTALL MEMPOOL ***" # always delete user and home directory sudo userdel -rf mempool exit 0 fi # switch on if [ "$1" = "1" ] || [ "$1" = "on" ]; then isInstalled=$(compgen -u | grep -c mempool) if [ "${isInstalled}" == "0" ]; then echo "# Install code base first ...." /home/admin/config.scripts/bonus.mempool.sh install fi echo "# *** Activate MEMPOOL ***" isActive=$(sudo ls /etc/systemd/system/mempool.service 2>/dev/null | grep -c 'mempool.service') if [ ${isActive} -eq 0 ]; then # make sure that txindex of blockchain is switched on /home/admin/config.scripts/network.txindex.sh on 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;" if [ -f "mariadb-structure.sql" ]; then mariadb -umempool -pmempool mempool < mariadb-structure.sql 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 /var/cache/raspiblitz/mempool-config.json chmod 600 /var/cache/raspiblitz/mempool-config.json || exit 1 cat > /var/cache/raspiblitz/mempool-config.json < /var/cache/raspiblitz/mempool.service <