Browse Source

added scripts

#146
rootzoll 6 years ago
parent
commit
280f9e0add
  1. 177
      home.admin/00infoBlitz.sh
  2. 98
      home.admin/00infoLCD.sh
  3. 91
      home.admin/00mainMenu.sh
  4. 109
      home.admin/10setupBlitz.sh
  5. 77
      home.admin/20initDialog.sh
  6. 40
      home.admin/30initHDD.sh
  7. 68
      home.admin/40addHDD.sh
  8. 96
      home.admin/50copyHDD.sh
  9. 44
      home.admin/50downloadHDD.sh
  10. 29
      home.admin/50syncHDD.sh
  11. 45
      home.admin/60finishHDD.sh
  12. 179
      home.admin/70initLND.sh
  13. 20
      home.admin/80scanLND.sh
  14. 51
      home.admin/90finishSetup.sh
  15. 20
      home.admin/AAunlockLND.sh
  16. 22
      home.admin/XXcleanHDD.sh

177
home.admin/00infoBlitz.sh

@ -0,0 +1,177 @@
#!/bin/sh
# RaspiBolt LND Mainnet: systemd unit for getpublicip.sh script
# /etc/systemd/system/20-raspibolt-welcome.sh
# make executable and copy script to /etc/update-motd.d/
# root must be able to execute bitcoin-cli and lncli
# set colors
color_red='\033[0;31m'
color_green='\033[0;32m'
color_yellow='\033[0;33m'
color_gray='\033[0;37m'
# set datadir
bitcoin_dir="/home/bitcoin/.bitcoin"
lnd_dir="/home/bitcoin/.lnd"
# get uptime & load
load=$(w | grep "load average:" | cut -c11-)
# get CPU temp
cpu=$(cat /sys/class/thermal/thermal_zone0/temp)
temp=$((cpu/1000))
# get memory
ram_avail=$(free -m | grep Mem | awk '{ print $7 }')
ram=$(printf "%sM / %sM" "${ram_avail}" "$(free -m | grep Mem | awk '{ print $2 }')")
if [ ${ram_avail} -lt 100 ]; then
color_ram="${color_red}\e[7m"
else
color_ram=${color_green}
fi
# get storage
sd_free_ratio=$(printf "%d" "$(df -h | grep "/$" | awk '{ print $4/$2*100 }')") 2>/dev/null
sd=$(printf "%s (%s%%)" "$(df -h | grep '/$' | awk '{ print $4 }')" "${sd_free_ratio}")
if [ ${sd_free_ratio} -lt 10 ]; then
color_sd="${color_red}"
else
color_sd=${color_green}
fi
hdd_free_ratio=$(printf "%d" "$(df -h | grep '/mnt/hdd$' | awk '{ print $4/$2*100 }')") 2>/dev/null
hdd=$(printf "%s (%s%%)" "$(df -h | grep '/mnt/hdd$' | awk '{ print $4 }')" "${hdd_free_ratio}")
if [ ${hdd_free_ratio} -lt 10 ]; then
color_hdd="${color_red}\e[7m"
else
color_hdd=${color_green}
fi
# get network traffic
network_rx=$(ifconfig eth0 | grep 'RX packets' | awk '{ print $6$7 }' | sed 's/[()]//g')
network_tx=$(ifconfig eth0 | grep 'TX packets' | awk '{ print $6$7 }' | sed 's/[()]//g')
# Bitcoin blockchain
btc_path=$(command -v bitcoin-cli)
if [ -n ${btc_path} ]; then
btc_title="Bitcoin"
chain="$(bitcoin-cli -datadir=${bitcoin_dir} getblockchaininfo | jq -r '.chain')"
if [ -n $chain ]; then
btc_title="${btc_title} (${chain}net)"
# get sync status
block_chain="$(bitcoin-cli -datadir=${bitcoin_dir} getblockcount)"
block_verified="$(bitcoin-cli -datadir=${bitcoin_dir} getblockchaininfo | jq -r '.blocks')"
block_diff=$(expr ${block_chain} - ${block_verified})
progress="$(bitcoin-cli -datadir=${bitcoin_dir} getblockchaininfo | jq -r '.verificationprogress')"
sync_percentage=$(printf "%.2f%%" "$(echo $progress | awk '{print 100 * $1}')")
if [ ${block_diff} -eq 0 ]; then # fully synced
sync="OK"
sync_color="${color_green}"
sync_behind=" "
elif [ ${block_diff} -eq 1 ]; then # fully synced
sync="OK"
sync_color="${color_green}"
sync_behind="-1 block"
elif [ ${block_diff} -le 10 ]; then # <= 2 blocks behind
sync="catchup"
sync_color="${color_red}"
sync_behind="-${block_diff} blocks"
else
sync="progress"
sync_color="${color_red}"
sync_behind="${sync_percentage}"
fi
# get last known block
last_block="$(bitcoin-cli -datadir=${bitcoin_dir} getblockcount)"
if [ ! -z "${last_block}" ]; then
btc_line2="${btc_line2} ${color_gray}(block ${last_block})"
fi
# get mem pool transactions
mempool="$(bitcoin-cli -datadir=${bitcoin_dir} getmempoolinfo | jq -r '.size')"
else
btc_line2="${color_red}NOT RUNNING\t\t"
fi
fi
# get IP address & port
local_ip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
public_ip=$(curl -s ipinfo.io/ip)
public_port=$(cat ${bitcoin_dir}/bitcoin.conf 2>/dev/null | grep port= | awk -F"=" '{print $2}')
if [ "${public_port}" = "" ]; then
if [ $chain = "test" ]; then
public_port=18333
else
public_port=8333
fi
fi
public_check=$(curl -s https://bitnodes.earn.com/api/v1/nodes/me-${public_port}/ | jq .success)
if [ $public_check = "true" ]; then
public="Yes"
public_color="${color_green}"
else
public="Not reachable"
public_color="${color_red}"
fi
public_addr="${public_ip}:${public_port}"
# get LND info
/usr/local/bin/lncli --macaroonpath=${lnd_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert getinfo 2>&1 | grep "Please unlock" >/dev/null
wallet_unlocked=$?
if [ "$wallet_unlocked" -eq 0 ] ; then
alias_color="${color_red}"
ln_alias="Wallet Locked"
else
alias_color="${color_grey}"
ln_alias="$(/usr/local/bin/lncli --macaroonpath=${lnd_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert getinfo | jq -r '.alias')" 2>/dev/null
ln_walletbalance="$(/usr/local/bin/lncli --macaroonpath=${lnd_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert walletbalance | jq -r '.confirmed_balance')" 2>/dev/null
ln_channelbalance="$(/usr/local/bin/lncli --macaroonpath=${lnd_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert channelbalance | jq -r '.balance')" 2>/dev/null
fi
ln_channels_online="$(/usr/local/bin/lncli --macaroonpath=${lnd_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert getinfo | jq -r '.num_active_channels')" 2>/dev/null
ln_channels_total="$(/usr/local/bin/lncli --macaroonpath=${lnd_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert listchannels | jq '.[] | length')" 2>/dev/null
ln_external="$(/usr/local/bin/lncli --macaroonpath=${lnd_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert getinfo | jq -r '.uris[0]' | tr "@" " " | awk '{ print $2 }')" 2>/dev/null
ln_external_ip="$(echo $ln_external | tr ":" " " | awk '{ print $1 }' )" 2>/dev/null
if [ "$ln_external_ip" = "$public_ip" ]; then
external_color="${color_grey}"
else
external_color="${color_red}"
fi
printf "
${color_yellow}
${color_yellow}
${color_yellow}
${color_yellow} ${color_yellow}%s ${color_green} ${ln_alias}
${color_yellow} ${color_gray}Bitcoin Fullnode + Lightning Network
${color_yellow} ${color_yellow}%s
${color_yellow} ,/ ${color_yellow}
${color_yellow} ,'/ ${color_gray}%s, CPU %s°C
${color_yellow} ,' / ${color_gray}Free Mem ${color_ram}${ram} ${color_gray} Free HDD ${color_hdd}%s
${color_yellow} ,' /_____, ${color_gray}
${color_yellow} .'____ ,' ${color_gray}Local ${color_green}${local_ip}${color_gray}${network_rx}${network_tx}
${color_yellow} / ,' ${color_gray}Public ${public_color}${public_addr} ${public}
${color_yellow} / ,' ${color_gray}
${color_yellow} /,' ${color_gray}Bitcoin ${color_green}v0.16.1 ${chain}net ${color_gray}Sync ${sync_color}${sync} (%s)
${color_yellow} /' ${color_gray}LND ${color_green}v0.4.2 ${color_gray}wallet ${ln_walletbalance} sat
${color_yellow} ${color_gray}${ln_channels_online}/${ln_channels_total} Channels ${ln_channelbalance} sat
${color_yellow} ${ln_external}
${color_yellow}
" \
"RaspiBlitz v0.3" \
"-------------------------------------------" \
"${load##up*, }" "${temp}" \
"${hdd}" "${sync_percentage}"
echo "$(tput -T xterm sgr0)"

98
home.admin/00infoLCD.sh

@ -0,0 +1,98 @@
#!/bin/sh
if [ "$USER" = "pi" ]; then
### USER PI AUTOSTART (LCD Display)
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
# check if bitcoin service is configured
bitcoinInstalled=$(sudo -u bitcoin ls /mnt/hdd/bitcoin/ | grep -c bitcoin.conf)
if [ ${bitcoinInstalled} -eq 1 ]; then
# wait enough secs to let bitcoind init
dialog --pause " Waiting for Bitcoin to startup and init ..." 8 58 130
fi
# show updating status in loop
while :
do
# get the setup state
setupStepExists=$(sudo -u admin ls -la /home/admin/.setup | grep -c .setup)
if [ ${setupStepExists} -eq 1 ]; then
setupStep=$(sudo -u admin cat /home/admin/.setup)
else
setupStep=0
fi
if [ ${setupStep} -eq 0 ]; then
# setup process has not started yet
l1="Login to your RaspiBlitz with:\n"
l2="ssh admin@${localip}\n"
l3="Use password: raspiblitz\n"
dialog --backtitle "RaspiBlitz - Welcome" --infobox "$l1$l2$l3" 5 34
sleep 5
elif [ ${setupStep} -lt 100 ]; then
# setup process init is done and not finished
lndSyncing=$(sudo -u bitcoin lncli getinfo | jq -r '.synced_to_chain' | grep -c false)
chain=$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.chain')
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/bitcoin/${chain}net/lnd.log | grep -c unlock)
if [ ${locked} -gt 0 ]; then
# special case: LND wallet is locked ---> show unlock info
l1="!!! LND WALLET IS LOCKED !!!\n"
l2="Login: ssh admin@${localip}\n"
l3="Use your Password A\n"
dialog --backtitle "RaspiBlitz - Action Required" --infobox "$l1$l2$l3" 5 36
sleep 5
elif [ ${lndSyncing} -gt 0 ]; then
# special case: LND is syncing
/home/admin/80scanLND.sh
sleep 5
else
# setup in progress without special case - password has been changed
l1="Login to your RaspiBlitz with:\n"
l2="ssh admin@${localip}\n"
l3="Use your Password A\n"
dialog --backtitle "RaspiBlitz - SetUp Mode" --infobox "$l1$l2$l3" 5 34
sleep 10
fi
else
# RaspiBlitz is full Setup
chain=$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.chain')
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/bitcoin/${chain}net/lnd.log | grep -c unlock)
if [ ${locked} -gt 0 ]; then
# special case: LND wallet is locked ---> show unlock info
l1="!!! LND WALLET IS LOCKED !!!\n"
l2="Login: ssh admin@${localip}\n"
l3="Use your Password A\n"
dialog --backtitle "RaspiBlitz - Action Required" --infobox "$l1$l2$l3" 5 36
sleep 5
else
# no special case - show status display
/home/admin/00infoBlitz.sh
sleep 5
fi
fi
done
else
echo "plz run as user pi --> su pi"
fi

91
home.admin/00mainMenu.sh

@ -0,0 +1,91 @@
#!/bin/bash
## default menu settings
HEIGHT=9
WIDTH=64
CHOICE_HEIGHT=4
BACKTITLE="RaspiBlitz"
TITLE=""
MENU="Choose one of the following options:"
OPTIONS=()
## get actual setup state
setupState=0;
if [ -f "/home/admin/.setup" ]; then
setupState=$( cat /home/admin/.setup )
fi
if [ ${setupState} -eq 0 ]; then
# start setup
BACKTITLE="RaspiBlitz - SetUp"
TITLE="⚡ Welcome to your RaspiBlitz ⚡"
MENU="\nYou need to setup and init Bitcoin and Lightning services: \n "
OPTIONS+=(1 "Start the SetUp of your RaspiBlitz")
HEIGHT=10
elif [ ${setupState} -lt 100 ]; then
# continue setup
BACKTITLE="RaspiBlitz - SetUp"
TITLE="⚡ Welcome to your RaspiBlitz ⚡"
MENU="\nContinue setup and init of Bitcoin and Lightning services: \n "
OPTIONS+=(1 "Continue SetUp of your RaspiBlitz")
HEIGHT=10
else
# make sure to have a init pause aufter fresh boot
uptimesecs=$(awk '{print $1}' /proc/uptime | awk '{print int($1)}')
waittimesecs=$(expr 150 - $uptimesecs)
if [ ${waittimesecs} -gt 0 ]; then
dialog --pause " Waiting for Bitcoin to startup and init ..." 8 58 ${waittimesecs}
fi
# MAIN MENU AFTER SETUP
chain=$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.chain')
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/bitcoin/${chain}net/lnd.log | grep -c unlock)
if [ ${locked} -gt 0 ]; then
# LOCK SCREEN
MENU="!!! YOUR WALLET IS LOCKED !!!"
OPTIONS+=(X "Unlock your Lightning Wallet with 'lncli unlock'")
else
# REGULAR MENU
OPTIONS+=(INFO "Show RaspiBlitz Status Screen")
fi
fi
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
clear
case $CHOICE in
CLOSE)
exit 1;
;;
1) # SETUP
./10setupBlitz.sh
exit 1;
;;
INFO)
./00infoBlitz.sh
echo "Screen is not updating ... press ENTER to continue."
read key
./00mainMenu.sh;
;;
X) # unlock
./AAunlockLND.sh
./00mainMenu.sh
;;
esac

