Christian Rotzoll
6 years ago
committed by
GitHub
28 changed files with 1726 additions and 682 deletions
@ -0,0 +1,390 @@ |
|||
#!/bin/bash |
|||
echo "Starting the main menu ..." |
|||
|
|||
# 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" |
|||
echo "***********************************************************" |
|||
echo "Press ENTER to create a Partition - or CTRL+C to abort" |
|||
read key |
|||
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` |
|||
echo "DONE." |
|||
sleep 3 |
|||
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" |
|||
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" |
|||
/home/admin/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 |
|||
|
|||
# singal that torrent is in re-download |
|||
if [ "${state}" = "retorrent" ]; then |
|||
echo "Re-Index in progress ... start monitoring:" |
|||
/home/admin/50torrentHDD.sh |
|||
sudo sed -i "s/^state=.*/state=repair/g" /home/admin/raspiblitz.info |
|||
/home/admin/00raspiblitz.sh |
|||
exit |
|||
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 |
|||
|
|||
## default menu settings |
|||
# to fit the main menu without scrolling: |
|||
HEIGHT=13 |
|||
WIDTH=64 |
|||
CHOICE_HEIGHT=6 |
|||
BACKTITLE="RaspiBlitz" |
|||
TITLE="" |
|||
MENU="Choose one of the following options:" |
|||
OPTIONS=() |
|||
|
|||
# check if RTL web interface is installed |
|||
runningRTL=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service') |
|||
|
|||
# function to use later |
|||
waitUntilChainNetworkIsReady() |
|||
{ |
|||
echo "checking ${network}d - please wait .." |
|||
echo "can take longer if device was off or first time" |
|||
while : |
|||
do |
|||
|
|||
# check for error on network |
|||
sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 1>/dev/null 2>error.tmp |
|||
clienterror=`cat error.tmp` |
|||
rm error.tmp |
|||
|
|||
# check for missing blockchain data |
|||
minSize=250000000000 |
|||
if [ "${network}" = "litecoin" ]; then |
|||
minSize=20000000000 |
|||
fi |
|||
blockchainsize=$(sudo du -shbc /mnt/hdd/${network} | head -n1 | awk '{print $1;}') |
|||
if [ ${#blockchainsize} -gt 0 ]; then |
|||
if [ ${blockchainsize} -lt ${minSize} ]; then |
|||
echo "blockchainsize(${blockchainsize})" |
|||
echo "Missing Blockchain Data (<${minSize}) ..." |
|||
clienterror="missing blockchain" |
|||
sleep 3 |
|||
fi |
|||
fi |
|||
|
|||
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 ] || [ "${clienterror}" = "missing blockchain" ]; then |
|||
echo "!! DETECTED NEED FOR RE-INDEX in debug.log ... starting repair options." |
|||
sudo sed -i "s/^state=.*/state=repair/g" /home/admin/raspiblitz.info |
|||
sleep 3 |
|||
|
|||
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 |
|||
'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. |
|||
" 13 65 |
|||
|
|||
clear |
|||
# Basic Options |
|||
OPTIONS=(TORRENT "Redownload Prepared Torrent (DEFAULT)" \ |
|||
COPY "Copy from another Computer (SKILLED)" \ |
|||
REINDEX "Resync thru ${network}d (TAKES VERY VERY LONG)" \ |
|||
BACKUP "Run Backup LND data first (optional)" |
|||
) |
|||
|
|||
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 ..." |
|||
sudo sed -i "s/^state=.*/state=retorrent/g" /home/admin/raspiblitz.info |
|||
/home/admin/50torrentHDD.sh |
|||
sudo sed -i "s/^state=.*/state=repair/g" /home/admin/raspiblitz.info |
|||
/home/admin/00raspiblitz.sh |
|||
exit |
|||
|
|||
elif [ "${CHOICE}" = "COPY" ]; then |
|||
echo "Starting COPY ..." |
|||
sudo sed -i "s/^state=.*/state=recopy/g" /home/admin/raspiblitz.info |
|||
/home/admin/50copyHDD.sh |
|||
sudo sed -i "s/^state=.*/state=repair/g" /home/admin/raspiblitz.info |
|||
/home/admin/00raspiblitz.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 |
|||
/home/admin/00raspiblitz.sh |
|||
exit |
|||
|
|||
else |
|||
echo "CANCEL" |
|||
exit |
|||
fi |
|||
|
|||
fi |
|||
|
|||
# let 80scanLND script to the info to use |
|||
/home/admin/80scanLND.sh |
|||
if [ $? -gt 0 ]; then |
|||
echo "${network} error: ${clienterror}" |
|||
exit 0 |
|||
fi |
|||
|
|||
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 |
|||
uptime=$(awk '{printf("%d\n",$1 + 0.5)}' /proc/uptime) |
|||
if [ "${autoUnlock}" == "on" ] && [ ${uptime} -lt 300 ]; then |
|||
# give autounlock 5 min after startup to react |
|||
sleep 1 |
|||
else |
|||
/home/admin/AAunlockLND.sh |
|||
echo "please wait ... update to next screen can be slow" |
|||
fi |
|||
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 |
|||
/home/admin/80scanLND.sh |
|||
if [ $? -gt 0 ]; then |
|||
exit 0 |
|||
fi |
|||
else |
|||
# everything is ready - return from loop |
|||
return |
|||
fi |
|||
fi |
|||
sleep 5 |
|||
done |
|||
} |
|||
|
|||
if [ ${#setupStep} -eq 0 ]; then |
|||
echo "WARN: no setup step found in raspiblitz.info" |
|||
setupStep=0 |
|||
fi |
|||
if [ ${setupStep} -eq 0 ]; then |
|||
|
|||
# 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 ⚡" |
|||
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 |
|||
|
|||
# show hardware test |
|||
/home/admin/05hardwareTest.sh |
|||
|
|||
# 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 |
|||
|
|||
elif [ ${setupStep} -lt 100 ]; then |
|||
|
|||
# see function above |
|||
if [ ${setupStep} -gt 59 ]; then |
|||
waitUntilChainNetworkIsReady |
|||
fi |
|||
|
|||
# continue setup |
|||
BACKTITLE="${hostname} / ${network} / ${chain}" |
|||
TITLE="⚡ Welcome to your RaspiBlitz ⚡" |
|||
MENU="\nThe setup process is not finished yet: \n " |
|||
OPTIONS+=(CONTINUE "Continue Setup of your RaspiBlitz") |
|||
HEIGHT=10 |
|||
|
|||
else |
|||
|
|||
# when all is setup - forward to main menu |
|||
waitUntilChainNetworkIsReady |
|||
/home/admin/00mainMenu.sh |
|||
exit 0 |
|||
|
|||
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; |
|||
;; |
|||
BITCOIN) |
|||
sed -i "s/^network=.*/network=bitcoin/g" ${infoFile} |
|||
sed -i "s/^chain=.*/chain=main/g" ${infoFile} |
|||
/home/admin/10setupBlitz.sh |
|||
exit 1; |
|||
;; |
|||
LITECOIN) |
|||
sed -i "s/^network=.*/network=litecoin/g" ${infoFile} |
|||
sed -i "s/^chain=.*/chain=main/g" ${infoFile} |
|||
/home/admin/10setupBlitz.sh |
|||
exit 1; |
|||
;; |
|||
CONTINUE) |
|||
/home/admin/10setupBlitz.sh |
|||
exit 1; |
|||
;; |
|||
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 |
|||
sleep 3 |
|||
sync |
|||
echo "starting shutdown ..." |
|||
sudo shutdown now |
|||
exit 0 |
|||
;; |
|||
MANUAL) |
|||
echo "************************************************************************************" |
|||
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?" |
|||
echo "************************************************************************************" |
|||
exit 0 |
|||
;; |
|||
DELETE) |
|||
sudo /home/admin/XXcleanHDD.sh |
|||
sudo shutdown -r now |
|||
exit 0 |
|||
;; |
|||
X) |
|||
lncli -h |
|||
echo "OK you now on the command line." |
|||
echo "You can return to the main menu with the command:" |
|||
echo "raspiblitz" |
|||
;; |
|||
R) |
|||
/home/admin/00raspiblitz.sh |
|||
;; |
|||
U) # unlock |
|||
/home/admin/AAunlockLND.sh |
|||
/home/admin/00raspiblitz.sh |
|||
;; |
|||
esac |
@ -0,0 +1,101 @@ |
|||
#!/bin/bash |
|||
|
|||
source /home/admin/raspiblitz.info |
|||
source /mnt/hdd/raspiblitz.conf |
|||
|
|||
### USER PI AUTOSTART (LCD Display) |
|||
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') |
|||
|
|||
# parse the actual scanned height progress from LND logs |
|||
item=0 |
|||
blockchaininfo=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo) |
|||
chain="$(echo "${blockchaininfo}" | jq -r '.chain')" |
|||
|
|||
## TRY to get the actual progress height of scanning |
|||
|
|||
# 1) First try the "Rescanned through block" - it seems to happen if it restarts |
|||
item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "Rescanned through block" | tail -n1 | cut -d ']' -f2 | cut -d '(' -f2 | tr -dc '0-9') |
|||
action="Rescanning" |
|||
|
|||
# 2) Second try the "Caught up to height" - thats the usual on first scan start |
|||
if [ ${#item} -eq 0 ]; then |
|||
item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "Caught up to height" | tail -n1 | cut -d ']' -f2 | tr -dc '0-9') |
|||
action="Catching-Up" |
|||
fi |
|||
|
|||
# 3) Third try the "LNWL: Filtering block" - thats the usual on later starts |
|||
if [ ${#item} -eq 0 ]; then |
|||
item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "LNWL: Filtering block" | tail -n1 | cut -d ' ' -f7 | tr -dc '0-9') |
|||
action="Filtering" |
|||
fi |
|||
|
|||
# if no progress info |
|||
online=1 |
|||
if [ ${#item} -eq 0 ]; then |
|||
item="?" |
|||
|
|||
# check if offline |
|||
online=$(ping 1.0.0.1 -c 1 -W 2 | grep -c '1 received') |
|||
if [ ${online} -eq 0 ]; then |
|||
# re-test with other server |
|||
online=$(ping 8.8.8.8 -c 1 -W 2 | grep -c '1 received') |
|||
fi |
|||
if [ ${online} -eq 0 ]; then |
|||
# re-test with other server |
|||
online=$(ping 208.67.222.222 -c 1 -W 2 | grep -c '1 received') |
|||
fi |
|||
|
|||
fi |
|||
|
|||
# get total number of blocks |
|||
total=$(echo "${blockchaininfo}" | jq -r '.blocks') |
|||
# put scanstate |
|||
scanstate="${item}/${total}" |
|||
|
|||
# get blockchain sync progress |
|||
progress="$(echo "${blockchaininfo}" | jq -r '.verificationprogress')" |
|||
#progress=$(echo "${progress}*100" | bc) |
|||
progress=$(echo $progress | awk '{printf( "%.2f%%", 100 * $1)}') |
|||
|
|||
# check if blockchain is still syncing |
|||
heigh=6 |
|||
width=44 |
|||
isInitialChainSync=$(echo "${blockchaininfo}" | grep 'initialblockdownload' | grep "true" -c) |
|||
isWaitingBlockchain=$( sudo -u bitcoin tail -n 2 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "Waiting for chain backend to finish sync" -c ) |
|||
if [ ${isWaitingBlockchain} -gt 0 ]; then |
|||
isInitialChainSync=1 |
|||
fi |
|||
if [ ${online} -eq 0 ]; then |
|||
heigh=7 |
|||
width=44 |
|||
infoStr=$(echo " Waiting INTERNET CONNECTION\n RaspiBlitz cannot ping 1.0.0.1\n Local IP is ${localip}\n Please check cables and router.") |
|||
elif [ ${isInitialChainSync} -gt 0 ]; then |
|||
heigh=7 |
|||
infoStr=" Waiting for final Blockchain Sync\n Progress: ${progress} \n Please wait - this can take some time.\n ssh admin@${localip}\n Password A" |
|||
if [ "$USER" = "admin" ]; then |
|||
heigh=6 |
|||
width=53 |
|||
infoStr=$(echo " Waiting for final Blockchain Sync\n Progress: ${progress} %\n Please wait - this can take some long time.\n Its OK to close terminal and ssh back in later.") |
|||
fi |
|||
else |
|||
heigh=7 |
|||
# check if wallet has any UTXO |
|||
# reason see: https://github.com/lightningnetwork/lnd/issues/2326 |
|||
txlines=$(sudo -u bitcoin lncli listchaintxns 2>/dev/null | wc -l) |
|||
# has just 4 lines if empty |
|||
if [ ${txlines} -eq 4 ]; then |
|||
infoStr=$(echo " Lightning ${action} Blockchain\n Progress: ${scanstate}\n re-rescan every start until funding\n ssh admin@${localip}\n Password A") |
|||
else |
|||
infoStr=$(echo " Lightning ${action} Blockchain\n Progress: ${scanstate}\n Please wait - this can take some time\n ssh admin@${localip}\n Password A") |
|||
if [ "$USER" = "admin" ]; then |
|||
heigh=6 |
|||
width=53 |
|||
infoStr=$(echo " Lightning ${action} Blockchain\n Progress: ${scanstate}\n Please wait - this can take some long time.\n Its OK to close terminal and ssh back in later.") |
|||
fi |
|||
fi |
|||
fi |
|||
|
|||
# display progress to user |
|||
sleep 3 |
|||
temp=$(echo "scale=1; $(cat /sys/class/thermal/thermal_zone0/temp)/1000" | bc) |
|||
dialog --title " ${network} / ${chain} " --backtitle "RaspiBlitz (${hostname}) CPU: ${temp}°C" --infobox "${infoStr}" ${heigh} ${width} |
@ -1,101 +1,123 @@ |
|||
#!/bin/bash |
|||
|
|||
source /home/admin/_version.info |
|||
source /home/admin/raspiblitz.info |
|||
source /mnt/hdd/raspiblitz.conf |
|||
|
|||
### USER PI AUTOSTART (LCD Display) |
|||
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') |
|||
source <(sudo /home/admin/config.scripts/blitz.statusscan.sh) |
|||
|
|||
# parse the actual scanned height progress from LND logs |
|||
item=0 |
|||
blockchaininfo=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo) |
|||
chain="$(echo "${blockchaininfo}" | jq -r '.chain')" |
|||
adminStr="ssh admin@${localIP} ->Password A" |
|||
if [ "$USER" == "admin" ]; then |
|||
adminStr="Use CTRL+c to EXIT to Terminal" |
|||
fi |
|||
|
|||
## TRY to get the actual progress height of scanning |
|||
if [ ${bitcoinActive} -eq 0 ] || [ ${#bitcoinErrorFull} -gt 0 ]; then |
|||
|
|||
# 1) First try the "Rescanned through block" - it seems to happen if it restarts |
|||
item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "Rescanned through block" | tail -n1 | cut -d ']' -f2 | cut -d '(' -f2 | tr -dc '0-9') |
|||
action="Rescanning" |
|||
#################### |
|||
# On Bitcoin Error |
|||
#################### |
|||
|
|||
# 2) Second try the "Caught up to height" - thats the usual on first scan start |
|||
if [ ${#item} -eq 0 ]; then |
|||
item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "Caught up to height" | tail -n1 | cut -d ']' -f2 | tr -dc '0-9') |
|||
action="Catching-Up" |
|||
fi |
|||
height=5 |
|||
width=43 |
|||
title="Blockchain Info" |
|||
if [ ${uptime} -gt 300 ]; then |
|||
infoStr=" The ${network}d service is not running.\n Login for more details:" |
|||
if [ "$USER" == "admin" ]; then |
|||
echo "" |
|||
echo "*****************************************" |
|||
echo "* The ${network}d service is not running." |
|||
echo "*****************************************" |
|||
echo "If you just started some config/setup, this might be OK." |
|||
echo |
|||
if [ ${#bitcoinErrorFull} -gt 0 ]; then |
|||
echo "More Error Detail:" |
|||
echo ${bitcoinErrorFull} |
|||
echo |
|||
fi |
|||
echo "-> To start ${network}d run: sudo systemctl start ${network}d" |
|||
echo "-> To force Main Menu run: /home/admin/00mainMenu.sh" |
|||
echo "-> Use following command to debug: /home/admin/XXdebugLogs.sh" |
|||
echo "" |
|||
exit 1 |
|||
fi |
|||
else |
|||
height=6 |
|||
if [ ${#bitcoinErrorShort} -eq 0 ]; then |
|||
bitcoinErrorShort="Initial Startup - Please Wait" |
|||
fi |
|||
infoStr=" The ${network}d service is starting:\n ${bitcoinErrorShort}\n Login for more details:" |
|||
if [ "$USER" == "admin" ]; then |
|||
infoStr=" The ${network}d service is starting:\n ${bitcoinErrorShort}\n Please wait up to 5min ..." |
|||
fi |
|||
fi |
|||
|
|||
# 3) Third try the "LNWL: Filtering block" - thats the usual on later starts |
|||
if [ ${#item} -eq 0 ]; then |
|||
item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "LNWL: Filtering block" | tail -n1 | cut -d ' ' -f7 | tr -dc '0-9') |
|||
action="Filtering" |
|||
fi |
|||
elif [ ${lndActive} -eq 0 ] || [ ${#lndErrorFull} -gt 0 ]; then |
|||
|
|||
# if no progress info |
|||
online=1 |
|||
if [ ${#item} -eq 0 ]; then |
|||
item="?" |
|||
#################### |
|||
# On LND Error |
|||
#################### |
|||
|
|||
# check if offline |
|||
online=$(ping 1.0.0.1 -c 1 -W 2 | grep -c '1 received') |
|||
if [ ${online} -eq 0 ]; then |
|||
# re-test with other server |
|||
online=$(ping 8.8.8.8 -c 1 -W 2 | grep -c '1 received') |
|||
fi |
|||
if [ ${online} -eq 0 ]; then |
|||
# re-test with other server |
|||
online=$(ping 208.67.222.222 -c 1 -W 2 | grep -c '1 received') |
|||
height=5 |
|||
width=43 |
|||
title="Lightning Info" |
|||
if [ ${uptime} -gt 300 ]; then |
|||
infoStr=" The LND service is not running.\n Login for more details:" |
|||
if [ "$USER" == "admin" ]; then |
|||
echo "" |
|||
echo "*********************************" |
|||
echo "* The LND service is not running." |
|||
echo "*********************************" |
|||
echo "If you just started some config/setup, this might be OK." |
|||
echo |
|||
if [ ${#lndErrorFull} -gt 0 ]; then |
|||
echo "More Error Detail:" |
|||
echo ${lndErrorFull} |
|||
echo |
|||
fi |
|||
echo "-> To start LND run: sudo systemctl start lnd" |
|||
echo "-> To force Main Menu run: /home/admin/00mainMenu.sh" |
|||
echo "-> Use following command to debug: /home/admin/XXdebugLogs.sh" |
|||
echo "" |
|||
exit 1 |
|||
fi |
|||
else |
|||
infoStr=" The LND service is starting.\n Login for more details:" |
|||
if [ "$USER" == "admin" ]; then |
|||
infoStr=" The LND service is starting.\n Please wait up to 5min ..." |
|||
fi |
|||
fi |
|||
|
|||
fi |
|||
else |
|||
|
|||
# get total number of blocks |
|||
total=$(echo "${blockchaininfo}" | jq -r '.blocks') |
|||
# put scanstate |
|||
scanstate="${item}/${total}" |
|||
|
|||
# get blockchain sync progress |
|||
progress="$(echo "${blockchaininfo}" | jq -r '.verificationprogress')" |
|||
#progress=$(echo "${progress}*100" | bc) |
|||
progress=$(echo $progress | awk '{printf( "%.2f%%", 100 * $1)}') |
|||
|
|||
# check if blockchain is still syncing |
|||
heigh=6 |
|||
width=44 |
|||
isInitialChainSync=$(echo "${blockchaininfo}" | grep 'initialblockdownload' | grep "true" -c) |
|||
isWaitingBlockchain=$( sudo -u bitcoin tail -n 2 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "Waiting for chain backend to finish sync" -c ) |
|||
if [ ${isWaitingBlockchain} -gt 0 ]; then |
|||
isInitialChainSync=1 |
|||
fi |
|||
if [ ${online} -eq 0 ]; then |
|||
heigh=7 |
|||
width=44 |
|||
infoStr=$(echo " Waiting INTERNET CONNECTION\n RaspiBlitz cannot ping 1.0.0.1\n Local IP is ${localip}\n Please check cables and router.") |
|||
elif [ ${isInitialChainSync} -gt 0 ]; then |
|||
heigh=7 |
|||
infoStr=" Waiting for final Blockchain Sync\n Progress: ${progress} %\n Please wait - this can take some time.\n ssh admin@${localip}\n Password A" |
|||
if [ "$USER" = "admin" ]; then |
|||
heigh=6 |
|||
width=53 |
|||
infoStr=$(echo " Waiting for final Blockchain Sync\n Progress: ${progress} %\n Please wait - this can take some long time.\n Its OK to close terminal and ssh back in later.") |
|||
#################### |
|||
# Sync Progress |
|||
#################### |
|||
|
|||
# basic dialog info |
|||
height=6 |
|||
width=43 |
|||
title="Node is Syncing (${scriptRuntime})" |
|||
|
|||
# formatting progress values |
|||
if [ ${#syncProgress} -eq 0 ]; then |
|||
syncProgress="waiting" |
|||
elif [ ${#syncProgress} -lt 6 ]; then |
|||
syncProgress=" ${syncProgress} %" |
|||
else |
|||
syncProgress="${syncProgress} %" |
|||
fi |
|||
else |
|||
heigh=7 |
|||
# check if wallet has any UTXO |
|||
# reason see: https://github.com/lightningnetwork/lnd/issues/2326 |
|||
txlines=$(sudo -u bitcoin lncli listchaintxns 2>/dev/null | wc -l) |
|||
# has just 4 lines if empty |
|||
if [ ${txlines} -eq 4 ]; then |
|||
infoStr=$(echo " Lightning ${action} Blockchain\n Progress: ${scanstate}\n re-rescan every start until funding\n ssh admin@${localip}\n Password A") |
|||
if [ ${#scanProgress} -eq 0 ]; then |
|||
scanProgress="waiting" |
|||
elif [ ${#scanProgress} -lt 6 ]; then |
|||
scanProgress=" ${scanProgress} %" |
|||
else |
|||
infoStr=$(echo " Lightning ${action} Blockchain\n Progress: ${scanstate}\n Please wait - this can take some time\n ssh admin@${localip}\n Password A") |
|||
if [ "$USER" = "admin" ]; then |
|||
heigh=6 |
|||
width=53 |
|||
infoStr=$(echo " Lightning ${action} Blockchain\n Progress: ${scanstate}\n Please wait - this can take some long time.\n Its OK to close terminal and ssh back in later.") |
|||
fi |
|||
scanProgress="${scanProgress} %" |
|||
fi |
|||
|
|||
# setting info string |
|||
infoStr=" Blockchain Progress : ${syncProgress}\n Lightning Progress : ${scanProgress}\n Please wait - this can take some time" |
|||
|
|||
fi |
|||
|
|||
# display progress to user |
|||
sleep 3 |
|||
temp=$(echo "scale=1; $(cat /sys/class/thermal/thermal_zone0/temp)/1000" | bc) |
|||
dialog --title " ${network} / ${chain} " --backtitle "RaspiBlitz (${hostname}) CPU: ${temp}°C" --infobox "${infoStr}" ${heigh} ${width} |
|||
# display info to user |
|||
dialog --title " ${title} " --backtitle "RaspiBlitz ${codeVersion} ${hostname} / ${network} / ${chain} / ${tempCelsius}°C" --infobox "${infoStr}\n ${adminStr}" ${height} ${width} |
@ -0,0 +1,133 @@ |
|||
#!/bin/bash |
|||
|
|||
# load raspiblitz config data |
|||
source /home/admin/raspiblitz.info |
|||
source /mnt/hdd/raspiblitz.conf |
|||
source /home/admin/_version.info |
|||
|
|||
clear |
|||
|
|||
# get latest release verison from GitHub |
|||
sudo curl -s -X GET https://raw.githubusercontent.com/rootzoll/raspiblitz/master/home.admin/_version.info > /home/admin/.version.tmp |
|||
gitHubVersionMain=$(cut -d"=" -f2 /home/admin/.version.tmp | cut -d'"' -f2 | cut -d"." -f1 | egrep "^[0-9]") |
|||
gitHubVersionSub=$(cut -d"=" -f2 /home/admin/.version.tmp | cut -d'"' -f2 | cut -d"." -f2 | egrep "^[0-9]") |
|||
sudo shred /home/admin/.version.tmp |
|||
sudo rm /home/admin/.version.tmp 2>/dev/null |
|||
|
|||
# check valid version info |
|||
if [ ${#gitHubVersionMain} -eq 0 ] || [ ${#gitHubVersionSub} -eq 0 ]; then |
|||
echo "FAIL: Was not able to get latest release Version from GitHub." |
|||
echo "PRESS ENTER to continue." |
|||
read key |
|||
exit 1 |
|||
fi |
|||
|
|||
# get local version |
|||
localVersionMain=$(cut -d"=" -f2 /home/admin/_version.info | cut -d'"' -f2 | cut -d"." -f1 | egrep "^[0-9]") |
|||
localVersionSub=$(cut -d"=" -f2 /home/admin/_version.info | cut -d'"' -f2 | cut -d"." -f2 | egrep "^[0-9]") |
|||
|
|||
echo "github version: ${gitHubVersionMain}.${gitHubVersionSub}" |
|||
echo "local version: ${localVersionMain}.${localVersionSub}" |
|||
|
|||
# compare versions |
|||
newerVersionAvailable=0 |
|||
if [ ${gitHubVersionMain} -gt ${localVersionMain} ]; then |
|||
echo "Main version is higher ..." |
|||
newerVersionAvailable=1 |
|||
else |
|||
if [ ${gitHubVersionMain} -lt ${localVersionMain} ]; then |
|||
echo "Strange that GutHub main version is lower then local - you maybe using a early release." |
|||
elif [ ${gitHubVersionSub} -gt ${localVersionSub} ]; then |
|||
echo "Sub version is higher ..." |
|||
newerVersionAvailable=1 |
|||
fi |
|||
fi |
|||
|
|||
# give feedback on version number |
|||
if [ ${newerVersionAvailable} -eq 0 ]; then |
|||
dialog --title " Update Check " --yes-button "OK" --no-button "Update Anyway" --yesno " |
|||
OK. You are running the newest version of RaspiBlitz. |
|||
" 7 57 |
|||
if [ $? -eq 0 ]; then |
|||
exit 1 |
|||
fi |
|||
clear |
|||
else |
|||
|
|||
whiptail --title "Update Check" --yes-button "Yes" --no-button "Not Now" --yesno " |
|||
There is a new Version of RaspiBlitz available. |
|||
You are running: ${localVersionMain}.${localVersionSub} |
|||
New Version: ${gitHubVersionMain}.${gitHubVersionSub} |
|||
|
|||
Do you want more Information on how to update? |
|||
" 12 52 |
|||
if [ $? -eq 1 ]; then |
|||
exit 1 |
|||
fi |
|||
fi |
|||
|
|||
whiptail --title "Update Instructions" --yes-button "Not Now" --no-button "Start Update" --yesno "To update your RaspiBlitz to a new version: |
|||
|
|||
- Download the new SD card image to your laptop: |
|||
https://github.com/rootzoll/raspiblitz |
|||
- Flash that SD card image to a new SD card |
|||
- Choose 'Start Update' below. |
|||
|
|||
No need to close channels or download blockchain again. |
|||
|
|||
Do you want to start the Update now? |
|||
" 16 62 |
|||
if [ $? -eq 0 ]; then |
|||
exit 1 |
|||
fi |
|||
|
|||
whiptail --title "LND Data Backup" --yes-button "Download Backup" --no-button "Skip" --yesno " |
|||
Before we start the RaspiBlitz Update process, |
|||
its recommended to make a backup of all your LND Data |
|||
and download that file to your laptop. |
|||
|
|||
Do you want to download LND Data Backup now? |
|||
" 12 58 |
|||
if [ $? -eq 0 ]; then |
|||
clear |
|||
echo "*************************************" |
|||
echo "* PREPARING LND BACKUP DOWNLOAD" |
|||
echo "*************************************" |
|||
echo "please wait .." |
|||
sleep 2 |
|||
/home/admin/config.scripts/lnd.rescue.sh backup |
|||
echo |
|||
echo "PRESS ENTER to continue once your done downloading." |
|||
read key |
|||
else |
|||
clear |
|||
echo "*************************************" |
|||
echo "* JUST MAKING BACKUP TO OLD SD CARD" |
|||
echo "*************************************" |
|||
echo "please wait .." |
|||
sleep 2 |
|||
/home/admin/config.scripts/lnd.rescue.sh backup no-download |
|||
fi |
|||
|
|||
whiptail --title "READY TO UPDATE?" --yes-button "START UPDATE" --no-button "Cancel" --yesno "If you start the update: The RaspiBlitz will power down. |
|||
Once the LCD is white and no LEDs are blicking anymore: |
|||
|
|||
- Remove the Power from RaspiBlitz |
|||
- Exchange the old with the new SD card |
|||
- Connect Power back to the RaspiBlitz |
|||
- Follow the instructions on the LCD |
|||
|
|||
Do you have the SD card with the new version image ready |
|||
and do you WANT TO START UPDATE NOW? |
|||
" 16 62 |
|||
|
|||
if [ $? -eq 1 ]; then |
|||
dialog --title " Update Canceled " --msgbox " |
|||
OK. RaspiBlitz will NOT update now. |
|||
" 7 39 |
|||
sudo systemctl start lnd |
|||
exit 1 |
|||
fi |
|||
|
|||
clear |
|||
sudo shutdown now |
@ -0,0 +1,118 @@ |
|||
#!/bin/bash |
|||
|
|||
source /home/admin/raspiblitz.info |
|||
source /mnt/hdd/raspiblitz.conf |
|||
|
|||
# command info |
|||
if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then |
|||
echo "# script to scan the state of the system after setup" |
|||
exit 1 |
|||
fi |
|||
|
|||
# measure time of scan |
|||
startTime=$(date +%s) |
|||
|
|||
# macke sure temp folder on HDD is available and fro all usable |
|||
sudo mkdir /mnt/hdd/temp 2>/dev/null |
|||
sudo chmod 777 -R /mnt/hdd/temp 2>/dev/null |
|||
|
|||
# localIP |
|||
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') |
|||
echo "localIP='${localip}'" |
|||
|
|||
# temp |
|||
tempC=$(echo "scale=1; $(cat /sys/class/thermal/thermal_zone0/temp)/1000" | bc) |
|||
echo "tempCelsius='${tempC}'" |
|||
|
|||
# uptime in seconds |
|||
uptime=$(awk '{printf("%d\n",$1 + 0.5)}' /proc/uptime) |
|||
echo "uptime=${uptime}" |
|||
|
|||
# is bitcoind running |
|||
bitcoinRunning=$(systemctl status ${network}d.service 2>/dev/null | grep -c running) |
|||
echo "bitcoinActive=${bitcoinRunning}" |
|||
|
|||
if [ ${bitcoinRunning} -eq 1 ]; then |
|||
|
|||
# get blockchain info |
|||
sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 1>/mnt/hdd/temp/.bitcoind.out 2>/mnt/hdd/temp/.bitcoind.error |
|||
# check if error on request |
|||
blockchaininfo=$(cat /mnt/hdd/temp/.bitcoind.out 2>/dev/null) |
|||
bitcoinError=$(cat /mnt/hdd/temp/.bitcoind.error 2>/dev/null) |
|||
#rm /mnt/hdd/temp/.bitcoind.error 2>/dev/null |
|||
if [ ${#bitcoinError} -gt 0 ]; then |
|||
echo "bitcoinErrorFull='${bitcoinError}'" |
|||
bitcoinErrorShort=$(echo ${bitcoinError/error*:/} | sed 's/[^a-zA-Z0-9 ]//g') |
|||
echo "bitcoinErrorShort='${bitcoinErrorShort}'" |
|||
else |
|||
|
|||
############################## |
|||
# Get data from blockchaininfo |
|||
############################## |
|||
|
|||
# get total number of blocks |
|||
total=$(echo ${blockchaininfo} | jq -r '.blocks') |
|||
echo "blockchainHeight=${total}" |
|||
|
|||
# is initial sync of blockchain |
|||
initialSync=$(echo ${blockchaininfo} | jq -r '.initialblockdownload' | grep -c 'true') |
|||
echo "initialSync=${initialSync}" |
|||
|
|||
# get blockchain sync progress |
|||
syncProgress="$(echo ${blockchaininfo} | jq -r '.verificationprogress')" |
|||
syncProgress=$(echo $syncProgress | awk '{printf( "%.2f%%", 100 * $1)}' | tr '%' ' ' | tr -s " ") |
|||
echo "syncProgress=${syncProgress}" |
|||
|
|||
fi |
|||
fi |
|||
|
|||
# is LND running |
|||
lndRunning=$(systemctl status lnd.service 2>/dev/null | grep -c running) |
|||
|
|||
# TODO: check how long running ... try to find out if problem on starting |
|||
|
|||
echo "lndActive=${lndRunning}" |
|||
|
|||
if [ ${lndRunning} -eq 1 ]; then |
|||
|
|||
# get LND info |
|||
lndinfo=$(sudo -u bitcoin lncli getinfo 2>/mnt/hdd/temp/.lnd.error) |
|||
|
|||
# check if error on request |
|||
lndErrorFull=$(cat /mnt/hdd/temp/.lnd.error 2>/dev/null) |
|||
#rm /mnt/hdd/temp/.lnd.error 2>/dev/null |
|||
if [ ${#lndError} -gt 0 ]; then |
|||
echo "lndErrorFull='${lndErrorFull}'" |
|||
echo "lndErrorShort=''" |
|||
else |
|||
|
|||
# synced to chain |
|||
syncedToChain=$(echo ${lndinfo} | jq -r '.synced_to_chain' | grep -c 'true') |
|||
echo "syncedToChain=${syncedToChain}" |
|||
|
|||
# lnd scan progress |
|||
scanTimestamp=$(echo ${lndinfo} | jq -r '.best_header_timestamp') |
|||
echo "scanTimestamp=${scanTimestamp}" |
|||
if [ ${#scanTimestamp} -gt 0 ]; then |
|||
scanDate=$(date -d @${scanTimestamp}) |
|||
echo "scanDate='${scanDate}'" |
|||
|
|||
# calculate LND scan progress by seconds since Genesisblock |
|||
genesisTimestamp=1230940800 |
|||
nowTimestamp=$(date +%s) |
|||
totalSeconds=$(echo "${nowTimestamp}-${genesisTimestamp}" | bc) |
|||
scannedSeconds=$(echo "${scanTimestamp}-${genesisTimestamp}" | bc) |
|||
scanProgress=$(echo "scale=2; $scannedSeconds*100/$totalSeconds" | bc) |
|||
echo "scanProgress=${scanProgress}" |
|||
fi |
|||
|
|||
fi |
|||
|
|||
fi |
|||
|
|||
# check if online if problem with other stuff |
|||
|
|||
# info on scan run time |
|||
endTime=$(date +%s) |
|||
runTime=$(echo "${endTime}-${startTime}" | bc) |
|||
echo "scriptRuntime=${runTime}" |
@ -0,0 +1,99 @@ |
|||
#!/bin/bash |
|||
|
|||
# command info |
|||
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then |
|||
echo "# script to upload a file to DropBox (without third party libs)" |
|||
echo "# dropbox.upload.sh upload [AUTHTOKEN] [FILEPATH]" |
|||
echo "# dropbox.upload.sh check [AUTHTOKEN]" |
|||
echo "# for Dropbox Setup with Authtoken, see:" |
|||
echo "# https://gist.github.com/vindard/e0cd3d41bb403a823f3b5002488e3f90" |
|||
echo "err='just informational output'" |
|||
exit 1 |
|||
fi |
|||
|
|||
# get first parameter |
|||
MODE="$1" |
|||
if [ "${MODE}" == "check" ]; then |
|||
|
|||
# get needed second parameter |
|||
DROPBOX_APITOKEN="$2" |
|||
if [ ${#DROPBOX_APITOKEN} -eq 0 ]; then |
|||
echo "err='missing Parameter AUTHTOKEN'" |
|||
exit 1 |
|||
fi |
|||
|
|||
# run API check |
|||
curl -s -X POST https://api.dropboxapi.com/2/users/get_current_account \ |
|||
--header "Authorization: Bearer "$DROPBOX_APITOKEN | grep rror |
|||
if [[ ! $? -eq 0 ]] ; then |
|||
echo "# Dropbox API Token worked" |
|||
echo "check=1" |
|||
else |
|||
echo "# Invalid Dropbox API Token!" |
|||
echo "check=0" |
|||
fi |
|||
|
|||
elif [ "${MODE}" == "upload" ]; then |
|||
|
|||
# get needed second parameter |
|||
DROPBOX_APITOKEN="$2" |
|||
if [ ${#DROPBOX_APITOKEN} -eq 0 ]; then |
|||
echo "err='missing Parameter AUTHTOKEN'" |
|||
exit 1 |
|||
fi |
|||
|
|||
# get needed third parameter |
|||
SOURCEFILE="$3" |
|||
if [ ${#SOURCEFILE} -eq 0 ]; then |
|||
echo "err='missing Parameter SOURCEFILE'" |
|||
exit 1 |
|||
fi |
|||
|
|||
source /mnt/hdd/raspiblitz.conf |
|||
if [ ${#hostname} -eq 0 ]; then |
|||
hostname="raspiblitz" |
|||
fi |
|||
|
|||
DEVICE=$(echo "${hostname}" | awk '{print tolower($0)}' | sed -e 's/ /-/g') |
|||
BACKUPFOLDER=lndbackup-$DEVICE |
|||
FILENAME=$(basename "${SOURCEFILE}") |
|||
|
|||
sudo curl -s -X POST https://content.dropboxapi.com/2/files/upload \ |
|||
--header "Authorization: Bearer "${DROPBOX_APITOKEN}"" \ |
|||
--header "Dropbox-API-Arg: {\"path\": \"/"$BACKUPFOLDER"/"$FILENAME"\",\"mode\": \"overwrite\",\"autorename\": true,\"mute\": false,\"strict_conflict\": false}" \ |
|||
--header "Content-Type: application/octet-stream" \ |
|||
--data-binary @$SOURCEFILE > /home/admin/.dropbox.tmp |
|||
safeResponse=$(sed 's/[^a-zA-Z0-9 ]//g' /home/admin/.dropbox.tmp) |
|||
sudo shred /home/admin/.dropbox.tmp |
|||
sudo rm /home/admin/.dropbox.tmp 2>/dev/null |
|||
|
|||
success=$(echo "${safeResponse}" | grep -c 'servermodified') |
|||
sizeZero=$(echo "${safeResponse}" | grep -c 'size 0') |
|||
if [ ${sizeZero} -gt 0 ]; then |
|||
echo "# Upload happened but is size zero" |
|||
echo "upload=0" |
|||
echo "err='size zero'" |
|||
echo "errMore='${safeResponse}'" |
|||
elif [ ${success} -gt 0 ] ; then |
|||
echo "# Successfully uploaded!" |
|||
echo "upload=1" |
|||
else |
|||
echo "# Unknown Error" |
|||
echo "upload=0" |
|||
echo "err='unknown'" |
|||
echo "errMore='${safeResponse}'" |
|||
fi |
|||
|
|||
else |
|||
echo "err='unkown mode'" |
|||
exit 1 |
|||
fi |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,43 @@ |
|||
#!/bin/bash |
|||
|
|||
# command info |
|||
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then |
|||
echo "# config script to init/show/transfer ssh pub keys." |
|||
echo "# To init and return pubkey as data:" |
|||
echo "# internet.sshpubkey.sh get" |
|||
echo "# To init and transfer ssh-pub to a authorizedkey of remote server:" |
|||
echo "# internet.sshpubkey.sh transfer [REMOTEUSER]@[REMOTESERVER]" |
|||
echo "err='just informational output'" |
|||
exit 1 |
|||
fi |
|||
|
|||
# 1. parameter MODE |
|||
MODE="$1" |
|||
|
|||
# root as default user |
|||
# its used for all ssh tunnel/back action |
|||
|
|||
# make sure the ssh keys for that user are initialized |
|||
sshKeysExist=$(sudo ls /root/.ssh/id_rsa.pub | grep -c 'id_rsa.pub') |
|||
if [ ${sshKeysExist} -eq 0 ]; then |
|||
echo "# generation SSH keys for user root" |
|||
sudo mkdir /root/.ssh 2>/dev/null |
|||
sudo sh -c 'yes y | sudo ssh-keygen -b 2048 -t rsa -f /root/.ssh/id_rsa -q -N ""' |
|||
fi |
|||
|
|||
if [ "${MODE}" == "get" ]; then |
|||
|
|||
# get ssh pub key and print |
|||
sshPubKey=$(sudo cat /root/.ssh/id_rsa.pub) |
|||
echo "user='root'" |
|||
echo "sshPubKey='${sshPubKey}'" |
|||
|
|||
elif [ "${MODE}" == "transfer" ]; then |
|||
|
|||
sudo ssh-copy-id $2 |
|||
|
|||
else |
|||
echo "err='paremeter not known - run with -help'" |
|||
fi |
|||
|
|||
|
Loading…
Reference in new issue