mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2025-02-24 22:58:43 +01:00
run with a single bitcoin.conf on all networks
This commit is contained in:
parent
a8aa7875fa
commit
936d550d70
2 changed files with 50 additions and 44 deletions
|
@ -1,9 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
# SHORTCUT COMMANDS you can call as user 'admin' from terminal
|
||||
# source aliases from /home/admin/_aliases.sh
|
||||
source /home/admin/_aliases.sh
|
||||
|
||||
# SHORTCUT COMMANDS you can call as user 'admin' from terminal
|
||||
|
||||
# command: raspiblitz
|
||||
# calls the the raspiblitz mainmenu (legacy)
|
||||
function raspiblitz() {
|
||||
|
|
|
@ -7,29 +7,36 @@ if [ $# -lt 2 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ];then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
parallelService=$2
|
||||
if [ $parallelService = signet ] || [ $parallelService = testnet ];then
|
||||
echo "# Installing $parallelService"
|
||||
testnetwork=$2
|
||||
if [ ${testnetwork} = signet ] || [ ${testnetwork} = testnet ];then
|
||||
echo "# Installing Bitcoin Core instance on ${testnetwork}"
|
||||
else
|
||||
echo "# $parallelService not supported"
|
||||
echo "# ${testnetwork} is not supported"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# prefix for parallel services
|
||||
if [ ${testnetwork} = testnet ];then
|
||||
prefix="t"
|
||||
elif [ ${testnetwork} = signet ];then
|
||||
prefix="s"
|
||||
fi
|
||||
|
||||
function removeParallelService() {
|
||||
if [ -f "/etc/systemd/system/${parallelService}d.service" ];then
|
||||
sudo systemctl stop ${parallelService}d
|
||||
sudo systemctl disable ${parallelService}d
|
||||
echo "# Bitcoin Core on ${parallelService} service is stopped and disabled"
|
||||
if [ -f "/etc/systemd/system/${prefix}bitcoind.service" ];then
|
||||
sudo systemctl stop ${prefix}bitcoind
|
||||
sudo systemctl disable ${prefix}bitcoind
|
||||
echo "# Bitcoin Core on ${testnetwork} service is stopped and disabled"
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
function installParallelService() {
|
||||
# ${parallelService}.conf
|
||||
if [ ! -f /home/bitcoin/.bitcoin/${parallelService}.conf ];then
|
||||
# bitcoin.conf
|
||||
if [ ! -f /home/bitcoin/.bitcoin/bitcoin.conf ];then
|
||||
randomRPCpass=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c8)
|
||||
echo "
|
||||
# bitcoind configuration for ${parallelService}
|
||||
# bitcoind configuration for ${testnetwork}
|
||||
|
||||
# Connection settings
|
||||
rpcuser=raspiblitz
|
||||
|
@ -39,25 +46,24 @@ onlynet=onion
|
|||
proxy=127.0.0.1:9050
|
||||
|
||||
datadir=/mnt/hdd/bitcoin
|
||||
" | sudo -u bitcoin tee /home/bitcoin/.bitcoin/${parallelService}.conf
|
||||
" | sudo -u bitcoin tee /home/bitcoin/.bitcoin/bitcoin.conf
|
||||
else
|
||||
echo "# /home/bitcoin/.bitcoin/${parallelService}.conf is present"
|
||||
echo "# /home/bitcoin/.bitcoin/bitcoin.conf is present"
|
||||
fi
|
||||
|
||||
removeParallelService
|
||||
# /etc/systemd/system/${parallelService}d.service
|
||||
# /etc/systemd/system/${prefix}bitcoind.service
|
||||
echo "
|
||||
[Unit]
|
||||
Description=Bitcoin daemon on ${parallelService}
|
||||
Description=Bitcoin daemon on ${testnetwork}
|
||||
|
||||
[Service]
|
||||
User=bitcoin
|
||||
Group=bitcoin
|
||||
Type=forking
|
||||
PIDFile=/mnt/hdd/bitcoin/${parallelService}d.pid
|
||||
ExecStart=/usr/local/bin/bitcoind -${parallelService} -daemon \
|
||||
-conf=/home/bitcoin/.bitcoin/${parallelService}.conf \
|
||||
-pid=/mnt/hdd/bitcoin/${parallelService}d.pid
|
||||
PIDFile=/mnt/hdd/bitcoin/${prefix}bitcoind.pid
|
||||
ExecStart=/usr/local/bin/bitcoind -${testnetwork} -daemon \
|
||||
-pid=/mnt/hdd/bitcoin/${prefix}bitcoind.pid
|
||||
KillMode=process
|
||||
Restart=always
|
||||
TimeoutSec=120
|
||||
|
@ -67,39 +73,38 @@ StandardError=journal
|
|||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
" | sudo tee /etc/systemd/system/${parallelService}d.service
|
||||
sudo systemctl enable ${parallelService}d
|
||||
echo "# OK - the bitcoin daemon on ${parallelService} service is now enabled"
|
||||
" | sudo tee /etc/systemd/system/${prefix}bitcoind.service
|
||||
sudo systemctl enable ${prefix}bitcoind
|
||||
echo "# OK - the bitcoin daemon on ${testnetwork} service is now enabled"
|
||||
|
||||
# add aliases
|
||||
if [ $(alias | grep -c ${parallelService}) -eq 0 ];then
|
||||
bash -c "echo 'alias ${parallelService}-cli=\"/usr/local/bin/bitcoin-cli\
|
||||
-${parallelService}\
|
||||
-conf=/home/bitcoin/.bitcoin/${parallelService}.conf\"' \
|
||||
if [ $(alias | grep -c ${prefix}bitcoin) -eq 0 ];then
|
||||
bash -c "echo 'alias ${prefix}bitcoin-cli=\"/usr/local/bin/bitcoin-cli\
|
||||
-${testnetwork}\"' \
|
||||
>> /home/admin/_aliases.sh"
|
||||
bash -c "echo 'alias ${parallelService}d=\"/usr/local/bin/bitcoind\
|
||||
-${parallelService}\
|
||||
-conf=/home/bitcoin/.bitcoin/${parallelService}.conf\"' \
|
||||
bash -c "echo 'alias ${prefix}bitcoind=\"/usr/local/bin/bitcoind\
|
||||
-${testnetwork}\"' \
|
||||
>> /home/admin/_aliases.sh"
|
||||
fi
|
||||
|
||||
source /home/admin/raspiblitz.info
|
||||
if [ "${state}" == "ready" ]; then
|
||||
echo "# OK - the ${parallelService}d.service is enabled, system is ready so starting service"
|
||||
sudo systemctl start ${parallelService}d
|
||||
echo "# OK - the ${prefix}bitcoind.service is enabled, system is ready so starting service"
|
||||
sudo systemctl start ${prefix}bitcoind
|
||||
else
|
||||
echo "# OK - the ${parallelService}dservice is enabled, to start manually use: 'sudo systemctl start ${parallelService}d'"
|
||||
echo "# OK - the ${prefix}bitcoindservice is enabled, to start manually use:"
|
||||
echo "sudo systemctl start ${prefix}bitcoind"
|
||||
fi
|
||||
|
||||
isInstalled=$(systemctl status ${parallelService}d | grep -c active)
|
||||
isInstalled=$(systemctl status ${prefix}bitcoind | grep -c active)
|
||||
if [ $isInstalled -gt 0 ];then
|
||||
echo "# Installed $(bitcoind --version | grep version) ${parallelService}d.service"
|
||||
echo "# Installed $(bitcoind --version | grep version) ${prefix}bitcoind.service"
|
||||
echo
|
||||
echo "# Monitor the ${parallelService} bitcoind with:"
|
||||
if [ ${parallelService} = signet ]; then
|
||||
echo "# 'sudo tail -f /mnt/hdd/bitcoin/signet/debug.log'"
|
||||
elif [ ${parallelService} = testnet ]; then
|
||||
echo "# 'sudo tail -f /mnt/hdd/bitcoin/testnet3/debug.log'"
|
||||
echo "# Monitor the ${prefix}bitcoind with:"
|
||||
if [ ${testnetwork} = signet ]; then
|
||||
echo "sudo tail -f /mnt/hdd/bitcoin/signet/debug.log"
|
||||
elif [ ${testnetwork} = testnet ]; then
|
||||
echo "sudo tail -f /mnt/hdd/bitcoin/testnet3/debug.log"
|
||||
fi
|
||||
echo
|
||||
else
|
||||
|
@ -111,15 +116,15 @@ WantedBy=multi-user.target
|
|||
source /mnt/hdd/raspiblitz.conf
|
||||
|
||||
# add default value to raspi config if needed
|
||||
if ! grep -Eq "^${parallelService}=" /mnt/hdd/raspiblitz.conf; then
|
||||
echo "${parallelService}=off" >> /mnt/hdd/raspiblitz.conf
|
||||
if ! grep -Eq "^${testnetwork}=" /mnt/hdd/raspiblitz.conf; then
|
||||
echo "${testnetwork}=off" >> /mnt/hdd/raspiblitz.conf
|
||||
fi
|
||||
|
||||
# switch on
|
||||
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
||||
installParallelService
|
||||
# setting value in raspi blitz config
|
||||
sudo sed -i "s/^${parallelService}=.*/${parallelService}=on/g" /mnt/hdd/raspiblitz.conf
|
||||
sudo sed -i "s/^${testnetwork}=.*/${testnetwork}=on/g" /mnt/hdd/raspiblitz.conf
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
@ -127,7 +132,7 @@ fi
|
|||
if [ "$1" = "0sudo " ] || [ "$1" = "off" ]; then
|
||||
removeParallelService
|
||||
# setting value in raspi blitz config
|
||||
sudo sed -i "s/^${parallelService}=.*/${parallelService}=off/g" /mnt/hdd/raspiblitz.conf
|
||||
sudo sed -i "s/^${testnetwork}=.*/${testnetwork}=off/g" /mnt/hdd/raspiblitz.conf
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue