Browse Source

bugfixes, bonus, screen session download

#146
rootzoll 7 years ago
parent
commit
7373dac395
  1. 19
      home.admin/00infoLCD.sh
  2. 27
      home.admin/00mainMenu.sh
  3. 22
      home.admin/10setupBlitz.sh
  4. 162
      home.admin/50downloadHDD.sh
  5. 5
      home.admin/80scanLND.sh
  6. 14
      home.admin/90finishSetup.sh
  7. 122
      home.admin/BBconnectPeer.sh
  8. 54
      home.admin/BBfundWallet.sh
  9. 88
      home.admin/XXscreenMonitor.sh

19
home.admin/00infoLCD.sh

@ -8,7 +8,7 @@ if [ "$USER" = "pi" ]; then
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/${network}/ | grep -c ${network}.conf)
bitcoinInstalled=$(sudo -u bitcoin ls /mnt/hdd/${network}/ 2>/dev/null | grep -c ${network}.conf)
if [ ${bitcoinInstalled} -eq 1 ]; then
# wait enough secs to let bitcoind init
dialog --pause " Waiting for ${network} to startup and init ..." 8 58 130
@ -36,15 +36,15 @@ if [ "$USER" = "pi" ]; then
l2="ssh admin@${localip}\n"
l3="Use password: raspiblitz\n"
boxwidth=$((${#localip} + 20))
dialog --backtitle "RaspiBlitz - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth}
dialog --backtitle "RaspiBlitz - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth}
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=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain')
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c unlock)
lndSyncing=$(sudo -u bitcoin lncli getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c false)
chain=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 2>/dev/null | jq -r '.chain')
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2>/dev/null | grep -c unlock)
if [ ${locked} -gt 0 ]; then
@ -69,7 +69,14 @@ if [ "$USER" = "pi" ]; then
l2="ssh admin@${localip}\n"
l3="Use your Password A\n"
boxwidth=$((${#localip} + 20))
dialog --backtitle "RaspiBlitz - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth}
if [ ${setupStep} -eq 50 ]; then
l1="Blockhain Setup - monitor progress:\n"
boxwidth=45
fi
sleep 3
dialog --backtitle "RaspiBlitz - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 10
fi

27
home.admin/00mainMenu.sh

@ -1,9 +1,9 @@
#!/bin/bash
## default menu settings
HEIGHT=11
HEIGHT=13
WIDTH=64
CHOICE_HEIGHT=4
CHOICE_HEIGHT=6
BACKTITLE="RaspiBlitz"
TITLE=""
MENU="Choose one of the following options:"
@ -62,8 +62,11 @@ else
# REGULAR MENU
OPTIONS+=(INFO "RaspiBlitz Status Screen" \
lnbalance "Detailed Wallet Balances" \
lnchannels "Lightning Channel List")
FUNDING "Fund your Wallet" \
CONNECT "Connect to a Peer" \
lnbalance "Detailed Wallet Balances" \
lnchannels "Lightning Channel List" \
RECKLES "Console / Terminal")
fi
@ -114,6 +117,22 @@ case $CHOICE in
read key
./00mainMenu.sh
;;
CONNECT)
./BBconnectPeer.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
FUNDING)
./BBfundWallet.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
RECKLES)
lncli -h
echo "SUCH WOW come back with ./00mainMenu.sh"
;;
X) # unlock
./AAunlockLND.sh
./00mainMenu.sh

22
home.admin/10setupBlitz.sh

