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.

393 lines
11 KiB

7 years ago
#!/bin/bash
6 years ago
echo "Starting the main menu - please wait ..."
7 years ago
# check data from _bootstrap.sh that was running on device setup
infoFile='/home/admin/raspiblitz.info'
bootstrapInfoExists=$(ls $infoFile | grep -c '.info')
if [ ${bootstrapInfoExists} -eq 1 ]; then
# load the data from the info file
source ${infoFile}
# if pre-sync is running - stop it
if [ "${state}" = "presync" ]; then
# stopping the pre-sync
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 10
# 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
# signal if bootstrap recover is not ready yet
if [ "${state}" = "recovering" ]; then
echo "WARNING: bootstrap is still updating - please close SSH and login later again"
exit 1
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
fi
7 years ago
## default menu settings
HEIGHT=13
7 years ago
WIDTH=64
CHOICE_HEIGHT=6
7 years ago
BACKTITLE="RaspiBlitz"
TITLE=""
MENU="Choose one of the following options:"
OPTIONS=()
## get basic info (its OK if not set yet)
source /mnt/hdd/raspiblitz.conf
# check hostname and get backup if from old config
if [ ${#hostname} -eq 0 ]; then
echo "backup info for old nodes: hostname"
6 years ago
hostname=`sudo cat /home/admin/.hostname` 2>/dev/null
if [ ${#hostname} -eq 0 ]; then
hostname="raspiblitz"
fi
fi
# check network and get backup if from old config
if [ ${#network} -eq 0 ]; then
echo "backup info for old nodes: network"
network="bitcoin"
litecoinActive=$(sudo ls /mnt/hdd/litecoin/litecoin.conf 2>/dev/null | grep -c 'litecoin.conf')
if [ ${litecoinActive} -eq 1 ]; then
network="litecoin"
else
# keep for old nodes
network=`sudo cat /home/admin/.network 2>/dev/null`
fi
if [ ${#network} -eq 0 ]; then
network="bitcoin"
fi
fi
# for old nodes
if [ ${#chain} -eq 0 ]; then
echo "backup info for old nodes: chain"
chain="test"
isMainChain=$(sudo cat /mnt/hdd/${network}/${network}.conf 2>/dev/null | grep "#testnet=1" -c)
if [ ${isMainChain} -gt 0 ];then
chain="main"
fi
7 years ago
fi
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()
{
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
l1="Waiting for ${network}d to get ready.\n"
l2="---> Starting Up\n"
l3="Can take longer if device was off."
isVerifying=$(echo "${clienterror}" | grep -c 'Verifying blocks')
if [ ${isVerifying} -gt 0 ]; then
l2="---> Verifying Blocks\n"
fi
boxwidth=40
dialog --backtitle "RaspiBlitz ${localip} - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 5
else
return
6 years ago
fi
done
}
## get actual setup info
source ${infoFile}
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
6 years ago
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 COINTAIN FUNDS\n"
6 years ago
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
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
6 years ago
BACKTITLE="${localip} / ${hostname} / ${network} / ${chain}"
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
switchOption="to MAINNET"
6 years ago
if [ "${chain}" = "main" ]; then
switchOption="back to TESTNET"
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" \
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
6 years ago
openChannels=$(sudo -u bitcoin /usr/local/bin/lncli 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
;;
OFF)
echo "After Shutdown remove power from RaspiBlitz."
6 years ago
echo "Press ENTER to start shutdown - then wait some seconds."
read key
sudo shutdown now
exit 0
6 years ago
;;
6 years ago
MANUAL)
6 years ago
echo "************************************************************************************"
6 years ago
echo "PLEASE open in browser for more information:"
echo "https://github.com/rootzoll/raspiblitz#recover-your-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
echo "SUCH WOW come back with ./00mainMenu.sh"
6 years ago
;;
R)
./00mainMenu.sh
;;
U) # unlock
7 years ago
./AAunlockLND.sh
./00mainMenu.sh
7 years ago
;;
esac