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