From 4467d2dd42461513d0e139fb2d441dd485f8aa15 Mon Sep 17 00:00:00 2001 From: rootzoll Date: Sun, 29 Jul 2018 01:33:54 +0200 Subject: [PATCH] litecoin basics --- home.admin/00infoBlitz.sh | 32 +++++++++-------- home.admin/00mainMenu.sh | 35 +++++++++++++----- home.admin/10setupBlitz.sh | 55 +++++++++++++++++++---------- home.admin/20initDialog.sh | 15 +++++--- home.admin/40addHDD.sh | 2 +- home.admin/50copyHDD.sh | 30 +++++++++------- home.admin/50downloadHDD.sh | 27 ++++++++++---- home.admin/50syncHDD.sh | 40 ++++++++++++--------- home.admin/60finishHDD.sh | 33 +++++++++-------- home.admin/70initLND.sh | 52 +++++++++++++++++---------- home.admin/80scanLND.sh | 11 +++--- home.admin/AAunlockLND.sh | 8 +++-- home.admin/XXcleanHDD.sh | 25 +++++++------ home.admin/assets/litecoin.conf | 28 +++++++++++++++ home.admin/assets/lnd.litecoin.conf | 21 +++++++++++ 15 files changed, 281 insertions(+), 133 deletions(-) create mode 100755 home.admin/assets/litecoin.conf create mode 100755 home.admin/assets/lnd.litecoin.conf diff --git a/home.admin/00infoBlitz.sh b/home.admin/00infoBlitz.sh index 93f8d3f..20dd8a0 100755 --- a/home.admin/00infoBlitz.sh +++ b/home.admin/00infoBlitz.sh @@ -3,7 +3,7 @@ # /etc/systemd/system/20-raspibolt-welcome.sh # make executable and copy script to /etc/update-motd.d/ -# root must be able to execute bitcoin-cli and lncli +# root must be able to execute network cli and lncli # set colors color_red='\033[0;31m' @@ -11,8 +11,11 @@ color_green='\033[0;32m' color_yellow='\033[0;33m' color_gray='\033[0;37m' +# load network +network=`sudo cat /home/admin/.network` + # set datadir -bitcoin_dir="/home/bitcoin/.bitcoin" +bitcoin_dir="/home/bitcoin/.${network}" lnd_dir="/home/bitcoin/.lnd" # get uptime & load @@ -55,19 +58,19 @@ network_rx=$(ifconfig eth0 | grep 'RX packets' | awk '{ print $6$7 }' | sed 's/[ network_tx=$(ifconfig eth0 | grep 'TX packets' | awk '{ print $6$7 }' | sed 's/[()]//g') # Bitcoin blockchain -btc_path=$(command -v bitcoin-cli) +btc_path=$(command -v ${network}-cli) if [ -n ${btc_path} ]; then - btc_title="Bitcoin" - chain="$(bitcoin-cli -datadir=${bitcoin_dir} getblockchaininfo | jq -r '.chain')" + btc_title=$network + chain="$(${network}-cli -datadir=${bitcoin_dir} getblockchaininfo | jq -r '.chain')" if [ -n $chain ]; then btc_title="${btc_title} (${chain}net)" # get sync status - block_chain="$(bitcoin-cli -datadir=${bitcoin_dir} getblockcount)" - block_verified="$(bitcoin-cli -datadir=${bitcoin_dir} getblockchaininfo | jq -r '.blocks')" + block_chain="$(${network}-cli -datadir=${bitcoin_dir} getblockcount)" + block_verified="$(${network}-cli -datadir=${bitcoin_dir} getblockchaininfo | jq -r '.blocks')" block_diff=$(expr ${block_chain} - ${block_verified}) - progress="$(bitcoin-cli -datadir=${bitcoin_dir} getblockchaininfo | jq -r '.verificationprogress')" + progress="$(${network}-cli -datadir=${bitcoin_dir} getblockchaininfo | jq -r '.verificationprogress')" sync_percentage=$(printf "%.2f%%" "$(echo $progress | awk '{print 100 * $1}')") if [ ${block_diff} -eq 0 ]; then # fully synced @@ -89,13 +92,13 @@ if [ -n ${btc_path} ]; then fi # get last known block - last_block="$(bitcoin-cli -datadir=${bitcoin_dir} getblockcount)" + last_block="$(${network}-cli -datadir=${bitcoin_dir} getblockcount)" if [ ! -z "${last_block}" ]; then btc_line2="${btc_line2} ${color_gray}(block ${last_block})" fi # get mem pool transactions - mempool="$(bitcoin-cli -datadir=${bitcoin_dir} getmempoolinfo | jq -r '.size')" + mempool="$(${network}-cli -datadir=${bitcoin_dir} getmempoolinfo | jq -r '.size')" else btc_line2="${color_red}NOT RUNNING\t\t" @@ -105,7 +108,7 @@ fi # get IP address & port local_ip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') public_ip=$(curl -s http://v4v6.ipv6-test.com/api/myip.php) -public_port=$(cat ${bitcoin_dir}/bitcoin.conf 2>/dev/null | grep port= | awk -F"=" '{print $2}') +public_port=$(cat ${bitcoin_dir}/${network}.conf 2>/dev/null | grep port= | awk -F"=" '{print $2}') if [ "${public_port}" = "" ]; then if [ $chain = "test" ]; then public_port=18333 @@ -148,13 +151,14 @@ else external_color="${color_red}" fi +networkVersion = $(${network}-cli -cli -version | cut -d " " -f6) printf " ${color_yellow} ${color_yellow} ${color_yellow} ${color_yellow} ${color_yellow}%s ${color_green} ${ln_alias} -${color_yellow} ${color_gray}Bitcoin Fullnode + Lightning Network +${color_yellow} ${color_gray}$Fullnode + Lightning Network ${color_yellow} ${color_yellow}%s ${color_yellow} ,/ ${color_yellow} ${color_yellow} ,'/ ${color_gray}%s, CPU %s°C @@ -163,13 +167,13 @@ ${color_yellow} ,' /_____, ${color_gray} ${color_yellow} .'____ ,' ${color_gray}Local ${color_green}${local_ip}${color_gray} ▼ ${network_rx} ▲ ${network_tx} ${color_yellow} / ,' ${color_gray}Public ${public_color}${public_addr} ${public} ${color_yellow} / ,' ${color_gray} -${color_yellow} /,' ${color_gray}Bitcoin ${color_green}v0.16.1 ${chain}net ${color_gray}Sync ${sync_color}${sync} (%s) +${color_yellow} /,' ${color_gray}${network} ${color_green}${networkVersion} ${chain}net ${color_gray}Sync ${sync_color}${sync} (%s) ${color_yellow} /' ${color_gray}LND ${color_green}v0.4.2 ${color_gray}wallet ${ln_walletbalance} sat ${color_yellow} ${color_gray}${ln_channels_online}/${ln_channels_total} Channels ${ln_channelbalance} sat ${color_yellow} ${ln_external} ${color_yellow} " \ -"RaspiBlitz v0.3" \ +"RaspiBlitz v0.4" \ "-------------------------------------------" \ "${load##up*, }" "${temp}" \ "${hdd}" "${sync_percentage}" diff --git a/home.admin/00mainMenu.sh b/home.admin/00mainMenu.sh index bb873da..a6a9cac 100755 --- a/home.admin/00mainMenu.sh +++ b/home.admin/00mainMenu.sh @@ -9,6 +9,12 @@ TITLE="" MENU="Choose one of the following options:" OPTIONS=() +# default config values (my get changed later) +if [ ! -f ./.network ]; then + echo "bitcoin" > /home/admin/.network +fi +network=`cat .network` + ## get actual setup state setupState=0; if [ -f "/home/admin/.setup" ]; then @@ -19,17 +25,18 @@ if [ ${setupState} -eq 0 ]; then # start setup BACKTITLE="RaspiBlitz - Setup" TITLE="⚡ Welcome to your RaspiBlitz ⚡" - MENU="\nYou need to setup and init Bitcoin and Lightning services: \n " - OPTIONS+=(1 "Start the Setup of your RaspiBlitz") - HEIGHT=10 + MENU="\nChoose how you want to setup your RaspiBlitz: \n " + OPTIONS+=(BITCOIN "Setup BITCOIN and Lightning (DEFAULT)" \ + LITECOIN "Setup LITECOIN and Lightning (EXPERIMENTAL)" ) + HEIGHT=11 elif [ ${setupState} -lt 100 ]; then # continue setup BACKTITLE="RaspiBlitz - Setup" TITLE="⚡ Welcome to your RaspiBlitz ⚡" - MENU="\nContinue setup and init of Bitcoin and Lightning services: \n " - OPTIONS+=(1 "Continue Setup of your RaspiBlitz") + MENU="\nThe setup process in snot finished yet: \n " + OPTIONS+=(CONTINUE "Continue Setup of your RaspiBlitz") HEIGHT=10 else @@ -38,13 +45,13 @@ else uptimesecs=$(awk '{print $1}' /proc/uptime | awk '{print int($1)}') waittimesecs=$(expr 150 - $uptimesecs) if [ ${waittimesecs} -gt 0 ]; then - dialog --pause " Waiting for Bitcoin to startup and init ..." 8 58 ${waittimesecs} + dialog --pause " Waiting for ${network} to startup and init ..." 8 58 ${waittimesecs} fi # MAIN MENU AFTER 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=$(${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) if [ ${locked} -gt 0 ]; then # LOCK SCREEN @@ -75,7 +82,17 @@ case $CHOICE in CLOSE) exit 1; ;; - 1) # SETUP + BITCOIN) + echo "bitcoin" > /home/admin/.network + ./10setupBlitz.sh + exit 1; + ;; + LITECOIN) + echo "litecoin" > /home/admin/.network + ./10setupBlitz.sh + exit 1; + ;; + CONTINUE) ./10setupBlitz.sh exit 1; ;; diff --git a/home.admin/10setupBlitz.sh b/home.admin/10setupBlitz.sh index abafb8d..5bb14d9 100755 --- a/home.admin/10setupBlitz.sh +++ b/home.admin/10setupBlitz.sh @@ -1,6 +1,9 @@ #!/bin/sh echo "" +# load network +network=`cat .network` + # CHECK WHAT IS ALREADY WORKING # check list from top down - so ./10setupBlitz.sh # and re-enters the setup process at the correct spot @@ -10,8 +13,8 @@ echo "" lndRunning=$(systemctl status lnd.service | grep -c running) if [ ${lndRunning} -eq 1 ]; then - 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=$(${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) if [ ${locked} -gt 0 ]; then # LND wallet is locked @@ -26,20 +29,20 @@ if [ ${lndRunning} -eq 1 ]; then fi # check if bitcoin is running -bitcoinRunning=$(systemctl status bitcoind.service | grep -c running) +bitcoinRunning=$(sudo -u bitcoin ${network}-cli getblockchaininfo | grep -c blocks) if [ ${bitcoinRunning} -eq 1 ]; then - echo "OK - Bitcoind is running" + echo "OK - ${network}d is running" echo "Next step run Lightning" ./70initLND.sh exit 1 fi # check if HDD is mounted -mountOK=$(df | grep -c /mnt/hdd) +mountOK=$( df | grep -c /mnt/hdd ) if [ ${mountOK} -eq 1 ]; then - - # if there are signs of blockchain data - if [ -d "/mnt/hdd/bitcoin" ]; then + + # are there any signs of blockchain data + if [ -d "/mnt/hdd/${network}" ]; then echo "UNKOWN STATE" echo "It seems that something went wrong during sync/download/copy of the blockchain." echo "Maybe try --> ./60finishHDD.sh" @@ -47,17 +50,32 @@ if [ ${mountOK} -eq 1 ]; then fi # HDD is empty - ask how to get Blockchain - _temp="./download/dialog.$$" - dialog --clear --beep --backtitle "RaspiBlitz" --title "Getting the Blockchain" \ - --menu "You need a copy of the Blockchan - 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>$_temp - opt=${?} + + #Bitcoin + if [ ${network} = "bitcoin" ]; 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) + + # 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) + + # error + else + echo "FAIL Unkown network(${network})" + exit 1 + fi + clear - if [ $opt != 0 ]; then rm $_temp; exit; fi - menuitem=`cat $_temp` - rm $_temp case $menuitem in 3) ./50syncHDD.sh @@ -73,6 +91,7 @@ if [ ${mountOK} -eq 1 ]; then fi + # the HDD is not mounted --> very early stage of setup # if the script is called for the first time diff --git a/home.admin/20initDialog.sh b/home.admin/20initDialog.sh index 95c1f81..b2a1a05 100755 --- a/home.admin/20initDialog.sh +++ b/home.admin/20initDialog.sh @@ -1,6 +1,9 @@ #!/bin/sh _temp="./download/dialog.$$" +# load network +network=`cat .network` + # welcome and ask for name of RaspiBlitz result="" while [ ${#result} -eq 0 ] @@ -14,6 +17,7 @@ while [ ${#result} -eq 0 ] # set lightning alias sed -i "7s/.*/alias=$result/" ./assests/lnd.conf +sed -i "7s/.*/alias=$result/" ./assests/lnd.litecoin.conf # store hostname for later - to be set right before the next reboot # work around - because without a reboot the hostname seems not updates in the whole system @@ -24,7 +28,7 @@ dialog --backtitle "RaspiBlitz - Setup" --msgbox "RaspiBlitz uses 4 different pa Referenced as password A, B, C and D. A) Master User Password -B) Bitcoin RPC Password +B) Blockchain RPC Password C) LND Wallet Password D) LND Seed Password @@ -68,10 +72,11 @@ while [ ${#result} -lt 8 ] shred $_temp done -# set Bitcoin RPC Password (for admin bitcoin-cli & template for user bitcoin bitcoind) -sed -i "14s/.*/rpcpassword=$result/" ./assets/bitcoin.conf -sed -i "6s/.*/rpcpassword=$result/" ./.bitcoin/bitcoin.conf +# set Blockchain RPC Password (for admin cli & template for user bitcoin) +sed -i "14s/.*/rpcpassword=$result/" ./assets/${network}.conf +sed -i "6s/.*/rpcpassword=$result/" ./.${network}/${network}.conf + # success info dialog dialog --backtitle "RaspiBlitz - SetUP" --msgbox "OK - RPC password changed to '$result'\n\nNow starting the Setup of your RaspiBlitz." 7 52 -clear +clear \ No newline at end of file diff --git a/home.admin/40addHDD.sh b/home.admin/40addHDD.sh index 0aec50f..3d791a8 100755 --- a/home.admin/40addHDD.sh +++ b/home.admin/40addHDD.sh @@ -44,7 +44,7 @@ if [ ${existsHDD} -eq 1 ]; then echo "40" > /home/admin/.setup echo "*** Analysing HDD Content ***" - if [ -d "/mnt/hdd/bitcoin" ]; then + if [ -d "/mnt/hdd/${network}" ]; then echo "Looks like the HDD is prepared with the Blockchain." echo "Continuing with finishing the system setup ..." ./60finishHDD.sh diff --git a/home.admin/50copyHDD.sh b/home.admin/50copyHDD.sh index 14a0789..87c2181 100755 --- a/home.admin/50copyHDD.sh +++ b/home.admin/50copyHDD.sh @@ -1,4 +1,8 @@ #!/bin/sh + +# load network +network=`cat .network` + echo "" echo "*** Check 1st HDD ***" sleep 4 @@ -19,7 +23,7 @@ echo "Like this one: https://www.amazon.de/dp/B00ZJBIHVY" echo "If you see on LCD a error on connecting the 2nd HDD do a restart." echo "" echo "You can use the HDD of another RaspiBlitz for this." -echo "The 2nd HDD needs to be formated Ext4/exFAT and the folder 'bitcoin' is in root of HDD." +echo "The 2nd HDD needs to be formated Ext4/exFAT and the folder '${network}' is in root of HDD." echo "" echo "**********************************" echo "--> Please connect now the 2nd HDD" @@ -72,18 +76,18 @@ echo "" echo "*** Copy Blockchain ***" sudo rsync --append --info=progress2 -a /mnt/genesis/bitcoin /mnt/hdd/ echo "cleaning up - ok if files do not exists" -sudo rm /mnt/hdd/bitcoin/bitcoin.conf -sudo rm /mnt/hdd/bitcoin/bitcoin.pid -sudo rm /mnt/hdd/bitcoin/banlist.dat -sudo rm /mnt/hdd/bitcoin/debug.log -sudo rm /mnt/hdd/bitcoin/fee_estimates.dat -sudo rm /mnt/hdd/bitcoin/mempool.dat -sudo rm /mnt/hdd/bitcoin/peers.dat -sudo rm /mnt/hdd/bitcoin/testnet3/banlist.dat -sudo rm /mnt/hdd/bitcoin/testnet3/debug.log -sudo rm /mnt/hdd/bitcoin/testnet3/fee_estimates.dat -sudo rm /mnt/hdd/bitcoin/testnet3/mempool.dat -sudo rm /mnt/hdd/bitcoin/testnet3/peers.dat +sudo rm /mnt/hdd/${network}/${network}.conf +sudo rm /mnt/hdd/${network}/${network}.pid +sudo rm /mnt/hdd/${network}/banlist.dat +sudo rm /mnt/hdd/${network}/debug.log +sudo rm /mnt/hdd/${network}/fee_estimates.dat +sudo rm /mnt/hdd/${network}/mempool.dat +sudo rm /mnt/hdd/${network}/peers.dat +sudo rm /mnt/hdd/${network}/testnet3/banlist.dat +sudo rm /mnt/hdd/${network}/testnet3/debug.log +sudo rm /mnt/hdd/${network}/testnet3/fee_estimates.dat +sudo rm /mnt/hdd/${network}/testnet3/mempool.dat +sudo rm /mnt/hdd/${network}/testnet3/peers.dat sudo umount -l /mnt/genesis echo "OK - Copy done :)" echo "" diff --git a/home.admin/50downloadHDD.sh b/home.admin/50downloadHDD.sh index e9f7c3e..c49c762 100755 --- a/home.admin/50downloadHDD.sh +++ b/home.admin/50downloadHDD.sh @@ -1,16 +1,30 @@ #!/bin/sh -# name of torrentfile = name of directory in torrent -torrent="raspiblitz-hdd-2018-07-16" -# size of a valid download (run on seed directory 'du -s ./[TORRENTDIRECTORY]') -torrentsize=231230512 +# *** 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` + +# set torrent based on network +torrent=$bitcoinTorrent +torrentsize=$bitcoinTorrentsize +if [ "$network" = "litecoin" ]; then + torrent=$litecoinTorrent + torrentsize=$litecoinTorrentsize +fi echo "" echo "*** Checking HDD ***" mountOK=$(df | grep -c /mnt/hdd) if [ ${mountOK} -eq 1 ]; then # HDD is mounted - if [ -d "/mnt/hdd/bitcoin" ]; then + 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 @@ -23,6 +37,7 @@ if [ ${mountOK} -eq 1 ]; then while [ $downloading -eq 1 ] do echo "*** Downloading HDD ***" + echo "torrentFile: ${torrent}" tmpfile=$(mktemp) chmod a+x $tmpfile echo "killall transmission-cli" > $tmpfile @@ -70,7 +85,7 @@ if [ ${mountOK} -eq 1 ]; then echo "*** Moving Files ***" echo "moving files ..." - sudo mv /mnt/hdd/$torrent /mnt/hdd/bitcoin + sudo mv /mnt/hdd/$torrent /mnt/hdd/${network} echo "" # set SetupState diff --git a/home.admin/50syncHDD.sh b/home.admin/50syncHDD.sh index d0eaf49..4674b84 100755 --- a/home.admin/50syncHDD.sh +++ b/home.admin/50syncHDD.sh @@ -1,25 +1,31 @@ #!/bin/sh -msg="" -msg="$msg Syncing is just practical for Bitcoin TESTNET!\n" -msg="$msg TESTNET is OK for learning, testing and development.\n" -msg="$msg MAINNET is where things get real and fun.\n" -msg="$msg \n" -msg="$msg Syncing MAINNET on a raspberry is NOT practical.\n" -msg="$msg If you want MAINET, go back & try DOWNLOAD.\n" -msg="$msg \n" -msg="$msg Do you really want to work with ONLY TESTNET?" +# load network +network=`cat .network` -dialog --title " WARNING " --yesno "${msg}" 12 57 -response=$? -case $response in - 0) echo "--> OK";; - 1) ./10setupBlitz.sh; exit 1;; - 255) ./10setupBlitz.sh; exit 1;; -esac +# only show warning when bitcoin +if [ "$network" = "bitcoin" ]; then + msg="" + msg="$msg Syncing is just practical for Bitcoin TESTNET!\n" + msg="$msg TESTNET is OK for learning, testing and development.\n" + msg="$msg MAINNET is where things get real and fun.\n" + msg="$msg \n" + msg="$msg Syncing MAINNET on a raspberry is NOT practical.\n" + msg="$msg If you want MAINET, go back & try DOWNLOAD.\n" + msg="$msg \n" + msg="$msg Do you really want to work with ONLY TESTNET?" + + dialog --title " WARNING " --yesno "${msg}" 12 57 + response=$? + case $response in + 0) echo "--> OK";; + 1) ./10setupBlitz.sh; exit 1;; + 255) ./10setupBlitz.sh; exit 1;; + esac +fi echo "*** Activating Blockain Sync ***" -sudo mkdir /mnt/hdd/bitcoin +sudo mkdir /mnt/hdd/${network} echo "OK - sync is activated" # set SetupState diff --git a/home.admin/60finishHDD.sh b/home.admin/60finishHDD.sh index f051167..edae438 100755 --- a/home.admin/60finishHDD.sh +++ b/home.admin/60finishHDD.sh @@ -1,34 +1,39 @@ #!/bin/sh echo "" + +# load network +network=`cat .network` + echo "*** Checking HDD ***" mountOK=$(df | grep -c /mnt/hdd) if [ ${mountOK} -eq 1 ]; then # HDD is mounted - if [ -d "/mnt/hdd/bitcoin" ]; then + if [ -d "/mnt/hdd/${network}" ]; then # HDD has content - continue echo "OK - HDD is ready." ###### LINK HDD echo "" - echo "*** Prepare Bitcoin ***" - sudo cp /home/admin/assets/bitcoin.conf /mnt/hdd/bitcoin/bitcoin.conf - sudo ln -s /mnt/hdd/bitcoin /home/bitcoin/.bitcoin + echo "*** Prepare ${network} ***" + sudo cp /home/admin/assets/${network}.conf /mnt/hdd/${network}/${network}.conf + sudo ln -s /mnt/hdd/${network} /home/bitcoin/.${network} sudo mkdir /mnt/hdd/lnd sudo chown -R bitcoin:bitcoin /mnt/hdd/lnd - sudo chown -R bitcoin:bitcoin /mnt/hdd/bitcoin + sudo chown -R bitcoin:bitcoin /mnt/hdd/${network} sudo ln -s /mnt/hdd/lnd /home/bitcoin/.lnd - sudo chown -R bitcoin:bitcoin /home/bitcoin/.bitcoin + sudo chown -R bitcoin:bitcoin /home/bitcoin/.${network} sudo chown -R bitcoin:bitcoin /home/bitcoin/.lnd - echo "OK - Bitcoin setup ready" + echo "OK - ${network} setup ready" - ###### START BITCOIN SERVICE + ###### START NETWORK SERVICE echo "" - echo "*** Start Bitcoin ***" - sudo systemctl enable bitcoind.service - sudo systemctl start bitcoind.service - echo "Giving bitcoind service 180 seconds to init - please wait ..." + echo "*** Start ${network} ***" + echo "This can take a while .." + sudo systemctl enable ${network}d.service + sudo systemctl start ${network}d.service + echo "Giving ${network}d service 180 seconds to init - please wait ..." sleep 180 - echo "OK - bitcoind started" + echo "OK - ${network}d started" sleep 2 # set SetupState @@ -43,4 +48,4 @@ if [ ${mountOK} -eq 1 ]; then else # HDD is not available yet echo "FAIL - HDD is not mounted." -fi +fi \ No newline at end of file diff --git a/home.admin/70initLND.sh b/home.admin/70initLND.sh index 67be4b7..18d6ec7 100755 --- a/home.admin/70initLND.sh +++ b/home.admin/70initLND.sh @@ -1,16 +1,19 @@ #!/bin/sh echo "" +# load network +network=`cat .network` + # verify that bitcoin is running -echo "*** Checking Bitcoin ***" -bitcoinRunning=$(systemctl status bitcoind.service | grep -c running) +echo "*** Checking ${network} ***" +bitcoinRunning=$(sudo -u bitcoin ${network}-cli getblockchaininfo | grep -c blocks) if [ ${bitcoinRunning} -eq 0 ]; then # HDD is not available yet - echo "FAIL - Bitcoind is not running" + echo "FAIL - ${network}d is not running" echo "recheck with orignal tutorial -->" echo "https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_30_bitcoin.md" fi -echo "OK - Bitcoind is running" +echo "OK - ${network}d is running" echo "" ###### Wait for Blochain Sync @@ -18,20 +21,25 @@ echo "*** Syncing Blockchain ***" ready=0 while [ ${ready} -eq 0 ] do - progress="$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.verificationprogress')" - sync_percentage=$(printf "%.2f%%" "$(echo $progress | awk '{print 100 * $1}')") + progress="$(sudo -u bitcoin ${network}-cli getblockchaininfo | jq -r '.verificationprogress')" + verySmallProgress=$(echo $progress | grep -c 'e-'); + if [ ${verySmallProgress} -eq 1 ]; then + progress="0.00"; + fi ready=$(echo $progress'>0.99' | bc -l) - if [ ${ready} -eq 0 ]; then + sync_percentage=$(printf "%.2f%%" "$(echo $progress | awk '{print 100 * $1}')") + #echo "progress($progress) verySmallProgress($verySmallProgress) ready($ready) sync_percentage($sync_percentage)" + if [ ${#ready} -eq 0 ]; then + echo "waiting for init ... can take a while" + ready=0 + elif [ "$sync_percentage" = "0.00%" ]; then + echo "waiting for network ... can take a while" + ready=0 + elif [ ${ready} -eq 0 ]; then echo "${sync_percentage}" else - if [ ${ready} -eq 1 ]; then - echo "${sync_percentage}" - else - echo "waiting to start sync" - ready=0 - fi + echo "finishing sync ... can take a while" fi - echo "${sync_percentage}" sleep 3 done echo "OK - Blockchain is synced" @@ -41,7 +49,13 @@ echo "" echo "*** LND Config ***" configExists=$( sudo ls /mnt/hdd/lnd/ | grep -c lnd.conf ) if [ ${configExists} -eq 0 ]; then - sudo cp /home/admin/assets/lnd.conf /mnt/hdd/lnd/lnd.conf + if [ "$network" = "litecoin" ]; then + # litecoin + sudo cp /home/admin/assets/lnd.litecoin.conf /mnt/hdd/lnd/lnd.conf + else + # bitcoin + sudo cp /home/admin/assets/lnd.conf /mnt/hdd/lnd/lnd.conf + fi sudo chown bitcoin:bitcoin /mnt/hdd/lnd/lnd.conf if [ -d /home/bitcoin/.lnd ]; then echo "OK - LND config written" @@ -82,7 +96,7 @@ setupStep=$(sudo cat "/home/admin/.setup") if [ ${setupStep} -lt 65 ]; then # setup state signals, that no wallet has been created yet dialog --backtitle "RaspiBlitz - LND Lightning Wallet" --msgbox " -Bitcoin and Lighthing Services are installed. +${network} and Lighthing Services are installed. You now need to setup your Lightning Wallet: We will now call the command: lncli create @@ -139,8 +153,8 @@ fi ###### Unlock Wallet (if needed) echo "*** Check Wallet Lock ***" -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=$(${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) if [ ${locked} -gt 0 ]; then echo "OK - Wallet is locked ... starting unlocking dialog" ./unlockLND.sh @@ -152,7 +166,7 @@ fi echo "" echo "*** Check LND Sync ***" item=0 -chain="$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.chain')" +chain="$(${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain')" lndSyncing=$(sudo -u bitcoin lncli getinfo | jq -r '.synced_to_chain' | grep -c true) if [ ${lndSyncing} -eq 0 ]; then echo "OK - wait for LND to be synced" diff --git a/home.admin/80scanLND.sh b/home.admin/80scanLND.sh index 95b08b4..79a9cf6 100755 --- a/home.admin/80scanLND.sh +++ b/home.admin/80scanLND.sh @@ -1,13 +1,16 @@ +# load network +network=`sudo cat /home/admin/.network` + # parse the actual scanned height progress from LND logs item=0 -chain="$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.chain')" -gotData=$(sudo tail -n 100 /mnt/hdd/lnd/logs/bitcoin/${chain}net/lnd.log | grep -c height) +chain="$(sudo -u bitcoin ${network}-cli getblockchaininfo | jq -r '.chain')" +gotData=$(sudo tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c height) if [ ${gotData} -gt 0 ]; then - item=$(sudo tail -n 100 /mnt/hdd/lnd/logs/bitcoin/${chain}net/lnd.log | grep height | tail -n1 | awk '{print $9} {print $10} {print $11} {print $12}' | tr -dc '0-9') + item=$(sudo tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep height | tail -n1 | awk '{print $9} {print $10} {print $11} {print $12}' | tr -dc '0-9') fi # get total number of blocks -total=$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.blocks') +total=$(sudo -u bitcoin ${network}-cli getblockchaininfo | jq -r '.blocks') # calculate progress in percent percent=$(awk "BEGIN { pc=100*${item}/${total}; i=int(pc); print (pc-i<0.5)?i:i+1 }") diff --git a/home.admin/AAunlockLND.sh b/home.admin/AAunlockLND.sh index 93bc9d3..2eab7c3 100755 --- a/home.admin/AAunlockLND.sh +++ b/home.admin/AAunlockLND.sh @@ -1,16 +1,20 @@ #!/bin/sh + +# load network +network=`.network` + echo "" echo "****************************************************************************" echo "Unlock LND Wallet --> lncli unlock" echo "****************************************************************************" echo "HELP: Enter your PASSWORD C" echo "****************************************************************************" -chain="$(bitcoin-cli -datadir=/home/bitcoin/.bitcoin getblockchaininfo | jq -r '.chain')" +chain="$(${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain')" while : do lncli unlock sleep 4 - 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} -eq 0 ]; then break fi diff --git a/home.admin/XXcleanHDD.sh b/home.admin/XXcleanHDD.sh index 20051da..a07a232 100755 --- a/home.admin/XXcleanHDD.sh +++ b/home.admin/XXcleanHDD.sh @@ -1,22 +1,25 @@ echo "" + +# load network +network=`cat .network` + echo "!!!! This will DELETE your personal data from the HDD !!!!" echo "--> use the HDD with just blockchain in a fresh setup" echo "Press ENTER to continue - CTRL+c to CANCEL" read key sudo dphys-swapfile swapoff -sudo systemctl stop bitcoind.service +sudo systemctl stop ${network}d.service sudo systemctl stop lnd.service sudo rm -f -r /mnt/hdd/lnd sudo rm -f /mnt/hdd/swapfile -sudo rm -f /mnt/hdd/bitcoin/bitcoin.conf -sudo rm -f /mnt/hdd/bitcoin/bitcoin.pid -sudo rm -f /mnt/hdd/bitcoin/*.dat -sudo rm -f /mnt/hdd/bitcoin/*.log -sudo rm -f /mnt/hdd/bitcoin/bitcoin.conf -sudo rm -f /mnt/hdd/bitcoin/testnet3/*.dat -sudo rm -f /mnt/hdd/bitcoin/testnet3/*.log -sudo rm -f /mnt/hdd/bitcoin/testnet3/.lock -sudo rm -f -r /mnt/hdd/bitcoin/database -sudo chown admin:admin -R /mnt/hdd/bitcoin +sudo rm -f /mnt/hdd/${network}/${network}.conf +sudo rm -f /mnt/hdd/${network}/${network}.pid +sudo rm -f /mnt/hdd/${network}/*.dat +sudo rm -f /mnt/hdd/${network}/*.log +sudo rm -f /mnt/hdd/${network}/testnet3/*.dat +sudo rm -f /mnt/hdd/${network}/testnet3/*.log +sudo rm -f /mnt/hdd/${network}/testnet3/.lock +sudo rm -f -r /mnt/hdd/${network}/database +sudo chown admin:admin -R /mnt/hdd/${network} echo "1" > /home/admin/.setup echo "OK - the HDD is now clean" diff --git a/home.admin/assets/litecoin.conf b/home.admin/assets/litecoin.conf new file mode 100755 index 0000000..6e1f0a6 --- /dev/null +++ b/home.admin/assets/litecoin.conf @@ -0,0 +1,28 @@ +# litecoind configuration + +# lightning on litecoin just has mainnet +#testnet=1 + +# Bitcoind options +server=1 +daemon=1 +txindex=1 +disablewallet=1 + +# Connection settings +rpcuser=raspibolt +# LINE15 -insert-> rpcpassword=[PASSWORDB] +zmqpubrawblock=tcp://127.0.0.1:28332 +zmqpubrawtx=tcp://127.0.0.1:28332 + +# Raspberry Pi optimizations +dbcache=100 +maxorphantx=10 +maxmempool=50 +maxconnections=40 +maxuploadtarget=5000 + +# litecoin specials +discardfee=0.00000001 +mintxfee=0.00000001 +minrelaytxfee=0.00000001 diff --git a/home.admin/assets/lnd.litecoin.conf b/home.admin/assets/lnd.litecoin.conf new file mode 100755 index 0000000..ae01d40 --- /dev/null +++ b/home.admin/assets/lnd.litecoin.conf @@ -0,0 +1,21 @@ +# lnd configuration + +[Application Options] +debuglevel=info +debughtlc=true +maxpendingchannels=5 +# LINE7 -insert-> alias=[ALIAS] +color=#68F442 + +[Litecoin] +litecoin.active=1 +litecoin.mainnet=1 +litecoin.node=litecoind +litecoind.rpcuser=jason +litecoind.rpcpass=litecoin +litecoind.zmqpath=tcp://127.0.0.1:28332 + +[autopilot] +autopilot.active=1 +autopilot.maxchannels=5 +autopilot.allocation=0.6