added ftp download fallback

This commit is contained in:
rootzoll
2018-07-29 12:21:52 +02:00
parent 4467d2dd42
commit 8a9d00d90e
12 changed files with 224 additions and 113 deletions

View File

@@ -1,14 +1,17 @@
#!/bin/sh #!/bin/sh
if [ "$USER" = "pi" ]; then if [ "$USER" = "pi" ]; then
# load network
network=`sudo cat /home/admin/.network`
### USER PI AUTOSTART (LCD Display) ### USER PI AUTOSTART (LCD Display)
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
# check if bitcoin service is configured # check if bitcoin service is configured
bitcoinInstalled=$(sudo -u bitcoin ls /mnt/hdd/bitcoin/ | grep -c bitcoin.conf) bitcoinInstalled=$(sudo -u bitcoin ls /mnt/hdd/${network}/ | grep -c ${network}.conf)
if [ ${bitcoinInstalled} -eq 1 ]; then if [ ${bitcoinInstalled} -eq 1 ]; then
# wait enough secs to let bitcoind init # wait enough secs to let bitcoind init
dialog --pause " Waiting for Bitcoin to startup and init ..." 8 58 130 dialog --pause " Waiting for ${network} to startup and init ..." 8 58 130
fi fi
# show updating status in loop # show updating status in loop
@@ -37,8 +40,8 @@ if [ "$USER" = "pi" ]; then
# setup process init is done and not finished # setup process init is done and not finished
lndSyncing=$(sudo -u bitcoin lncli getinfo | jq -r '.synced_to_chain' | grep -c false) 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') chain=$(sudo -u bitcoin ${network}-cli getblockchaininfo | jq -r '.chain')
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/bitcoin/${chain}net/lnd.log | grep -c unlock) locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c unlock)
if [ ${locked} -gt 0 ]; then if [ ${locked} -gt 0 ]; then
@@ -72,15 +75,14 @@ if [ "$USER" = "pi" ]; then
# RaspiBlitz is full Setup # RaspiBlitz is full Setup
chain=$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.chain') chain=$(su -u bitcoin ${network}-cli getblockchaininfo | jq -r '.chain')
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/bitcoin/${chain}net/lnd.log | grep -c unlock) locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c unlock)
if [ ${locked} -gt 0 ]; then if [ ${locked} -gt 0 ]; then
# special case: LND wallet is locked ---> show unlock info
# special case: LND wallet is locked ---> show unlock info
l1="!!! LND WALLET IS LOCKED !!!\n" l1="!!! LND WALLET IS LOCKED !!!\n"
l2="Login: ssh admin@${localip}\n" l2="Login: ssh admin@${localip}\n"
l3="Use your Password A\n" l3="Use your Password A\n"
boxwidth=$((${#localip} + 20)) boxwidth=$((${#localip} + 20))
dialog --backtitle "RaspiBlitz - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth} dialog --backtitle "RaspiBlitz - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 5 sleep 5

View File

@@ -56,18 +56,19 @@ if [ ${mountOK} -eq 1 ]; then
echo "Bitcoin Options" echo "Bitcoin Options"
menuitem=$(dialog --clear --beep --backtitle "RaspiBlitz" --title "Getting the Blockchain" \ menuitem=$(dialog --clear --beep --backtitle "RaspiBlitz" --title "Getting the Blockchain" \
--menu "You need a copy of the Bitcoin Blockchain - you have 3 options:" 13 75 4 \ --menu "You need a copy of the Bitcoin Blockchain - you have 3 options:" 13 75 4 \
1 "DOWNLOAD --> TESTNET + MAINNET thru torrent (RECOMMENDED 8h)" \ T "TORRENT --> TESTNET + MAINNET per FTP (DEFAULT)" \
2 "COPY --> TESTNET + MAINNET from another HDD (TRICKY 3h)" \ C "COPY --> TESTNET + MAINNET from another HDD (TRICKY+FAST)" \
3 "SYNC --> JUST TESTNET thru Bitoin Network (FALLBACK)" 2>&1 >/dev/tty) D "DOWNLOAD --> TESTNET + MAINNET per FTP (FALLBACK+SLOW)" \
S "SYNC --> JUST TESTNET thru Bitoin Network (FALLBACK)" 2>&1 >/dev/tty)
# Litecoin # Litecoin
elif [ ${network} = "litecoin" ]; then elif [ ${network} = "litecoin" ]; then
echo "Litecoin Options" echo "Litecoin Options"
menuitem=$(dialog --clear --beep --backtitle "RaspiBlitz" --title "Getting the Blockchain" \ menuitem=$(dialog --clear --beep --backtitle "RaspiBlitz" --title "Getting the Blockchain" \
--menu "You need a copy of the Litecoin Blockchain - you have 3 options:" 13 75 4 \ --menu "You need a copy of the Litecoin Blockchain - you have 3 options:" 13 75 4 \
1 "DOWNLOAD --> MAINNET thru torrent (RECOMMENDED)" \ D "DOWNLOAD --> MAINNET thru torrent (RECOMMENDED)" \
2 "COPY --> MAINNET from another HDD (TRICKY)" \ C "COPY --> MAINNET from another HDD (TRICKY+FAST)" \
3 "SYNC --> MAINNET thru Litecoin Network (FALLBACK)" 2>&1 >/dev/tty) S "SYNC --> MAINNET thru Litecoin Network (FALLBACK+SLOW)" 2>&1 >/dev/tty)
# error # error
else else
@@ -77,15 +78,18 @@ if [ ${mountOK} -eq 1 ]; then
clear clear
case $menuitem in case $menuitem in
3) T)
./50torrentHDD.sh
;;
C)
./50copyHDD.sh
;;
S)
./50syncHDD.sh ./50syncHDD.sh
;; ;;
1) D)
./50downloadHDD.sh ./50downloadHDD.sh
;; ;;
2)
./50copyHDD.sh
;;
esac esac
exit 1 exit 1

