You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

548 lines
18 KiB

7 years ago
#!/bin/bash
echo "Starting the main menu ..."
7 years ago
# CONFIGFILE - configuration of RaspiBlitz
configFile="/mnt/hdd/raspiblitz.conf"
# INFOFILE - state data from bootstrap
infoFile="/home/admin/raspiblitz.info"
# check if HDD is connected
hddExists=$(lsblk | grep -c sda1)
if [ ${hddExists} -eq 0 ]; then
# check if there is maybe a HDD but woth no partitions
noPartition=$(lsblk | grep -c sda)
if [ ${noPartition} -eq 1 ]; then
echo "***********************************************************"
echo "WARNING: HDD HAS NO PARTITIONS"
6 years ago
echo "***********************************************************"
echo "Press ENTER to create a Partition - or CTRL+C to abort"
read key
6 years ago
echo "Creating Partition ..."
sudo parted -s /dev/sda unit s mkpart primary `sudo parted /dev/sda unit s print free | grep 'Free Space' | tail -n 1`
6 years ago
echo "DONE."
sleep 3
6 years ago
else
echo "***********************************************************"
echo "WARNING: NO HDD FOUND -> Shutdown, connect HDD and restart."
echo "***********************************************************"
exit
fi
fi
# check data from _bootstrap.sh that was running on device setup
bootstrapInfoExists=$(ls $infoFile | grep -c '.info')
if [ ${bootstrapInfoExists} -eq 0 ]; then
echo "***********************************************************"
echo "WARNING: NO raspiblitz.info FOUND -> bootstrap not running?"
echo "***********************************************************"
exit
fi
# load the data from the info file (will get produced on every startup)
source ${infoFile}
if [ "${state}" = "recovering" ]; then
echo "***********************************************************"
echo "WARNING: bootstrap still updating - close SSH, login later"
6 years ago
echo "To monitor progress --> tail -n1000 -f raspiblitz.log"
echo "***********************************************************"
exit
fi
# signal that after bootstrap recover user dialog is needed
if [ "${state}" = "recovered" ]; then
echo "System recovered - needs final user settings"
./20recoverDialog.sh
exit 1
fi
# signal that a reindex was triggered
if [ "${state}" = "reindex" ]; then
echo "Re-Index in progress ... start monitoring:"
/home/admin/config.scripts/network.reindex.sh
exit 1
fi
# if pre-sync is running - stop it - before continue
if [ "${state}" = "presync" ]; then
# stopping the pre-sync
echo ""
# analyse if blockchain was detected broken by pre-sync
blockchainBroken=$(sudo tail /mnt/hdd/bitcoin/debug.log | grep -c "Please restart with -reindex or -reindex-chainstate to recover.")
if [ ${blockchainBroken} -eq 1 ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "Detected corrupted blockchain on pre-sync !"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "Deleting blockchain data ..."
echo "(needs to get downloaded fresh during setup)"
sudo rm -f -r /mnt/hdd/bitcoin
else
echo "********************************************"
echo "Stopping pre-sync ... pls wait (up to 1min)"
echo "********************************************"
sudo -u root bitcoin-cli -conf=/home/admin/assets/bitcoin.conf stop
echo "bitcoind called to stop .."
sleep 50
fi
# unmount the temporary mount
echo "Unmount HDD .."
sudo umount -l /mnt/hdd
sleep 3
# update info file
state=waitsetup
sudo sed -i "s/^state=.*/state=waitsetup/g" $infoFile
sudo sed -i "s/^message=.*/message='Pre-Sync Stopped'/g" $infoFile
fi
# if state=ready -> setup is done or started
if [ "${state}" = "ready" ]; then
configExists=$(ls ${configFile} | grep -c '.conf')
if [ ${configExists} -eq 1 ]; then
echo "loading config data"
source ${configFile}
else
echo "setup still in progress - setupStep(${setupStep})"
fi
fi
7 years ago
## default menu settings
# to fit the main menu without scrolling:
# HEIGHT=23
# CHOICE_HEIGHT=20
HEIGHT=13
7 years ago
WIDTH=64
CHOICE_HEIGHT=6
7 years ago
BACKTITLE="RaspiBlitz"
TITLE=""
MENU="Choose one of the following options:"
OPTIONS=()
6 years ago
# check if RTL web interface is installed
6 years ago
runningRTL=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service')
6 years ago
# get the local network IP to be displayed on the lCD
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
# function to use later
waitUntilChainNetworkIsReady()
{
6 years ago
echo "checking ${network}d - please wait .."
echo "can take longer if device was off or first time"
while :
do
sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 1>/dev/null 2>error.tmp
clienterror=`cat error.tmp`
rm error.tmp
if [ ${#clienterror} -gt 0 ]; then
# analyse LOGS for possible reindex
reindex=$(sudo cat /mnt/hdd/${network}/debug.log | grep -c 'Please restart with -reindex or -reindex-chainstate to recover')
if [ ${reindex} -gt 0 ]; then
echo "!! DETECTED NEED FOR RE-INDEX in debug.log ... starting repair options."
sleep 3
6 years ago
dialog --backtitle "RaspiBlitz - Repair Script" --msgbox "Your blockchain data needs to be repaired.
This can be due to power problems or a failing HDD.
Please check the FAQ on RaspiBlitz Github
6 years ago
'My blockchain data is corrupted - what can I do?'
https://github.com/rootzoll/raspiblitz/blob/master/FAQ.md
The RaspiBlitz will now try to help you on with the repair.
To run a BACKUP of funds & channels first is recommended.
6 years ago
" 13 65
6 years ago
clear
# Basic Options
OPTIONS=(TORRENT "Redownload Prepared Torrent (DEFAULT)" \
6 years ago
COPY "Copy from another Computer (SKILLED)" \
6 years ago
REINDEX "Resync thru ${network}d (TAKES VERY VERY LONG)" \
BACKUP "Run Backup LND data first (optional)"
)
6 years ago
CHOICE=$(dialog --backtitle "RaspiBlitz - Repair Script" --clear --title "Repair Blockchain Data" --menu "Choose a repair/recovery option:" 11 60 6 "${OPTIONS[@]}" 2>&1 >/dev/tty)
clear
if [ "${CHOICE}" = "TORRENT" ]; then
echo "Starting TORRENT ..."
6 years ago
sudo sed -i "s/^state=.*/state=retorrent/g" /home/admin/raspiblitz.info
/home/admin/50torrentHDD.sh
6 years ago
/home/admin/00mainMenu.sh
exit
elif [ "${CHOICE}" = "COPY" ]; then
echo "Starting COPY ..."
6 years ago
sudo sed -i "s/^state=.*/state=recopy/g" /home/admin/raspiblitz.info
/home/admin/50copyHDD.sh
6 years ago
/home/admin/00mainMenu.sh
exit
elif [ "${CHOICE}" = "REINDEX" ]; then
echo "Starting REINDEX ..."
sudo /home/admin/config.scripts/network.reindex.sh
exit
elif [ "${CHOICE}" = "BACKUP" ]; then
sudo /home/admin/config.scripts/lnd.rescue.sh backup
echo "PRESS ENTER to return to menu."
read key
6 years ago
/home/admin/00mainMenu.sh
exit
else
echo "CANCEL"
exit
fi
6 years ago
else
echo "${network} error: ${clienterror}"
fi
# normal info
boxwidth=40
l1="Waiting for ${network}d to get ready.\n"
l2="---> ${clienterror/error*:/}\n"
l3="Can take longer if device was off."
uptimeSeconds="$(cat /proc/uptime | grep -o '^[0-9]\+')"
# after 2 min show complete long string (full detail)
if [ ${uptimeSeconds} -gt 120 ]; then
boxwidth=80
l2="${clienterror}\n"
l3="CTRL+C => terminal"
fi
dialog --backtitle "RaspiBlitz ${localip} - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth}
else
locked=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>&1 | grep -c unlock)
if [ ${locked} -gt 0 ]; then
./AAunlockLND.sh
echo "please wait ... update to next screen can be slow"
fi
lndSynced=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true)
if [ ${lndSynced} -eq 0 ]; then
./80scanLND.sh
else
# everything is ready - return from loop
return
fi
6 years ago
fi
sleep 5
6 years ago
done
}
if [ ${#setupStep} -eq 0 ]; then
echo "WARN: no setup step found in raspiblitz.info"
setupStep=0
7 years ago
fi
if [ ${setupStep} -eq 0 ]; then
7 years ago
# check data from boostrap
# TODO: when olddata --> CLEAN OR MANUAL-UPDATE-INFO
if [ "${state}" = "olddata" ]; then
# old data setup
BACKTITLE="RaspiBlitz - Manual Update"
TITLE="⚡ Found old RaspiBlitz Data on HDD ⚡"
6 years ago
MENU="\n ATTENTION: OLD DATA COULD CONTAIN FUNDS\n"
OPTIONS+=(MANUAL "read how to recover your old funds" \
DELETE "erase old data, keep blockchain, reboot" )
HEIGHT=11
else
6 years ago
# start setup
BACKTITLE="RaspiBlitz - Setup"
TITLE="⚡ Welcome to your RaspiBlitz ⚡"
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
fi
7 years ago
elif [ ${setupStep} -lt 100 ]; then
7 years ago
# see function above
if [ ${setupStep} -gt 59 ]; then
waitUntilChainNetworkIsReady
6 years ago
fi
7 years ago
# continue setup
BACKTITLE="${hostname} / ${network} / ${chain}"
7 years ago
TITLE="⚡ Welcome to your RaspiBlitz ⚡"
MENU="\nThe setup process is not finished yet: \n "
7 years ago
OPTIONS+=(CONTINUE "Continue Setup of your RaspiBlitz")
7 years ago
HEIGHT=10
else
# see function above
waitUntilChainNetworkIsReady
7 years ago
# MAIN MENU AFTER SETUP
plus=""
if [ "${runBehindTor}" = "on" ]; then
plus=" / TOR"
fi
if [ ${#dynDomain} -gt 0 ]; then
plus="${plus} / ${dynDomain}"
fi
BACKTITLE="${localip} / ${hostname} / ${network} / ${chain}${plus}"
7 years ago
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c unlock)
7 years ago
if [ ${locked} -gt 0 ]; then
6 years ago
if [ "${rtlWebinterface}" = "on" ]; then
# WEBINTERFACE INFO LOCK SCREEN
TITLE="SSH UNLOCK"
6 years ago
MENU="IMPORTANT: Please unlock thru the RTL Webinterface.\nWebinterface --> http://${localip}:3000\nThen TRY AGAIN to get to main menu."
OPTIONS+=(R "TRY AGAIN - check again if unlocked" \
U "FALLBACK -> Unlock with 'lncli unlock'")
6 years ago
else
# NORMAL LOCK SCREEN
MENU="!!! YOUR WALLET IS LOCKED !!!"
OPTIONS+=(U "Unlock your Lightning Wallet with 'lncli unlock'")
fi
7 years ago
else
6 years ago
if [ ${runningRTL} -eq 1 ]; then
TITLE="Webinterface: http://${localip}:3000"
fi
6 years ago
# Basic Options
OPTIONS+=(INFO "RaspiBlitz Status Screen" \
6 years ago
FUNDING "Fund your on-chain Wallet" \
CONNECT "Connect to a Peer" \
CHANNEL "Open a Channel with Peer" \
SEND "Pay an Invoice/PaymentRequest" \
RECEIVE "Create Invoice/PaymentRequest" \
SERVICES "Activate/Deactivate Services" \
MOBILE "Connect Mobile Wallet" \
EXPORT "Macaroons and TLS.cert" \
NAME "Change Name/Alias of Node" \
PASSWORD "Change Passwords" \
CASHOUT "Remove Funds from on-chain Wallet")
6 years ago
# dont offer lnbalance/lnchannels on testnet
if [ "${chain}" = "main" ]; then
OPTIONS+=(lnbalance "Detailed Wallet Balances" \
lnchannels "Lightning Channel List")
fi
6 years ago
# Depending Options
openChannels=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net listchannels 2>/dev/null | jq '.[] | length')
if [ ${openChannels} -gt 0 ]; then
OPTIONS+=(CLOSEALL "Close all open Channels")
fi
if [ "${runBehindTor}" = "on" ]; then
6 years ago
OPTIONS+=(NYX "Monitor TOR")
fi
6 years ago
# final Options
OPTIONS+=(OFF "PowerOff RaspiBlitz")
OPTIONS+=(X "Console / Terminal")
7 years ago
fi
fi
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
clear
case $CHOICE in
CLOSE)
exit 1;
;;
7 years ago
BITCOIN)
sed -i "s/^network=.*/network=bitcoin/g" ${infoFile}
sed -i "s/^chain=.*/chain=main/g" ${infoFile}
7 years ago
./10setupBlitz.sh
exit 1;
;;
LITECOIN)
sed -i "s/^network=.*/network=litecoin/g" ${infoFile}
sed -i "s/^chain=.*/chain=main/g" ${infoFile}
7 years ago
./10setupBlitz.sh
exit 1;
;;
CONTINUE)
7 years ago
./10setupBlitz.sh
exit 1;
;;
INFO)
./00infoBlitz.sh
echo "Screen is not updating ... press ENTER to continue."
read key
./00mainMenu.sh
;;
lnbalance)
lnbalance ${network}
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
6 years ago
NYX)
sudo nyx
./00mainMenu.sh
;;
lnchannels)
lnchannels ${network}
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
7 years ago
;;
CONNECT)
./BBconnectPeer.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
6 years ago
;;
FUNDING)
./BBfundWallet.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
6 years ago
;;
6 years ago
CASHOUT)
./BBcashoutWallet.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
6 years ago
CHANNEL)
./BBopenChannel.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
6 years ago
;;
SEND)
./BBpayInvoice.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
6 years ago
;;
RECEIVE)
./BBcreateInvoice.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
6 years ago
;;
SERVICES)
./00settingsMenuServices.sh
./00mainMenu.sh
6 years ago
;;
CLOSEALL)
./BBcloseAllChannels.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
6 years ago
;;
SWITCH)
sudo ./95switchMainTest.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
6 years ago
;;
MOBILE)
6 years ago
./97addMobileWallet.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
6 years ago
;;
6 years ago
TOR)
sudo ./96addTorService.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
RTL)
sudo ./98installRTL.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
6 years ago
;;
EXPORT)
sudo /home/admin/config.scripts/lnd.export.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
NAME)
sudo /home/admin/config.scripts/lnd.setname.sh
noreboot=$?
if [ "${noreboot}" = "0" ]; then
sudo -u bitcoin ${network}-cli stop
echo "Press ENTER to Reboot."
read key
sudo shutdown -r now
else
./00mainMenu.sh
fi
;;
PASSWORD)
6 years ago
sudo /home/admin/config.scripts/blitz.setpassword.sh
noreboot=$?
if [ "${noreboot}" = "0" ]; then
sudo -u bitcoin ${network}-cli stop
6 years ago
echo "Press ENTER to Reboot .."
read key
sudo shutdown -r now
else
echo "Press ENTER to return to main menu .."
read key
6 years ago
./00mainMenu.sh
fi
;;
OFF)
echo ""
echo "LCD turns white when shutdown complete."
echo "Then wait 5 seconds and disconnect power."
echo "-----------------------------------------------"
echo "stop lnd - please wait .."
sudo systemctl stop lnd
echo "stop ${network}d (1) - please wait .."
sudo -u bitcoin ${network}-cli stop
sleep 10
echo "stop ${network}d (2) - please wait .."
sudo systemctl stop ${network}d
echo "starting shutdown"
sudo shutdown now
exit 0
6 years ago
;;
6 years ago
MANUAL)
6 years ago
echo "************************************************************************************"
6 years ago
echo "PLEASE go to RaspiBlitz FAQ:"
echo "https://github.com/rootzoll/raspiblitz"
echo "And check: How can I recover my coins from a failing RaspiBlitz?"
6 years ago
echo "************************************************************************************"
6 years ago
exit 0
6 years ago
;;
6 years ago
DELETE)
sudo ./XXcleanHDD.sh
sudo shutdown -r now
exit 0
;;
X)
lncli -h
6 years ago
echo "OK you now on the command line."
echo "You can return to the main menu with the command:"
echo "raspiblitz"
6 years ago
;;
R)
./00mainMenu.sh
;;
U) # unlock
7 years ago
./AAunlockLND.sh
./00mainMenu.sh
7 years ago
;;
esac