From 8a9d00d90e87f4d61871fd99304f583e0d019854 Mon Sep 17 00:00:00 2001 From: rootzoll Date: Sun, 29 Jul 2018 12:21:52 +0200 Subject: [PATCH] added ftp download fallback --- home.admin/00infoLCD.sh | 20 ++-- home.admin/10setupBlitz.sh | 26 ++--- home.admin/40addHDD.sh | 6 +- home.admin/50downloadHDD.sh | 142 ++++++++++------------------ home.admin/50torrentHDD.sh | 62 ++++++++++++ home.admin/60finishHDD.sh | 1 + home.admin/70initLND.sh | 3 + home.admin/assets/bitcoin.conf | 2 + home.admin/assets/bitcoind.service | 23 +++++ home.admin/assets/litecoin.conf | 1 + home.admin/assets/litecoind.service | 20 ++++ home.admin/assets/lnd.service | 27 ++++++ 12 files changed, 222 insertions(+), 111 deletions(-) create mode 100755 home.admin/50torrentHDD.sh create mode 100644 home.admin/assets/bitcoind.service create mode 100644 home.admin/assets/litecoind.service create mode 100644 home.admin/assets/lnd.service diff --git a/home.admin/00infoLCD.sh b/home.admin/00infoLCD.sh index 7a7bd51..9f0f417 100755 --- a/home.admin/00infoLCD.sh +++ b/home.admin/00infoLCD.sh @@ -1,14 +1,17 @@ #!/bin/sh if [ "$USER" = "pi" ]; then + # 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'/') # 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 # 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 # show updating status in loop @@ -37,8 +40,8 @@ if [ "$USER" = "pi" ]; 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) + chain=$(sudo -u bitcoin ${network}-cli getblockchaininfo | jq -r '.chain') + locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c unlock) if [ ${locked} -gt 0 ]; then @@ -72,15 +75,14 @@ if [ "$USER" = "pi" ]; then # 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) + chain=$(su -u bitcoin ${network}-cli getblockchaininfo | jq -r '.chain') + locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c unlock) 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" l2="Login: ssh admin@${localip}\n" l3="Use your Password A\n" - boxwidth=$((${#localip} + 20)) + boxwidth=$((${#localip} + 20)) dialog --backtitle "RaspiBlitz - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth} sleep 5 diff --git a/home.admin/10setupBlitz.sh b/home.admin/10setupBlitz.sh index 5bb14d9..1a949f0 100755 --- a/home.admin/10setupBlitz.sh +++ b/home.admin/10setupBlitz.sh @@ -56,18 +56,19 @@ if [ ${mountOK} -eq 1 ]; then echo "Bitcoin Options" 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 \ - 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>&1 >/dev/tty) + T "TORRENT --> TESTNET + MAINNET per FTP (DEFAULT)" \ + C "COPY --> TESTNET + MAINNET from another HDD (TRICKY+FAST)" \ + D "DOWNLOAD --> TESTNET + MAINNET per FTP (FALLBACK+SLOW)" \ + S "SYNC --> JUST TESTNET thru Bitoin Network (FALLBACK)" 2>&1 >/dev/tty) # Litecoin elif [ ${network} = "litecoin" ]; then echo "Litecoin Options" 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 \ - 1 "DOWNLOAD --> MAINNET thru torrent (RECOMMENDED)" \ - 2 "COPY --> MAINNET from another HDD (TRICKY)" \ - 3 "SYNC --> MAINNET thru Litecoin Network (FALLBACK)" 2>&1 >/dev/tty) + D "DOWNLOAD --> MAINNET thru torrent (RECOMMENDED)" \ + C "COPY --> MAINNET from another HDD (TRICKY+FAST)" \ + S "SYNC --> MAINNET thru Litecoin Network (FALLBACK+SLOW)" 2>&1 >/dev/tty) # error else @@ -77,15 +78,18 @@ if [ ${mountOK} -eq 1 ]; then clear case $menuitem in - 3) + T) + ./50torrentHDD.sh + ;; + C) + ./50copyHDD.sh + ;; + S) ./50syncHDD.sh ;; - 1) + D) ./50downloadHDD.sh ;; - 2) - ./50copyHDD.sh - ;; esac exit 1 diff --git a/home.admin/40addHDD.sh b/home.admin/40addHDD.sh index 3d791a8..b07aa6c 100755 --- a/home.admin/40addHDD.sh +++ b/home.admin/40addHDD.sh @@ -1,5 +1,9 @@ #!/bin/sh echo "" + +# load network +network=`cat .network` + echo "*** Adding HDD to the System ***" sleep 5 existsHDD=$(lsblk | grep -c sda1) @@ -38,7 +42,7 @@ if [ ${existsHDD} -eq 1 ]; then mountOK=$(df | grep -c /mnt/hdd) if [ ${mountOK} -eq 1 ]; then echo "OK - HDD is mounted" - echo "" + echo "" # set SetupState echo "40" > /home/admin/.setup diff --git a/home.admin/50downloadHDD.sh b/home.admin/50downloadHDD.sh index c49c762..501050f 100755 --- a/home.admin/50downloadHDD.sh +++ b/home.admin/50downloadHDD.sh @@ -1,105 +1,67 @@ #!/bin/sh +echo "" -# *** BITCOIN Torrent *** -bitcoinTorrent="raspiblitz-hdd-2018-07-16" -bitcoinTorrentsize=231230512 +# *** BITCOIN *** +bitcoinList="" # url to list with other sources +bitcoinUrl="ftp://anonymous:anonymous@tll9xsfkjht8j26z.myfritz.net/raspiblitz-hdd-2018-07-16" +bitcoinSize=100 -# *** LITECOIN Torrent *** -litecoinTorrent="raspiblitz-litecoin-2018-07-28" -litecoinTorrentsize=100 +# *** LITECOIN *** +litecoinList="" # url to list with other sources +litecoinUrl="ftp://anonymous:anonymous@ftp.rotzoll.de/pub/raspiblitz-litecoin-2018-07-29" +litecoinSize=19184980 # load network network=`cat .network` -# set torrent based on network -torrent=$bitcoinTorrent -torrentsize=$bitcoinTorrentsize +# settings based on network +list=$bitcoinList +url=$bitcoinUrl +size=$bitcoinSize if [ "$network" = "litecoin" ]; then - torrent=$litecoinTorrent - torrentsize=$litecoinTorrentsize + list=$litecoinList + url=$litecoinUrl + size=$litecoinSize fi -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 - retry=0 - while [ $downloading -eq 1 ] - do - 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 "" +# the path wget will download to +targetPath=$(echo ${url} | cut -d '@' -f2) - echo "*** Moving Files ***" - echo "moving files ..." - sudo mv /mnt/hdd/$torrent /mnt/hdd/${network} - echo "" +echo "network($network)" +echo "list($list)" +echo "url($url)" +echo "size($size)" +echo "targetPath($targetPath)" - # 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 +exit 1 - # continue setup - ./60finishHDD.sh +echo "*** Downloading HDD / FTP ***" +sudo wget -r -P /mnt/hdd/ -q --show-progress ${url} +echo "OK" +echo "" - fi -else - # HDD is not available yet - echo "*** Mount HDD on /mnt/hdd first ***" +echo "*** Checking Download ***" +downloadsize=$(sudo du -s /mnt/hdd/${targetPath} | awk '{print $1}' | tr -dc '0-9') +if [ ${#downloadsize} -eq 0 ]; then + downloadsize=0 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 \ No newline at end of file diff --git a/home.admin/50torrentHDD.sh b/home.admin/50torrentHDD.sh new file mode 100755 index 0000000..1be3983 --- /dev/null +++ b/home.admin/50torrentHDD.sh @@ -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 \ No newline at end of file diff --git a/home.admin/60finishHDD.sh b/home.admin/60finishHDD.sh index edae438..3793ed4 100755 --- a/home.admin/60finishHDD.sh +++ b/home.admin/60finishHDD.sh @@ -29,6 +29,7 @@ if [ ${mountOK} -eq 1 ]; then echo "" echo "*** Start ${network} ***" 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 start ${network}d.service echo "Giving ${network}d service 180 seconds to init - please wait ..." diff --git a/home.admin/70initLND.sh b/home.admin/70initLND.sh index 18d6ec7..dd266c0 100755 --- a/home.admin/70initLND.sh +++ b/home.admin/70initLND.sh @@ -72,6 +72,9 @@ echo "" echo "*** Starting LND ***" lndRunning=$(systemctl status lnd.service | grep -c running) 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 start lnd echo "Started LND .. waiting 30 seconds for init ..." diff --git a/home.admin/assets/bitcoin.conf b/home.admin/assets/bitcoin.conf index 75e91d6..220a79b 100755 --- a/home.admin/assets/bitcoin.conf +++ b/home.admin/assets/bitcoin.conf @@ -21,3 +21,5 @@ maxorphantx=10 maxmempool=50 maxconnections=40 maxuploadtarget=5000 + +datadir=/home/bitcoin/.bitcoin diff --git a/home.admin/assets/bitcoind.service b/home.admin/assets/bitcoind.service new file mode 100644 index 0000000..59a906e --- /dev/null +++ b/home.admin/assets/bitcoind.service @@ -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 \ No newline at end of file diff --git a/home.admin/assets/litecoin.conf b/home.admin/assets/litecoin.conf index 6e1f0a6..4681f31 100755 --- a/home.admin/assets/litecoin.conf +++ b/home.admin/assets/litecoin.conf @@ -26,3 +26,4 @@ maxuploadtarget=5000 discardfee=0.00000001 mintxfee=0.00000001 minrelaytxfee=0.00000001 +datadir=/home/bitcoin/.litecoin diff --git a/home.admin/assets/litecoind.service b/home.admin/assets/litecoind.service new file mode 100644 index 0000000..fd56c65 --- /dev/null +++ b/home.admin/assets/litecoind.service @@ -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 \ No newline at end of file diff --git a/home.admin/assets/lnd.service b/home.admin/assets/lnd.service new file mode 100644 index 0000000..857f64d --- /dev/null +++ b/home.admin/assets/lnd.service @@ -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 \ No newline at end of file