2019-11-24 13:12:55 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# command info
|
|
|
|
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
|
|
|
|
echo "config script to switch txindex on or off"
|
2020-06-28 15:53:44 +02:00
|
|
|
echo "network.txindex.sh [status|on|off|delete]"
|
2019-11-24 13:12:55 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-12-18 22:16:54 +01:00
|
|
|
source /mnt/hdd/raspiblitz.conf
|
2019-11-24 13:12:55 +00:00
|
|
|
|
2020-01-03 13:51:09 +00:00
|
|
|
# add txindex with default value (0) to bitcoin.conf if missing
|
|
|
|
if ! grep -Eq "^txindex=.*" /mnt/hdd/${network}/${network}.conf; then
|
|
|
|
echo "txindex=0" | sudo tee -a /mnt/hdd/${network}/${network}.conf >/dev/null
|
2019-12-18 22:40:17 +01:00
|
|
|
fi
|
|
|
|
|
2020-01-03 13:51:09 +00:00
|
|
|
# set variable ${txindex}
|
|
|
|
source <(grep -E "^txindex=.*" /mnt/hdd/${network}/${network}.conf)
|
|
|
|
|
|
|
|
# check for testnet and set pathAdd (e.g. for debug.log)
|
|
|
|
pathAdd=""
|
|
|
|
if [ "${chain}" = "test" ]; then
|
|
|
|
pathAdd="/testnet3"
|
|
|
|
fi
|
|
|
|
|
|
|
|
###################
|
|
|
|
# STATUS
|
|
|
|
###################
|
2019-12-18 22:40:17 +01:00
|
|
|
if [ "$1" = "status" ]; then
|
|
|
|
|
|
|
|
echo "##### STATUS TXINDEX"
|
|
|
|
|
|
|
|
echo "txindex=${txindex}"
|
|
|
|
if [ ${txindex} -eq 0 ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# try to gather if still indexing
|
2020-01-03 13:51:09 +00:00
|
|
|
indexedToBlock=$(sudo tail -n 200 /mnt/hdd/${network}${pathAdd}/debug.log | grep "Syncing txindex with block chain from height" | tail -n 1 | cut -d " " -f 9 | sed 's/[^0-9]*//g')
|
2019-12-18 22:40:17 +01:00
|
|
|
blockchainHeight=$(sudo -u bitcoin ${network}-cli getblockchaininfo 2>/dev/null | jq -r '.blocks' | sed 's/[^0-9]*//g')
|
2020-01-03 13:51:09 +00:00
|
|
|
indexFinished=$(sudo tail -n 200 /mnt/hdd/${network}${pathAdd}/debug.log | grep -c "txindex is enabled at height")
|
2019-12-18 22:45:20 +01:00
|
|
|
echo "indexedToBlock=${indexedToBlock}"
|
|
|
|
echo "blockchainHeight=${blockchainHeight}"
|
2019-12-18 23:56:55 +01:00
|
|
|
echo "indexFinished=${indexFinished}"
|
|
|
|
if [ ${#indexedToBlock} -eq 0 ] || [ ${indexFinished} -gt 0 ] || [ "${indexedToBlock}" = "${blockchainHeight}" ]; then
|
2019-12-18 22:45:20 +01:00
|
|
|
echo "isIndexed=1"
|
|
|
|
indexInfo="OK"
|
2019-12-18 22:40:17 +01:00
|
|
|
else
|
2019-12-18 22:45:20 +01:00
|
|
|
echo "isIndexed=0"
|
2020-06-28 14:53:30 +02:00
|
|
|
if [ ${#indexedToBlock} -gt 0 ] && [ ${#blockchainHeight} -gt 0 ]; then
|
2020-01-02 19:39:31 +00:00
|
|
|
progressPercent=$(printf %.2f $(echo "${indexedToBlock}/${blockchainHeight}*100" | bc -l))
|
|
|
|
indexInfo="Indexing is at ${progressPercent}% (please wait)"
|
2019-12-18 22:45:20 +01:00
|
|
|
else
|
|
|
|
indexInfo="Indexing is running (please wait)"
|
|
|
|
fi
|
2019-12-18 22:45:49 +01:00
|
|
|
echo "indexInfo='${indexInfo}'"
|
2019-12-18 22:40:17 +01:00
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
|
2019-11-24 13:12:55 +00:00
|
|
|
fi
|
|
|
|
|
2020-01-03 13:51:09 +00:00
|
|
|
|
|
|
|
###################
|
2019-11-24 13:12:55 +00:00
|
|
|
# switch on
|
2020-01-03 13:51:09 +00:00
|
|
|
###################
|
2019-11-24 13:12:55 +00:00
|
|
|
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
2020-06-27 22:29:31 +02:00
|
|
|
|
|
|
|
# check txindex (parsed and sourced from bitcoin network config above)
|
2019-11-24 13:12:55 +00:00
|
|
|
if [ ${txindex} == 0 ]; then
|
2019-12-18 22:16:54 +01:00
|
|
|
sudo sed -i "s/^txindex=.*/txindex=1/g" /mnt/hdd/${network}/${network}.conf
|
|
|
|
echo "switching txindex=1 and restarting ${network}d"
|
|
|
|
sudo systemctl restart ${network}d
|
2019-11-24 13:12:55 +00:00
|
|
|
echo "The indexing takes ~7h on an RPi4 with SSD"
|
2020-01-03 13:51:09 +00:00
|
|
|
echo "monitor with: sudo tail -n 20 -f /mnt/hdd/${network}${pathAdd}/debug.log"
|
2019-11-24 13:12:55 +00:00
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "txindex is already active"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-01-03 13:51:09 +00:00
|
|
|
|
|
|
|
###################
|
2019-11-24 13:12:55 +00:00
|
|
|
# switch off
|
2020-01-03 13:51:09 +00:00
|
|
|
###################
|
2019-11-24 13:12:55 +00:00
|
|
|
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
|
2019-12-18 22:16:54 +01:00
|
|
|
sudo sed -i "s/^txindex=.*/txindex=0/g" /mnt/hdd/${network}/${network}.conf
|
|
|
|
sudo systemctl restart ${network}d
|
2019-11-24 13:12:55 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-05-01 21:40:25 +02:00
|
|
|
|
|
|
|
###################
|
|
|
|
# delete (and make sure all using apps are deinstalled)
|
|
|
|
# on version update check all bonus scripts that this network.txindex.sh on
|
|
|
|
###################
|
|
|
|
if [ "$1" = "delete" ]; then
|
|
|
|
echo "# deinstalling apps needing txindex ..."
|
|
|
|
sudo -u admin /home/admin/config.scripts/bonus.btc-rpc-explorer.sh off
|
|
|
|
echo "# changing config ..."
|
|
|
|
sudo systemctl stop ${network}d
|
|
|
|
sudo sed -i "s/^txindex=.*/txindex=0/g" /mnt/hdd/${network}/${network}.conf
|
|
|
|
echo "# deleting tx index ..."
|
|
|
|
sudo rm -r /mnt/hdd/${network}/indexes/txindex
|
2020-07-26 03:00:21 +02:00
|
|
|
echo "# restarting bitcoind ..."
|
2020-05-01 21:40:25 +02:00
|
|
|
sudo systemctl restart ${network}d
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2019-11-24 13:12:55 +00:00
|
|
|
echo "FAIL - Unknown Parameter $1"
|
2020-01-03 13:51:09 +00:00
|
|
|
exit 1
|