@ -13,9 +13,9 @@ network=`cat .network`
lndRunning=$(systemctl status lnd.service | grep -c running)
if [ ${lndRunning} -eq 1 ]; then
chain=$(${network}-cli -datadir=/home/${network}/.${network} getblockchaininfo | jq -r '.chain')
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c unlock)
lndSyncing=$(sudo -u bitcoin lncli getinfo | jq -r '.synced_to_chain' | grep -c false)
chain=$(${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 2>/dev/null | jq -r '.chain')
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2>/dev/null | grep -c unlock)
lndSyncing=$(sudo -u bitcoin lncli getinfo | jq -r '.synced_to_chain' 2>/dev/null | grep -c false)
if [ ${locked} -gt 0 ]; then
# LND wallet is locked
./AAunlockLND.sh
@ -29,7 +29,7 @@ if [ ${lndRunning} -eq 1 ]; then
fi
# check if bitcoin is running
bitcoinRunning=$(sudo -u bitcoin ${network}-cli getblockchaininfo | grep -c blocks)
bitcoinRunning=$(sudo -u bitcoin ${network}-cli getblockchaininfo 2>/dev/null | grep -c blocks)
if [ ${bitcoinRunning} -eq 1 ]; then
echo "OK - ${network}d is running"
echo "Next step run Lightning"
@ -43,9 +43,18 @@ if [ ${mountOK} -eq 1 ]; then
# are there any signs of blockchain data
if [ -d "/mnt/hdd/${network}" ]; then
echo "UNKOWN STATE"
echo "UNKOWN STATE - there is blockain data folder, but blockchaind is not running"
echo "It seems that something went wrong during sync/download/copy of the blockchain."
echo "Maybe try --> ./60finishHDD.sh"
echo "If this sill is not working reboot after running --> sudo rm -r /mnt/hdd/${network}"
exit 1
fi
# check if there is a download to continue
downloadProgressExists=$(sudo ls /home/admin/.Download.progress 2>/dev/null | grep ".Download.progress" -c)
if [ ${downloadProgressExists} -eq 1 ]; then
echo "found download in progress .."
./50downloadHDD.sh
exit 1
fi
@ -77,6 +86,9 @@ if [ ${mountOK} -eq 1 ]; then
exit 1
fi
# set SetupState
echo "50" > /home/admin/.setup
clear
case $menuitem in
T)

162
home.admin/50downloadHDD.sh

