2018-08-02 18:03:28 +02:00
#!/bin/bash
2018-07-29 12:21:52 +02:00
echo ""
2018-07-17 13:12:03 +02:00
2018-09-21 01:13:00 +02:00
# *** BITCOIN (just mainnet) ***
2018-07-29 12:21:52 +02:00
bitcoinList = "" # url to list with other sources
2018-09-14 13:40:34 +02:00
#bitcoinUrl="ftp://anonymous:anonymous@91.83.237.185:21/raspiblitz-bitcoin-2018-07-16"
2018-10-07 21:10:45 +02:00
bitcoinUrl = "ftp://f00f39c4:download@w0189aba.kasserver.com/"
2018-10-08 14:02:01 +02:00
bitcoinSize = 253000000 # 253827180-tolerance
2018-07-29 01:33:54 +02:00
2018-07-29 12:21:52 +02:00
# *** LITECOIN ***
litecoinList = "" # url to list with other sources
2018-12-03 14:30:33 +01:00
litecoinUrl = "ftp://anonymous:anonymous@ftp.rotzoll.de/pub/raspiblitz-litecoin-2018-11-30"
2018-12-04 01:57:01 +01:00
litecoinSize = 35000000 # 35021940-tolerance
2018-07-29 01:33:54 +02:00
2018-12-03 22:03:53 +01:00
# NOTE TO GET THE SIZE RIGHT: for new download add 9999999999 as size. Runf download.
# When finished the warning comes up and behind WARNING: copy that number
2018-07-29 01:33:54 +02:00
# load network
network = ` cat .network`
2018-07-29 12:21:52 +02:00
# settings based on network
list = $bitcoinList
url = $bitcoinUrl
size = $bitcoinSize
2018-07-29 01:33:54 +02:00
if [ " $network " = "litecoin" ] ; then
2018-07-29 12:21:52 +02:00
list = $litecoinList
url = $litecoinUrl
size = $litecoinSize
2018-07-29 01:33:54 +02:00
fi
2018-07-17 13:12:03 +02:00
2018-08-02 03:50:31 +02:00
# screen background monitoring settings
name = "Download"
targetDir = "/mnt/hdd/download/"
targetSize = $size
command = " sudo wget -c -r -P ${ targetDir } -q --show-progress ${ url } "
2018-07-25 14:57:07 +02:00
2018-08-02 03:50:31 +02:00
# 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"
2018-08-02 18:03:28 +02:00
sudo mkdir ${ targetDir } 2>/dev/null
2018-08-02 03:50:31 +02:00
screen -S ${ name } -dm ${ command }
else
echo "Continue screen session"
fi
sleep 3
2018-07-17 13:12:03 +02:00
2018-08-02 03:50:31 +02:00
# monitor session
screenDump = "... started ..."
actualSize = 0
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
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)
2018-09-10 22:05:54 +02:00
echo $progress > " . ${ name } .progress "
2018-08-02 03:50:31 +02:00
actualSize = $freshSize
# display info screen
clear
echo "****************************************************"
echo " Monitoring Screen Session: ${ name } "
echo " Progress: ${ progress } % ( ${ actualSize } of ${ targetSize } ) "
echo " If needed press key x to stop ${ name } "
2018-08-19 19:57:59 +02:00
echo "NOTICE: This can take multiple hours or days !!"
2018-08-02 03:50:31 +02:00
echo "Its OK to close terminal now and SSH back in later."
echo "****************************************************"
screen -S ${ name } -X hardcopy .${ name } .out
2018-09-06 18:02:22 +02:00
newScreenDump = $( cat .${ name } .out | grep . | tail -8)
2018-08-02 03:50:31 +02:00
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
2018-07-17 13:12:03 +02:00
2018-08-02 03:50:31 +02:00
# 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
2018-07-17 13:12:03 +02:00
fi
2018-08-02 03:50:31 +02:00
# 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
2018-08-02 18:03:28 +02:00
finalSize = $( du -s ${ targetDir } 2>/dev/null | head -n1 | awk '{print $1;}' )
if [ ${# finalSize } -eq 0 ] ; then
2018-08-02 03:50:31 +02:00
finalSize = 0
fi
echo " final size is ${ finalSize } of targeted size ${ targetSize } "
# check result
if [ ${ finalSize } -lt ${ targetSize } ] ; then
# Download failed
2018-07-29 12:21:52 +02:00
sleep 3
echo -ne '\007'
2018-12-03 22:03:53 +01:00
dialog --title " WARNING ( ${ finalSize } ) " --yesno "The download failed or is not complete. Maybe try again (later). Do you want keep already downloaded data for next try?" 8 57
2018-07-29 12:21:52 +02:00
response = $?
case $response in
2018-08-20 22:51:50 +02:00
1) sudo rm -rf ${ targetDir } ; ;
2018-07-29 12:21:52 +02:00
esac
./00mainMenu.sh
exit 1;
2018-08-02 03:50:31 +02:00
else
# Download worked
echo "*** Moving Files ***"
sudo mv ${ targetDir } ${ targetPath } /mnt/hdd/${ network }
echo "OK"
2018-07-29 12:21:52 +02:00
2018-08-02 03:50:31 +02:00
# continue setup
./60finishHDD.sh
2018-07-29 12:21:52 +02:00
2018-08-02 03:50:31 +02:00
fi