raspiblitz/home.admin/config.scripts/bonus.electrs.sh

506 lines
16 KiB
Bash
Raw Normal View History

2019-12-04 08:13:21 +00:00
#!/bin/bash
2021-09-21 18:38:21 +01:00
# https://github.com/romanz/electrs/releases
2022-02-10 17:56:35 +00:00
ELECTRSVERSION="v0.9.5"
2021-09-21 18:38:21 +01:00
# https://github.com/romanz/electrs/commits/master
2021-09-24 15:14:36 +01:00
# ELECTRSVERSION="3041e89cd2fb377541b929d852ef6298c2d4e60a"
2019-12-04 08:13:21 +00:00
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
2019-12-24 10:23:49 +01:00
echo "config script to switch the Electrum Rust Server on or off"
echo "bonus.electrs.sh status [?showAddress]"
echo "bonus.electrs.sh [on|off|menu]"
echo "installs the version $ELECTRSVERSION"
2019-12-04 08:13:21 +00:00
exit 1
fi
PGPsigner="romanz"
PGPpubkeyLink="https://github.com/${PGPsigner}.gpg"
PGPpubkeyFingerprint="87CAE5FA46917CBB"
2019-12-04 08:13:21 +00:00
source /mnt/hdd/raspiblitz.conf
# get local and global internet info
source <(/home/admin/config.scripts/internet.sh status global)
2019-12-18 12:25:51 +01:00
# give status
if [ "$1" = "status" ]; then
echo "##### STATUS ELECTRS SERVICE"
if [ "${ElectRS}" = "on" ]; then
echo "configured=1"
else
echo "configured=0"
fi
serviceInstalled=$(sudo systemctl status electrs --no-page 2>/dev/null | grep -c "electrs.service - Electrs")
echo "serviceInstalled=${serviceInstalled}"
2019-12-18 13:07:55 +01:00
if [ ${serviceInstalled} -eq 0 ]; then
echo "infoSync='Service not installed'"
fi
2019-12-18 12:25:51 +01:00
serviceRunning=$(sudo systemctl status electrs --no-page 2>/dev/null | grep -c "active (running)")
echo "serviceRunning=${serviceRunning}"
if [ ${serviceRunning} -eq 1 ]; then
2020-01-26 18:29:24 +01:00
2019-12-18 12:25:51 +01:00
# Experimental try to get sync Info
2021-09-21 18:38:21 +01:00
syncedToBlock=$(sudo journalctl -u electrs --no-pager -n2000 | grep "height=" | tail -n1| cut -d= -f3)
2019-12-18 12:38:03 +01:00
blockchainHeight=$(sudo -u bitcoin ${network}-cli getblockchaininfo 2>/dev/null | jq -r '.headers' | sed 's/[^0-9]*//g')
lastBlockchainHeight=$(($blockchainHeight -1))
2021-09-14 16:31:05 +02:00
syncProgress=0
if [ "${syncedToBlock}" != "" ] && [ "${blockchainHeight}" != "" ] && [ "${blockchainHeight}" != "0" ]; then
2021-09-14 16:35:19 +02:00
syncProgress="$(echo "$syncedToBlock" "$blockchainHeight" | awk '{printf "%.2f", $1 / $2 * 100}')"
2021-09-14 16:31:05 +02:00
fi
echo "syncProgress=${syncProgress}%"
if [ "${syncedToBlock}" = "${blockchainHeight}" ] || [ "${syncedToBlock}" = "${lastBlockchainHeight}" ]; then
echo "tipSynced=1"
else
echo "tipSynced=0"
fi
# check if initial sync was done, by setting a file as once electrs is the first time responding on port 50001
electrumResponding=$(echo '{"jsonrpc":"2.0","method":"server.ping","params":[],"id":"electrs-check"}' | netcat -w 2 127.0.0.1 50001 | grep -c "result")
if [ ${electrumResponding} -gt 1 ]; then
electrumResponding=1
fi
echo "electrumResponding=${electrumResponding}"
fileFlagExists=$(sudo ls /mnt/hdd/app-storage/electrs/initial-sync.done 2>/dev/null | grep -c 'initial-sync.done')
if [ ${fileFlagExists} -eq 0 ] && [ ${electrumResponding} -gt 0 ]; then
# set file flag for the future
sudo touch /mnt/hdd/app-storage/electrs/initial-sync.done
sudo chmod 544 /mnt/hdd/app-storage/electrs/initial-sync.done
fileFlagExists=1
fi
if [ ${fileFlagExists} -eq 0 ]; then
echo "initialSynced=0"
echo "infoSync='Building Index (please wait)'"
2019-12-18 12:25:51 +01:00
else
echo "initialSynced=1"
2019-12-18 12:25:51 +01:00
fi
2020-01-26 18:29:24 +01:00
# check local IPv4 port
echo "localIP='${localip}'"
if [ "$2" = "showAddress" ]; then
echo "publicIP='${cleanip}'"
fi
2020-01-26 18:42:47 +01:00
echo "portTCP='50001'"
localPortRunning=$(sudo netstat -an | grep -c '0.0.0.0:50001')
2020-01-26 18:42:47 +01:00
echo "localTCPPortActive=${localPortRunning}"
publicPortRunning=$(nc -z -w6 ${publicip} 50001 2>/dev/null; echo $?)
2020-01-26 18:29:24 +01:00
if [ "${publicPortRunning}" == "0" ]; then
# OK looks good - but just means that something is answering on that port
2020-01-26 18:42:47 +01:00
echo "publicTCPPortAnswering=1"
2020-01-26 18:29:24 +01:00
else
# no answer on that port
2020-01-26 18:42:47 +01:00
echo "publicTCPPortAnswering=0"
2020-01-26 18:29:24 +01:00
fi
2021-09-21 18:38:21 +01:00
echo "portSSL='50002'"
localPortRunning=$(sudo netstat -an | grep -c '0.0.0.0:50002')
2020-01-28 14:37:55 +01:00
echo "localHTTPPortActive=${localPortRunning}"
publicPortRunning=$(nc -z -w6 ${publicip} 50002 2>/dev/null; echo $?)
2020-01-26 18:42:47 +01:00
if [ "${publicPortRunning}" == "0" ]; then
# OK looks good - but just means that something is answering on that port
2020-01-28 14:37:55 +01:00
echo "publicHTTPPortAnswering=1"
2020-01-26 18:42:47 +01:00
else
# no answer on that port
2020-01-28 14:37:55 +01:00
echo "publicHTTPPortAnswering=0"
2020-01-26 18:42:47 +01:00
fi
2020-01-26 22:12:46 +01:00
# add TOR info
if [ "${runBehindTor}" == "on" ]; then
2021-09-21 18:38:21 +01:00
echo "TorRunning=1"
if [ "$2" = "showAddress" ]; then
TORaddress=$(sudo cat /mnt/hdd/tor/electrs/hostname)
echo "TORaddress='${TORaddress}'"
fi
2020-01-26 22:12:46 +01:00
else
2021-09-21 18:38:21 +01:00
echo "TorRunning=0"
2020-01-26 22:12:46 +01:00
fi
# check Nginx
nginxTest=$(sudo nginx -t 2>&1 | grep -c "test is successful")
echo "nginxTest=$nginxTest"
2020-01-26 18:29:24 +01:00
2019-12-18 12:25:51 +01:00
else
echo "tipSynced=0"
echo "initialSynced=0"
echo "electrumResponding=0"
echo "infoSync='Not running - check: sudo journalctl -u electrs'"
2019-12-18 12:25:51 +01:00
fi
exit 0
fi
2020-01-26 20:33:05 +01:00
if [ "$1" = "menu" ]; then
# get status
2020-01-26 22:13:47 +01:00
echo "# collecting status info ... (please wait)"
source <(sudo /home/admin/config.scripts/bonus.electrs.sh status showAddress)
2020-01-26 20:33:05 +01:00
if [ ${serviceInstalled} -eq 0 ]; then
echo "# FAIL not installed"
exit 1
fi
if [ ${serviceRunning} -eq 0 ]; then
dialog --title "Electrum Service Not Running" --msgbox "
The electrum system service is not running.
Please check the following debug info.
" 8 48
merging pre-1.7.1 (#2462) * fix copychain returns * typo in sync loop * stop services on inconsistent state * calling correct provisioning * apply bitcoin and lncli aliases in all scripts * network.aliases: add CLNETWORK * make cln default plugin dir: cln-plugins-enabled similar to the nginx model make 2 directories for plugins: cln-plugins-enabled - symlinked to ~/.lightning/plugins plugins from here are loaded automatically on cln start cln-plugins-available: plugins are downloaded here to be run until the next cln restart (or stopped with runonce) note the disk is mounted with noexec so plugins can't run from there discuss in: https://github.com/rootzoll/raspiblitz/issues/2295 * move shutdown script * change all place where shutdown script is used * change notify & release * moved shutdown script * moved shutdown scripts * add more debug info * moving github script * remove chain in sync * no longer needed chain in sync * move debug script * patch patch command * make sure setup file is sourced * remove debug output * make sure lnd is put behind tor * change indent * get fresh sync progress * avoid scrolling in menus * use new selfsignedcert if no lnd tls.cert present * sparko: add info and connect menu with own cert https://github.com/rootzoll/raspiblitz/issues/2295 * cln.rest: add connect option for Zeus https://github.com/rootzoll/raspiblitz/issues/2295 * cln: add the backup plugin + options Usage options: cln-plugin.backup.sh [on] [testnet|mainnet|signet] cln-plugin.backup.sh [restore] [testnet|mainnet|signet] [force] cln-plugin.backup.sh [backup-compact] [testnet|mainnet|signet] https://github.com/lightningd/plugins/tree/master/backup Discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * cln: add cln-plugin.standard.python.sh Install and show the output of the chosen plugin for C-lightning Usage: cln-plugin.standard-python.sh on [plugin-name] [testnet|mainnet|signet] [runonce] tested plugins: summary | helpme | feeadjuster find more at: https://github.com/lightningd/plugins discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * shellcheck: change all `egrep` to `grep -E` https://github.com/koalaman/shellcheck/wiki/SC2196 * do not resolve aliases, use as variables * lnd: fix lnd.conf for parallel networks discussed in: https://github.com/rootzoll/raspiblitz/issues/2290 * lnd: add LND option for parallel networks * deprecate Testnet in SETTINGS keysend and autopilot only for mainnet due to: https://github.com/rootzoll/raspiblitz/issues/2290 * lnd: autopilot and autounlock for testnet * fix comments * add the SYSTEM menu for parallel chains * RTL update to v0.11.0 make chain specific directory for the config: /home/rtl/${netprefix}RTL/ use ${netprefix}lnd.conf in config override Environmen tvaribales for cln in the systemd service: /etc/systemd/system/${netprefix}${typeprefix}RTL.service discussed in: https://github.com/rootzoll/raspiblitz/issues/2384 * lnd.setname.sh for testnet * display ${CHAIN} in the SYSTEM menu options * keep _aliases file when live patches are applied * all lncli_aliases to be used as variables * default to KIllMode=control-group in services https://www.man7.org/linux/man-pages/man5/systemd.kill.5.html discussed in: https://github.com/rootzoll/raspiblitz/issues/1901 * add cln.hsmtool.sh for hsm_secret handling encrypt | decrypt | autounlock the hsm_secret for C-lightning usage: cln.hsmtool.sh [unlock] [testnet|mainnet|signet] cln.hsmtool.sh [encrypt|decrypt] [testnet|mainnet|signet] cln.hsmtool.sh [autounlock-on|autounlock-off] [testnet|mainnet|signet] discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * add cln.install-service.sh to set up cln with systemd script to set up or update the CLN systemd service checks for hsm_secret encryption, autounlock and the sparko plugin usage: /home/admin/config.scripts/cln.install-service.sh $CHAIN discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * use symlink to cln-plugins-enabled for all plugins * keep lnd autopilot and autounlock mainnet only mainnet only settings: lnd autopilot lnd keysend circuibreaker lnd autounlock StaticChannelBackup to DropBox and USB * cln FUNDING fix parsing address * cln.hsmtool: add change-password and lock options * always set password A * cached peer info * fix printing cache * fix check for existing files * handle bitcoind not running * result with newline * test line break * test new line * test new line * two vars on output * #2388 improve online check (less pinging) * used cached peer status * move chache * cach file permissions * allow sudo call * fix cache * remove double scan info * add conf info to sync screen * reorder info * add space * add space * order info * internet suppress error messages * order info * fix offering Blockchain copy * fix hostname * final ready state info * lnd unlock after provision * remove debug exit * harmonize ready state * add status to lnd unlock * update lnd unlock script * edit the unlock * remove debug echo * add debug * add debug * fix if statement * debug output * switch position of source setupdata * #1126 preparing new setup with new c-lightning (#2396) * move debug script * patch patch command * make sure setup file is sourced * remove debug output * make sure lnd is put behind tor * change indent * get fresh sync progress * always set password A * cached peer info * fix printing cache * fix check for existing files * handle bitcoind not running * result with newline * test line break * test new line * test new line * two vars on output * #2388 improve online check (less pinging) * used cached peer status * move chache * cach file permissions * allow sudo call * fix cache * remove double scan info * add conf info to sync screen * reorder info * add space * add space * order info * internet suppress error messages * order info * fix offering Blockchain copy * fix hostname * final ready state info * lnd unlock after provision * remove debug exit * harmonize ready state * add status to lnd unlock * update lnd unlock script * edit the unlock * remove debug echo * add debug * add debug * fix if statement * debug output * switch position of source setupdata * lnd.unlock: fix typo * netwok.monitor.sh debug * cln-plugin.summary: fix paths * rtl: fix permission of config on copy * CASHOUT: use aliases for lnd * rtl: install correctly for paralell chains * use CHAIN in CLN and LND menu * cln: add CASHOUT option * CLOSEALL and CASHOUT: Improve labels and comments Explaining CASHOUT in the label as discussed in: https://github.com/rootzoll/raspiblitz/issues/2358 * cln.install: fix tor config * cln: installthe latest master until the next release * _commands: source _aliases only if exists * network aliases: fall back to 'main' for 'chain' * new setup: keep testnet3 blocks and chainstate * new setup: improve capitalization in menu * improve help and comments * cln: install Sparko if configured, but not present * cln: add new wallet and import seed options * fix peernum * make sure that aliases get created on lnd setup * no error if aliases not yet exist * debug state * fix network alias when not set * fix syntax error * add debug error info * mute unlocking echos * add debug wait * add debug wait * make sure info is uptodate * make alias info as defaults * rename option * update sync info for no lightning * add action string * update sync info * move name dialog * wait for sync progress info * wait for syncprogress info * fix syntax * get fresh data * make sure to disable lnd * add c-lightning to debug * add setup logs to debug output * fix syntax error * add new-force wallet * try fix call hsmtool * hsm output tool * fix output * add seed-force * refactor blitz.mnemonic.py * test seed * debug info * dump object * try check * correct putput * fix syntax * check lnd for valid seed * fix gui * add Suez install script discussed in: https://github.com/rootzoll/raspiblitz/issues/2366 * cln rescue file export * get correct version * add cln export gui * cln.backup.sh cln-import * correct bytesize * generate cln wallet with passwordc * fix syntax * fix syntax * mute not needed error msg * PEERING: correct message on success * cln.install-service: fix sparko check * add Suez to menu for CLN and LND needs to be installed with the bitcoin user to be able to interact with CLN related: https://github.com/rootzoll/raspiblitz/issues/2366 * debug _provison.setup.sh stop bitcoind and restart with new config to avoid rpc password error disable and enable service instead of daemon-reload CLN: don't use passwordC as seedPassword * add cln.setname.sh make lnd.setname.sh work with parallel wallets * improve comments * SYSTEM: add CLNLOG and CLNCONF options * SYSTEM menu fixes * cln: add more aliases cln, clnlog, clnconf * cln: activate the backup plugin on every install * SERVICES menu: fix chantools/CLN switch * cln: load plugins from ${netprefix}cln-plugins-enabled changed the config paths to $lightning-dir/config or /networkname/config plugins are downloaded to the SDcard: /home/bitcoin/cln-plugins-available/ symlinked and loaded automatically from: /home/bitcoin/${netprefix}cln-plugins-enabled Related: #2295 * sparko: don't show logs after install * #2425 Adding experimental Blitz WebUI & API (#2426) * no password C & D when cln * add debug echos * set defaults before * #2228 wider grep to detect nvms (#2427) * cln.hsmtool: init backup with the new wallet * cln.install: fix access to raspiblitz.conf * cln-plugin.backup: fix path to backup-cli * cln: hide unhelpful warnings during setup * remove old jinja template rendering * fix lnd unlock detection * cln: look for files in .lightning dir with sudo * cln: correct lightning name in FInalDialog + typo * cln: make sure .lightning/bitcoin dir exists * FinalDialog: make the 24 words fit * cln.install.sh: create cln config if not present * Simplify localIP detection and improve compatibility (#2432) * show tail info on provision * only show lnd options when activated * fix syntax * only show main lightning impl options for RC1 * cln: always start the lightnind.service * cln: clear before showing summary * start cln on the end of provisioning * exit 0 on cln menu * press key after single actions * remove key press on cln actions * change to none * detect cln running * fix syntax * fix lightniing info * add TODO for CLN * add clnblockheight * zty with user bitcoin * check synced to chain for cln * fix increment * try scanprogress * use cln sync detection and progress * replace LNTYPE * next line * fix spaces * fix spaces * Update README.md (#2456) Fix 404 * Fix FAQ links (#2441) * Fix invalid URL ( (#2440) * support channels (#2382) * use #2370 height optimization * adjust exit codes in menu scripts * adjust password menu exit codes * adapt shutdown for cln * settings adapt to running lightning impl * fix syntax * debug info * add debug * better height * add default values * add config entry if not there yet * change default value * Added exit info for cln * make sure to load config file if available * add sparko to menu * add default for sparko * replace default sparko entry * show sparko installed or not * add more description to sparko option * RTL for clightnign in service menu * main menu item rtl * add RTL description * debug in RTL install * install sparko on recovery * update menu with cln * rework menu options Co-authored-by: openoms <oms@tuta.io> Co-authored-by: openoms <43343391+openoms@users.noreply.github.com> Co-authored-by: rek79 <rek79@users.noreply.github.com> Co-authored-by: Bitpaint <67663265+bitpaint@users.noreply.github.com> Co-authored-by: João Thallis <joaothallis@icloud.com> Co-authored-by: Peter Flock <78184669+peterflock@users.noreply.github.com> Co-authored-by: nyxnor <nyxnor@protonmail.com>
2021-08-04 00:18:30 +02:00
/home/admin/config.scripts/blitz.debug.sh
echo "Press ENTER to get back to main menu."
read key
exit 0
fi
if [ ${initialSynced} -eq 0 ]; then
dialog --title "Electrum Index Not Ready" --msgbox "
Electrum server is still building its index.
Please wait and try again later.
This can take multiple hours.
" 9 48
exit 0
fi
if [ ${nginxTest} -eq 0 ]; then
dialog --title "Testing nginx.conf has failed" --msgbox "
Nginx is in a failed state. Will attempt to fix.
Try connecting via port 50002 or Tor again once finished.
Check 'sudo nginx -t' for a detailed error message.
" 9 61
logFileMissing=$(sudo nginx -t 2>&1 | grep -c "/var/log/nginx/access.log")
if [ ${logFileMissing} -eq 1 ]; then
sudo mkdir /var/log/nginx
sudo systemctl restart nginx
fi
/home/admin/config.scripts/blitz.web.sh
echo "Press ENTER to get back to main menu."
read key
exit 0
fi
2020-01-26 20:33:05 +01:00
# Options (available without TOR)
OPTIONS=( \
CONNECT "How to Connect" \
INDEX "Delete&Rebuild Index" \
2020-01-26 21:52:00 +01:00
STATUS "ElectRS Status Info"
2020-01-26 20:33:05 +01:00
)
2020-01-26 22:15:07 +01:00
CHOICE=$(whiptail --clear --title "Electrum Rust Server" --menu "menu" 10 50 4 "${OPTIONS[@]}" 2>&1 >/dev/tty)
2020-01-26 20:33:05 +01:00
clear
case $CHOICE in
CONNECT)
echo "######## How to Connect to Electrum Rust Server #######"
2020-01-26 21:52:00 +01:00
echo
echo "Install the Electrum Wallet App on your laptop from:"
echo "https://electrum.org"
echo
echo "On Network Settings > Server menu:"
echo "- deactivate automatic server selection"
2021-09-21 18:38:21 +01:00
echo "- as manual server set '${localip}' & '${portSSL}'"
2020-01-26 21:52:00 +01:00
echo "- laptop and RaspiBlitz need to be within same local network"
echo
2020-01-26 22:12:46 +01:00
echo "To start directly from laptop terminal use:"
2021-09-21 18:38:21 +01:00
echo "electrum --oneserver --server ${localip}:${portSSL}:s"
if [ ${TorRunning} -eq 1 ]; then
echo
echo "The Tor Hidden Service address for electrs is (see LCD for QR code):"
2020-01-26 22:12:46 +01:00
echo "${TORaddress}"
2020-01-27 06:44:10 +01:00
echo
echo "To connect through TOR open the Tor Browser and start with the options:"
echo "electrum --oneserver --server ${TORaddress}:50002:s --proxy socks5:127.0.0.1:9150"
2022-02-13 12:23:34 +00:00
sudo /home/admin/config.scripts/blitz.display.sh qr "${TORaddress}"
2020-01-26 22:12:46 +01:00
fi
2020-01-26 21:52:00 +01:00
echo
echo "For more details check the RaspiBlitz README on ElectRS:"
echo "https://github.com/rootzoll/raspiblitz"
echo
echo "Press ENTER to get back to main menu."
2020-01-26 20:33:05 +01:00
read key
2022-02-13 12:23:34 +00:00
sudo /home/admin/config.scripts/blitz.display.sh hide
2020-01-26 20:33:05 +01:00
;;
STATUS)
sudo /home/admin/config.scripts/bonus.electrs.sh status
echo
echo "Press ENTER to get back to main menu."
read key
;;
INDEX)
echo "######## Delete/Rebuild Index ########"
echo "# stopping service"
sudo systemctl stop electrs
echo "# deleting index"
sudo rm -r /mnt/hdd/app-storage/electrs/db
2020-06-05 18:38:13 +02:00
sudo rm /mnt/hdd/app-storage/electrs/initial-sync.done 2>/dev/null
echo "# starting service"
sudo systemctl start electrs
echo "# ok"
echo
echo "Press ENTER to get back to main menu."
2020-01-26 20:33:05 +01:00
read key
;;
esac
exit 0
fi
2019-12-18 12:27:42 +01:00
# stop service
echo "# Making sure services are not running"
2019-12-18 12:27:42 +01:00
sudo systemctl stop electrs 2>/dev/null
2019-12-04 08:13:21 +00:00
# switch on
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
echo "# INSTALL ELECTRS"
2019-12-04 08:13:21 +00:00
isInstalled=$(sudo ls /etc/systemd/system/electrs.service 2>/dev/null | grep -c 'electrs.service')
if [ ${isInstalled} -eq 0 ]; then
#cleanup
sudo rm -f /home/electrs/.electrs/config.toml
2019-12-04 08:13:21 +00:00
echo
echo "# Creating the electrs user"
echo
2019-12-04 08:13:21 +00:00
sudo adduser --disabled-password --gecos "" electrs
cd /home/electrs
echo
2021-10-10 10:50:23 +01:00
echo "# Installing Rust for the electrs user"
echo
# https://github.com/romanz/electrs/blob/master/doc/usage.md#build-dependencies
2021-10-10 10:50:23 +01:00
sudo -u electrs curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sudo -u electrs sh -s -- --default-toolchain none -y
sudo apt install -y clang cmake build-essential # for building 'rust-rocksdb'
2019-12-04 08:13:21 +00:00
echo
echo "# Downloading and building electrs $ELECTRSVERSION. This will take ~40 minutes"
echo
2019-12-04 08:13:21 +00:00
sudo -u electrs git clone https://github.com/romanz/electrs
cd /home/electrs/electrs || exit 1
sudo -u electrs git reset --hard $ELECTRSVERSION
sudo -u electrs /home/admin/config.scripts/blitz.git-verify.sh \
"${PGPsigner}" "${PGPpubkeyLink}" "${PGPpubkeyFingerprint}" || exit 1
2021-10-10 10:50:23 +01:00
sudo -u electrs /home/electrs/.cargo/bin/cargo build --locked --release || exit 1
2019-12-04 08:13:21 +00:00
echo
echo "# The electrs database will be built in /mnt/hdd/app-storage/electrs/db. Takes ~18 hours and ~50Gb diskspace"
echo
2019-12-17 14:05:20 +01:00
sudo mkdir /mnt/hdd/app-storage/electrs 2>/dev/null
sudo chown -R electrs:electrs /mnt/hdd/app-storage/electrs
2019-12-04 08:13:21 +00:00
echo
echo "# Getting RPC credentials from the bitcoin.conf"
2019-12-04 08:13:21 +00:00
#read PASSWORD_B
RPC_USER=$(sudo cat /mnt/hdd/bitcoin/bitcoin.conf | grep rpcuser | cut -c 9-)
PASSWORD_B=$(sudo cat /mnt/hdd/bitcoin/bitcoin.conf | grep rpcpassword | cut -c 13-)
echo "# Done"
2019-12-04 08:13:21 +00:00
echo
echo "# Generating electrs.toml setting file with the RPC passwords"
echo
2019-12-04 08:13:21 +00:00
# generate setting file: https://github.com/romanz/electrs/issues/170#issuecomment-530080134
# https://github.com/romanz/electrs/blob/master/doc/usage.md#configuration-files-and-environment-variables
sudo -u electrs mkdir /home/electrs/.electrs 2>/dev/null
echo "\
log_filters = \"INFO\"
2019-12-04 08:13:21 +00:00
timestamp = true
jsonrpc_import = true
index-batch-size = 10
wait_duration_secs = 10
jsonrpc_timeout_secs = 15
db_dir = \"/mnt/hdd/app-storage/electrs/db\"
2021-12-19 23:43:07 +01:00
auth = \"${RPC_USER}:${PASSWORD_B}\"
# allow BTC-RPC-explorer show tx-s for addresses with a history of more than 100
2021-01-11 20:52:32 +01:00
txid_limit = 1000
server_banner = \"Welcome to electrs $ELECTRSVERSION - the Electrum Rust Server on your RaspiBlitz\"
" | sudo tee /home/electrs/.electrs/config.toml
sudo chmod 600 /home/electrs/.electrs/config.toml
2019-12-04 08:13:21 +00:00
sudo chown electrs:electrs /home/electrs/.electrs/config.toml
echo
echo "# Checking for config.toml"
echo
2019-12-04 08:13:21 +00:00
if [ ! -f "/home/electrs/.electrs/config.toml" ]
then
echo "Failed to create config.toml"
exit 1
else
echo "OK"
fi
echo
echo "# Setting up the nginx.conf"
echo
2019-12-04 08:13:21 +00:00
isElectrs=$(sudo cat /etc/nginx/nginx.conf 2>/dev/null | grep -c 'upstream electrs')
if [ ${isElectrs} -gt 0 ]; then
echo "electrs is already configured with Nginx. To edit manually run \`sudo nano /etc/nginx/nginx.conf\`"
elif [ ${isElectrs} -eq 0 ]; then
isStream=$(sudo cat /etc/nginx/nginx.conf 2>/dev/null | grep -c 'stream {')
if [ ${isStream} -eq 0 ]; then
echo "
stream {
upstream electrs {
server 127.0.0.1:50001;
}
server {
listen 50002 ssl;
proxy_pass electrs;
ssl_certificate /mnt/hdd/app-data/nginx/tls.cert;
ssl_certificate_key /mnt/hdd/app-data/nginx/tls.key;
2019-12-04 08:13:21 +00:00
ssl_session_cache shared:SSL-electrs:1m;
ssl_session_timeout 4h;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
2019-12-04 08:13:21 +00:00
ssl_prefer_server_ciphers on;
}
}" | sudo tee -a /etc/nginx/nginx.conf
elif [ ${isStream} -eq 1 ]; then
sudo truncate -s-2 /etc/nginx/nginx.conf
echo "
upstream electrs {
server 127.0.0.1:50001;
}
server {
listen 50002 ssl;
proxy_pass electrs;
ssl_certificate /mnt/hdd/app-data/nginx/tls.cert;
ssl_certificate_key /mnt/hdd/app-data/nginx/tls.key;
2019-12-04 08:13:21 +00:00
ssl_session_cache shared:SSL-electrs:1m;
ssl_session_timeout 4h;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
2019-12-04 08:13:21 +00:00
ssl_prefer_server_ciphers on;
}
}" | sudo tee -a /etc/nginx/nginx.conf
elif [ ${isStream} -gt 1 ]; then
echo " Too many \`stream\` commands in nginx.conf. Please edit manually: \`sudo nano /etc/nginx/nginx.conf\` and retry"
exit 1
fi
fi
echo
echo "# Open ports 50001 and 5002 on UFW "
echo
sudo ufw allow 50001 comment 'electrs TCP'
sudo ufw allow 50002 comment 'electrs SSL'
echo
echo "# Installing the systemd service"
echo
# sudo nano /etc/systemd/system/electrs.service
2019-12-04 08:13:21 +00:00
echo "
[Unit]
Description=Electrs
After=bitcoind.service
2019-12-04 08:13:21 +00:00
[Service]
WorkingDirectory=/home/electrs/electrs
ExecStart=/home/electrs/electrs/target/release/electrs --electrum-rpc-addr=\"0.0.0.0:50001\"
2019-12-04 08:13:21 +00:00
User=electrs
Group=electrs
Type=simple
TimeoutSec=60
Restart=always
RestartSec=60
merging pre-1.7.1 (#2462) * fix copychain returns * typo in sync loop * stop services on inconsistent state * calling correct provisioning * apply bitcoin and lncli aliases in all scripts * network.aliases: add CLNETWORK * make cln default plugin dir: cln-plugins-enabled similar to the nginx model make 2 directories for plugins: cln-plugins-enabled - symlinked to ~/.lightning/plugins plugins from here are loaded automatically on cln start cln-plugins-available: plugins are downloaded here to be run until the next cln restart (or stopped with runonce) note the disk is mounted with noexec so plugins can't run from there discuss in: https://github.com/rootzoll/raspiblitz/issues/2295 * move shutdown script * change all place where shutdown script is used * change notify & release * moved shutdown script * moved shutdown scripts * add more debug info * moving github script * remove chain in sync * no longer needed chain in sync * move debug script * patch patch command * make sure setup file is sourced * remove debug output * make sure lnd is put behind tor * change indent * get fresh sync progress * avoid scrolling in menus * use new selfsignedcert if no lnd tls.cert present * sparko: add info and connect menu with own cert https://github.com/rootzoll/raspiblitz/issues/2295 * cln.rest: add connect option for Zeus https://github.com/rootzoll/raspiblitz/issues/2295 * cln: add the backup plugin + options Usage options: cln-plugin.backup.sh [on] [testnet|mainnet|signet] cln-plugin.backup.sh [restore] [testnet|mainnet|signet] [force] cln-plugin.backup.sh [backup-compact] [testnet|mainnet|signet] https://github.com/lightningd/plugins/tree/master/backup Discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * cln: add cln-plugin.standard.python.sh Install and show the output of the chosen plugin for C-lightning Usage: cln-plugin.standard-python.sh on [plugin-name] [testnet|mainnet|signet] [runonce] tested plugins: summary | helpme | feeadjuster find more at: https://github.com/lightningd/plugins discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * shellcheck: change all `egrep` to `grep -E` https://github.com/koalaman/shellcheck/wiki/SC2196 * do not resolve aliases, use as variables * lnd: fix lnd.conf for parallel networks discussed in: https://github.com/rootzoll/raspiblitz/issues/2290 * lnd: add LND option for parallel networks * deprecate Testnet in SETTINGS keysend and autopilot only for mainnet due to: https://github.com/rootzoll/raspiblitz/issues/2290 * lnd: autopilot and autounlock for testnet * fix comments * add the SYSTEM menu for parallel chains * RTL update to v0.11.0 make chain specific directory for the config: /home/rtl/${netprefix}RTL/ use ${netprefix}lnd.conf in config override Environmen tvaribales for cln in the systemd service: /etc/systemd/system/${netprefix}${typeprefix}RTL.service discussed in: https://github.com/rootzoll/raspiblitz/issues/2384 * lnd.setname.sh for testnet * display ${CHAIN} in the SYSTEM menu options * keep _aliases file when live patches are applied * all lncli_aliases to be used as variables * default to KIllMode=control-group in services https://www.man7.org/linux/man-pages/man5/systemd.kill.5.html discussed in: https://github.com/rootzoll/raspiblitz/issues/1901 * add cln.hsmtool.sh for hsm_secret handling encrypt | decrypt | autounlock the hsm_secret for C-lightning usage: cln.hsmtool.sh [unlock] [testnet|mainnet|signet] cln.hsmtool.sh [encrypt|decrypt] [testnet|mainnet|signet] cln.hsmtool.sh [autounlock-on|autounlock-off] [testnet|mainnet|signet] discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * add cln.install-service.sh to set up cln with systemd script to set up or update the CLN systemd service checks for hsm_secret encryption, autounlock and the sparko plugin usage: /home/admin/config.scripts/cln.install-service.sh $CHAIN discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * use symlink to cln-plugins-enabled for all plugins * keep lnd autopilot and autounlock mainnet only mainnet only settings: lnd autopilot lnd keysend circuibreaker lnd autounlock StaticChannelBackup to DropBox and USB * cln FUNDING fix parsing address * cln.hsmtool: add change-password and lock options * always set password A * cached peer info * fix printing cache * fix check for existing files * handle bitcoind not running * result with newline * test line break * test new line * test new line * two vars on output * #2388 improve online check (less pinging) * used cached peer status * move chache * cach file permissions * allow sudo call * fix cache * remove double scan info * add conf info to sync screen * reorder info * add space * add space * order info * internet suppress error messages * order info * fix offering Blockchain copy * fix hostname * final ready state info * lnd unlock after provision * remove debug exit * harmonize ready state * add status to lnd unlock * update lnd unlock script * edit the unlock * remove debug echo * add debug * add debug * fix if statement * debug output * switch position of source setupdata * #1126 preparing new setup with new c-lightning (#2396) * move debug script * patch patch command * make sure setup file is sourced * remove debug output * make sure lnd is put behind tor * change indent * get fresh sync progress * always set password A * cached peer info * fix printing cache * fix check for existing files * handle bitcoind not running * result with newline * test line break * test new line * test new line * two vars on output * #2388 improve online check (less pinging) * used cached peer status * move chache * cach file permissions * allow sudo call * fix cache * remove double scan info * add conf info to sync screen * reorder info * add space * add space * order info * internet suppress error messages * order info * fix offering Blockchain copy * fix hostname * final ready state info * lnd unlock after provision * remove debug exit * harmonize ready state * add status to lnd unlock * update lnd unlock script * edit the unlock * remove debug echo * add debug * add debug * fix if statement * debug output * switch position of source setupdata * lnd.unlock: fix typo * netwok.monitor.sh debug * cln-plugin.summary: fix paths * rtl: fix permission of config on copy * CASHOUT: use aliases for lnd * rtl: install correctly for paralell chains * use CHAIN in CLN and LND menu * cln: add CASHOUT option * CLOSEALL and CASHOUT: Improve labels and comments Explaining CASHOUT in the label as discussed in: https://github.com/rootzoll/raspiblitz/issues/2358 * cln.install: fix tor config * cln: installthe latest master until the next release * _commands: source _aliases only if exists * network aliases: fall back to 'main' for 'chain' * new setup: keep testnet3 blocks and chainstate * new setup: improve capitalization in menu * improve help and comments * cln: install Sparko if configured, but not present * cln: add new wallet and import seed options * fix peernum * make sure that aliases get created on lnd setup * no error if aliases not yet exist * debug state * fix network alias when not set * fix syntax error * add debug error info * mute unlocking echos * add debug wait * add debug wait * make sure info is uptodate * make alias info as defaults * rename option * update sync info for no lightning * add action string * update sync info * move name dialog * wait for sync progress info * wait for syncprogress info * fix syntax * get fresh data * make sure to disable lnd * add c-lightning to debug * add setup logs to debug output * fix syntax error * add new-force wallet * try fix call hsmtool * hsm output tool * fix output * add seed-force * refactor blitz.mnemonic.py * test seed * debug info * dump object * try check * correct putput * fix syntax * check lnd for valid seed * fix gui * add Suez install script discussed in: https://github.com/rootzoll/raspiblitz/issues/2366 * cln rescue file export * get correct version * add cln export gui * cln.backup.sh cln-import * correct bytesize * generate cln wallet with passwordc * fix syntax * fix syntax * mute not needed error msg * PEERING: correct message on success * cln.install-service: fix sparko check * add Suez to menu for CLN and LND needs to be installed with the bitcoin user to be able to interact with CLN related: https://github.com/rootzoll/raspiblitz/issues/2366 * debug _provison.setup.sh stop bitcoind and restart with new config to avoid rpc password error disable and enable service instead of daemon-reload CLN: don't use passwordC as seedPassword * add cln.setname.sh make lnd.setname.sh work with parallel wallets * improve comments * SYSTEM: add CLNLOG and CLNCONF options * SYSTEM menu fixes * cln: add more aliases cln, clnlog, clnconf * cln: activate the backup plugin on every install * SERVICES menu: fix chantools/CLN switch * cln: load plugins from ${netprefix}cln-plugins-enabled changed the config paths to $lightning-dir/config or /networkname/config plugins are downloaded to the SDcard: /home/bitcoin/cln-plugins-available/ symlinked and loaded automatically from: /home/bitcoin/${netprefix}cln-plugins-enabled Related: #2295 * sparko: don't show logs after install * #2425 Adding experimental Blitz WebUI & API (#2426) * no password C & D when cln * add debug echos * set defaults before * #2228 wider grep to detect nvms (#2427) * cln.hsmtool: init backup with the new wallet * cln.install: fix access to raspiblitz.conf * cln-plugin.backup: fix path to backup-cli * cln: hide unhelpful warnings during setup * remove old jinja template rendering * fix lnd unlock detection * cln: look for files in .lightning dir with sudo * cln: correct lightning name in FInalDialog + typo * cln: make sure .lightning/bitcoin dir exists * FinalDialog: make the 24 words fit * cln.install.sh: create cln config if not present * Simplify localIP detection and improve compatibility (#2432) * show tail info on provision * only show lnd options when activated * fix syntax * only show main lightning impl options for RC1 * cln: always start the lightnind.service * cln: clear before showing summary * start cln on the end of provisioning * exit 0 on cln menu * press key after single actions * remove key press on cln actions * change to none * detect cln running * fix syntax * fix lightniing info * add TODO for CLN * add clnblockheight * zty with user bitcoin * check synced to chain for cln * fix increment * try scanprogress * use cln sync detection and progress * replace LNTYPE * next line * fix spaces * fix spaces * Update README.md (#2456) Fix 404 * Fix FAQ links (#2441) * Fix invalid URL ( (#2440) * support channels (#2382) * use #2370 height optimization * adjust exit codes in menu scripts * adjust password menu exit codes * adapt shutdown for cln * settings adapt to running lightning impl * fix syntax * debug info * add debug * better height * add default values * add config entry if not there yet * change default value * Added exit info for cln * make sure to load config file if available * add sparko to menu * add default for sparko * replace default sparko entry * show sparko installed or not * add more description to sparko option * RTL for clightnign in service menu * main menu item rtl * add RTL description * debug in RTL install * install sparko on recovery * update menu with cln * rework menu options Co-authored-by: openoms <oms@tuta.io> Co-authored-by: openoms <43343391+openoms@users.noreply.github.com> Co-authored-by: rek79 <rek79@users.noreply.github.com> Co-authored-by: Bitpaint <67663265+bitpaint@users.noreply.github.com> Co-authored-by: João Thallis <joaothallis@icloud.com> Co-authored-by: Peter Flock <78184669+peterflock@users.noreply.github.com> Co-authored-by: nyxnor <nyxnor@protonmail.com>
2021-08-04 00:18:30 +02:00
# Hardening measures
PrivateTmp=true
ProtectSystem=full
NoNewPrivileges=true
PrivateDevices=true
2019-12-04 08:13:21 +00:00
[Install]
WantedBy=multi-user.target
" | sudo tee -a /etc/systemd/system/electrs.service
sudo systemctl enable electrs
# manual start:
# sudo -u electrs /home/electrs/.cargo/bin/cargo run --release -- --index-batch-size=10 --electrum-rpc-addr="0.0.0.0:50001"
else
echo "# ElectRS is already installed."
2019-12-04 08:13:21 +00:00
fi
# setting value in raspiblitz config
/home/admin/config.scripts/blitz.conf.sh set ElectRS "on"
2019-12-04 08:13:21 +00:00
# Hidden Service for electrs if Tor active
if [ "${runBehindTor}" = "on" ]; then
# make sure to keep in sync with tor.network.sh script
/home/admin/config.scripts/tor.onion-service.sh electrs 50002 50002 50001 50001
2019-12-04 08:13:21 +00:00
fi
# whitelist downloading to localhost from bitcoind
if ! sudo grep -Eq "^whitelist=download@127.0.0.1" /mnt/hdd/bitcoin/bitcoin.conf;then
echo "whitelist=download@127.0.0.1" | sudo tee -a /mnt/hdd/bitcoin/bitcoin.conf
bitcoindRestart=yes
fi
source <(/home/admin/_cache.sh get state)
if [ "${state}" == "ready" ]; then
if [ "${bitcoindRestart}" == "yes" ]; then
sudo systemctl restart bitcoind
fi
sudo systemctl restart nginx
sudo systemctl start electrs
# restart BTC-RPC-Explorer to reconfigure itself to use electrs for address API
if [ "${BTCRPCexplorer}" == "on" ]; then
sudo systemctl restart btc-rpc-explorer
echo "# BTC-RPC-Explorer restarted"
fi
2021-09-16 19:23:38 +02:00
fi
echo
2020-01-26 22:12:46 +01:00
echo "# To connect through SSL from outside of the local network make sure the port 50002 is forwarded on the router"
echo
2019-12-04 08:13:21 +00:00
exit 0
fi
# switch off
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
# setting value in raspiblitz config
/home/admin/config.scripts/blitz.conf.sh set ElectRS "off"
2019-12-04 08:13:21 +00:00
# if second parameter is "deleteindex"
if [ "$2" == "deleteindex" ]; then
echo "# deleting electrum index"
sudo rm -rf /mnt/hdd/app-storage/electrs/
fi
# Hidden Service if Tor is active
if [ "${runBehindTor}" = "on" ]; then
/home/admin/config.scripts/tor.onion-service.sh off electrs
fi
2019-12-04 08:13:21 +00:00
isInstalled=$(sudo ls /etc/systemd/system/electrs.service 2>/dev/null | grep -c 'electrs.service')
if [ ${isInstalled} -eq 1 ]; then
2019-12-18 13:07:55 +01:00
echo "# REMOVING ELECTRS"
2019-12-04 08:13:21 +00:00
sudo systemctl disable electrs
sudo rm /etc/systemd/system/electrs.service
# delete user and home directory
sudo userdel -rf electrs
# close ports on firewall
sudo ufw deny 50001
sudo ufw deny 50002
2020-01-26 22:12:46 +01:00
echo "# OK ElectRS removed."
2021-09-16 19:23:38 +02:00
# restart BTC-RPC-Explorer to reconfigure itself to use electrs for address API
if [ "${BTCRPCexplorer}" == "on" ]; then
sudo systemctl restart btc-rpc-explorer
echo "# BTC-RPC-Explorer restarted"
fi
else
2020-01-26 22:12:46 +01:00
echo "# ElectRS is not installed."
2019-12-04 08:13:21 +00:00
fi
exit 0
fi
echo "# FAIL - Unknown Parameter $1"
2019-12-04 08:13:21 +00:00
exit 1