@ -4,12 +4,12 @@ echo ""
# *** BITCOIN ***
bitcoinList="" # url to list with other sources
bitcoinUrl="ftp://anonymous:anonymous@tll9xsfkjht8j26z.myfritz.net/raspiblitz-bitcoin-2018-07-16"
bitcoinSize=100
bitcoinSize=231000000 # 231235816-tolerance
# *** LITECOIN ***
litecoinList="" # url to list with other sources
litecoinUrl="ftp://anonymous:anonymous@ftp.rotzoll.de/pub/raspiblitz-litecoin-2018-07-29"
litecoinSize=19000000
litecoinSize=19180000 # 19184960-tolerance
# load network
network=`cat .network`
@ -24,43 +24,149 @@ if [ "$network" = "litecoin" ]; then
size=$litecoinSize
fi
# the path wget will download to
targetPath=$(echo ${url} | cut -d '@' -f2)
# screen background monitoring settings
name="Download"
targetDir="/mnt/hdd/download/"
targetSize=$size
maxTimeoutLoops=500
command="sudo wget -c -r -P ${targetDir} -q --show-progress ${url}"
echo "network($network)"
echo "list($list)"
echo "url($url)"
echo "size($size)"
echo "targetPath($targetPath)"
echo ""
# starting session if needed
echo "checking if ${name} has a running screen session"
screen -wipe 1>/dev/null
isRunning=$( screen -S ${name} -ls | grep "${name}" -c )
echo "isRunning(${isRunning})"
if [ ${isRunning} -eq 0 ]; then
echo "Starting screen session"
screen -S ${name} -dm ${command}
else
echo "Continue screen session"
fi
sleep 3
echo "*** Downloading HDD / FTP ***"
sudo wget -r -P /mnt/hdd/ -q --show-progress ${url}
echo "OK"
echo ""
# monitor session
screenDump="... started ..."
actualSize=0
timeout=1
timeoutInfo="-"
while :
do
# check if session is still running
screen -wipe 1>/dev/null
isRunning=$( screen -S ${name} -ls | grep "${name}" -c )
if [ ${isRunning} -eq 0 ]; then
timeout=0
echo "OK - session finished"
break
fi
# calculate progress and write it to file for LCD to read
freshSize=$( du -s ${targetDir} | head -n1 | awk '{print $1;}' )
if [ ${#actualSize} -eq 0 ]; then
freshSize=0
fi
progress=$(echo "scale=2; $freshSize*100/$targetSize" | bc)
echo $progress > '.${name}.progress'
# detect if since last loop any progress occured
if [ ${actualSize} -eq ${freshSize} ]; then
timeoutInfo="${timeout}/${maxTimeoutLoops}"
timeout=$(( $timeout + 1 ))
else
timeout=1
timeoutInfo="no timeout detected"
fi
actualSize=$freshSize
# detect if mx timeout loop limit is reached
if [ ${timeout} -gt ${maxTimeoutLoops} ]; then
echo "FAIL - download hit timeout"
break
fi
# display info screen
clear
echo "****************************************************"
echo "Monitoring Screen Session: ${name}"
echo "Progress: ${progress}% (${actualSize} of ${targetSize})"
echo "Timeout: ${timeoutInfo}"
echo "If needed press key x to stop ${name}"
echo "Its OK to close terminal now and SSH back in later."
echo "****************************************************"
screen -S ${name} -X hardcopy .${name}.out
newScreenDump=$(cat .Download.out | grep . | tail -10)
if [ ${#newScreenDump} -gt 0 ]; then
screenDump=$newScreenDump
fi
echo "$screenDump"
# wait 2 seconds for key input
read -n 1 -t 2 keyPressed
# check if user wants to abort session
if [ "${keyPressed}" = "x" ]; then
echo ""
echo "Aborting ${name}"
break
fi
done
echo "*** Checking Download ***"
downloadsize=$(sudo du -s /mnt/hdd/${targetPath} | awk '{print $1}' | tr -dc '0-9')
if [ ${#downloadsize} -eq 0 ]; then
downloadsize=0
# clean up
rm -f .${name}.out
rm -f .${name}.progress
# quit session if still running
if [ ${isRunning} -eq 1 ]; then
# get the PID of screen session
sessionPID=$(screen -ls | grep "${name}" | cut -d "." -f1 | xargs)
echo "killing screen session PID(${sessionPID})"
# kill all child processes of screen sceesion
pkill -P ${sessionPID}
echo "proccesses klilled"
sleep 3
# tell the screen session to quit and wait a bit
screen -S ${name} -X quit 1>/dev/null
sleep 3
echo "cleaning screen"
screen -wipe 1>/dev/null
sleep 3
fi
echo "download size is(${downloadsize}) needs to be minimum(${size}})"
if [ ${downloadsize} -lt ${size} ]; then
# the path wget will download to
targetPath=$(echo ${url} | cut -d '@' -f2)
echo "path to downloaded data is ${targetPath}"
# calculate progress and write it to file for LCD to read
finalSize=$( du -s ${targetDir} | head -n1 | awk '{print $1;}' )
if [ ${#actualSize} -eq 0 ]; then
finalSize=0
fi
echo "final size is ${finalSize} of targeted size ${targetSize}"
# check result
if [ ${finalSize} -lt ${targetSize} ]; then
# Download failed
sleep 3
echo -ne '\007'
dialog --title " WARNING " --yesno "The download failed or is not complete. Do you want keep already downloaded data?" 6 57
response=$?
case $response in
1) sudo rm -rf /mnt/hdd/${targetPath} ;;
1) sudo rm -rf ${targetDir}${targetPath} ;;
esac
./00mainMenu.sh
exit 1;
fi
echo ""
else
# Download worked
echo "*** Moving Files ***"
sudo mv ${targetDir}${targetPath} /mnt/hdd/${network}
echo "OK"
echo "*** Moving Files ***"
sudo mv /mnt/hdd/${targetPath} /mnt/hdd/${network}
echo "OK"
# continue setup
./60finishHDD.sh
# continue setup
./60finishHDD.sh
fi

5
home.admin/80scanLND.sh

@ -1,6 +1,9 @@
# load network
network=`sudo cat /home/admin/.network`
### USER PI AUTOSTART (LCD Display)
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
# parse the actual scanned height progress from LND logs
item=0
chain="$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain')"
@ -20,4 +23,4 @@ if [ ${percent} -e 100 ]; then
fi
# display progress to user
dialog --backtitle "RaspiBlitz (${network} / ${chain})" --infobox " Lightning Rescanning Blockchain ${percent}%\nplease wait - this can take some time" 4 42
dialog --backtitle "RaspiBlitz (${localip} / ${network} / ${chain})" --infobox " Lightning Rescanning Blockchain ${percent}%\nplease wait - this can take some time" 4 42

14
home.admin/90finishSetup.sh

@ -32,18 +32,13 @@ else
sleep 60
fi
# mark setup is done
echo "90" > /home/admin/.setup
# expand FS of SD
echo "*** Expand RootFS ***"
sudo raspi-config --expand-rootfs
echo ""
# set the hostname inputed on initDialog
hostname=`cat .hostname`
echo "Setting new network hostname '$hostname'"
sudo hostnamectl set-hostname ${hostname}
# mark setup is done
echo "90" > /home/admin/.setup
# show info to user
dialog --backtitle "RaspiBlitz - Setup" --title " RaspiBlitz Setup is done :) " --msgbox "
@ -53,6 +48,11 @@ dialog --backtitle "RaspiBlitz - Setup" --title " RaspiBlitz Setup is done :) "
you need to unlock the LND wallet.
" 10 42
# set the hostname inputed on initDialog
hostname=`cat .hostname`
echo "Setting new network hostname '$hostname'"
sudo raspi-config nonint do_hostname ${hostname}
# mark setup is done (100%)
echo "100" > /home/admin/.setup

122
home.admin/BBconnectPeer.sh

@ -0,0 +1,122 @@
#!/bin/sh
_temp="./download/dialog.$$"
_error="./.error.out"
# load network and chain info
network=`cat .network`
chain=$(sudo -bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain')
# set ntwork map info
networkMap="https://lnmainnet.gaben.win"
if [ "$network" = "litecoin" ]; then
networkMap="https://lnexplorer.hcwong.me"
fi
if [ "$chain" = "test" ]; then
networkMap="https://explorer.acinq.co"
fi
# let user enter a <pubkey>@host
l1="Enter the node pubkey address with host information:"
l2="example -----> 024ddf33[...]1f5f9f3@91.65.1.38:9735"
l3="network map -> ${networkMap}"
dialog --title "Open a Connection to a Peer" \
--backtitle "Lightning ( ${network} | ${chain} )" \
--inputbox "$l1\n$l2\n$l3" 10 60 2>$_temp
_input=$(cat $_temp | xargs )
shred $_temp
if [ ${#_input} -eq 0 ]; then
exit 1
fi
# build command
command="lncli connect ${_input}"
# info output
clear
echo "******************************"
echo "Connect to A Lightning Node"
echo "******************************"
echo ""
echo "COMMAND LINE: "
echo $command
echo ""
echo "RESULT:"
win=1
info=""
# check if input is available
if [ ${#_input} -lt 10 ]; then
win=0
info="node pubkey@host info is too short"
else
gotAt=$(echo $_input | grep '@' -c)
if [ ${gotAt} -eq 0 ]; then
win=0
info="format is not pubkey@host - @ is missing"
fi
fi
# execute command
sleep 2
result="$info"
if [ ${win} -eq 1 ]; then
result=$($command 2>$_error)
fi
# on no result
if [ ${#result} -eq 0 ]; then
# basic error
win=0
info="No return value. Error not known."
# try to get error output
result=`cat ${_error}`
echo "$result"
# basic cli error
cliError=$(echo "${result}" | grep "[lncli]" -c )
if [ ${cliError} -gt 0 ]; then
info="Its possible that LND daemon is not running, not configured correct or not connected to the lncli."
fi
else
# when result is available
echo "$result"
# check if the node is now in peer list
pubkey=$(echo $_input | cut -d '@' -f1)
isPeer=$(lncli listpeers 2>/dev/null| grep "${pubkey}" -c)
if [ ${isPeer} -eq 0 ]; then
# basic error message
win=0
info="Was not able to establish connection to node."
# TODO: try to find out more details from cli output
else
info="Perfect - a connection to that node got established :)"
fi
fi
# output info
echo ""
if [ ${win} -eq 1 ]; then
echo "******************************"
echo "WIN"
echo "******************************"
echo "${info}"
echo ""
echo "Whats next? --> Open a channel with that node."
else
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "FAIL"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "${info}"
fi
echo ""

54
home.admin/BBfundWallet.sh

@ -0,0 +1,54 @@
#!/bin/bash
# load network and chain info
network=`cat .network`
chain=$(${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 2>/dev/null | jq -r '.chain')
command="lncli newaddress np2wkh"
clear
echo "******************************"
echo "Fund your Blockchain Wallet"
echo "******************************"
echo ""
echo "COMMAND LINE: "
echo $command
echo ""
echo "RESULT:"
# execute command
result=$($command)
# on no result
if [ ${#result} -eq 0 ]; then
echo "Sorry something went wrong - thats unusual."
echo ""
exit 1
fi
# when result is available
echo "$result"
# get address from result
address=$( echo "$result" | grep "address" | cut -d '"' -f4)
# prepare coin info
coininfo="REAL Bitcoin"
if [ "$network" = "litecoin" ]; then
coininfo="REAL Litecoin"
fi
if [ "$chain" = "test" ]; then
coininfo="TESTNET Bitcoin"
fi
# output info
echo ""
echo "******************************"
echo "TODO"
echo "******************************"
echo "Send ${coininfo} to address --> ${address}"
if [ "$chain" = "test" ]; then
echo "get some testnet coins from https://testnet.manu.backend.hamburg/faucet"
fi
echo "Whats next? --> Wait for confirmations. You can use lnbalance for main menu or info on LCD to check if funds have arrived."
echo ""

88
home.admin/51screenMonitor.sh → home.admin/XXscreenMonitor.sh

@ -1,11 +1,35 @@
# experimental script to let downloads run
# in background with screen an monitor
#!/bin/sh
echo ""
# *** BITCOIN ***
bitcoinList="" # url to list with other sources
bitcoinUrl="ftp://anonymous:anonymous@tll9xsfkjht8j26z.myfritz.net/raspiblitz-bitcoin-2018-07-16"
bitcoinSize=100
# *** LITECOIN ***
litecoinList="" # url to list with other sources
litecoinUrl="ftp://anonymous:anonymous@ftp.rotzoll.de/pub/raspiblitz-litecoin-2018-07-29"
litecoinSize=19000000
# load network
network=`cat .network`
# settings based on network
list=$bitcoinList
url=$bitcoinUrl
size=$bitcoinSize
if [ "$network" = "litecoin" ]; then
list=$litecoinList
url=$litecoinUrl
size=$litecoinSize
fi
# screen background monitoring settings
name="Download"
targetDir="./test/"
targetSize=2085832
maxTimeoutLoops=10
command="wget -P ${targetDir} http://wiki.fulmo.org/downloads/raspiblitz-2018-07-29b.img.gz"
targetDir="/mnt/hdd/download/"
targetSize=$size
maxTimeoutLoops=100
command="sudo wget -c -r -P ${targetDir} -q --show-progress ${url}"
# starting session if needed
echo "checking if ${name} has a running screen session"
@ -32,6 +56,7 @@ while :
screen -wipe 1>/dev/null
isRunning=$( screen -S ${name} -ls | grep "${name}" -c )
if [ ${isRunning} -eq 0 ]; then
timeout=0
echo "OK - session finished"
break
fi
@ -93,9 +118,54 @@ rm -f .${name}.progress
# quit session if still running
if [ ${isRunning} -eq 1 ]; then
echo "killing screen session TODO: KILL PROCESS"
screen -S ${name} -X quit
# get the PID of screen session
sessionPID=$(screen -ls | grep "${name}" | cut -d "." -f1 | xargs)
echo "killing screen session PID(${sessionPID})"
# kill all child processes of screen sceesion
pkill -P ${sessionPID}
echo "proccesses klilled"
sleep 3
# tell the screen session to quit and wait a bit
screen -S ${name} -X quit 1>/dev/null
sleep 3
echo "cleaning screen"
screen -wipe 1>/dev/null
sleep 3
fi
# decide on how to continue
# the path wget will download to
targetPath=$(echo ${url} | cut -d '@' -f2)
echo "path to downloaded data is ${targetPath}"
# calculate progress and write it to file for LCD to read
finalSize=$( du -s ${targetDir} | head -n1 | awk '{print $1;}' )
if [ ${#actualSize} -eq 0 ]; then
finalSize=0
fi
echo "final size is ${finalSize} of targeted size ${targetSize}"
# check result
if [ ${finalSize} -lt ${targetSize} ]; then
# Download failed
sleep 3
echo -ne '\007'
dialog --title " WARNING " --yesno "The download failed or is not complete. Do you want keep already downloaded data?" 6 57
response=$?
case $response in
1) sudo rm -rf ${targetDir}${targetPath} ;;
esac
./00mainMenu.sh
exit 1;
else
# Download worked
echo "*** Moving Files ***"
sudo mv ${targetDir}${targetPath} /mnt/hdd/${network}
echo "OK"
# continue setup
./60finishHDD.sh
fi
Loading…
Cancel
Save