2019-12-04 08:13:21 +00:00
#!/bin/bash
2021-09-21 18:38:21 +01:00
# https://github.com/romanz/electrs/releases
2023-11-18 10:17:28 +02:00
ELECTRSVERSION = "v0.10.1"
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"
2022-06-30 17:19:43 +02:00
echo "bonus.electrs.sh status -> dont call in loops"
2022-06-30 16:09:54 +02:00
echo "bonus.electrs.sh status-sync"
2022-11-04 15:50:54 +01:00
echo "bonus.electrs.sh [on|off|menu|update]"
2021-08-21 18:17:12 +01:00
echo " installs the version $ELECTRSVERSION "
2019-12-04 08:13:21 +00:00
exit 1
fi
2021-11-30 11:43:52 +00:00
PGPsigner = "romanz"
PGPpubkeyLink = " https://github.com/ ${ PGPsigner } .gpg "
PGPpubkeyFingerprint = "87CAE5FA46917CBB"
2019-12-04 08:13:21 +00:00
source /mnt/hdd/raspiblitz.conf
2022-06-30 16:09:54 +02:00
# give status (dont call regularly - just on occasions)
2019-12-18 12:25:51 +01:00
if [ " $1 " = "status" ] ; then
2022-06-30 17:16:16 +02:00
# get local and global internet info
source <( /home/admin/config.scripts/internet.sh status global)
2019-12-18 12:25:51 +01:00
echo "##### STATUS ELECTRS SERVICE"
2022-12-15 23:45:46 +01:00
echo " version=' ${ ELECTRSVERSION } ' "
2019-12-18 12:25:51 +01:00
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
# check local IPv4 port
2020-09-18 00:54:34 +02:00
echo " localIP=' ${ localip } ' "
2022-06-30 17:19:43 +02:00
echo " publicIP=' ${ cleanip } ' "
2020-01-26 18:42:47 +01:00
echo "portTCP='50001'"
2021-03-23 12:54:00 +01:00
localPortRunning = $( sudo netstat -an | grep -c '0.0.0.0:50001' )
2020-01-26 18:42:47 +01:00
echo " localTCPPortActive= ${ localPortRunning } "
2020-09-18 00:54:34 +02:00
publicPortRunning = $( nc -z -w6 ${ publicip } 50001 2>/dev/null; echo $? )
2020-01-26 18:29:24 +01:00
if [ " ${ publicPortRunning } " = = "0" ] ; then
2020-04-10 22:30:21 +01:00
# 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
2020-04-10 22:30:21 +01:00
# 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'"
2021-03-23 12:54:00 +01:00
localPortRunning = $( sudo netstat -an | grep -c '0.0.0.0:50002' )
2020-01-28 14:37:55 +01:00
echo " localHTTPPortActive= ${ localPortRunning } "
2020-09-18 00:54:34 +02:00
publicPortRunning = $( nc -z -w6 ${ publicip } 50002 2>/dev/null; echo $? )
2020-01-26 18:42:47 +01:00
if [ " ${ publicPortRunning } " = = "0" ] ; then
2020-04-10 22:30:21 +01:00
# 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
2020-04-10 22:30:21 +01:00
# 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
2023-02-03 20:46:07 +01:00
# add Tor info
2020-01-26 22:12:46 +01:00
if [ " ${ runBehindTor } " = = "on" ] ; then
2021-09-21 18:38:21 +01:00
echo "TorRunning=1"
2020-06-11 17:07:20 +01:00
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
2020-04-10 22:30:21 +01:00
# check Nginx
nginxTest = $( sudo nginx -t 2>& 1 | grep -c "test is successful" )
echo " nginxTest= $nginxTest "
2020-01-26 18:29:24 +01:00
2022-06-30 16:09:54 +02:00
fi
fi
# give sync-status (can be called regularly)
if [ " $1 " = "status-sync" ] || [ " $1 " = "status" ] ; then
serviceRunning = $( sudo systemctl status electrs --no-page 2>/dev/null | grep -c "active (running)" )
echo " serviceRunning= ${ serviceRunning } "
if [ ${ serviceRunning } -eq 1 ] ; then
2023-01-25 19:07:13 +01:00
# Experimental try to get sync Info (electrs debug info would need more details)
#source <(/home/admin/_cache.sh get btc_mainnet_blocks_headers)
#blockchainHeight="${btc_mainnet_blocks_headers}"
#lastBlockchainHeight=$(($blockchainHeight -1))
#syncedToBlock=$(sudo journalctl -u electrs --no-pager -n2000 | grep "height=" | tail -n1| cut -d= -f3)
#syncProgress=0
#if [ "${syncedToBlock}" != "" ] && [ "${blockchainHeight}" != "" ] && [ "${blockchainHeight}" != "0" ]; then
# syncProgress="$(echo "$syncedToBlock" "$blockchainHeight" | awk '{printf "%.2f", $1 / $2 * 100}')"
#fi
#echo "syncProgress=${syncProgress}%"
#if [ "${syncedToBlock}" = "${blockchainHeight}" ] || [ "${syncedToBlock}" = "${lastBlockchainHeight}" ]; then
# echo "tipSynced=1"
#else
# echo "tipSynced=0"
#fi
2022-06-30 16:09:54 +02:00
# 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)'"
else
echo "initialSynced=1"
fi
2019-12-18 12:25:51 +01:00
else
2023-01-25 19:07:13 +01:00
# echo "tipSynced=0"
2020-06-05 18:25:46 +02:00
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)"
2022-11-04 16:07:57 +01:00
source <( sudo /home/admin/config.scripts/bonus.electrs.sh status showAddress)
2020-01-26 20:33:05 +01:00
2020-01-26 21:24: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
2021-08-04 00:18:30 +02:00
/home/admin/config.scripts/blitz.debug.sh
2020-01-26 21:24:05 +01:00
echo "Press ENTER to get back to main menu."
read key
exit 0
fi
2020-06-05 18:25:46 +02:00
if [ ${ initialSynced } -eq 0 ] ; then
2020-01-26 21:24:05 +01:00
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
2021-12-14 23:34:35 +01:00
2020-04-10 22:45:07 +01:00
if [ ${ nginxTest } -eq 0 ] ; then
2020-04-11 09:50:05 +01:00
dialog --title "Testing nginx.conf has failed" --msgbox "
Nginx is in a failed state. Will attempt to fix.
2020-04-10 22:45:07 +01:00
Try connecting via port 50002 or Tor again once finished.
Check 'sudo nginx -t' for a detailed error message.
2020-04-11 09:50:05 +01:00
" 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
2020-06-11 17:07:20 +01:00
/home/admin/config.scripts/blitz.web.sh
2020-04-10 22:45:07 +01:00
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 = ( \
2020-01-26 21:24:05 +01:00
CONNECT "How to Connect" \
2020-05-01 21:40:25 +02:00
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)
2020-01-26 21:24:05 +01:00
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:"
2020-04-10 22:30:21 +01:00
echo "- deactivate automatic server selection"
2022-11-14 18:41:49 +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"
2021-12-14 23:34:35 +01:00
echo
2023-08-08 17:01:01 +02:00
echo "To start directly from laptop terminal use"
echo " PC: electrum --oneserver --server ${ localIP } : ${ portSSL } :s "
echo " MAC: open -a /Applications/Electrum.app --args --oneserver --server ${ localIP } : ${ portSSL } :s "
2021-09-21 18:38:21 +01:00
if [ ${ TorRunning } -eq 1 ] ; then
2021-03-16 18:02:36 +00:00
echo
2020-04-10 22:30:21 +01:00
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
2021-12-14 23:34:35 +01:00
echo "To connect through TOR open the Tor Browser and start with the options:"
2020-08-20 20:41:31 -07:00
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"
2021-12-14 23:34:35 +01:00
echo
2020-01-26 21:24:05 +01:00
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)
2020-01-26 21:24:05 +01:00
sudo /home/admin/config.scripts/bonus.electrs.sh status
2021-12-14 23:34:35 +01:00
echo
2020-01-26 21:24:05 +01:00
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
2020-01-26 21:24:05 +01:00
echo "# starting service"
sudo systemctl start electrs
echo "# ok"
2021-12-14 23:34:35 +01:00
echo
2020-01-26 21:24:05 +01:00
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
2021-03-16 18:02:36 +00:00
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
2021-03-16 18:02:36 +00:00
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
2023-02-03 20:46:07 +01:00
# cleanup
2021-12-14 23:34:35 +01:00
sudo rm -f /home/electrs/.electrs/config.toml
2019-12-04 08:13:21 +00:00
2021-03-16 18:02:36 +00:00
echo
echo "# Creating the electrs user"
echo
2023-09-09 21:36:35 +03:00
sudo adduser --system --group --home /home/electrs electrs
2019-12-04 08:13:21 +00:00
cd /home/electrs
2021-03-16 18:02:36 +00:00
echo
2021-10-10 10:50:23 +01:00
echo "# Installing Rust for the electrs user"
2021-03-16 18:02:36 +00:00
echo
2021-08-17 14:51:54 +01:00
# 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
2021-08-17 14:51:54 +01:00
sudo apt install -y clang cmake build-essential # for building 'rust-rocksdb'
2019-12-04 08:13:21 +00:00
2021-03-16 18:02:36 +00:00
echo
2021-09-20 10:20:51 +01:00
echo " # Downloading and building electrs $ELECTRSVERSION . This will take ~40 minutes "
2021-03-16 18:02:36 +00:00
echo
2019-12-04 08:13:21 +00:00
sudo -u electrs git clone https://github.com/romanz/electrs
2021-12-14 23:34:35 +01:00
cd /home/electrs/electrs || exit 1
2023-02-03 20:46:07 +01:00
2021-03-16 18:02:36 +00:00
sudo -u electrs git reset --hard $ELECTRSVERSION
2023-02-03 20:46:07 +01:00
# verify
2021-11-30 11:43:52 +00:00
sudo -u electrs /home/admin/config.scripts/blitz.git-verify.sh \
" ${ PGPsigner } " " ${ PGPpubkeyLink } " " ${ PGPpubkeyFingerprint } " || exit 1
2023-02-03 20:46:07 +01:00
# build
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
2021-03-16 18:02:36 +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
2021-03-16 18:02:36 +00:00
echo
echo "# Getting RPC credentials from the bitcoin.conf"
2023-02-03 20:46:07 +01:00
# read PASSWORD_B
2019-12-04 08:13:21 +00:00
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-)
2021-03-16 18:02:36 +00:00
echo "# Done"
2019-12-04 08:13:21 +00:00
2021-03-16 18:02:36 +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
2022-01-11 10:04:24 +00:00
echo " \
2023-08-25 16:58:53 +02:00
log_filters = \" WARN\"
2019-12-04 08:13:21 +00:00
timestamp = true
jsonrpc_import = true
2021-09-25 18:06:17 +01:00
index-batch-size = 10
wait_duration_secs = 10
jsonrpc_timeout_secs = 15
2021-03-16 18:02:36 +00:00
db_dir = \" /mnt/hdd/app-storage/electrs/db\"
2021-12-19 23:43:07 +01:00
auth = \" ${ RPC_USER } :${ PASSWORD_B } \"
2019-12-11 13:44:29 +00:00
# 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
2021-03-16 18:02:36 +00:00
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
2021-03-16 18:02:36 +00:00
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
2021-03-16 18:02:36 +00:00
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;
2020-06-11 17:07:20 +01:00
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;
2020-06-11 17:07:20 +01:00
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;
2020-06-11 17:07:20 +01:00
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;
2020-06-11 17:07:20 +01:00
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
2021-03-16 18:02:36 +00:00
echo
echo "# Open ports 50001 and 5002 on UFW "
echo
2020-06-11 17:07:20 +01:00
sudo ufw allow 50001 comment 'electrs TCP'
sudo ufw allow 50002 comment 'electrs SSL'
2021-03-16 18:02:36 +00:00
echo
echo "# Installing the systemd service"
echo
2021-12-14 23:34:35 +01:00
# sudo nano /etc/systemd/system/electrs.service
2019-12-04 08:13:21 +00:00
echo "
[ Unit]
Description = Electrs
2021-09-20 10:20:51 +01:00
After = bitcoind.service
2019-12-04 08:13:21 +00:00
[ Service]
WorkingDirectory = /home/electrs/electrs
2021-09-21 10:16:51 +01:00
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
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"
2021-12-14 23:34:35 +01:00
else
2021-03-16 18:02:36 +00:00
echo "# ElectRS is already installed."
2019-12-04 08:13:21 +00:00
fi
# setting value in raspiblitz config
2021-12-14 23:34:35 +01:00
/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
2021-12-14 23:34:35 +01:00
# 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
2021-09-20 10:49:04 +01:00
# 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
2022-05-10 08:32:14 +01:00
2022-12-06 17:25:06 +01:00
# clean up
sudo rm -R /home/electrs/.cargo
sudo rm -R /home/electrs/.rustup
2021-12-14 23:34:35 +01:00
source <( /home/admin/_cache.sh get state)
2021-09-20 10:49:04 +01:00
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
2021-03-16 18:02:36 +00:00
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"
2021-03-16 18:02:36 +00:00
echo
2021-12-14 23:34:35 +01:00
2019-12-04 08:13:21 +00:00
exit 0
fi
# switch off
if [ " $1 " = "0" ] || [ " $1 " = "off" ] ; then
2023-02-03 20:46:07 +01:00
echo "# REMOVING ELECTRS"
2019-12-04 08:13:21 +00:00
2020-05-01 21:40:25 +02:00
# if second parameter is "deleteindex"
if [ " $2 " = = "deleteindex" ] ; then
echo "# deleting electrum index"
sudo rm -rf /mnt/hdd/app-storage/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
sudo systemctl disable electrs
sudo rm /etc/systemd/system/electrs.service
2021-09-16 19:23:38 +02:00
2021-09-20 10:49:04 +01: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
2021-12-14 23:34:35 +01:00
else
2023-02-03 20:46:07 +01:00
echo "# electrs.service is not installed."
fi
# Hidden Service if Tor is active
if [ " ${ runBehindTor } " = "on" ] ; then
/home/admin/config.scripts/tor.onion-service.sh off electrs
2019-12-04 08:13:21 +00:00
fi
2023-02-03 20:46:07 +01:00
# close ports on firewall
sudo ufw delete allow 50001
sudo ufw delete allow 50002
# delete user and home directory
sudo userdel -rf electrs
# setting value in raspiblitz config
/home/admin/config.scripts/blitz.conf.sh set ElectRS "off"
echo "# OK ElectRS removed."
2019-12-04 08:13:21 +00:00
exit 0
fi
2022-11-04 15:50:54 +01:00
if [ " $1 " = "update" ] ; then
echo "# Update Electrs"
cd /home/electrs/electrs || exit 1
sudo -u electrs git fetch
2023-02-03 20:46:07 +01:00
localVersion = $( /home/electrs/electrs/target/release/electrs --version)
2022-12-16 11:12:56 +01:00
updateVersion = $( curl --header "X-GitHub-Api-Version:2022-11-28" -s https://api.github.com/repos/romanz/electrs/releases/latest| grep tag_name| head -1| cut -d '"' -f4)
2022-11-04 15:50:54 +01:00
if [ $localVersion = $updateVersion ] ; then
echo " # Up-to-date on version $localVersion "
else
echo "# Pulling latest changes..."
sudo -u electrs git pull -p
echo " # Reset to the latest release tag: $updateVersion "
sudo -u electrs git reset --hard $updateVersion
2023-02-03 20:46:07 +01:00
sudo -u electrs /home/admin/config.scripts/blitz.git-verify.sh \
" ${ PGPsigner } " " ${ PGPpubkeyLink } " " ${ PGPpubkeyFingerprint } " || exit 1
echo "# Installing build dependencies"
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'
echo
2022-11-04 15:50:54 +01:00
echo "# Build Electrs ..."
sudo -u electrs /home/electrs/.cargo/bin/cargo build --locked --release || exit 1
2023-02-03 20:46:07 +01:00
2022-11-22 21:31:10 +01:00
# update config
2023-02-03 20:46:07 +01:00
sudo -u electrs sed -i "/^server_banner = /d" /home/electrs/.electrs/config.toml
sudo -u electrs bash -c " echo 'server_banner = \"Welcome to electrs $updateVersion - the Electrum Rust Server on your RaspiBlitz\"' >> /home/electrs/.electrs/config.toml "
2022-11-22 21:31:10 +01:00
2022-11-04 15:50:54 +01:00
echo " # Updated Electrs to $updateVersion "
fi
sudo systemctl start electrs
exit 0
fi
2021-03-16 18:02:36 +00:00
echo " # FAIL - Unknown Parameter $1 "
2019-12-04 08:13:21 +00:00
exit 1