2020-08-24 01:26:26 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -x
|
|
|
|
set -e
|
|
|
|
|
2021-04-11 00:51:26 +00:00
|
|
|
# Try to get peer info - if it fails serice will restart until bitcoin is ready
|
2020-08-24 01:26:26 +00:00
|
|
|
bitcoin-cli getpeerinfo
|
|
|
|
|
2021-04-11 00:51:26 +00:00
|
|
|
# Give bitcoin some time to start
|
2022-10-08 17:34:04 +00:00
|
|
|
sleep 1m
|
2020-08-24 01:26:26 +00:00
|
|
|
|
|
|
|
# Check if btc has peers
|
|
|
|
while true; do
|
|
|
|
echo "Checking Bitcoin peer count..."
|
2022-10-08 17:34:04 +00:00
|
|
|
PEER_COUNT=$(bitcoin-cli getpeerinfo | jq '. | length')
|
|
|
|
if [ "$PEER_COUNT" -lt "6" ]; then
|
2020-08-24 01:26:26 +00:00
|
|
|
echo "$PEER_COUNT peers. Try adding one."
|
|
|
|
|
2022-10-08 17:34:04 +00:00
|
|
|
echo -n "" > /tmp/new_peer
|
|
|
|
if [ -f /mnt/hdd/mynode/settings/btc_ipv4_enabled ] || [ -f /home/bitcoin/.mynode/btc_ipv4_enabled ]; then
|
|
|
|
RANDOM_PEER=$(shuf /usr/share/mynode/bitcoin_peers.txt | egrep "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | head -n 1)
|
|
|
|
echo "$RANDOM_PEER" >> /tmp/new_peer
|
|
|
|
fi
|
|
|
|
if [ -f /mnt/hdd/mynode/settings/btc_tor_enabled ] || [ -f /home/bitcoin/.mynode/btc_tor_enabled ]; then
|
|
|
|
RANDOM_PEER=$(shuf /usr/share/mynode/bitcoin_peers.txt | grep ".onion" | head -n 1)
|
|
|
|
echo "$RANDOM_PEER" >> /tmp/new_peer
|
|
|
|
fi
|
|
|
|
if [ -f /mnt/hdd/mynode/settings/btc_i2p_enabled ] || [ -f /home/bitcoin/.mynode/btc_i2p_enabled ]; then
|
|
|
|
RANDOM_PEER=$(shuf /usr/share/mynode/bitcoin_peers.txt | grep "b32.i2p:0" | head -n 1)
|
|
|
|
echo "$RANDOM_PEER" >> /tmp/new_peer
|
|
|
|
fi
|
|
|
|
RANDOM_PEER=$(shuf /tmp/new_peer | head -n 1)
|
|
|
|
|
2020-08-24 01:26:26 +00:00
|
|
|
echo "Attempting to add peer $RANDOM_PEER"
|
|
|
|
bitcoin-cli addnode "$RANDOM_PEER" "onetry"
|
|
|
|
|
2022-10-08 17:34:04 +00:00
|
|
|
sleep 30s
|
2020-08-24 01:26:26 +00:00
|
|
|
else
|
|
|
|
echo "We have $PEER_COUNT peers!"
|
|
|
|
sleep 60m
|
|
|
|
fi
|
|
|
|
done
|