mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2025-02-24 06:48:00 +01:00
added ftp download fallback
This commit is contained in:
parent
4467d2dd42
commit
8a9d00d90e
12 changed files with 224 additions and 113 deletions
|
@ -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,10 +75,9 @@ 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
|
||||
l1="!!! LND WALLET IS LOCKED !!!\n"
|
||||
l2="Login: ssh admin@${localip}\n"
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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."
|
||||
# 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 ""
|
||||
|
||||
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')
|
||||
downloadsize=$(sudo du -s /mnt/hdd/${targetPath} | 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
|
||||
echo "download size is(${downloadsize}) needs to be minimum(${size}})"
|
||||
if [ ${downloadsize} -lt ${size} ]; 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
|
||||
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
|
||||
0) sudo rm -rf /mnt/hdd/$torrent ; sudo rm -rf /root/.config/transmission ;;
|
||||
1) sudo rm -rf /mnt/hdd/${targetPath} ;;
|
||||
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
|
||||
sudo mv /mnt/hdd/${targetPath} /mnt/hdd/litecoin
|
||||
echo "OK"
|
||||
|
||||
# continue setup
|
||||
./60finishHDD.sh
|
||||
|
||||
fi
|
||||
else
|
||||
# HDD is not available yet
|
||||
echo "*** Mount HDD on /mnt/hdd first ***"
|
||||
fi
|
||||
|
|
62
home.admin/50torrentHDD.sh
Executable file
62
home.admin/50torrentHDD.sh
Executable 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
|
|
@ -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 ..."
|
||||
|
|
|
@ -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 ..."
|
||||
|
|
|
@ -21,3 +21,5 @@ maxorphantx=10
|
|||
maxmempool=50
|
||||
maxconnections=40
|
||||
maxuploadtarget=5000
|
||||
|
||||
datadir=/home/bitcoin/.bitcoin
|
||||
|
|
23
home.admin/assets/bitcoind.service
Normal file
23
home.admin/assets/bitcoind.service
Normal 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
|
|
@ -26,3 +26,4 @@ maxuploadtarget=5000
|
|||
discardfee=0.00000001
|
||||
mintxfee=0.00000001
|
||||
minrelaytxfee=0.00000001
|
||||
datadir=/home/bitcoin/.litecoin
|
||||
|
|
20
home.admin/assets/litecoind.service
Normal file
20
home.admin/assets/litecoind.service
Normal 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
|
27
home.admin/assets/lnd.service
Normal file
27
home.admin/assets/lnd.service
Normal 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
|
Loading…
Add table
Reference in a new issue