109
home.admin/10setupBlitz.sh

@ -0,0 +1,109 @@
#!/bin/sh
echo ""
# CHECK WHAT IS ALREADY WORKING
# check list from top down - so ./10setupBlitz.sh
# and re-enters the setup process at the correct spot
# in case it got interrupted
# check if lightning is running
lndRunning=$(systemctl status lnd.service | grep -c running)
if [ ${lndRunning} -eq 1 ]; then
chain=$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.chain')
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/bitcoin/${chain}net/lnd.log | grep -c unlock)
lndSyncing=$(sudo -u bitcoin lncli getinfo | jq -r '.synced_to_chain' | grep -c false)
if [ ${locked} -gt 0 ]; then
# LND wallet is locked
./unlockLND.sh
./10setupBlitz.sh
elif [ ${lndSyncing} -gt 0 ]; then
./70initLND.sh
else
./90finishSetup.sh
fi
exit 1
fi
# check if bitcoin is running
bitcoinRunning=$(systemctl status bitcoind.service | grep -c running)
if [ ${bitcoinRunning} -eq 1 ]; then
echo "OK - Bitcoind is running"
echo "Next step run Lightning"
./70initLND.sh
exit 1
fi
# check if HDD is mounted
mountOK=$(df | grep -c /mnt/hdd)
if [ ${mountOK} -eq 1 ]; then
# if there are signs of blockchain data
if [ -d "/mnt/hdd/bitcoin" ]; then
echo "UNKOWN STATE"
echo "It seems that something went wrong during sync/download/copy of the blockchain."
echo "This needs manual work (get in contact with RaspiBlitz dev team)"
exit 1
fi
# HDD is empty - ask how to get Blockchain
_temp="./download/dialog.$$"
dialog --clear --beep --backtitle "RaspiBlitz" --title "Getting the Blockchain" \
--menu "You need a copy of the Blockchan - you have 3 options:" 13 75 4 \
1 "DOWNLOAD --> TESTNET + MAINNET thru torrent (RECOMMENDED 8h)" \
2 "COPY --> TESTNET + MAINNET from another HDD (TRICKY 3h)" \
3 "SYNC --> JUST TESTNET thru Bitoin Network (FALLBACK)" 2>$_temp
opt=${?}
clear
if [ $opt != 0 ]; then rm $_temp; exit; fi
menuitem=`cat $_temp`
rm $_temp
case $menuitem in
3)
./50syncHDD.sh
;;
1)
./50downloadHDD.sh
;;
2)
./50copyHDD.sh
;;
esac
exit 1
fi
# the HDD is not mounted --> very early stage of setup
# if the script is called for the first time
if [ ! -f "home/admin/.setup" ]; then
# run initial user dialog
./20initDialog.sh
# set SetupState to 10
echo "20" > /home/admin/.setup
# update system
echo ""
echo "*** Update System ***"
sudo apt-mark hold raspberrypi-bootloader
sudo apt-get update
sudo apt-get upgrade -f -y --force-yes
echo "OK - System is now up to date"
fi
# the HDD is already ext4 formated and called blockchain
formatExt4OK=$(lsblk -o UUID,NAME,FSTYPE,SIZE,LABEL,MODEL | grep BLOCKCHAIN | grep -c ext4)
if [ ${formatExt4OK} -eq 1 ]; then
echo "HDD was already inited or prepared"
echo "Now needs to be mounted"
./40addHDD.sh
exit 1
fi
# the HDD had no init yet
echo "HDD needs init"
./30initHDD.sh
exit 1

