#!/bin/sh


cd
ln -s /data/bitcoin /home/bitcoin/.bitcoin
cd .bitcoin
cat <<EOF > /home/bitcoin/.bitcoin/bitcoin.conf
# RaspiBolt: bitcoind configuration
# /home/bitcoin/.bitcoin/bitcoin.conf

# Bitcoin daemon
server=1
txindex=1

# Network
listen=1
listenonion=1
proxy=127.0.0.1:9050
bind=127.0.0.1

# Connections
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333
zmqpubhashblock=tcp://127.0.0.1:8433
whitelist=download@127.0.0.1          # for Electrs

# Raspberry Pi optimizations
maxconnections=40
maxuploadtarget=5000

# Initial block download optimizations
dbcache=2000
blocksonly=1
EOF

wget https://raw.githubusercontent.com/bitcoin/bitcoin/master/share/rpcauth/rpcauth.py

# add rpc-auth string to config 
# query user to enter rpcuser and rpcpass 
echo "" 
echo -e "${Y}Create rpc-auth string for RPC protocol authentication${NC}" 
echo "And rpc-auth string is now been created based on your user input. This will be added into the bitcoind config to allow rpc communiation." 
echo -e "${B}Please enter an rpcuser name:${NC}" 
read RPCUSER 
echo -e "${B}Please enter an rpcpass:${NC}" 
read RPCPASS 
rpcoutput=$(python3 "/data/bitcoin/rpcauth.py" "$RPCUSER" "$RPCPASS" | sed -n '2p') 
echo "$rpcoutput" >> /data/bitcoin/bitcoin.conf

##################

chmod 640 /home/bitcoin/.bitcoin/bitcoin.conf


echo > /data/bitcoin/debug.log


chmod g+r /data/bitcoin/debug.log

############
cd && rm bitcoin2.sh