View File

@@ -1,5 +1,9 @@
#!/bin/sh #!/bin/sh
echo "" echo ""
# load network
network=`cat .network`
echo "*** Adding HDD to the System ***" echo "*** Adding HDD to the System ***"
sleep 5 sleep 5
existsHDD=$(lsblk | grep -c sda1) existsHDD=$(lsblk | grep -c sda1)
@@ -38,7 +42,7 @@ if [ ${existsHDD} -eq 1 ]; then
mountOK=$(df | grep -c /mnt/hdd) mountOK=$(df | grep -c /mnt/hdd)
if [ ${mountOK} -eq 1 ]; then if [ ${mountOK} -eq 1 ]; then
echo "OK - HDD is mounted" echo "OK - HDD is mounted"
echo "" echo ""
# set SetupState # set SetupState
echo "40" > /home/admin/.setup echo "40" > /home/admin/.setup

View File

@@ -1,105 +1,67 @@
#!/bin/sh #!/bin/sh
echo ""
# *** BITCOIN Torrent *** # *** BITCOIN ***
bitcoinTorrent="raspiblitz-hdd-2018-07-16" bitcoinList="" # url to list with other sources
bitcoinTorrentsize=231230512 bitcoinUrl="ftp://anonymous:anonymous@tll9xsfkjht8j26z.myfritz.net/raspiblitz-hdd-2018-07-16"
bitcoinSize=100
# *** LITECOIN Torrent *** # *** LITECOIN ***
litecoinTorrent="raspiblitz-litecoin-2018-07-28" litecoinList="" # url to list with other sources
litecoinTorrentsize=100 litecoinUrl="ftp://anonymous:anonymous@ftp.rotzoll.de/pub/raspiblitz-litecoin-2018-07-29"
litecoinSize=19184980
# load network # load network
network=`cat .network` network=`cat .network`
# set torrent based on network # settings based on network
torrent=$bitcoinTorrent list=$bitcoinList
torrentsize=$bitcoinTorrentsize url=$bitcoinUrl
size=$bitcoinSize
if [ "$network" = "litecoin" ]; then if [ "$network" = "litecoin" ]; then
torrent=$litecoinTorrent list=$litecoinList
torrentsize=$litecoinTorrentsize url=$litecoinUrl
size=$litecoinSize
fi fi
# the path wget will download to
targetPath=$(echo ${url} | cut -d '@' -f2)
echo "network($network)"
echo "list($list)"
echo "url($url)"
echo "size($size)"
echo "targetPath($targetPath)"
exit 1
echo "*** Downloading HDD / FTP ***"
sudo wget -r -P /mnt/hdd/ -q --show-progress ${url}
echo "OK"
echo "" echo ""
echo "*** Checking HDD ***"
mountOK=$(df | grep -c /mnt/hdd)
if [ ${mountOK} -eq 1 ]; then
# HDD is mounted
if [ -d "/mnt/hdd/${network}" ]; 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 ""
downloading=1 echo "*** Checking Download ***"
retry=0 downloadsize=$(sudo du -s /mnt/hdd/${targetPath} | awk '{print $1}' | tr -dc '0-9')
while [ $downloading -eq 1 ] if [ ${#downloadsize} -eq 0 ]; then
do downloadsize=0
echo "*** Downloading HDD ***"
echo "torrentFile: ${torrent}"
tmpfile=$(mktemp)
chmod a+x $tmpfile
echo "killall transmission-cli" > $tmpfile
sudo transmission-cli ./assets/$torrent.torrent -D -et -w /mnt/hdd -f $tmpfile
echo ""
echo "*** Checking Download ***"
echo "wait a moment"
sleep 5
downloadsize=$(sudo du -s /mnt/hdd/$torrent/ | awk '{print $1}' | tr -dc '0-9')
if [ ${#downloadsize} -eq 0 ]; then
downloadsize=0
fi
# add some tolerance for checking
torrentsize="$(($torrentsize-1024000))"
echo "download size is(${downloadsize})"
if [ ${downloadsize} -lt ${torrentsize} ]; then
echo ""
echo "FAIL - download is not ${torrentsize}"
retry=$(($retry+1))
if [ ${retry} -gt 2 ]; then
echo "All Retry FAILED"
downloading=0
else
echo "--> RETRY(${retry}) in 10 secs"
sleep 10
echo ""
fi
else
echo "OK - Download is complete"
downloading=0
fi
done
if [ ${downloadsize} -lt ${torrentsize} ]; then
sleep 3
dialog --title " WARNING " --yesno "The download failed or is not complete. Do you want to clean all download data before you continue?" 6 57
response=$?
case $response in
0) sudo rm -rf /mnt/hdd/$torrent ; sudo rm -rf /root/.config/transmission ;;
esac
#
./00mainMenu.sh
exit 1;
fi
echo ""
echo "*** Moving Files ***"
echo "moving files ..."
sudo mv /mnt/hdd/$torrent /mnt/hdd/${network}
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 fi
echo "download size is(${downloadsize}) needs to be minimum(${size}})"
if [ ${downloadsize} -lt ${size} ]; then
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} ;;
esac
./00mainMenu.sh
exit 1;
fi
echo ""
echo "*** Moving Files ***"
sudo mv /mnt/hdd/${targetPath} /mnt/hdd/litecoin
echo "OK"
# continue setup
./60finishHDD.sh

62
home.admin/50torrentHDD.sh Executable file
View File

@@ -0,0 +1,62 @@
#!/bin/sh
# *** BITCOIN Torrent ***
bitcoinTorrent="raspiblitz-hdd-2018-07-16"
bitcoinTorrentsize=231230512
# *** LITECOIN Torrent ***
litecoinTorrent="raspiblitz-litecoin-2018-07-28"
litecoinTorrentsize=100
# load network
network=`cat .network`
# settings based on network
torrent=$bitcoinTorrent
torrentsize=$bitcoinTorrentsize
if [ "$network" = "litecoin" ]; then
torrent=$litecoinTorrent
torrentsize=$litecoinTorrentsize
if
echo "*** Downloading TORRENT ***"
echo "torrentFile: ${torrent}"
tmpfile=$(mktemp)
chmod a+x $tmpfile
echo "killall transmission-cli" > $tmpfile
sudo transmission-cli ./assets/$torrent.torrent -D -et -w /mnt/hdd -f $tmpfile
echo "OK - Download is complete"
echo ""
echo "*** Checking TORRENT ***"
echo "wait a moment"
sleep 5
downloadsize=$(sudo du -s /mnt/hdd/$torrent/ | awk '{print $1}' | tr -dc '0-9')
if [ ${#downloadsize} -eq 0 ]; then
downloadsize=0
fi
# add some tolerance for checking
size="$(($size-1024000))"
echo "download size is(${downloadsize}) needs to be minimum(${size}})"
if [ ${downloadsize} -lt ${size} ]; then
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/$torrent ; sudo rm -rf /root/.config/transmission ;;
esac
./00mainMenu.sh
exit 1;
fi
echo "*** Moving Files ***"
echo "moving files ..."
sudo mv /mnt/hdd/$torrent /mnt/hdd/${network}
echo ""
# set SetupState
echo "50" > /home/admin/.setup
# continue setup
./60finishHDD.sh

View File

@@ -29,6 +29,7 @@ if [ ${mountOK} -eq 1 ]; then
echo "" echo ""
echo "*** Start ${network} ***" echo "*** Start ${network} ***"
echo "This can take a while .." echo "This can take a while .."
sudo cp /home/admin/assets/${network}d.service /etc/systemd/system/${network}d.service
sudo systemctl enable ${network}d.service sudo systemctl enable ${network}d.service
sudo systemctl start ${network}d.service sudo systemctl start ${network}d.service
echo "Giving ${network}d service 180 seconds to init - please wait ..." echo "Giving ${network}d service 180 seconds to init - please wait ..."

View File

@@ -72,6 +72,9 @@ echo ""
echo "*** Starting LND ***" echo "*** Starting LND ***"
lndRunning=$(systemctl status lnd.service | grep -c running) lndRunning=$(systemctl status lnd.service | grep -c running)
if [ ${lndRunning} -eq 0 ]; then if [ ${lndRunning} -eq 0 ]; then
sed -i "5s/.*/Wants=${network}d.service/" ./assets/lnd.service
sed -i "6s/.*/After=${network}d.service/" ./assets/lnd.service
sudo cp /home/admin/assets/lnd.service /etc/systemd/system/lnd.service
sudo systemctl enable lnd sudo systemctl enable lnd
sudo systemctl start lnd sudo systemctl start lnd
echo "Started LND .. waiting 30 seconds for init ..." echo "Started LND .. waiting 30 seconds for init ..."

View File

@@ -21,3 +21,5 @@ maxorphantx=10
maxmempool=50 maxmempool=50
maxconnections=40 maxconnections=40
maxuploadtarget=5000 maxuploadtarget=5000
datadir=/home/bitcoin/.bitcoin

View File

@@ -0,0 +1,23 @@
# RaspiBlitz: systemd unit for bitcoind
[Unit]
Description=Bitcoin daemon
Wants=getpublicip.service
After=getpublicip.service
# for use with sendmail alert (coming soon)
#OnFailure=systemd-sendmail@%n
[Service]
User=bitcoin
Group=bitcoin
Type=forking
PIDFile=/home/bitcoin/.bitcoin/bitcoind.pid
ExecStart=/usr/local/bin/bitcoind -daemon -conf=/home/bitcoin/.bitcoin/bitcoin.conf -pid=/home/bitcoin/.bitcoin/bitcoind.pid
KillMode=process
Restart=always
TimeoutSec=120
RestartSec=30
[Install]
WantedBy=multi-user.target

View File

@@ -26,3 +26,4 @@ maxuploadtarget=5000
discardfee=0.00000001 discardfee=0.00000001
mintxfee=0.00000001 mintxfee=0.00000001
minrelaytxfee=0.00000001 minrelaytxfee=0.00000001
datadir=/home/bitcoin/.litecoin

View File

@@ -0,0 +1,20 @@
[Unit]
Description=Bitcoin daemon
Wants=getpublicip.service
After=getpublicip.service
# for use with sendmail alert (coming soon)
#OnFailure=systemd-sendmail@%n
[Service]
User=bitcoin
Group=bitcoin
Type=simple
ExecStart=/usr/local/bin/litecoind -daemon -conf=/home/bitcoin/.litecoin/litecoin.conf
KillMode=process
Restart=always
TimeoutSec=120
RestartSec=30
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,27 @@
# RaspiBlitz: systemd unit for lnd
[Unit]
Description=LND Lightning Daemon
Wants=bitcoind.service
After=bitcoind.service
# for use with sendmail alert
#OnFailure=systemd-sendmail@%n
[Service]
# get var PUBIP from file
EnvironmentFile=/run/publicip
ExecStart=/usr/local/bin/lnd --externalip=${PUBLICIP}
PIDFile=/home/bitcoin/.lnd/lnd.pid
User=bitcoin
Group=bitcoin
LimitNOFILE=128000
Type=simple
KillMode=process
TimeoutSec=180
Restart=always
RestartSec=60
[Install]
WantedBy=multi-user.target