#4581 Add Publicpool (#4785)

* public-pool init (#4647)
* #4581 improve install script
* add to CHANGES
* #4581 add SSH menu
---------
Co-authored-by: WantClue <86001033+WantClue@users.noreply.github.com>
This commit is contained in:
/rootzoll 2024-10-06 21:39:00 +02:00 committed by GitHub
parent 57ddeab520
commit 5c3af683e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 290 additions and 1 deletions

View File

@ -1,5 +1,6 @@
## What's new in Version 1.11.3 of RaspiBlitz?
- New: Publicpool - Open Source Solo Bitcoin Mining (SSH Menu) [details](https://www.youtube.com/watch?v=QbOsH04Z9xM)
- New: Tailscale (SSH menu > SETTINGS) [details](https://en.wikipedia.org/wiki/Tailscale)
- New: Telegraf Metrics for InfluxDB/Grafana (SSH menu > SETTINGS) [details](https://github.com/raspiblitz/raspiblitz/tree/dev/home.admin/assets/telegraf/README.md)
- New: Connect Zeus to CLN via CLNrest (using the clnrest plugin and runes)

View File

@ -171,6 +171,9 @@ fi
if [ "${labelbase}" == "on" ]; then
OPTIONS+=(LABELBASE "Labelbase (UTXO labeling)")
fi
if [ "${publicpool}" == "on" ]; then
OPTIONS+=(PUBLICPOOL "Public Pool (Bitcoin Solo Mining)")
fi
if [ "${tailscale}" == "on" ]; then
OPTIONS+=(TAILSCALE "Tailscale VPN")
fi
@ -178,7 +181,6 @@ if [ "${telegraf}" == "on" ]; then
OPTIONS+=(TELEGRAF "Telegraf InfluxDB/Grafana Metrics")
fi
# dont offer to switch to "testnet view for now" - so no wswitch back to mainnet needed
#if [ ${chain} != "main" ]; then
# OPTIONS+=(MAINNET "Mainnet Service Options")
@ -341,6 +343,9 @@ case $CHOICE in
LABELBASE)
sudo /home/admin/config.scripts/bonus.labelbase.sh menu
;;
PUBLICPOOL)
/home/admin/config.scripts/bonus.publicpool.sh menu
;;
TAILSCALE)
sudo /home/admin/config.scripts/internet.tailscale.sh menu
;;

View File

@ -31,6 +31,7 @@ if [ ${#lightningtipbot} -eq 0 ]; then lightningtipbot="off"; fi
if [ ${#fints} -eq 0 ]; then fints="off"; fi
if [ ${#lndk} -eq 0 ]; then lndk="off"; fi
if [ ${#labelbase} -eq 0 ]; then labelbase="off"; fi
if [ ${#publicpool} -eq 0 ]; then publicpool="off"; fi
# show select dialog
echo "run dialog ..."
@ -48,6 +49,7 @@ if [ "${network}" == "bitcoin" ]; then
OPTIONS+=(za 'BTC Jam (JoinMarket WebUI)' ${jam})
OPTIONS+=(wa 'BTC Download Bitcoin Whitepaper' ${whitepaper})
OPTIONS+=(ls 'BTC Labelbase' ${labelbase})
OPTIONS+=(pp 'BTC Publicpool (Solo Mining)' ${publicpool})
fi
# available for both LND & c-lightning
@ -607,6 +609,22 @@ else
echo "Labelbase setting unchanged."
fi
# publicpool process choice
choice="off"; check=$(echo "${CHOICES}" | grep -c "pp")
if [ ${check} -eq 1 ]; then choice="on"; fi
if [ "${publicpool}" != "${choice}" ]; then
echo "Publicpool setting changed .."
anychange=1
sudo -u admin /home/admin/config.scripts/bonus.publicpool.sh ${choice}
source /mnt/hdd/raspiblitz.conf
if [ "${publicpool}" = "on" ]; then
sudo -u admin /home/admin/config.scripts/bonus.publicpool.sh menu
fi
else
echo "Publicpool setting unchanged."
fi
# fints process choice
choice="off"; check=$(echo "${CHOICES}" | grep -c "fn")
if [ ${check} -eq 1 ]; then choice="on"; fi

View File

@ -743,6 +743,15 @@ else
echo "Provisioning Telegraf - keep default" >> ${logFile}
fi
# Telegraf
if [ "${publicpool}" = "on" ]; then
echo "Provisioning Publicpool - run config script" >> ${logFile}
/home/admin/_cache.sh set message "Setup Publicpool"
sudo -u admin /home/admin/config.scripts/bonus.publicpool.sh on >> ${logFile} 2>&1
else
echo "Provisioning Publicpool - keep default" >> ${logFile}
fi
# custom install script from user
customInstallAvailable=$(ls /mnt/hdd/app-data/custom-installs.sh 2>/dev/null | grep -c "custom-installs.sh")
if [ ${customInstallAvailable} -gt 0 ]; then

View File

@ -432,6 +432,15 @@ else
echo "- FINTS is OFF by config"
fi
if [ "${publicpool}" == "on" ]; then
echo
echo "*** LAST 20 PUBLIPOOL LOGS ***"
echo "sudo journalctl -u publicpool -b --no-pager -n20"
sudo journalctl -u publicpool -b --no-pager -n20
else
echo "- PUBLICPOOL is OFF by config"
fi
echo
echo "*** MOUNTED DRIVES ***"
echo "df -T -h"

View File

@ -0,0 +1,247 @@
#!/bin/bash
APPID="publicpool"
VERSION="0.1"
GITHUB_REPO="https://github.com/benjamin-wilson/public-pool.git"
GITHUB_REPO_UI="https://github.com/benjamin-wilson/public-pool-ui.git"
GITHUB_TAG=""
PORT_API="3334"
PORT_STRATUM="3333"
PORT_UI="3335"
# Use /mnt/hdd for app data
APP_DATA_DIR="/mnt/hdd/app-data/${APPID}"
# Debug information
echo "# Script name: $0"
echo "# All parameters: $@"
echo "# First parameter: $1"
echo "# Parameter count: $#"
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "# bonus.${APPID}.sh status -> status information (key=value)"
echo "# bonus.${APPID}.sh on -> install the app"
echo "# bonus.${APPID}.sh off [delete-data] -> uninstall the app"
echo "# bonus.${APPID}.sh menu -> SSH menu dialog"
exit 1
fi
echo "# Running: 'bonus.${APPID}.sh $*'"
source /mnt/hdd/raspiblitz.conf
isInstalled=$(sudo ls /etc/systemd/system/${APPID}.service 2>/dev/null | grep -c "${APPID}.service")
isRunning=$(sudo systemctl status ${APPID} 2>/dev/null | grep -c 'active (running)')
if [ "${isInstalled}" == "1" ]; then
localIP=$(hostname -I | awk '{print $1}')
fi
if [ "$1" = "status" ]; then
echo "appID='${APPID}'"
echo "version='${VERSION}'"
echo "githubRepo='${GITHUB_REPO}'"
echo "githubRepoUI='${GITHUB_REPO_UI}'"
echo "githubVersion='${GITHUB_TAG}'"
echo "isInstalled=${isInstalled}"
echo "isRunning=${isRunning}"
if [ "${isInstalled}" == "1" ]; then
echo "portAPI=${PORT_API}"
echo "portStratum=${PORT_STRATUM}"
echo "portUI=${PORT_UI}"
echo "localIP='${localIP}'"
fi
exit 0
fi
if [ "$1" = "menu" ]; then
dialogTitle=" ${APPID} "
dialogText="Open in your local web browser:
http://${localIP}:${PORT_UI}\n
API: http://${localIP}:${PORT_API}\n
In your miner configuration, set the
Stratum: ${localIP}:${PORT_STRATUM}\n"
whiptail --title "Public Pool" --msgbox "${dialogText}" 14 57
echo "please wait ..."
exit 0
fi
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
if [ ${isInstalled} -eq 1 ]; then
echo "# ${APPID} is already installed."
exit 1
fi
echo "# Installing ${APPID} ..."
/home/admin/config.scripts/bonus.nodejs.sh on
sudo apt install -y build-essential
sudo apt install -y cmake
sudo apt install -y libzmq3-dev
echo "# create user"
sudo adduser --system --group --shell /usr/sbin/nologin --home /home/${APPID} ${APPID} || exit 1
sudo -u ${APPID} mkdir -p /home/${APPID}/.npm
# I dont think this needs lnd admin privs
# echo "# add user to special groups"
# sudo /usr/sbin/usermod --append --groups lndadmin ${APPID}
echo "# Install global dependencies"
cd /home/${APPID}
sudo npm install -g @nestjs/cli @angular/cli node-gyp node-pre-gyp
echo "# Create app directory and set permissions"
sudo mkdir -p ${APP_DATA_DIR}
sudo chown -R ${APPID}:${APPID} ${APP_DATA_DIR}
echo "# Clone repositories"
sudo -u ${APPID} git clone ${GITHUB_REPO} /home/${APPID}/${APPID}
sudo -u ${APPID} git clone ${GITHUB_REPO_UI} /home/${APPID}/${APPID}-ui
# check that the repos were cloned
if [ ! -d "/home/${APPID}/${APPID}" ] || [ ! -d "/home/${APPID}/${APPID}-ui" ]; then
echo "# FAIL - Was not able to clone the GitHub repos."
exit 1
fi
# Modify the environment.prod.ts file of WebUI
localIP=$(hostname -I | awk '{print $1}')
echo "# Updating environment.prod.ts with correct API and STRATUM URLs"
sudo -u ${APPID} tee /home/${APPID}/${APPID}-ui/src/environments/environment.ts > /dev/null << EOL
export const environment = {
production: true,
API_URL: 'http://${localIP}:${PORT_API}',
STRATUM_URL: '${localIP}:${PORT_STRATUM}'
};
EOL
echo "##### Install Backend"
cd /home/${APPID}/${APPID}
sudo npm install zeromq
sudo chown publicpool:publicpool -R /home/${APPID}/${APPID}
sudo -u ${APPID} npm install || exit 1
echo "##### Build Backend"
sudo -u ${APPID} npm run build || exit 1
echo "##### Install Frontend"
cd /home/${APPID}/${APPID}-ui
sudo -u ${APPID} npm install || exit 1
echo "##### Build Frontend"
sudo -u ${APPID} npm run build || exit 1
echo "# Set correct permissions for npm cache"
sudo chown -R ${APPID}:${APPID} /home/${APPID}/.npm
echo "# updating Firewall"
sudo ufw allow ${PORT_API} comment "${APPID} API"
sudo ufw allow ${PORT_STRATUM} comment "${APPID} Stratum"
sudo ufw allow ${PORT_UI} comment "${APPID} UI"
# get RPC credentials
RPC_USER=$(sudo cat /mnt/hdd/bitcoin/bitcoin.conf | grep rpcuser | cut -c 9-)
RPC_PASS=$(sudo cat /mnt/hdd/bitcoin/bitcoin.conf | grep rpcpassword | cut -c 13-)
echo "# create .env file"
echo "
BITCOIN_RPC_URL=http://127.0.0.1
BITCOIN_RPC_USER=$RPC_USER
BITCOIN_RPC_PASSWORD=$RPC_PASS
BITCOIN_RPC_PORT=8332
BITCOIN_RPC_TIMEOUT=10000
API_PORT=${PORT_API}
STRATUM_PORT=${PORT_STRATUM}
POOL_IDENTIFIER=raspiblitz
NETWORK=mainnet
API_SECURE=false
" | sudo tee /home/${APPID}/${APPID}/.env >/dev/null
echo "# create systemd service: ${APPID}.service"
echo "
[Unit]
Description=${APPID}
Wants=bitcoind
After=bitcoind
[Service]
WorkingDirectory=/home/${APPID}/${APPID}
ExecStart=/usr/bin/npm start
User=${APPID}
Restart=always
TimeoutSec=120
RestartSec=30
StandardOutput=null
StandardError=journal
[Install]
WantedBy=multi-user.target
" | sudo tee /etc/systemd/system/${APPID}.service
sudo chown root:root /etc/systemd/system/${APPID}.service
echo "# create systemd service: ${APPID}-ui.service"
echo "
[Unit]
Description=${APPID} UI
After=${APPID}.service
[Service]
WorkingDirectory=/home/${APPID}/${APPID}-ui
ExecStart=/usr/bin/ng serve --host 0.0.0.0 --port ${PORT_UI} --no-watch --poll 2000
User=${APPID}
Restart=always
StandardOutput=null
StandardError=journal
[Install]
WantedBy=multi-user.target
" | sudo tee /etc/systemd/system/${APPID}-ui.service
sudo chown root:root /etc/systemd/system/${APPID}-ui.service
# mark app as installed in raspiblitz config
/home/admin/config.scripts/blitz.conf.sh set ${APPID} "on"
# enable and start services
sudo systemctl enable ${APPID}
sudo systemctl enable ${APPID}-ui
sudo systemctl start ${APPID}
sudo systemctl start ${APPID}-ui
echo "# OK - the ${APPID} and ${APPID}-ui services are now enabled and started"
exit 0
fi
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
echo "# Uninstalling ${APPID} ..."
sudo systemctl stop ${APPID} 2>/dev/null
sudo systemctl stop ${APPID}-ui 2>/dev/null
sudo systemctl disable ${APPID}.service
sudo systemctl disable ${APPID}-ui.service
sudo rm /etc/systemd/system/${APPID}.service
sudo rm /etc/systemd/system/${APPID}-ui.service
echo "# close ports on firewall"
sudo ufw deny "${PORT_API}"
sudo ufw deny "${PORT_STRATUM}"
sudo ufw deny "${PORT_UI}"
echo "# delete user"
sudo userdel -rf ${APPID}
echo "# mark app as uninstalled in raspiblitz config"
/home/admin/config.scripts/blitz.conf.sh set ${APPID} "off"
if [ "$(echo "$@" | grep -c delete-data)" -gt 0 ]; then
echo "# found 'delete-data' parameter --> also deleting the app-data"
sudo rm -r ${APP_DATA_DIR}
fi
echo "# OK - app should be uninstalled now"
exit 0
fi
echo "# FAIL - Unknown Parameter $1"
exit 1