77
home.admin/20initDialog.sh

@ -0,0 +1,77 @@
#!/bin/sh
_temp="./download/dialog.$$"
# welcome and ask for name of RaspiBlitz
result=""
while [ ${#result} -eq 0 ]
do
l1="Please enter the name of your new RaspiBlitz:\n"
l2="one word, keep characters basic & not too long"
dialog --backtitle "RaspiBlitz - SetUp" --inputbox "$l1$l2" 11 52 2>$_temp
result=`cat $_temp`
shred $_temp
done
# set lightning alias
sed -i "7s/.*/alias=$result/" ./templates/lnd.conf
# store hostname for later - to be set right before the next reboot
# work around - because without a reboot the hostname seems not updates in the whole system
echo $result >> /home/admin/.hostname
# show password info dialog
dialog --backtitle "RaspiBlitz - SetUp" --msgbox "RaspiBlitz uses 4 different passwords.
Referenced as password A, B, C and D.
A) Master User Password
B) Bitcoin RPC Password
C) LND Wallet Password
D) LND Seed Password
Choose now 4 new passwords - all min 8 chars
Write them down & store them in a safe place.
" 14 52
# ask user for new password A
dialog --backtitle "RaspiBlitz - SetUp"\
--inputbox "Please enter your Master/Admin Password A:\n!!! This is new password to login per SSH !!!" 10 52 2>$_temp
# get user input
result=`cat $_temp`
shred $_temp
# check input (check for more later)
if [ ${#result} -eq 0 ]; then
clear
echo "FAIL - Password cannot be empty"
echo "Please restart with ./00mainMenu.sh"
exit 1
fi
# change user passwords and then change hostname
echo "pi:$result" | sudo chpasswd
echo "root:$result" | sudo chpasswd
echo "bitcoin:$result" | sudo chpasswd
echo "admin:$result" | sudo chpasswd
sleep 1
# sucess info dialog
dialog --backtitle "RaspiBlitz" --msgbox "OK - password changed to '$result'\nfor all users pi, admin, root & bitcoin" 6 52
# repeat until user input is nit length 0
result=""
while [ ${#result} -lt 8 ]
do
dialog --backtitle "RaspiBlitz - SetUp"\
--inputbox "Enter your RPC Password B (min 8 chars):" 9 52 2>$_temp
result=`cat $_temp`
shred $_temp
done
# set Bitcoin RPC Password (for admin bitcoin-cli & template for user bitcoin bitcoind)
sed -i "14s/.*/rpcpassword=$result/" ./templates/bitcoin.conf
sed -i "6s/.*/rpcpassword=$result/" ./.bitcoin/bitcoin.conf
# success info dialog
dialog --backtitle "RaspiBlitz - SetUP" --msgbox "OK - RPC password changed to '$result'\n\nNow starting the Setup of your RaspiBlitz." 7 52
clear

40
home.admin/30initHDD.sh

@ -0,0 +1,40 @@
#!/bin/sh
echo ""
echo "*** Checking if HDD is connected ***"
sleep 5
existsHDD=$(lsblk | grep -c sda1)
if [ ${existsHDD} -eq 1 ]; then
echo "OK - HDD found as sda1"
mountOK=$(df | grep -c /mnt/hdd)
if [ ${mountOK} -eq 1 ]; then
echo "FAIL - HDD is mounted"
echo "If you really want to reinit the HDD, then unmount the HDD first and try again"
else
echo ""
echo "*** Formatting the HDD ***"
echo "WARNING ALL DATA ON HDD WILL GET DELETED"
echo "Wait until you get a OK or FAIL"
sleep 4
sudo mkfs.ext4 /dev/sda1 -F -L BLOCKCHAIN
echo "format ext4 done - wait 6 secs"
sleep 6
formatExt4OK=$(lsblk -o UUID,NAME,FSTYPE,SIZE,LABEL,MODEL | grep BLOCKCHAIN | grep -c ext4)
if [ ${formatExt4OK} -eq 1 ]; then
echo "OK - HDD is now formatted in ext4"
sleep 1
# set SetupState
echo "30" > /home/admin/.setup
# automatically now add the HDD to the system
./40addHDD.sh
else
echo "FAIL - was not able to format the HDD to ext4 with the name 'BLOCKCHAIN'"
fi
fi
else
echo "FAIL - no HDD as device sda1 found"
echo "lsblk -o UUID,NAME,FSTYPE,SIZE,LABEL,MODEL"
echo "check if HDD is properly connected and has enough power - then try again"
echo "sometimes a reboot helps: sudo shutdown -r now"
fi

68
home.admin/40addHDD.sh

@ -0,0 +1,68 @@
#!/bin/sh
echo ""
echo "*** Adding HDD to the System ***"
sleep 5
existsHDD=$(lsblk | grep -c sda1)
if [ ${existsHDD} -eq 1 ]; then
echo "OK - HDD found as sda1"
mountOK=$(df | grep -c /mnt/hdd)
if [ ${mountOK} -eq 1 ]; then
echo "FAIL - HDD is already mounted"
echo "If you want to add HDD freshly to the system, then unmount the HDD first and try again"
else
echo ""
echo "*** Check HDD ***"
formatExt4OK=$(lsblk -o UUID,NAME,FSTYPE,SIZE,LABEL,MODEL | grep BLOCKCHAIN | grep -c ext4)
if [ ${formatExt4OK} -eq 1 ]; then
echo "OK - HDD is formatted with ext4 and is named BLOCKCHAIN"
uuid=$(lsblk -o UUID,NAME,FSTYPE,SIZE,LABEL,MODEL | grep BLOCKCHAIN)
set -- $uuid
uuid=$1
fstabOK=$(cat /etc/fstab | grep -c ${uuid})
if [ ${fstabOK} -eq 0 ]; then
fstabAdd="UUID=${uuid} /mnt/hdd ext4 noexec,defaults 0 0"
echo "Adding line to /etc/fstab ..."
echo ${fstabAdd}
# adding the new line after line 3 to the /etc/fstab
sudo sed "3 a ${fstabAdd}" -i /etc/fstab
else
echo "UUID is already in /etc/fstab"
fi
fstabOK=$(cat /etc/fstab | grep -c ${uuid})
if [ ${fstabOK} -eq 1 ]; then
echo "OK - HDD is listed in /etc/fstab"
echo ""
echo "*** Mount HDD ***"
sudo mkdir /mnt/hdd
sudo mount -a
mountOK=$(df | grep -c /mnt/hdd)
if [ ${mountOK} -eq 1 ]; then
echo "OK - HDD is mounted"
echo ""
# set SetupState
echo "40" > /home/admin/.setup
echo "*** Analysing HDD Content ***"
if [ -d "/mnt/hdd/bitcoin" ]; then
echo "Looks like the HDD is prepared with the Blockchain."
echo "Continuing with finishing the system setup ..."
./60finishHDD.sh
else
# HDD is empty - let setupBlitz - display next options
./10setupBlitz.sh
fi
else
echo "FAIL - was not able to mount"
fi
else
echo "FAIL - was not able to edit /etc/fstab"
fi
else
echo "FAIL - the HDD is not in ext4 format AND named 'BLOCKCHAIN'"
fi
fi
else
echo "FAIL - no HDD as device sda1 found"
echo "check if HDD is properly connected and has enough power - then try again"
fi

96
home.admin/50copyHDD.sh

@ -0,0 +1,96 @@
#!/bin/sh
echo ""
echo "*** Check 1st HDD ***"
sleep 4
hddA=$(lsblk | grep /mnt/hdd | grep -c sda1)
if [ ${hddA} -eq 0 ]; then
echo "FAIL - 1st HDD not found as sda1"
echo "Try 'sudo shutdown -r now'"
exit 1
fi
echo "OK - HDD as sda1 found"
echo ""
echo "*** Copy Blockchain form a second HDD ***"
echo ""
echo "WARNING: The RaspiBlitz cannot run 2 HDDs without extra Power!"
echo ""
echo "You can use a Y cable for the second HDD to inject extra power."
echo "Like this one: https://www.amazon.de/dp/B00ZJBIHVY"
echo "If you see on LCD a error on connecting the 2nd HDD do a restart."
echo ""
echo "You can use the HDD of another RaspiBlitz for this."
echo "The 2nd HDD needs to be formated Ext4/exFAT and the folder 'bitcoin' is in root of HDD."
echo ""
echo "**********************************"
echo "--> Please connect now the 2nd HDD"
echo "**********************************"
echo ""
echo "If 2nd HDD is connected but setup does not continue,"
echo "then cancel (CTRL+c) and reboot."
ready=0
while [ ${ready} -eq 0 ]
do
hddA=$(lsblk | grep /mnt/hdd | grep -c sda1)
if [ ${hddA} -eq 0 ]; then
echo "FAIL - connection to 1st HDD lost"
echo "It seems there was a POWEROUTAGE while connecting the 2nd HDD."
echo "Try to avoid this next time by adding extra Power or connect more securely."
echo "You need now to reboot with 'sudo shutdown -r now' and then try again."
exit 1
fi
hddB=$(lsblk | grep -c sdb1)
if [ ${hddB} -eq 1 ]; then
echo "OK - 2nd HDD found"
ready=1
fi
done
echo ""
echo "*** Mounting 2nd HDD ***"
sudo mkdir /mnt/genesis
echo "try ext4 .."
sudo mount -t ext4 /dev/sdb1 /mnt/genesis
sleep 2
mountOK=$(lsblk | grep -c /mnt/genesis)
if [ ${mountOK} -eq 0 ]; then
echo "try exfat .."
sudo mount -t exfat /dev/sdb1 /mnt/genesis
sleep 2
fi
mountOK=$(lsblk | grep -c /mnt/genesis)
if [ ${mountOK} -eq 0 ]; then
echo "FAIL - not able to mount the 2nd HDD"
echo "only ext4 and exfat possible"
sleep 4
./10setupBlitz.sh
exit 1
else
echo "OK - 2nd HDD mounted at /mnt/genesis"
fi
echo ""
echo "*** Copy Blockchain ***"
sudo rsync --append --info=progress2 -a /mnt/genesis/bitcoin /mnt/hdd/
echo "cleaning up - ok if files do not exists"
sudo rm /mnt/hdd/bitcoin/bitcoin.conf
sudo rm /mnt/hdd/bitcoin/bitcoin.pid
sudo rm /mnt/hdd/bitcoin/banlist.dat
sudo rm /mnt/hdd/bitcoin/debug.log
sudo rm /mnt/hdd/bitcoin/fee_estimates.dat
sudo rm /mnt/hdd/bitcoin/mempool.dat
sudo rm /mnt/hdd/bitcoin/peers.dat
sudo rm /mnt/hdd/bitcoin/testnet3/banlist.dat
sudo rm /mnt/hdd/bitcoin/testnet3/debug.log
sudo rm /mnt/hdd/bitcoin/testnet3/fee_estimates.dat
sudo rm /mnt/hdd/bitcoin/testnet3/mempool.dat
sudo rm /mnt/hdd/bitcoin/testnet3/peers.dat
sudo umount -l /mnt/genesis
echo "OK - Copy done :)"
echo ""
echo "---> You can now disconnect the 2nd HDD"
# set SetupState
echo "50" > /home/admin/.setup
sleep 5
./60finishHDD.sh

44
home.admin/50downloadHDD.sh

@ -0,0 +1,44 @@
#!/bin/sh
# name of torrentfile = name of directory in torrent
torrent="raspiblitz-hdd-2018-6-27"
echo ""
echo "*** Checking HDD ***"
mountOK=$(df | grep -c /mnt/hdd)
if [ ${mountOK} -eq 1 ]; then
# HDD is mounted
if [ -d "/mnt/hdd/bitcoin" ]; then
# HDD has already content
echo "It seems that HDD has already content. Try to continue with ./finishHDD.sh"
else
# HDD is empty - download HDD content
echo "OK - HDD is ready."
echo ""
echo "*** Downloading HDD ***"
tmpfile=$(mktemp)
chmod a+x $tmpfile
echo "killall transmission-cli" > $tmpfile
sudo transmission-cli ./download/$torrent.torrent -D -w /mnt/hdd -f $tmpfile
echo ""
echo "*** Moving Files ***"
echo "moving files ..."
mv /mnt/hdd/$torrent/* /mnt/hdd
rm -R /mnt/hdd/$torrent
echo ""
# set SetupState
echo "50" > /home/admin/.setup
echo "*** Next Step ***"
echo "You can now use this HDD as a source to copy the Blockchain during the setup of another RaspiBlitz."
sleep 4
# continue setup
./60finishHDD.sh
fi
else
# HDD is not available yet
echo "*** Mount HDD on /mnt/hdd first ***"
fi

29
home.admin/50syncHDD.sh

@ -0,0 +1,29 @@
#!/bin/sh
msg=""
msg="$msg Syncing is just practical for Bitcoin TESTNET!\n"
msg="$msg TESTNET is OK for learning, testing and development.\n"
msg="$msg MAINNET is where things get real and fun.\n"
msg="$msg \n"
msg="$msg Syncing MAINNET on a raspberry is NOT practical.\n"
msg="$msg If you want MAINET, go back & try DOWNLOAD.\n"
msg="$msg \n"
msg="$msg Do you really want to work with ONLY TESTNET?"
dialog --title " WARNING " --yesno "${msg}" 12 57
response=$?
case $response in
0) echo "--> OK";;
1) ./10setupBlitz.sh; exit 1;;
255) ./10setupBlitz.sh; exit 1;;
esac
echo "*** Activating Blockain Sync ***"
sudo mkdir /mnt/hdd/bitcoin
echo "OK - sync is activated"
# set SetupState
echo "50" > /home/admin/.setup
# continue setup
./60finishHDD.sh

45
home.admin/60finishHDD.sh

@ -0,0 +1,45 @@
#!/bin/sh
echo ""
echo "*** Checking HDD ***"
mountOK=$(df | grep -c /mnt/hdd)
if [ ${mountOK} -eq 1 ]; then
# HDD is mounted
if [ -d "/mnt/hdd/bitcoin" ]; then
# HDD has content - continue
echo "OK - HDD is ready."
###### LINK HDD
echo ""
echo "*** Prepare Bitcoin ***"
sudo cp /home/admin/templates/bitcoin.conf /mnt/hdd/bitcoin/bitcoin.conf
sudo ln -s /mnt/hdd/bitcoin /home/bitcoin/.bitcoin
sudo mkdir /mnt/hdd/lnd
sudo chown -R bitcoin:bitcoin /mnt/hdd/lnd
sudo ln -s /mnt/hdd/lnd /home/bitcoin/.lnd
sudo chown -R bitcoin:bitcoin /home/bitcoin/.bitcoin
sudo chown -R bitcoin:bitcoin /home/bitcoin/.lnd
echo "OK - Bitcoin setup ready"
###### START BITCOIN SERVICE
echo ""
echo "*** Start Bitcoin ***"
sudo systemctl enable bitcoind.service
sudo systemctl start bitcoind.service
echo "Giving bitcoind service 180 seconds to init - please wait ..."
sleep 180
echo "OK - bitcoind started"
sleep 2
# set SetupState
echo "60" > /home/admin/.setup
./10setupBlitz.sh
else
# HDD is empty - download HDD content
echo "FAIL - HDD is empty."
fi
else
# HDD is not available yet
echo "FAIL - HDD is not mounted."
fi

179
home.admin/70initLND.sh

@ -0,0 +1,179 @@
#!/bin/sh
echo ""
# verify that bitcoin is running
echo "*** Checking Bitcoin ***"
bitcoinRunning=$(systemctl status bitcoind.service | grep -c running)
if [ ${bitcoinRunning} -eq 0 ]; then
# HDD is not available yet
echo "FAIL - Bitcoind is not running"
echo "recheck with orignal tutorial -->"
echo "https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_30_bitcoin.md"
fi
echo "OK - Bitcoind is running"
echo ""
###### Wait for Blochain Sync
echo "*** Syncing Blockchain ***"
ready=0
while [ ${ready} -eq 0 ]
do
progress="$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.verificationprogress')"
sync_percentage=$(printf "%.2f%%" "$(echo $progress | awk '{print 100 * $1}')")
ready=$(echo $progress'>0.99' | bc -l)
if [ ${ready} -eq 0 ]; then
echo "${sync_percentage}"
else
if [ ${ready} -eq 1 ]; then
echo "${sync_percentage}"
else
echo "waiting to start sync"
ready=0
fi
fi
echo "${sync_percentage}"
sleep 3
done
echo "OK - Blockchain is synced"
echo ""
###### LND Config
echo "*** LND Config ***"
configExists=$( sudo ls /mnt/hdd/lnd/ | grep -c lnd.conf )
if [ ${configExists} -eq 0 ]; then
sudo cp /home/admin/templates/lnd.conf /mnt/hdd/lnd/lnd.conf
sudo chown bitcoin:bitcoin /mnt/hdd/lnd/lnd.conf
if [ -d /home/bitcoin/.lnd ]; then
echo "OK - LND config written"
else
echo "FAIL - Was not able to setup LND"
exit 1
fi
else
echo "OK - exists"
fi
echo ""
###### Start LND
echo "*** Starting LND ***"
lndRunning=$(systemctl status lnd.service | grep -c running)
if [ ${lndRunning} -eq 0 ]; then
sudo systemctl enable lnd
sudo systemctl start lnd
echo "Started LND .. waiting 30 seconds for init ..."
sleep 30
fi
###### Check LND is running
lndRunning=$(systemctl status lnd.service | grep -c running)
if [ ${lndRunning} -eq 0 ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "FAIL - LND is not running"
echo "recheck with original tutorial -->"
echo "https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_40_lnd.md"
exit 1
fi
echo "OK - LND is running"
echo ""
###### Instructions on Creating LND Wallet
setupStep=0
setupStep=$(sudo cat "/home/admin/.setup")
if [ ${setupStep} -lt 65 ]; then
# setup state signals, that no wallet has been created yet
dialog --backtitle "RaspiBlitz - LND Lightning Wallet" --msgbox "
Bitcoin and Lighthing Services are installed.
You now need to setup your Lightning Wallet:
We will now call the command: lncli create
lncli = Lightning Network Command Line Interface
Learn more: https://api.lightning.community
Press OK and follow the 'Helping Instructions'.
" 14 52
clear
echo "****************************************************************************"
echo "Helping Instructions --> for creating a new LND Wallet"
echo "****************************************************************************"
echo "A) For 'Wallet Password' use your PASSWORD C --> !! minimum 8 characters !!"
echo "B) Answere 'n' because you dont have a 'cipher seed mnemonic' (24 words) yet"
echo "C) For 'passphrase' to encrypt your 'cipher seed' use PASSWORD D (optional)"
echo "****************************************************************************"
echo ""
echo "lncli create"
sudo -u bitcoin lncli create
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!!! Make sure to write down the 24 words (cipher seed mnemonic) !!!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "If you are ready. Press ENTER."
read key
# set SetupState to 75 (mid thru this process)
echo "65" > /home/admin/.setup
fi
echo "--> lets wait 30 seconds for LND to get ready"
sleep 30
###### Copy LND macaroons to admin
echo ""
echo "*** Copy LND Macaroons to user admin ***"
macaroonExists=$(sudo -u bitcoin ls -la /mnt/hdd/lnd/admin.macaroon | grep -c admin.macaroon)
if [ ${macaroonExists} -eq 0 ]; then
echo ""
echo "FAIL - LND Macaroons not created"
echo "Please check the following LND issue:"
echo "https://github.com/lightningnetwork/lnd/issues/890"
exit 1
fi
sudo mkdir /home/admin/.lnd
macaroonExists=$(sudo ls -la /home/admin/.lnd/ | grep -c admin.macaroon)
if [ ${macaroonExists} -eq 0 ]; then
sudo mkdir /home/admin/.lnd
sudo cp /home/bitcoin/.lnd/tls.cert /home/admin/.lnd
sudo cp /home/bitcoin/.lnd/admin.macaroon /home/admin/.lnd
sudo chown -R admin:admin /home/admin/.lnd/
echo "OK - LND Macaroons created"
else
echo "OK - Macaroons are already copied"
fi
###### Unlock Wallet (if needed)
echo "*** Check Wallet Lock ***"
chain=$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.chain')
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/bitcoin/${chain}net/lnd.log | grep -c unlock)
if [ ${locked} -gt 0 ]; then
echo "OK - Wallet is locked ... starting unlocking dialog"
./unlockLND.sh
else
echo "OK - Wallet is already unlocked"
fi
### Show Lighthning Sync
echo ""
echo "*** Check LND Sync ***"
item=0
chain="$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.chain')"
lndSyncing=$(sudo -u bitcoin lncli getinfo | jq -r '.synced_to_chain' | grep -c true)
if [ ${lndSyncing} -eq 0 ]; then
echo "OK - wait for LND to be synced"
while :
do
# show sync status
./80scanLND.sh
sleep 3
# break loop when synced
lndSyncing=$(sudo -u bitcoin lncli getinfo | jq -r '.synced_to_chain' | grep -c true)
if [ ${lndSyncing} -eq 1 ]; then
break
fi
done
clear
else
echo "OK - LND is in sync"
fi
# set SetupState (scan is done - so its 80%)
echo "80" > /home/admin/.setup
###### finishSetUp
./90finishSetup.sh

20
home.admin/80scanLND.sh

@ -0,0 +1,20 @@
# parse the actual scanned height progress from LND logs
item=0
chain="$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.chain')"
gotData=$(sudo tail -n 100 /mnt/hdd/lnd/logs/bitcoin/${chain}net/lnd.log | grep -c height)
if [ ${gotData} -gt 0 ]; then
item=$(sudo tail -n 100 /mnt/hdd/lnd/logs/bitcoin/${chain}net/lnd.log | grep height | tail -n1 | awk '{print $9} {print $10} {print $11} {print $12}' | tr -dc '0-9')
fi
# get total number of blocks
total=$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.blocks')
# calculate progress in percent
percent=$(awk "BEGIN { pc=100*${item}/${total}; i=int(pc); print (pc-i<0.5)?i:i+1 }")
if [ ${percent} -e 100 ]; then
# normally if 100% gets calculated, item parsed the wrong height
percent=0
fi
# display progress to user
dialog --backtitle "RaspiBlitz" --infobox " Lightning Rescanning Blockchain $percent%\nplease wait - this can take some time" 4 42

51
home.admin/90finishSetup.sh

@ -0,0 +1,51 @@
#!/bin/sh
echo ""
###### SWAP
echo "*** SWAP file ***"
swapExists=$(swapon -s | grep -c /mnt/hdd/swapfile)
if [ ${swapExists} -eq 1 ]; then
echo "SWAP on HDD already exists"
else
echo "No SWAP found ... creating 1GB SWAP on HDD"
sudo sed -i "12s/.*/CONF_SWAPFILE=\/mnt\/hdd\/swapfile/" /etc/dphys-swapfile
sudo sed -i "16s/.*/CONF_SWAPSIZE=1024/" /etc/dphys-swapfile
echo "OK - edited /etc/dphys-swapfile"
echo "Creating file ... this can take some seconds .."
sudo dd if=/dev/zero of=/mnt/hdd/swapfile bs=1024 count=1024000
sudo mkswap /mnt/hdd/swapfile
sudo dphys-swapfile setup
sudo chmod 0600 /mnt/hdd/swapfile
sudo dphys-swapfile swapon
fi
swapExists=$(swapon -s | grep -c /mnt/hdd/swapfile)
if [ ${swapExists} -eq 1 ]; then
echo "OK - SWAP is working"
else
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "WARNING - Not able to to build SWAP on HDD"
echo "This is not critical ... but try to fix later."
echo "--> will continue in 60 seconds <--"
sleep 60
fi
# mark setup is done
echo "90" > /home/admin/.setup
# set the hostname inputed on initDialog
hostname=`cat .hostname`
echo "Setting new network hostname '$hostname'"
sudo hostnamectl set-hostname ${hostname}
# show info to user
dialog --backtitle "RaspiBlitz - SetUp" --title " RaspiBlitz Setup is done :) " --msgbox "
Press OK for a final reboot.
Remember: After every reboot
you need to unlock the LND wallet.
" 10 42
# mark setup is done (100%)
echo "100" > /home/admin/.setup
sudo shutdown -r now

20
home.admin/AAunlockLND.sh

@ -0,0 +1,20 @@
#!/bin/sh
echo ""
echo "****************************************************************************"
echo "Unlock LND Wallet --> lncli unlock"
echo "****************************************************************************"
echo "HELP: Enter your PASSWORD C"
echo "****************************************************************************"
chain="$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.chain')"
while :
do
lncli unlock
sleep 4
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/bitcoin/${chain}net/lnd.log | grep -c unlock)
if [ ${locked} -eq 0 ]; then
break
fi
echo ""
echo "Wallet still locked - please try again or Cancel with CTRL+C"
done

22
home.admin/XXcleanHDD.sh

@ -0,0 +1,22 @@
echo ""
echo "!!!! This will DELETE your personal data from the HDD !!!!"
echo "--> use the HDD with just blockchain in a fresh setup"
echo "Press ENTER to continue - CTRL+c to CANCEL"
read key
sudo dphys-swapfile swapoff
sudo systemctl stop bitcoind.service
sudo systemctl stop lnd.service
sudo rm -f -r /mnt/hdd/lnd
sudo rm -f /mnt/hdd/swapfile
sudo rm -f /mnt/hdd/bitcoin/bitcoin.conf
sudo rm -f /mnt/hdd/bitcoin/bitcoin.pid
sudo rm -f /mnt/hdd/bitcoin/*.dat
sudo rm -f /mnt/hdd/bitcoin/*.log
sudo rm -f /mnt/hdd/bitcoin/bitcoin.conf
sudo rm -f /mnt/hdd/bitcoin/testnet3/*.dat
sudo rm -f /mnt/hdd/bitcoin/testnet3/*.log
sudo rm -f /mnt/hdd/bitcoin/testnet3/.lock
sudo rm -f -r /mnt/hdd/bitcoin/database
sudo chown admin:admin -R /mnt/hdd/bitcoin
echo "1" > /home/admin/.setup
echo "OK - the HDD is now clean"
Loading…
Cancel
Save