raspiblitz/home.admin/00mainMenu.sh

346 lines
9.5 KiB
Bash
Raw Normal View History

2018-07-17 13:12:03 +02:00
#!/bin/bash
2018-11-27 04:19:57 +01:00
# check data from _bootstrap.sh that was running on device setup
bootstrapInfoExists=$(ls /home/admin/raspiblitz.info | grep -c '.info')
if [ ${bootstrapInfoExists} -eq 1 ]; then
# load the data from the info file
source /home/admin/raspiblitz.info
echo "Found raspiblitz.info from bootstrap - processing ..."
# if pre-sync is running - stop it
if [ "${state}" = "presync" ]; then
echo "TODO: Stop pre-sync ... press key to continue"
read key
# update info file
state=waitsetup
echo "state=waitsetup" > $infoFile
echo "message='Pre-Sync Stopped'" >> $infoFile
echo "device=${device}" >> $infoFile
fi
# wait until boostrap process is done
keepWaiting=1
while [ ${keepWaiting} -eq 1 ]
do
# 1) when bootstrap on configured device
if [ "${state}" = "ready" ]; then
echo "detected bootstrap ready"
keepWaiting=0
# 2) when bootstrap on a fresh sd card
elif [ "${state}" = "waitsetup" ]; then
echo "detected bootstrap waitinmg for setup"
# unmount the temporary mount
sudo umount -l /mnt/hdd
# update info file - that setup started
echo "state=setup" > $infoFile
echo "message='SetUp Started'" >> $infoFile
echo "device=${device}" >> $infoFile
keepWaiting=0
# 3) when bootstap is still running
else
# wait 2 sevs and check again
2018-11-27 04:40:46 +01:00
echo "bootstrap still running - state(${state}) message(${message})"
2018-11-27 04:42:25 +01:00
echo "please wait, act or CTRL+c --> Exit to terminal"
2018-11-27 04:19:57 +01:00
sleep 2
keepWaiting=1
fi
done
fi
2018-07-17 13:12:03 +02:00
## default menu settings
HEIGHT=13
2018-07-17 13:12:03 +02:00
WIDTH=64
CHOICE_HEIGHT=6
2018-07-17 13:12:03 +02:00
BACKTITLE="RaspiBlitz"
TITLE=""
MENU="Choose one of the following options:"
OPTIONS=()
2018-08-24 13:16:21 +02:00
## get basic info (its OK if not set yet)
# get name
name=`sudo cat /home/admin/.hostname`
# get network
network=`sudo cat /home/admin/.network`
# get 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"
2018-07-29 01:33:54 +02:00
fi
2018-11-04 00:52:31 +01:00
# check if RTL web interface is installed
2018-11-04 01:23:49 +01:00
runningRTL=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service')
2018-11-04 00:52:31 +01:00
# 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"
2018-11-12 21:13:34 +01:00
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
fi
done
}
2018-07-17 13:12:03 +02:00
## get actual setup state
setupState=0;
if [ -f "/home/admin/.setup" ]; then
setupState=$( cat /home/admin/.setup )
fi
if [ ${setupState} -eq 0 ]; then
# start setup
2018-07-25 11:40:50 -04:00
BACKTITLE="RaspiBlitz - Setup"
2018-07-17 13:12:03 +02:00
TITLE="âš¡ Welcome to your RaspiBlitz âš¡"
2018-07-29 01:33:54 +02:00
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
2018-07-17 13:12:03 +02:00
elif [ ${setupState} -lt 100 ]; then
# see function above
2018-11-19 01:06:35 +01:00
if [ ${setupState} -gt 59 ]; then
waitUntilChainNetworkIsReady
fi
2018-08-24 02:45:04 +02:00
2018-07-17 13:12:03 +02:00
# continue setup
2018-08-24 13:16:21 +02:00
BACKTITLE="${name} / ${network} / ${chain}"
2018-07-17 13:12:03 +02:00
TITLE="âš¡ Welcome to your RaspiBlitz âš¡"
2018-08-24 13:16:21 +02:00
MENU="\nThe setup process is not finished yet: \n "
2018-07-29 01:33:54 +02:00
OPTIONS+=(CONTINUE "Continue Setup of your RaspiBlitz")
2018-07-17 13:12:03 +02:00
HEIGHT=10
else
# see function above
waitUntilChainNetworkIsReady
2018-07-17 13:12:03 +02:00
# MAIN MENU AFTER SETUP
2018-08-24 13:16:21 +02:00
BACKTITLE="${name} / ${network} / ${chain}"
2018-07-29 01:33:54 +02:00
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c unlock)
2018-07-17 13:12:03 +02:00
if [ ${locked} -gt 0 ]; then
# LOCK SCREEN
MENU="!!! YOUR WALLET IS LOCKED !!!"
2018-08-08 17:36:04 +02:00
OPTIONS+=(U "Unlock your Lightning Wallet with 'lncli unlock'")
2018-07-17 13:12:03 +02:00
else
2018-11-04 00:52:31 +01:00
if [ ${runningRTL} -eq 1 ]; then
TITLE="Webinterface: http://${localip}:3000"
fi
2018-08-08 17:36:04 +02:00
switchOption="to MAINNET"
2018-08-08 23:22:20 +02:00
if [ "${chain}" = "main" ]; then
2018-08-08 17:36:04 +02:00
switchOption="back to TESTNET"
fi
2018-08-09 13:04:23 +02:00
# Basic Options
2018-07-27 11:17:59 +02:00
OPTIONS+=(INFO "RaspiBlitz Status Screen" \
2018-08-23 17:59:35 +02:00
FUNDING "Fund your on-chain Wallet" \
CASHOUT "Remove Funds from on-chain Wallet" \
CONNECT "Connect to a Peer" \
2018-08-09 01:25:52 +02:00
CHANNEL "Open a Channel with Peer" \
2018-08-09 14:44:45 +02:00
SEND "Pay an Invoice/PaymentRequest" \
RECEIVE "Create Invoice/PaymentRequest" \
2018-10-15 23:36:40 +02:00
SERVICES "Activate/Deactivate Services" \
lnbalance "Detailed Wallet Balances" \
2018-08-23 03:51:40 +02:00
lnchannels "Lightning Channel List" \
MOBILE "Connect Mobile Wallet")
2018-08-09 13:04:23 +02:00
# Depending Options
2018-08-27 11:08:04 +02:00
openChannels=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} listchannels 2>/dev/null | grep chan_id -c)
2018-08-09 13:26:44 +02:00
if [ ${openChannels} -gt 0 ]; then
OPTIONS+=(CLOSEALL "Close all open Channels")
fi
2018-08-09 13:04:23 +02:00
if [ "${network}" = "bitcoin" ]; then
OPTIONS+=(SWITCH "Switch ${switchOption}")
fi
2018-08-21 12:30:43 +02:00
torInstalled=$(sudo ls /mnt/hdd/tor/lnd9735/hostname 2>/dev/null | grep 'hostname' -c)
if [ ${torInstalled} -eq 0 ]; then
2018-08-22 11:34:15 +02:00
OPTIONS+=(TOR "Make reachable thru TOR")
2018-08-21 12:30:43 +02:00
else
OPTIONS+=(NYX "Monitor TOR")
fi
2018-08-09 13:04:23 +02:00
2018-11-04 01:02:12 +01:00
if [ ${runningRTL} -eq 0 ]; then
OPTIONS+=(RTL "Install RTL Web Interface")
2018-11-04 01:16:18 +01:00
else
OPTIONS+=(RTL "REMOVE RTL Web Interface")
2018-11-04 01:02:12 +01:00
fi
2018-08-09 13:04:23 +02:00
# final Options
2018-10-18 23:38:44 +02:00
OPTIONS+=(OFF "PowerOff RaspiBlitz")
OPTIONS+=(X "Console / Terminal")
2018-07-17 13:12:03 +02:00
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;
;;
2018-07-29 01:33:54 +02:00
BITCOIN)
echo "bitcoin" > /home/admin/.network
./10setupBlitz.sh
exit 1;
;;
LITECOIN)
echo "litecoin" > /home/admin/.network
./10setupBlitz.sh
exit 1;
;;
CONTINUE)
2018-07-17 13:12:03 +02:00
./10setupBlitz.sh
exit 1;
;;
INFO)
./00infoBlitz.sh
echo "Screen is not updating ... press ENTER to continue."
2018-07-27 11:17:59 +02:00
read key
./00mainMenu.sh
;;
lnbalance)
lnbalance ${network}
2018-07-27 11:17:59 +02:00
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
2018-08-21 12:30:43 +02:00
NYX)
sudo nyx
./00mainMenu.sh
;;
2018-07-27 11:17:59 +02:00
lnchannels)
lnchannels ${network}
2018-07-27 11:17:59 +02:00
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
2018-07-17 13:12:03 +02:00
;;
CONNECT)
./BBconnectPeer.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
FUNDING)
./BBfundWallet.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
2018-08-23 17:59:35 +02:00
CASHOUT)
./BBcashoutWallet.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
2018-08-09 01:27:29 +02:00
CHANNEL)
2018-08-09 01:25:52 +02:00
./BBopenChannel.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
2018-08-09 14:44:45 +02:00
SEND)
./BBpayInvoice.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
RECEIVE)
2018-08-09 14:58:44 +02:00
./BBcreateInvoice.sh
2018-08-09 14:44:45 +02:00
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
2018-10-15 23:36:40 +02:00
SERVICES)
./00settingsMenuServices.sh
./00mainMenu.sh
;;
2018-08-09 13:26:44 +02:00
CLOSEALL)
./BBcloseAllChannels.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
2018-08-08 17:36:04 +02:00
SWITCH)
sudo ./95switchMainTest.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
2018-08-23 03:51:40 +02:00
MOBILE)
2018-08-31 22:02:32 +02:00
./97addMobileWallet.sh
2018-08-23 03:51:40 +02:00
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
2018-08-21 12:30:43 +02:00
TOR)
sudo ./96addTorService.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
2018-11-04 01:02:12 +01:00
;;
RTL)
sudo ./98installRTL.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
2018-08-21 12:30:43 +02:00
;;
2018-10-18 23:38:44 +02:00
OFF)
echo "After Shutdown remove power from RaspiBlitz."
2018-10-18 23:48:04 +02:00
echo "Press ENTER to start shutdown - then wait some seconds."
2018-10-18 23:38:44 +02:00
read key
sudo shutdown now
exit 0
;;
2018-08-08 17:36:04 +02:00
X)
lncli -h
echo "SUCH WOW come back with ./00mainMenu.sh"
2018-08-08 17:36:04 +02:00
;;
U) # unlock
2018-07-17 13:12:03 +02:00
./AAunlockLND.sh
2018-07-27 11:17:59 +02:00
./00mainMenu.sh
2018-07-17 13:12:03 +02:00
;;
2018-11-12 21:13:34 +01:00
esac