@ -0,0 +1,93 @@ |
|||
# ⚡️ Alternative platforms for the RaspiBlitz ⚡️ |
|||
|
|||
Minimum requirements: |
|||
* ARM V7 or V8 processor architecture (32 or 64 bit) |
|||
* 1 GB RAM |
|||
* \> 300 GB HDD |
|||
|
|||
Desirable: |
|||
* \> 2GB DDR3 RAM |
|||
* USB 3.0 or SATA connector |
|||
* SSD |
|||
* Compact case with efficient cooling (heatsink / fan) |
|||
* HDMI / GPIO screen |
|||
|
|||
|
|||
Specifications of the tested hardware: [hw_comparison.md](hw_comparison.md) |
|||
|
|||
All testers are welcome. Open an issue for your specific board to collaborate and share your experience. |
|||
|
|||
--- |
|||
## Armbian |
|||
Many SBC-s are supported: |
|||
https://www.armbian.com/download/ |
|||
|
|||
Tested on: |
|||
* Odroid XU4 with the Armbian Stretch image from https://www.armbian.com/odroid-xu4/ |
|||
|
|||
|
|||
Burn the image to the SDCard with [Etcher](https://www.balena.io/etcher/). |
|||
|
|||
Assemble and boot. |
|||
|
|||
`ssh root@192.168.1.122` |
|||
|
|||
password: 1234 |
|||
|
|||
Follow the instructions in the terminal. |
|||
|
|||
Continue with building the SDcard: https://github.com/rootzoll/raspiblitz#build-the-sd-card-image |
|||
|
|||
--- |
|||
|
|||
## Ubuntu |
|||
|
|||
A common distro to be supplied by the manufacturer for various boards. |
|||
|
|||
Tested on: |
|||
* Odroid XU4 with ubuntu-18.04.1-4.14-minimal image from https://de.eu.odroid.in/ubuntu_18.04lts/XU3_XU4_MC1_HC1_HC2 |
|||
|
|||
Burn the image to the SDCard with [Etcher](https://www.balena.io/etcher/). |
|||
|
|||
Assemble and boot. |
|||
|
|||
`ssh root@192.168.1.122` |
|||
|
|||
password: odroid |
|||
|
|||
`apt-get update` |
|||
|
|||
`apt-get upgrade` |
|||
|
|||
if there is an error: |
|||
>E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable) |
|||
|
|||
>E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it? |
|||
|
|||
run: |
|||
`reboot` and update as above |
|||
|
|||
Continue with building the SDcard: https://github.com/rootzoll/raspiblitz#build-the-sd-card-image |
|||
|
|||
--- |
|||
|
|||
## DietPi |
|||
|
|||
Many SBC-s are supported: |
|||
https://dietpi.com/#download |
|||
|
|||
Tested on: |
|||
|
|||
* Odroid HC1 |
|||
* Odroid HC2 (the same board with a 3.5" 12V HDD) |
|||
* Odroid XU4 (with HDMI screen) |
|||
* Raspberry Pi 3 B+ (with the default GPIO or HDMI display) |
|||
|
|||
|
|||
The HDMI screen tested: https://www.aliexpress.com/item/3-5-inch-LCD-HDMI-USB-Touch-Screen-Real-HD-1920x1080-LCD-Display-Py-for-Raspberri/32818537950.html |
|||
|
|||
Detailed instructions for the RaspiBlitz-on-DietPi: [/dietpi/README.md](/dietpi/README.md) |
|||
|
|||
--- |
|||
Extras for advanced users and powerful hardware: |
|||
https://github.com/openoms/bitcoin-tutorials/ |
@ -0,0 +1,40 @@ |
|||
# ⚡️ RaspiBlitz-on-DietPi ⚡️ |
|||
## Tested on the Raspberry Pi 3 B + |
|||
|
|||
### The automated building process: |
|||
|
|||
1) Download the DietPi image for the Raspberry Pi: |
|||
https://dietpi.com/downloads/images/DietPi_RPi-ARMv6-Stretch.7z |
|||
|
|||
2) Burn it to the SD card with [Etcher](https://www.balena.io/etcher/) |
|||
|
|||
3) Right click and download the following two files: [DietPi.txt](https://raw.githubusercontent.com/rootzoll/raspiblitz/dev/dietpi/boot/dietpi.txt), [Automation_Custom_Script.sh](https://raw.githubusercontent.com/rootzoll/raspiblitz/dev/dietpi/boot/Automation_Custom_Script.sh) |
|||
|
|||
4) Copy them to the /boot directory of the DietPi SDcard |
|||
|
|||
[DietPi.txt](https://raw.githubusercontent.com/rootzoll/raspiblitz/dev/dietpi/boot/dietpi.txt): Overwrites the default dietpi.txt. Modified the settings to automate the DietPi setup. (see the details [here](https://github.com/rootzoll/raspiblitz/tree/dev/dietpi#excerpts-from-the-customized-dietpitxt)) |
|||
|
|||
[Automation_Custom_Script.sh](https://raw.githubusercontent.com/rootzoll/raspiblitz/dev/dietpi/boot/Automation_Custom_Script.sh): Runs after DietPi installation is completed. Contains the link to download and run the build_sdcard.sh from the dev branch of @rootzoll. |
|||
(Optionally open the file with a text editor and uncomment (remove the `#` from the front of) the line with the branch you want to build the SDcard from.) |
|||
|
|||
5) Assemble and boot the Raspberry Pi |
|||
|
|||
Insert the SDcard, connect the HDD, network cable and power supply to boot. |
|||
(The default LCD will be set up automatically) |
|||
|
|||
|
|||
The automated setup will continue and the Raspberry Pi will restart at least twice during the process. This will take up to an hour. |
|||
To follow the logs during the automated building process login with `root` and press CTRL+C. |
|||
`tail -n1000 -f /tmp/DietPi-Update/dietpi-update.log` - follow the dietpi-update process |
|||
`tail -n1000 -f /var/tmp/dietpi/logs/dietpi-automation_custom_script.log` follow the output of the build_sdcard.sh |
|||
|
|||
|
|||
6) When the setup is finished log in as `admin`: |
|||
`ssh admin@[IP-OF-RASPIBLITZ]` |
|||
password: `raspiblitz` |
|||
|
|||
The setup continues with the [RaspiBlitz Setup Process](https://github.com/rootzoll/raspiblitz/blob/master/README.md#setup-process-detailed-documentation) |
|||
|
|||
--- |
|||
### To build manually: |
|||
[Follow the generic DietPi install process.](https://github.com/rootzoll/raspiblitz/tree/dev/dietpi#general-guide-for-the-raspiblitz-on-dietpi) |
@ -1 +1,14 @@ |
|||
wget https://raw.githubusercontent.com/openoms/raspiblitz/raspiblitz-dev/build.sdcard/raspbianStretchDesktop.sh && sudo bash raspbianStretchDesktop.sh raspiblitz-dev openoms |
|||
# Use this format to build the SDcard with the Raspiblitz script: |
|||
# wget https://raw.githubusercontent.com/[GITHUB-USERNAME]/raspiblitz/[BRANCH]/build_sdcard.sh && sudo bash build_sdcard.sh [BRANCH] [GITHUB-USERNAME]` |
|||
# If you are working from a forked repo be aware of that the fork needs to be called `raspiblitz` for the git downloads to work. |
|||
|
|||
# Uncomment the line with the branch you want to build the SDcard from: |
|||
|
|||
# @rootzoll master branch: |
|||
# wget https://raw.githubusercontent.com/rootzoll/raspiblitz/master/build_sdcard.sh && sudo bash build_sdcard.sh |
|||
|
|||
# @rootzoll dev branch: |
|||
wget https://raw.githubusercontent.com/rootzoll/raspiblitz/dev/build_sdcard.sh && sudo bash build_sdcard.sh dev |
|||
|
|||
# @openoms DietPi branch: |
|||
# wget https://raw.githubusercontent.com/openoms/raspiblitz/DietPi/build_sdcard.sh && sudo bash build_sdcard.sh DietPi openoms |
@ -0,0 +1,210 @@ |
|||
# To run this script on your RaspiBlitz, copy the following line to the ssh terminal (after the #): |
|||
# wget https://raw.githubusercontent.com/openoms/raspiblitz/DietPi/dietpi/dietpi.display.sh && sudo chmod +x dietpi.display.sh && ./dietpi.display.sh |
|||
|
|||
# keep in mind that DietPi for Raspberry is also a stripped down Raspbian |
|||
echo "Detect Base Image ..." |
|||
baseImage="?" |
|||
isDietPi=$(uname -n | grep -c 'DietPi') |
|||
isRaspbian=$(cat /etc/os-release 2>/dev/null | grep -c 'Raspbian') |
|||
if [ ${isRaspbian} -gt 0 ]; then |
|||
baseImage="raspbian" |
|||
fi |
|||
if [ ${isDietPi} -gt 0 ]; then |
|||
baseImage="dietpi" |
|||
fi |
|||
if [ "${baseImage}" = "?" ]; then |
|||
cat /etc/os-release 2>/dev/null |
|||
echo "!!! FAIL !!!" |
|||
echo "Base Image cannot be detected or is not supported." |
|||
exit 1 |
|||
else |
|||
echo "OK running ${baseImage}" |
|||
fi |
|||
|
|||
|
|||
if [ "${baseImage}" = "raspbian" ]; then |
|||
echo "Press ENTER to install LCD and reboot ..." |
|||
read key |
|||
|
|||
# give Raspi a default hostname (optional) |
|||
sudo raspi-config nonint do_hostname "RaspiBlitz" |
|||
|
|||
# *** Display selection *** |
|||
dialog --title "Display" --yesno "Are you using the default display available from Amazon?\nSelect 'No' if you are using the Swiss version from play-zone.ch!" 6 80 |
|||
defaultDisplay=$? |
|||
|
|||
if [ "${defaultDisplay}" = "0" ]; then |
|||
|
|||
# *** RASPIBLITZ / LCD (at last - because makes a reboot) *** |
|||
# based on https://www.elegoo.com/tutorial/Elegoo%203.5%20inch%20Touch%20Screen%20User%20Manual%20V1.00.2017.10.09.zip |
|||
|
|||
echo "--> LCD DEFAULT" |
|||
cd /home/admin/ |
|||
sudo apt-mark hold raspberrypi-bootloader |
|||
git clone https://github.com/goodtft/LCD-show.git |
|||
sudo chmod -R 755 LCD-show |
|||
sudo chown -R admin:admin LCD-show |
|||
cd LCD-show/ |
|||
sudo ./LCD35-show |
|||
|
|||
else |
|||
|
|||
# Download and install the driver |
|||
# based on http://www.raspberrypiwiki.com/index.php/3.5_inch_TFT_800x480@60fps |
|||
|
|||
echo "--> LCD ALTERNATIVE" |
|||
cd /boot |
|||
sudo wget http://www.raspberrypiwiki.com/download/RPI-HD-35-INCH-TFT/dt-blob-For-3B-plus.bin |
|||
sudo mv dt-blob-For-3B-plus.bin dt-blob.bin |
|||
cat <<EOF >> config.txt |
|||
|
|||
dtparam=spi=off |
|||
dtparam=i2c_arm=off |
|||
|
|||
# Set screen size and any overscan required |
|||
overscan_left=0 |
|||
overscan_right=0 |
|||
overscan_top=0 |
|||
overscan_bottom=0 |
|||
framebuffer_width=800 |
|||
framebuffer_height=480 |
|||
|
|||
|
|||
enable_dpi_lcd=1 |
|||
display_default_lcd=1 |
|||
dpi_group=2 |
|||
dpi_mode=87 |
|||
dpi_output_format=0x6f015 |
|||
|
|||
# set up the size to 800x480 |
|||
hdmi_timings=480 0 16 16 24 800 0 4 2 2 0 0 0 60 0 32000000 6 |
|||
|
|||
#rotate screen |
|||
display_rotate=3 |
|||
|
|||
dtoverlay=i2c-gpio,i2c_gpio_scl=24,i2c_gpio_sda=23 |
|||
fi |
|||
EOF |
|||
init 6 |
|||
fi |
|||
fi |
|||
|
|||
|
|||
if [ "${baseImage}" = "dietpi" ]; then |
|||
|
|||
OPTIONS=(GPIO "Install the default display available from Amazon" \ |
|||
HDMI "Install the 3.5\" HDMI display from Aliexpress" \ |
|||
SWISS "Install the Swiss version from play-zone.ch" |
|||
) |
|||
|
|||
CHOICE=$(dialog --backtitle "RaspiBlitz - Display Install" --clear --title "Display Install" --menu "Choose a your diplay:" 10 70 6 "${OPTIONS[@]}" 2>&1 >/dev/tty) |
|||
|
|||
if [ "${CHOICE}" = "GPIO" ]; then |
|||
echo "Installing the default display available from Amazon" |
|||
|
|||
# based on https://www.elegoo.com/tutorial/Elegoo%203.5%20inch%20Touch%20Screen%20User%20Manual%20V1.00.2017.10.09.zip |
|||
cd /home/admin/ |
|||
#sudo apt-mark hold raspberrypi-bootloader |
|||
git clone https://github.com/goodtft/LCD-show.git |
|||
sudo chmod -R 755 LCD-show |
|||
sudo chown -R admin:admin LCD-show |
|||
cd LCD-show/ |
|||
# sudo ./LCD35-show |
|||
sudo rm -rf /etc/X11/xorg.conf.d/40-libinput.conf |
|||
sudo mkdir /etc/X11/xorg.conf.d |
|||
sudo cp ./usr/tft35a-overlay.dtb /boot/overlays/ |
|||
sudo cp ./usr/tft35a-overlay.dtb /boot/overlays/tft35a.dtbo |
|||
sudo cp -rf ./usr/99-calibration.conf-35 /etc/X11/xorg.conf.d/99-calibration.conf |
|||
sudo cp -rf ./usr/99-fbturbo.conf /usr/share/X11/xorg.conf.d/ |
|||
sudo cp ./usr/cmdline.txt /DietPi/ |
|||
sudo cp ./usr/inittab /etc/ |
|||
sudo cp ./boot/config-35.txt /DietPi/config.txt |
|||
|
|||
# revert font change |
|||
# based on https://www.raspberrypi-spy.co.uk/2014/04/how-to-change-the-command-line-font-size/ |
|||
sudo sed -i 's/FONTFACE="TerminusBold"/FONTFACE="Fixed"/' /etc/default/console-setup |
|||
sudo sed -i 's/FONTSIZE="12x24"/FONTSIZE="8x16"/' /etc/default/console-setup |
|||
|
|||
echo "***" |
|||
echo "reboot with \`sudo reboot\` to make the LCD work" |
|||
echo "***" |
|||
|
|||
exit |
|||
|
|||
elif [ "${CHOICE}" = "HDMI" ]; then |
|||
echo "Installing the 3.5\" HDMI display from Aliexpress" |
|||
|
|||
# based on http://www.lcdwiki.com/3.5inch_HDMI_Display-B |
|||
git clone https://github.com/goodtft/LCD-show.git |
|||
sudo chmod -R 755 LCD-show |
|||
cd LCD-show/ |
|||
#sudo ./MPI3508-show |
|||
sudo rm -rf /etc/X11/xorg.conf.d/40-libinput.conf |
|||
sudo cp -rf ./boot/config-35-480X320.txt /DietPi/config.txt |
|||
sudo cp ./usr/cmdline.txt /DietPi/ |
|||
sudo cp ./usr/inittab /etc/ |
|||
sudo cp -rf ./usr/99-fbturbo.conf-HDMI /usr/share/X11/xorg.conf.d/99-fbturbo.conf |
|||
sudo mkdir -p /etc/X11/xorg.conf.d |
|||
sudo cp -rf ./usr/99-calibration.conf-3508 /etc/X11/xorg.conf.d/99-calibration.conf |
|||
|
|||
# based on https://www.raspberrypi-spy.co.uk/2014/04/how-to-change-the-command-line-font-size/ |
|||
sudo sed -i 's/FONTFACE="Fixed"/FONTFACE="TerminusBold"/' /etc/default/console-setup |
|||
sudo sed -i 's/FONTSIZE="8x16"/FONTSIZE="12x24"/' /etc/default/console-setup |
|||
|
|||
echo "***" |
|||
echo "reboot with \`sudo reboot\` to make the LCD work" |
|||
echo "***" |
|||
|
|||
exit |
|||
|
|||
elif [ "${CHOICE}" = "SWISS" ]; then |
|||
|
|||
# Download and install the driver |
|||
# based on http://www.raspberrypiwiki.com/index.php/3.5_inch_TFT_800x480@60fps |
|||
|
|||
echo "--> LCD ALTERNATIVE" |
|||
|
|||
# revert font change |
|||
# based on https://www.raspberrypi-spy.co.uk/2014/04/how-to-change-the-command-line-font-size/ |
|||
sudo sed -i 's/FONTFACE="TerminusBold"/FONTFACE="Fixed"/' /etc/default/console-setup |
|||
sudo sed -i 's/FONTSIZE="12x24"/FONTSIZE="8x16"/' /etc/default/console-setup |
|||
|
|||
cd /DietPi |
|||
sudo wget http://www.raspberrypiwiki.com/download/RPI-HD-35-INCH-TFT/dt-blob-For-3B-plus.bin |
|||
sudo mv dt-blob-For-3B-plus.bin dt-blob.bin |
|||
cat <<EOF >> config.txt |
|||
|
|||
dtparam=spi=off |
|||
dtparam=i2c_arm=off |
|||
|
|||
# Set screen size and any overscan required |
|||
overscan_left=0 |
|||
overscan_right=0 |
|||
overscan_top=0 |
|||
overscan_bottom=0 |
|||
framebuffer_width=800 |
|||
framebuffer_height=480 |
|||
|
|||
|
|||
enable_dpi_lcd=1 |
|||
display_default_lcd=1 |
|||
dpi_group=2 |
|||
dpi_mode=87 |
|||
dpi_output_format=0x6f015 |
|||
|
|||
# set up the size to 800x480 |
|||
hdmi_timings=480 0 16 16 24 800 0 4 2 2 0 0 0 60 0 32000000 6 |
|||
|
|||
#rotate screen |
|||
display_rotate=3 |
|||
|
|||
dtoverlay=i2c-gpio,i2c_gpio_scl=24,i2c_gpio_sda=23 |
|||
fi |
|||
EOF |
|||
init 6 |
|||
fi |
|||
|
|||
else |
|||
echo "CANCEL" |
|||
exit |
|||
fi |
@ -1,2 +0,0 @@ |
|||
#!/bin/bash |
|||
/usr/bin/env python3 infoblitzd.py $@ |
@ -0,0 +1,469 @@ |
|||
#!/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 |
|||
recoveredInfoExists=$(sudo ls /home/admin/raspiblitz.recover.info 2>/dev/null | grep -c '.info') |
|||
if [ ${recoveredInfoExists} -gt 0 ]; 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 2>/dev/null | grep -c "Please restart with -reindex or -reindex-chainstate to recover.") |
|||
if [ ${blockchainBroken} -eq 1 ]; then |
|||
# dismiss if its just a date thing |
|||
futureBlock=$(sudo tail /mnt/hdd/bitcoin/debug.log 2>/dev/null | grep "Please restart with -reindex or -reindex-chainstate to recover." | grep -c "block database contains a block which appears to be from the future") |
|||
if [ ${futureBlock} -gt 0 ]; then |
|||
blockchainBroken=0 |
|||
echo "-> Ignore reindex - its just a future block" |
|||
fi |
|||
fi |
|||
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 "Preparing ... pls wait (up to 1min) " |
|||
echo "************************************" |
|||
sudo -u root bitcoin-cli -conf=/home/admin/assets/bitcoin.conf stop 2>/dev/null |
|||
echo "Calling presync to finish up .." |
|||
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() |
|||
{ |
|||
source ${configFile} |
|||
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} 2>/dev/null | 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 2>/dev/null | grep -c 'Please restart with -reindex or -reindex-chainstate to recover') |
|||
if [ ${reindex} -gt 0 ]; then |
|||
# dismiss if its just a date thing |
|||
futureBlock=$(sudo tail /mnt/hdd/${network}/debug.log 2>/dev/null | grep "Please restart with -reindex or -reindex-chainstate to recover" | grep -c "block database contains a block which appears to be from the future") |
|||
if [ ${futureBlock} -gt 0 ]; then |
|||
blockchainBroken=0 |
|||
echo "-> Ignore reindex - its just a future block" |
|||
fi |
|||
fi |
|||
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 |
|||
# check how many times LND was restarted |
|||
source <(sudo /home/admin/config.scripts/blitz.statusscan.sh) |
|||
if [ ${startcountLightning} -lt 4 ]; then |
|||
/home/admin/AAunlockLND.sh |
|||
echo "Starting up Wallet ... (10sec)" |
|||
sleep 5 |
|||
sleep 5 |
|||
echo "please wait ... update to next screen can be slow" |
|||
else |
|||
/home/admin/80scanLND.sh lightning-error |
|||
echo "(exit after too much restarts/unlocks - restart to try again)" |
|||
exit 0 |
|||
fi |
|||
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 |
|||
|
|||
# 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 |
|||
|
|||
# check if LND needs re-setup |
|||
source <(sudo /home/admin/config.scripts/lnd.check.sh basic-setup) |
|||
if [ ${wallet} -eq 0 ] || [ ${macaroon} -eq 0 ] || [ ${config} -eq 0 ] || [ ${tls} -eq 0 ]; then |
|||
echo "WARN: LND needs re-setup" |
|||
/home/admin/70initLND.sh |
|||
exit 0 |
|||
fi |
|||
|
|||
# wait all is synced and ready |
|||
waitUntilChainNetworkIsReady |
|||
|
|||
# check if there is a channel.backup to activate |
|||
gotSCB=$(ls /home/admin/channel.backup 2>/dev/null | grep -c 'channel.backup') |
|||
if [ ${gotSCB} -eq 1 ]; then |
|||
|
|||
echo "*** channel.backup Recovery ***" |
|||
lncli restorechanbackup --multi_file=/home/admin/channel.backup 2>/home/admin/.error.tmp |
|||
error=`cat /home/admin/.error.tmp` |
|||
rm /home/admin/.error.tmp 2>/dev/null |
|||
|
|||
if [ ${#error} -gt 0 ]; then |
|||
|
|||
# output error message |
|||
echo "" |
|||
echo "!!! FAIL !!! SOMETHING WENT WRONG:" |
|||
echo "${error}" |
|||
|
|||
# check if its possible to give background info on the error |
|||
notMachtingSeed=$(echo $error | grep -c 'unable to unpack chan backup') |
|||
if [ ${notMachtingSeed} -gt 0 ]; then |
|||
echo "--> ERROR BACKGROUND:" |
|||
echo "The WORD SEED is not matching the channel.backup file." |
|||
echo "Either there was an error in the word seed list or" |
|||
echo "or the channel.backup file is from another RaspiBlitz." |
|||
echo |
|||
fi |
|||
|
|||
# basic info on error |
|||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" |
|||
echo |
|||
echo "You can try after full setup to restore channel.backup file again with:" |
|||
echo "lncli restorechanbackup --multi_file=/home/admin/channel.backup" |
|||
echo |
|||
echo "Press ENTER to continue for now ..." |
|||
read key |
|||
else |
|||
mv /home/admin/channel.backup /home/admin/channel.backup.done |
|||
dialog --title " OK channel.backup IMPORT " --msgbox " |
|||
LND accepted the channel.backup file you uploaded. |
|||
It will now take around a hour until you can see, |
|||
if LND was able to recover funds from your channels. |
|||
" 9 56 |
|||
fi |
|||
|
|||
fi |
|||
|
|||
#forward to main menu |
|||
/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,177 @@ |
|||
#!/bin/bash |
|||
|
|||
# A solid hardware setup is important to garantuee stability of data |
|||
# This script checks the hardware and gives user feedback. |
|||
|
|||
# Start with parameter "no-new-stresstest" to just use the already |
|||
# made stresstest report during boostrap script. |
|||
|
|||
# INFOFILE - state data from bootstrap |
|||
source /home/admin/raspiblitz.info |
|||
source /home/admin/_version.info |
|||
|
|||
clear |
|||
echo "*** Hardware Test Report ***" |
|||
echo "" |
|||
|
|||
# check for parameter |
|||
parameter="$1" |
|||
|
|||
if [ "${parameter}" != "no-new-stresstest" ]; then |
|||
sudo /home/admin/config.scripts/blitz.stresstest.sh /home/admin/stresstest.report |
|||
echo "" |
|||
fi |
|||
|
|||
# load the stresstest values |
|||
source /home/admin/stresstest.report |
|||
|
|||
######################### |
|||
# Explain Report to User |
|||
######################### |
|||
|
|||
# check for power issues |
|||
showPowerImproveInfo=0 |
|||
if [ ${powerWARN} -gt 0 ]; then |
|||
showPowerImproveInfo=1 |
|||
if [ ${powerFAIL} -gt 0 ]; then |
|||
whiptail --backtitle "RaspiBlitz v${codeVersion} - ${powerMIN}" --title " POWER SUPPLY CRITICAL " --msgbox " |
|||
Your power supply was FAILING the stress test (${powerMIN}). |
|||
Most reports of data loss are caused by weak power supplies. |
|||
Also a lot of RaspiBlitz setups fail because of weak power supplies. |
|||
To SHUTDOWN and upgrade the Power Supply is HIGHLY RECOMMENDED. |
|||
|
|||
See upcomming screen on detailed info how to improve on power supply. |
|||
|
|||
" 14 78 |
|||
else |
|||
whiptail --backtitle "RaspiBlitz v${codeVersion} - ${powerMIN}" --title " Power Supply Warning " --msgbox " |
|||
Your power supply seems OK - but could be better for stable operations. |
|||
A replacement/upgrade of the Power Supply is recommended if possible. |
|||
Because most reports of data loss are caused by weak power supplies. |
|||
|
|||
See upcomming screen on detailed info how to improve on power supply. |
|||
|
|||
" 12 78 |
|||
fi |
|||
fi |
|||
|
|||
if [ ${#undervoltageReports} -gt 0 ]; then |
|||
if [ ${undervoltageReports} -gt 0 ]; then |
|||
showPowerImproveInfo=1 |
|||
whiptail --backtitle "RaspiBlitz v${codeVersion}" --title " Runtime Undervoltages Detected " --msgbox " |
|||
Already during runtime of RaspiBlitz Undervoltage Reports were detected. |
|||
A upgrade of the Power Supply is strongly recommended (see next screen). |
|||
|
|||
You should see the number of outages on your LCD as an ongoing counting. |
|||
Note that after replacement of power supply this number is not set to 0. |
|||
As long that counting is not going further up you are good. |
|||
|
|||
" 13 78 |
|||
fi |
|||
fi |
|||
|
|||
if [ ${showPowerImproveInfo} -gt 0 ]; then |
|||
|
|||
whiptail --backtitle "RaspiBlitz v${codeVersion}" --title " What todo on Power Issues " --msgbox " |
|||
To improve on power issues an upgrade of the power supply is recommended. |
|||
Check if you have the latest power supply listed in your shopping list. |
|||
If you have that one, please report on GitHub that alternative is needed. |
|||
|
|||
In general a good power supply needs to fullfill this three points: |
|||
- needs to deliver at least 3 Ampere |
|||
- needs to deliver a stable >=5V output (big & clunky is good) |
|||
- needs a thick cable (low AWG score) & best is no switch |
|||
|
|||
If you think all is good with your power supply please also re-run test |
|||
up to 3 times. Sometimes a good power supply has 1 or 2 bad measurements. |
|||
|
|||
" 18 78 |
|||
|
|||
choice=$(whiptail --backtitle "RaspiBlitz v${codeVersion}" --title " Hardware Check " --menu "What todo about Power Issues?" 12 60 6 \ |
|||
TESTAGAIN "Run Test again to be sure." \ |
|||
CONTINUE "I take the risk - continue." \ |
|||
SHUTDOWN "Shutdown to change hardware." 3>&1 1>&2 2>&3) |
|||
if [ ${#choice} -eq 0 ]; then |
|||
choice="CONTINUE" |
|||
fi |
|||
if [ "${choice}" == "TESTAGAIN" ]; then |
|||
echo "Shutting down ..." |
|||
sudo /home/admin/05hardwareTest.sh |
|||
exit 0 |
|||
elif [ "${choice}" == "SHUTDOWN" ]; then |
|||
echo "Shutting down ..." |
|||
sudo shutdown now |
|||
exit 1 |
|||
else |
|||
echo "OK continue .." |
|||
fi |
|||
fi |
|||
|
|||
# check for heat issues |
|||
showHeatImproveInfo=0 |
|||
if [ ${tempWARN} -gt 0 ]; then |
|||
showHeatImproveInfo=1 |
|||
if [ ${tempFAIL} -gt 0 ]; then |
|||
whiptail --backtitle "RaspiBlitz v${codeVersion} - ${tempMAX}" --title " HEAT MANAGEMENT CRITICAL " --msgbox " |
|||
Your RaspiBlitz is getting MUCH TOO HOT (${tempMAX}). |
|||
The system is getting very slow when hot - thats not a NO GO but bad. |
|||
An upgrade of the Heat Management is HIGHLY RECOMMENDED. |
|||
|
|||
See upcomming screen on detailed info how to improve heat management. |
|||
|
|||
" 12 78 |
|||
else |
|||
whiptail --backtitle "RaspiBlitz v${codeVersion} - ${tempMAX}" --title " Heat Management Warning " --msgbox " |
|||
Your RaspiBlitz is getting a bit too hot (${tempMAX}). |
|||
The system is getting slow when hot - thats not a NO GO but bad. |
|||
An upgrade of the Heat Management is recommended if possible. |
|||
|
|||
See upcomming screen on detailed info how to improve heat management. |
|||
|
|||
" 12 78 |
|||
fi |
|||
fi |
|||
|
|||
if [ ${showHeatImproveInfo} -gt 0 ]; then |
|||
|
|||
whiptail --backtitle "RaspiBlitz v${codeVersion}" --title " What todo on Heat Issues " --msgbox " |
|||
To improve on heat issues an upgrade of the casing is recommended. |
|||
Check if you have the latest casing listed in your shopping list. |
|||
The lastest casing is a big heat sink to prevent overheating. |
|||
If you have that one, check if its applied correctly to CPU. |
|||
Alternative casings should add some passive/active heat sinks. |
|||
In extreme cases consider some external fan helping out. |
|||
|
|||
Again a RaspiBlitz getting hot can be tolerated. But it is |
|||
slowing down your CPU and may reduce the lifetime of hardware. |
|||
|
|||
" 16 72 |
|||
|
|||
choice=$(whiptail --backtitle "RaspiBlitz v${codeVersion}" --title " Hardware Check " --menu "What todo about Heat Issues?" 12 60 6 \ |
|||
TESTAGAIN "Run Test again to be sure." \ |
|||
CONTINUE "I take the risk - continue." \ |
|||
SHUTDOWN "Shutdown to change hardware." 3>&1 1>&2 2>&3) |
|||
if [ ${#choice} -eq 0 ]; then |
|||
choice="CONTINUE" |
|||
fi |
|||
if [ "${choice}" == "TESTAGAIN" ]; then |
|||
echo "Shutting down ..." |
|||
sudo /home/admin/05hardwareTest.sh |
|||
exit 0 |
|||
elif [ "${choice}" == "SHUTDOWN" ]; then |
|||
echo "Shutting down ..." |
|||
sudo shutdown now |
|||
exit 1 |
|||
else |
|||
echo "OK continue .." |
|||
fi |
|||
|
|||
fi |
|||
|
|||
if [ ${showPowerImproveInfo} -eq 0 ] && [ ${showHeatImproveInfo} -eq 0 ]; then |
|||
dialog --backtitle "RaspiBlitz v${codeVersion}" --title " Hardware Check " --msgbox " |
|||
RaspiBlitz hardware setup looks good :) |
|||
Your are ready to continue - have fun. |
|||
|
|||
" 8 43 |
|||
fi |
@ -1,91 +1,218 @@ |
|||
#!/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'/') |
|||
# all system/service info gets detected by blitz.statusscan.sh |
|||
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')" |
|||
# when admin and no other error found run LND setup check |
|||
if [ "$USER" == "admin" ] && [ ${#lndErrorFull} -eq 0 ]; then |
|||
lndErrorFull=$(sudo /home/admin/config.scripts/lnd.check.sh basic-setup | grep "err=" | tail -1) |
|||
fi |
|||
|
|||
## TRY to get the actual progress height of scanning |
|||
# set follow up info different for LCD and ADMIN |
|||
adminStr="ssh admin@${localIP} ->Password A" |
|||
if [ "$USER" == "admin" ]; then |
|||
adminStr="Use CTRL+c to EXIT to Terminal" |
|||
fi |
|||
|
|||
# 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" |
|||
# bitcoin errors always first |
|||
if [ ${bitcoinActive} -eq 0 ] || [ ${#bitcoinErrorFull} -gt 0 ] || [ "${1}" == "blockchain-error" ]; then |
|||
|
|||
# 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 |
|||
#################### |
|||
# On Bitcoin Error |
|||
#################### |
|||
|
|||
# 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 |
|||
height=5 |
|||
width=43 |
|||
title="Blockchain Info" |
|||
if [ ${uptime} -gt 600 ] || [ "${1}" == "blockchain-error" ]; then |
|||
infoStr=" The ${network}d service is not running.\n Login for more details:" |
|||
if [ "$USER" == "admin" ]; then |
|||
clear |
|||
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 [ ${startcountBlockchain} -gt 1 ]; then |
|||
echo "${startcountBlockchain} RESTARTS DETECTED - ${network}d might be in a error loop" |
|||
cat /home/admin/systemd.blockchain.log | grep "ERROR" | tail -n -1 |
|||
echo |
|||
fi |
|||
if [ ${#bitcoinErrorFull} -gt 0 ]; then |
|||
echo "More Error Detail:" |
|||
echo ${bitcoinErrorFull} |
|||
echo |
|||
fi |
|||
echo "-> Use following command to debug: /home/admin/XXdebugLogs.sh" |
|||
echo "-> To force Main Menu run: /home/admin/00mainMenu.sh" |
|||
echo "-> To try restart: sudo shutdown -r now" |
|||
echo "" |
|||
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 with SSH for more details:" |
|||
if [ "$USER" == "admin" ]; then |
|||
infoStr=" The ${network}d service is starting:\n ${bitcoinErrorShort}\n Please wait up to 5min ..." |
|||
fi |
|||
fi |
|||
|
|||
# if no progress info |
|||
online=1 |
|||
if [ ${#item} -eq 0 ]; then |
|||
item="?" |
|||
# LND errors second |
|||
elif [ ${lndActive} -eq 0 ] || [ ${#lndErrorFull} -gt 0 ] || [ "${1}" == "lightning-error" ]; then |
|||
|
|||
# check if offline |
|||
# https://en.wikipedia.org/wiki/1.1.1.1 |
|||
online=$(ping 1.1.1.1 -c 1 -W 2 | grep -c '1 received') |
|||
fi |
|||
#################### |
|||
# On LND Error |
|||
#################### |
|||
|
|||
# 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) |
|||
|
|||
# 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.1.1.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.") |
|||
height=5 |
|||
width=43 |
|||
title="Lightning Info" |
|||
if [ ${uptime} -gt 600 ] || [ "${1}" == "lightning-error" ]; then |
|||
if [ ${#lndErrorShort} -gt 0 ]; then |
|||
height=6 |
|||
lndErrorShort=" ${lndErrorShort}\n" |
|||
fi |
|||
if [ ${lndActive} -eq 0 ]; then |
|||
infoStr=" The LND service is not running.\n${lndErrorShort} Login for more details:" |
|||
else |
|||
infoStr=" The LND service is running with error.\n${lndErrorShort} Login for more details:" |
|||
fi |
|||
if [ "$USER" == "admin" ]; then |
|||
clear |
|||
echo "" |
|||
echo "****************************************" |
|||
if [ ${lndActive} -eq 0 ]; then |
|||
echo "* The LND service is not running." |
|||
else |
|||
echo "* The LND service is running with error." |
|||
fi |
|||
echo "****************************************" |
|||
echo "If you just started some config/setup, this might be OK." |
|||
echo |
|||
if [ ${startcountLightning} -gt 1 ]; then |
|||
echo "${startcountLightning} RESTARTS DETECTED - LND might be in a error loop" |
|||
cat /home/admin/systemd.lightning.log | grep "ERROR" | tail -n -1 |
|||
fi |
|||
sudo journalctl -u lnd -b --no-pager -n14 | grep "lnd\[" |
|||
sudo /home/admin/config.scripts/lnd.check.sh basic-setup | grep "err=" |
|||
if [ ${#lndErrorFull} -gt 0 ]; then |
|||
echo "More Error Detail:" |
|||
echo ${lndErrorFull} |
|||
fi |
|||
echo |
|||
echo "-> Use following command to debug: /home/admin/XXdebugLogs.sh" |
|||
echo "-> To force Main Menu run: /home/admin/00mainMenu.sh" |
|||
echo "-> To try restart: sudo shutdown -r now" |
|||
echo "" |
|||
exit 1 |
|||
else |
|||
source <(sudo /home/admin/config.scripts/lnd.check.sh basic-setup) |
|||
if [ ${wallet} -eq 0 ] || [ ${macaroon} -eq 0 ] || [ ${config} -eq 0 ] || [ ${tls} -eq 0 ]; then |
|||
infoStr=" The LND service needs RE-SETUP.\n Login with SSH to continue:" |
|||
fi |
|||
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 |
|||
|
|||
# if LND wallet is locked |
|||
elif [ ${walletLocked} -gt 0 ]; then |
|||
|
|||
height=5 |
|||
width=43 |
|||
|
|||
if [ "${autoUnlock}" = "on" ]; then |
|||
title="Auto Unlock" |
|||
infoStr=" Waiting for Wallet Auto-Unlock.\n Please wait up to 5min ..." |
|||
else |
|||
title="Action Required" |
|||
infoStr=" LND WALLET IS LOCKED !!!\n" |
|||
if [ "${rtlWebinterface}" = "on" ]; then |
|||
height=6 |
|||
infoStr="${infoStr} Browser: http://${localIP}:3000\n PasswordB=login / PasswordC=unlock" |
|||
else |
|||
infoStr="${infoStr} Please use SSH to unlock:" |
|||
fi |
|||
if [ ${startcountLightning} -gt 1 ]; then |
|||
width=45 |
|||
height=$((height+3)) |
|||
infoStr=" LIGHTNING RESTARTED - login for details\n${infoStr}" |
|||
adminStr="${adminStr}\n or choose 'INFO' in main menu\n or type 'raspiblitz' on terminal" |
|||
fi |
|||
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") |
|||
|
|||
#################### |
|||
# Sync Progress |
|||
#################### |
|||
|
|||
# basic dialog info |
|||
height=6 |
|||
width=43 |
|||
title="Node is Syncing (${scriptRuntime})" |
|||
actionString="Please wait - this can take some time" |
|||
|
|||
# formatting BLOCKCHAIN SYNC PROGRESS |
|||
if [ ${#syncProgress} -eq 0 ]; then |
|||
if [ ${startcountBlockchain} -lt 2 ]; then |
|||
syncProgress="waiting" |
|||
else |
|||
syncProgress="${startcountBlockchain} restarts" |
|||
actionString="Login with SSH for more details:" |
|||
fi |
|||
elif [ ${#syncProgress} -lt 6 ]; then |
|||
syncProgress=" ${syncProgress} %" |
|||
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.") |
|||
syncProgress="${syncProgress} %" |
|||
fi |
|||
|
|||
|
|||
# formatting LIGHTNING SCAN PROGRESS |
|||
if [ ${#scanProgress} -eq 0 ]; then |
|||
|
|||
# in case of LND RPC is not ready yet |
|||
if [ ${scanTimestamp} -eq -2 ]; then |
|||
|
|||
scanProgress="prepare sync" |
|||
|
|||
# in case LND restarting >2 |
|||
elif [ ${startcountLightning} -gt 2 ]; then |
|||
|
|||
scanProgress="${startcountLightning} restarts" |
|||
actionString="Login with SSH for more details:" |
|||
|
|||
# check if a specific error can be identified for restarts |
|||
lndSetupErrorCount=$(sudo /home/admin/config.scripts/lnd.check.sh basic-setup | grep -c "err=") |
|||
if [ ${lndSetupErrorCount} -gt 0 ]; then |
|||
scanProgress="possible error" |
|||
fi |
|||
|
|||
# unkown cases |
|||
else |
|||
scanProgress="waiting" |
|||
fi |
|||
|
|||
elif [ ${#scanProgress} -lt 6 ]; then |
|||
scanProgress=" ${scanProgress} %" |
|||
else |
|||
scanProgress="${scanProgress} %" |
|||
fi |
|||
|
|||
# setting info string |
|||
infoStr=" Blockchain Progress : ${syncProgress}\n Lightning Progress : ${scanProgress}\n ${actionString}" |
|||
|
|||
fi |
|||
|
|||
# display progress to user |
|||
sleep 3 |
|||
dialog --title " ${network} / ${chain} " --backtitle "RaspiBlitz (${hostname})" --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,141 @@ |
|||
#!/bin/bash |
|||
|
|||
# get service port from argument |
|||
servicePort="10009" |
|||
if [ $# -gt 0 ]; then |
|||
if [ "$1" == "RPC" ]; then |
|||
echo "running RPC mode" |
|||
servicePort="10009" |
|||
fi |
|||
if [ "$1" == "REST" ]; then |
|||
echo "running REST mode" |
|||
servicePort="8080" |
|||
fi |
|||
fi |
|||
|
|||
# load raspiblitz config data |
|||
source /home/admin/raspiblitz.info |
|||
source /mnt/hdd/raspiblitz.conf |
|||
|
|||
# export go vars (if needed) |
|||
if [ ${#GOROOT} -eq 0 ]; then |
|||
export GOROOT=/usr/local/go |
|||
export PATH=$PATH:$GOROOT/bin |
|||
fi |
|||
if [ ${#GOPATH} -eq 0 ]; then |
|||
export GOPATH=/usr/local/gocode |
|||
export PATH=$PATH:$GOPATH/bin |
|||
fi |
|||
|
|||
# make sure go is installed |
|||
goVersion="1.11" |
|||
echo "### Check Framework: GO ###" |
|||
goInstalled=$(go version 2>/dev/null | grep -c 'go') |
|||
if [ ${goInstalled} -eq 0 ];then |
|||
echo "---> Installing GO" |
|||
wget https://storage.googleapis.com/golang/go${goVersion}.linux-armv6l.tar.gz |
|||
sudo tar -C /usr/local -xzf go${goVersion}.linux-armv6l.tar.gz |
|||
sudo rm *.gz |
|||
sudo mkdir /usr/local/gocode |
|||
sudo chmod 777 /usr/local/gocode |
|||
goInstalled=$(go version 2>/dev/null | grep -c 'go') |
|||
fi |
|||
if [ ${goInstalled} -eq 0 ];then |
|||
echo "FAIL: Was not able to install GO (needed to run LndConnect)" |
|||
sleep 4 |
|||
exit 1 |
|||
fi |
|||
|
|||
correctGoVersion=$(go version | grep -c "go${goVersion}") |
|||
if [ ${correctGoVersion} -eq 0 ]; then |
|||
echo "WARNING: You work with a untested version of GO - should be ${goVersion} .. trying to continue" |
|||
go version |
|||
sleep 6 |
|||
echo "" |
|||
fi |
|||
|
|||
# make sure qrcode-encoder in installed |
|||
echo "*** Setup ***" |
|||
echo "" |
|||
echo "Installing lndconnect. Please wait..." |
|||
echo "" |
|||
echo "Getting github.com/LN-Zap/lndconnect (please wait - can take several minutes) ..." |
|||
go get -d github.com/LN-Zap/lndconnect |
|||
cd $GOPATH/src/github.com/LN-Zap/lndconnect |
|||
echo "" |
|||
echo "Building github.com/LN-Zap/lndconnect ..." |
|||
make |
|||
cd |
|||
sleep 3 |
|||
|
|||
# default host to local IP and port |
|||
local=1 |
|||
localIP=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') |
|||
host="${localIP}" |
|||
port="${servicePort}" |
|||
|
|||
# change host to dynDNS if set |
|||
if [ ${#dynDomain} -gt 0 ]; then |
|||
local=0 |
|||
host="${dynDomain}" |
|||
echo "port ${servicePort} forwarding from dynDomain ${host}" |
|||
fi |
|||
|
|||
# check if local service port is forwarded |
|||
if [ ${#sshtunnel} -gt 0 ]; then |
|||
isForwarded=$(echo ${sshtunnel} | grep -c "${servicePort}<") |
|||
if [ ${isForwarded} -gt 0 ]; then |
|||
local=0 |
|||
host=$(echo $sshtunnel | cut -d '@' -f2 | cut -d ' ' -f1) |
|||
if [ "${servicePort}" == "10009" ]; then |
|||
port=$(echo $sshtunnel | awk '{split($0,a,"10009<"); print a[2]}' | cut -d ' ' -f1 | sed 's/[^0-9]//g') |
|||
elif [ "${servicePort}" == "8080" ]; then |
|||
port=$(echo $sshtunnel | awk '{split($0,a,"8080<"); print a[2]}' | cut -d ' ' -f1 | sed 's/[^0-9]//g') |
|||
fi |
|||
echo "port ${servicePort} forwarding from port ${port} from server ${host}" |
|||
else |
|||
echo "port ${servicePort} is not part of the ssh forwarding - keep default port ${servicePort}" |
|||
fi |
|||
fi |
|||
|
|||
# write qr code data to an image |
|||
lndconnect --host=${host} --port=${port} --image |
|||
|
|||
# display qr code image on LCD |
|||
./XXdisplayLCD.sh lndconnect-qr.png |
|||
|
|||
# show pairing info dialog |
|||
msg="" |
|||
if [ ${local} -eq 1 ]; then |
|||
msg="Make sure you are on the same local network.\n(WLAN same as LAN - use WIFI not cell network on phone).\n\n" |
|||
fi |
|||
msg="You should now see the pairing QR code on the RaspiBlitz LCD.\n\n${msg}When you start the App choose to connect to your own node.\n(DIY / Remote-Node / lndconnect)\n\nClick on the 'Scan QR' button. Scan the QR on the LCD and <continue> or <show QR code> to see it in this window." |
|||
whiptail --backtitle "Connecting Mobile Wallet" \ |
|||
--title "Pairing by QR code" \ |
|||
--yes-button "continue" \ |
|||
--no-button "show QR code" \ |
|||
--yesno "${msg}" 20 65 |
|||
if [ $? -eq 1 ]; then |
|||
lndconnect --host=${host} --port=${port} |
|||
echo "(To shrink QR code: OSX->CMD- / LINUX-> CTRL-) Press ENTER when finished." |
|||
read key |
|||
fi |
|||
|
|||
# clean up |
|||
./XXdisplayQRlcd_hide.sh |
|||
shred lndconnect-qr.png 2> /dev/null |
|||
rm -f lndconnect-qr.png 2> /dev/null |
|||
shred qr.txt 2> /dev/null |
|||
rm -f qr.txt 2> /dev/null |
|||
|
|||
echo "------------------------------" |
|||
echo "If the connection was not working:" |
|||
if [ ${#dynDomain} -gt 0 ]; then |
|||
echo "- Make sure that your router is forwarding port ${port} to the Raspiblitz with IP ${localIP}" |
|||
fi |
|||
if [ ${local} -eq 1 ]; then |
|||
echo "- Check that your WIFI devices can talk to the LAN devices on your router (deactivate IP isolation or guest mode)." |
|||
fi |
|||
echo "- check issues: https://github.com/LN-Zap/lndconnect/issues" |
|||
echo "- check issues: https://github.com/rootzoll/raspiblitz/issues" |
|||
echo "" |
@ -1,55 +1,65 @@ |
|||
#!/bin/bash |
|||
clear |
|||
|
|||
# load raspiblitz config data |
|||
source /home/admin/raspiblitz.info |
|||
source /mnt/hdd/raspiblitz.conf |
|||
|
|||
# make sure qrcode-encoder in installed |
|||
clear |
|||
echo "*** Setup ***" |
|||
sudo apt-get install qrencode -y |
|||
# default host to local IP & port 10009 |
|||
local=1 |
|||
host=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') |
|||
port="10009" |
|||
|
|||
# get local IP |
|||
myip=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p') |
|||
# change host to dynDNS if set |
|||
if [ ${#dynDomain} -gt 0 ]; then |
|||
local=0 |
|||
host="${dynDomain}" |
|||
echo "port 10009 forwarding from dynDomain ${host}" |
|||
fi |
|||
|
|||
# replace dyndomain if available |
|||
if [ ${#dynDomain} -gt 0 ]; then |
|||
myip="${dynDomain}" |
|||
# check if port 10009 is forwarded |
|||
if [ ${#sshtunnel} -gt 0 ]; then |
|||
isForwarded=$(echo ${sshtunnel} | grep -c "10009<") |
|||
if [ ${isForwarded} -gt 0 ]; then |
|||
local=0 |
|||
host=$(echo $sshtunnel | cut -d '@' -f2 | cut -d ' ' -f1) |
|||
port=$(echo $sshtunnel | awk '{split($0,a,"10009<"); print a[2]}' | cut -d ' ' -f1 | sed 's/[^0-9]//g') |
|||
echo "port 10009 forwarding from port ${port} from server ${host}" |
|||
else |
|||
echo "port 10009 is not part of the ssh forwarding - keep default port 10009" |
|||
fi |
|||
fi |
|||
|
|||
clear |
|||
echo "******************************" |
|||
echo "Connect Shango Mobile Wallet" |
|||
echo "******************************" |
|||
echo "" |
|||
echo "GETTING THE APP" |
|||
echo "At the moment this app is in public beta testing:" |
|||
echo "iOS: Read https://testflight.apple.com/join/WwCjFnS8 (open on device)" |
|||
echo "Android: https://play.google.com/apps/testing/com.shango (open on device)" |
|||
echo "" |
|||
echo "*** STEP 1 ***" |
|||
if [ ${#dynDomain} -eq 0 ]; then |
|||
echo "Once you have the app is running make sure you are on the same local network (WLAN same as LAN)." |
|||
fi |
|||
echo "On Setup Step 'Choose LND Server Type' connect to 'DIY SELF HOSTED'" |
|||
echo "(Or in the App go to --> 'Settings' > 'Connect to your LND Server')" |
|||
echo "There you see three 3 form fields to fill out. Skip those and go right to the buttons below." |
|||
echo "" |
|||
echo "Click on the 'Scan QR' button" |
|||
echo "Make the this terminal as big as possible - fullscreen would be best." |
|||
echo "Then PRESS ENTER here in the terminal to generare the QR code and scan it with the app." |
|||
read key |
|||
# write qr code data to text file |
|||
echo -e "${host}:${port},\n$(xxd -p -c2000 ./.lnd/data/chain/${network}/${chain}net/admin.macaroon)," > qr.txt |
|||
|
|||
clear |
|||
echo "*** STEP 2 : SCAN MACAROON (make whole QR code fill camera) ***" |
|||
#echo -e "${myip}:10009,\n$(xxd -p -c2000 ~/.lnd/data/chain/${network}/${chain}net/admin.macaroon)," > qr.txt && qrencode -t ANSIUTF8 < qr.txt |
|||
echo -e "${myip}:10009,\n$(xxd -p -c2000 ./.lnd/data/chain/${network}/${chain}net/admin.macaroon)," > qr.txt && qrencode -t ANSI256 < qr.txt |
|||
echo "(To shrink QR code: OSX->CMD- / LINUX-> CTRL-) Press ENTER when finished." |
|||
read key |
|||
shred qr.txt |
|||
# display qr code on LCD |
|||
./XXdisplayQRlcd.sh |
|||
|
|||
# show pairing info |
|||
clear |
|||
echo "Now press 'Connect' within the Shango Wallet." |
|||
echo "If its not working - check issues on GitHub:" |
|||
echo "https://github.com/neogeno/shango-lightning-wallet/issues" |
|||
echo "" |
|||
msg="" |
|||
if [ ${local} -eq 1 ]; then |
|||
msg="Once you have the app running make sure you are on the same local network (WLAN same as LAN).\n\n" |
|||
fi |
|||
msg="You should now see the pairing QR code on the RaspiBlitz LCD.\n\n${msg}On Setup Step 'Choose LND Server Type' connect to 'DIY SELF HOSTED'\n\n(Or in the App go to --> 'Settings' > 'Connect to your LND Server') \n\nThere you see three 3 form fields to fill out. Skip those and go right to the buttons below.\n\nClick on the 'Scan QR' button. Scan the QR on the LCD and <continue> or <show QR code> to see it in this window." |
|||
whiptail --backtitle "Connecting Shango Mobile Wallet" \ |
|||
--title "Setup Shango Step 1" \ |
|||
--yes-button "continue" \ |
|||
--no-button "show QR code" \ |
|||
--yesno "${msg}" 20 70 |
|||
if [ $? -eq 1 ]; then |
|||
/home/admin/XXdisplayQR.sh |
|||
fi |
|||
|
|||
# clean up |
|||
./XXdisplayQRlcd_hide.sh |
|||
shred qr.png 2> /dev/null |
|||
rm -f qr.png 2> /dev/null |
|||
shred qr.txt 2> /dev/null |
|||
rm -f qr.txt 2> /dev/null |
|||
|
|||
# follow up dialog |
|||
whiptail --backtitle "Connecting Shango Mobile Wallet" \ |
|||
--title "Press Connect on Shango" \ |
|||
--msgbox "Now press 'Connect' within the Shango Wallet.\n\nIf its not working - check issues on GitHub:\n\nhttps://github.com/neogeno/shango-lightning-wallet/issues" 15 65 |
@ -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,4 @@ |
|||
# Installs package if not yet installed |
|||
if [ $(sudo dpkg-query -l | grep "ii $1" | wc -l) = 0 ]; then |
|||
sudo apt-get install $1 -y > /dev/null |
|||
fi |
@ -0,0 +1,37 @@ |
|||
#!/bin/bash |
|||
|
|||
# Check if lnd is synced to chain and channels are open |
|||
# If it isn't, wait until it is |
|||
# exits with 1 if it isn't. |
|||
|
|||
network=$1 |
|||
chain=$2 |
|||
|
|||
# check if chain is in sync |
|||
cmdChainInSync="lncli --chain=${network} --network=${chain}net getinfo | grep '"synced_to_chain": true' -c" |
|||
chainInSync=${cmdChainInSync} |
|||
while [ $chainInSync -eq 0 ]; do |
|||
dialog --title "Fail: not in sync" \ |
|||
--ok-label "Try now" \ |
|||
--cancel-label "Give up" \ |
|||
--pause "\n\n'lncli getinfo' shows 'synced_to_chain': false\n\nTry again in a few seconds." 15 60 5 |
|||
|
|||
if [ $? -gt 0 ]; then |
|||
exit 1 |
|||
fi |
|||
chainInSync=${cmdChainInSync} |
|||
done |
|||
|
|||
# check number of connected peers |
|||
echo "check for open channels" |
|||
openChannels=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net listchannels 2>/dev/null | grep chan_id -c) |
|||
if [ ${openChannels} -eq 0 ]; then |
|||
echo "" |
|||
echo "!!!!!!!!!!!!!!!!!!!" |
|||
echo "FAIL - You have NO ESTABLISHED CHANNELS .. open a channel first." |
|||
echo "!!!!!!!!!!!!!!!!!!!" |
|||
echo "" |
|||
exit 1 |
|||
fi |
|||
|
|||
exit 0 |
@ -0,0 +1,8 @@ |
|||
#!/bin/bash |
|||
|
|||
# Display an image on the LCD |
|||
|
|||
# make sure fbi is installed |
|||
./XXaptInstall.sh fbi |
|||
|
|||
sudo fbi -a -T 1 -d /dev/fb1 --noverbose $1 2> /dev/null |
@ -0,0 +1,24 @@ |
|||
#!/bin/bash |
|||
|
|||
# Display a QR code for the string in qr.txt |
|||
|
|||
# make sure qrcode-encode and fbi are installed |
|||
#clear |
|||
#echo "*** Setup ***" |
|||
|
|||
echo 50 | whiptail --title "Installing" --backtitle "QR-Code" --gauge "please wait" 4 40 100 |
|||
./XXaptInstall.sh qrencode |
|||
echo 90 | whiptail --title "Installing" --backtitle "QR-Code" --gauge "please wait" 4 40 100 |
|||
./XXaptInstall.sh fbi |
|||
|
|||
whiptail --title "Get ready" --backtitle "QR-Code in Terminal Window" \ |
|||
--msgbox "Make this terminal window as large as possible - fullscreen would be best. \n\nThe QR-Code might be too large for your display. In that case, shrink the letters by pressing the keys Ctrl and Minus (or Cmd and Minus if you are on a Mac) \n\nPRESS ENTER when you are ready to see the QR-code." 20 60 |
|||
|
|||
clear |
|||
qrencode -t ANSI256 < /home/admin/qr.txt |
|||
shred /home/admin/qr.txt |
|||
rm -f /home/admin/qr.txt |
|||
echo "(To shrink QR code: macOS press CMD- / LINUX press CTRL-) Press ENTER when finished." |
|||
read key |
|||
|
|||
clear |
@ -0,0 +1,10 @@ |
|||
#!/bin/bash |
|||
|
|||
# Display a QR code for the string in qr.txt |
|||
|
|||
# make sure qrcode-encode and fbi are installed |
|||
./XXaptInstall.sh qrencode |
|||
./XXaptInstall.sh fbi |
|||
|
|||
qrencode -l L -o /home/admin/qr.png < /home/admin/qr.txt > /dev/null |
|||
sudo fbi -a -T 1 -d /dev/fb1 --noverbose /home/admin/qr.png 2> /dev/null |
@ -0,0 +1,4 @@ |
|||
#!/bin/bash |
|||
sudo killall -3 fbi |
|||
shred /home/admin/qr.png 2> /dev/null |
|||
rm -f /home/admin/qr.png 2> /dev/null |
@ -1,2 +1,2 @@ |
|||
# RaspiBlitz Version - always [main].[sub] |
|||
codeVersion="1.1" |
|||
codeVersion="1.2" |
After Width: | Height: | Size: 47 KiB |
@ -0,0 +1,139 @@ |
|||
#!/bin/bash |
|||
|
|||
# command info |
|||
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then |
|||
echo "STILL EXPERIMENTAL - NOT FINISHED" |
|||
echo "managing additional data storage" |
|||
echo "blitz.datadrive.sh [on|off]" |
|||
echo "exits on 0 = needs reboot" |
|||
exit 1 |
|||
fi |
|||
|
|||
# check if sudo |
|||
if [ "$EUID" -ne 0 ] |
|||
then echo "Please run as root (with sudo)" |
|||
exit 1 |
|||
fi |
|||
|
|||
# update install sources |
|||
echo "make sure BTRFS is installed ..." |
|||
sudo apt-get install -y btrfs-tools |
|||
echo "" |
|||
|
|||
# check on/off state |
|||
dataStorageNotAvailableYet=$(sudo btrfs filesystem df /mnt/data 2>&1 | grep -c "ERROR: not a btrfs filesystem") |
|||
if [ "$1" = "1" ] || [ "$1" = "on" ]; then |
|||
echo "Trying to switch additional data storage on ..." |
|||
if [ ${dataStorageNotAvailableYet} -eq 0 ]; then |
|||
echo "FAIL -> data storage is already on" |
|||
exit 1 |
|||
fi |
|||
elif [ "$1" = "0" ] || [ "$1" = "off" ]; then |
|||
echo "Trying to switch additional data storage off ..." |
|||
if [ ${dataStorageNotAvailableYet} -eq 1 ]; then |
|||
echo "FAIL -> data storage is already off" |
|||
exit 1 |
|||
fi |
|||
else |
|||
echo "FAIL -> Parameter '${$1}' not known." |
|||
exit 1 |
|||
fi |
|||
|
|||
################### |
|||
# SWITCH ON |
|||
################### |
|||
|
|||
if [ "$1" = "1" ] || [ "$1" = "on" ]; then |
|||
|
|||
# detect the two usb drives |
|||
echo "Detecting two USB sticks/drives with same size ..." |
|||
lsblk -o NAME | grep "^sd" | while read -r test1 ; do |
|||
size1=$(lsblk -o NAME,SIZE -b | grep "^${test1}" | awk '$1=$1' | cut -d " " -f 2) |
|||
echo "Checking : ${test1} size(${size1})" |
|||
lsblk -o NAME | grep "^sd" | grep -v "${test1}" | while read -r test2 ; do |
|||
size2=$(lsblk -o NAME,SIZE -b | grep "^${test2}" | awk '$1=$1' | cut -d " " -f 2) |
|||
if [ "${size1}" = "${size2}" ]; then |
|||
echo " MATCHING ${test2} size(${size2})" |
|||
echo "${test1}" > .dev1.tmp |
|||
echo "${test2}" > .dev2.tmp |
|||
else |
|||
echo " different ${test2} size(${size2})" |
|||
fi |
|||
done |
|||
done |
|||
dev1=$(cat .dev1.tmp) |
|||
dev2=$(cat .dev2.tmp) |
|||
rm -f .dev1.tmp |
|||
rm -f .dev2.tmp |
|||
echo "RESULTS:" |
|||
echo "dev1(${dev1})" |
|||
echo "dev2(${dev2})" |
|||
echo "" |
|||
|
|||
# check that results are available |
|||
if [ ${#dev1} -eq 0 ] || [ ${#dev2} -eq 0 ]; then |
|||
echo "!! FAIL -> was not able to detect two devices with the same size" |
|||
exit 1 |
|||
fi |
|||
|
|||
# check size (at least 4GB minus some tolerance) |
|||
size=$(lsblk -o NAME,SIZE -b | grep "^${dev1}" | awk '$1=$1' | cut -d " " -f 2) |
|||
if [ ${size} -lt 3500000000 ]; then |
|||
echo "!! FAIL -> too small - additional storage needs to be bigger than 4GB" |
|||
exit 1 |
|||
fi |
|||
|
|||
# check if devices are containing old data |
|||
echo "Analysing Drives ..." |
|||
nameDev1=$(lsblk -o NAME,LABEL | grep "^${dev1}" | awk '$1=$1' | cut -d " " -f 2) |
|||
nameDev2=$(lsblk -o NAME,LABEL | grep "^${dev2}" | awk '$1=$1' | cut -d " " -f 2) |
|||
if [ "${nameDev1}" = "DATASTORE" ] || [ "${nameDev2}" = "DATASTORE" ]; then |
|||
# TODO: once implemented -> also make sure that dev1 is named "DATASTORE" and if 2nd is other -> format and add as raid |
|||
echo "!! NOT IMPLEMENTED YET -> devices seem contain old data, because name is 'DATASTORE'" |
|||
echo "if you dont care about that data: format devices devices on other computer with FAT(32) named TEST" |
|||
exit 1 |
|||
fi |
|||
echo "OK drives dont contain old data." |
|||
echo "" |
|||
|
|||
# format first drive |
|||
echo "Formatting /dev/${dev1} with BTRFS ..." |
|||
sudo mkfs.btrfs -L DATASTORE -f /dev/${dev1} |
|||
echo "OK" |
|||
echo "" |
|||
|
|||
# mount the BTRFS drive |
|||
echo "Mounting under /mnt/data ..." |
|||
sudo mkdir -p /mnt/data |
|||
sudo mount /dev/${dev1} /mnt/data |
|||
echo "OK" |
|||
echo "" |
|||
|
|||
# adding the second device |
|||
echo "Adding the second device as RAID1 .." |
|||
sudo btrfs device add -f /dev/${dev2} /mnt/data |
|||
sudo btrfs filesystem balance start -dconvert=raid1 -mconvert=raid1 /mnt/data |
|||
echo "" |
|||
exit 0 |
|||
|
|||
# adding the second device |
|||
uuid=$(sudo btrfs filesystem show /mnt/data | grep "uuid:" | awk '$1=$1' | cut -d " " -f 4) |
|||
|
|||
fi |
|||
|
|||
################### |
|||
# SWITCH OFF |
|||
################### |
|||
|
|||
if [ "$1" = "0" ] || [ "$1" = "off" ]; then |
|||
|
|||
echo "TODO -> Turn off" |
|||
|
|||
sudo btrfs filesystem show /mnt/data |
|||
sudo btrfs filesystem df /mnt/data |
|||
|
|||
sudo umount /mnt/data |
|||
|
|||
exit 0 |
|||
|
|||
fi |
@ -0,0 +1,246 @@ |
|||
#!/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}" |
|||
|
|||
# count restarts of bitcoind/litecoind |
|||
startcountBlockchain=$(cat /home/admin/systemd.blockchain.log 2>/dev/null | grep -c "STARTED") |
|||
echo "startcountBlockchain=${startcountBlockchain}" |
|||
|
|||
# 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 |
|||
bitcoinErrorShort=$(echo ${bitcoinError/error*:/} | sed 's/[^a-zA-Z0-9 ]//g') |
|||
echo "bitcoinErrorShort='${bitcoinErrorShort}'" |
|||
bitcoinErrorFull=$(echo ${bitcoinError} | tr -d "'") |
|||
echo "bitcoinErrorFull='${bitcoinErrorFull}'" |
|||
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 |
|||
else |
|||
|
|||
# find out why Bitcoin not running |
|||
|
|||
pathAdd="" |
|||
if [ "${chain}" = "test" ]; then |
|||
pathAdd="/testnet3" |
|||
fi |
|||
|
|||
#### POSSIBLE/SOFT PROBLEMS |
|||
# place here in future analysis |
|||
|
|||
#### HARD PROBLEMS |
|||
|
|||
# LOW DISK SPACE |
|||
lowDiskSpace=$(sudo tail -n 100 /mnt/hdd/${network}${pathAdd}/debug.log 2>/dev/null | grep -c "Error: Disk space is low!") |
|||
if [ ${lowDiskSpace} -gt 0 ]; then |
|||
bitcoinErrorShort="HDD DISK SPACE LOW" |
|||
bitcoinErrorFull="HDD DISK SPACE LOW - check what data you can delete on HDD and restart" |
|||
fi |
|||
|
|||
#### GENERIC ERROR FIND |
|||
|
|||
# if still no error identified - search logs for generic error (after 4min uptime) |
|||
if [ ${#bitcoinErrorShort} -eq 0 ] && [ ${uptime} -gt 240 ]; then |
|||
bitcoinErrorFull=$(sudo tail -n 100 /mnt/hdd/${network}${pathAdd}/debug.log 2>/dev/null | grep -c "Error:" | tail -1 | tr -d "'") |
|||
if [ ${#bitcoinErrorFull} -gt 0 ]; then |
|||
bitcoinErrorShort="Error found in Logs" |
|||
fi |
|||
fi |
|||
|
|||
# output error if found |
|||
if [ ${#bitcoinErrorShort} -gt 0 ]; then |
|||
echo "bitcoinErrorShort='${bitcoinErrorShort}'" |
|||
echo "bitcoinErrorFull='${bitcoinErrorFull}'" |
|||
/home/admin/config.scripts/blitz.systemd.sh log blockchain "ERROR: ${bitcoinErrorShort}" |
|||
fi |
|||
|
|||
fi |
|||
|
|||
# count restarts of bitcoind/litecoind |
|||
startcountLightning=$(cat /home/admin/systemd.lightning.log 2>/dev/null | grep -c "STARTED") |
|||
echo "startcountLightning=${startcountLightning}" |
|||
|
|||
# is LND running |
|||
lndRunning=$(systemctl status lnd.service 2>/dev/null | grep -c running) |
|||
echo "lndActive=${lndRunning}" |
|||
|
|||
if [ ${lndRunning} -eq 1 ]; then |
|||
|
|||
# get LND info |
|||
lndRPCReady=1 |
|||
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) |
|||
lndErrorShort='' |
|||
#rm /mnt/hdd/temp/.lnd.error 2>/dev/null |
|||
|
|||
if [ ${#lndErrorFull} -gt 0 ]; then |
|||
|
|||
# flag if error could be resoled by analysis |
|||
errorResolved=0 |
|||
|
|||
### analyse LND logs since start |
|||
|
|||
# find a the line number in logs of start of LND |
|||
# just do this on error case to save on processing memory |
|||
lndStartLineNumber=$(sudo cat /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2>/dev/null | grep -in "LTND: Active chain:" | tail -1 | cut -d ":" -f1) |
|||
|
|||
# get logs of last LND start |
|||
lndLogsAfterStart=$(sudo tail --lines=+${lndStartLineNumber} /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2>/dev/null) |
|||
|
|||
# check RPC server ready (can take some time after wallet was unlocked) |
|||
lndRPCReady=$(echo "${lndLogsAfterStart}" | grep -c "RPCS: RPC server listening on") |
|||
echo "lndRPCReady=${lndRPCReady}" |
|||
|
|||
# check wallet if wallet was opened (after correct password) |
|||
lndWalletOpened=$(echo "${lndLogsAfterStart}" | grep -c "LNWL: Opened wallet") |
|||
echo "walletOpened=${lndWalletOpened}" |
|||
|
|||
# check wallet if wallet is ready (can take some time after wallet was opened) |
|||
lndWalletReady=$(echo "${lndLogsAfterStart}" | grep -c "LTND: LightningWallet opened") |
|||
echo "walletReady=${lndWalletReady}" |
|||
|
|||
### check errors |
|||
|
|||
# scan error for walletLocked as common error |
|||
locked=$(echo ${lndErrorFull} | grep -c 'Wallet is encrypted') |
|||
if [ ${locked} -gt 0 ]; then |
|||
echo "walletLocked=1" |
|||
else |
|||
echo "walletLocked=0" |
|||
|
|||
rpcNotWorking=$(echo ${lndErrorFull} | grep -c 'connection refused') |
|||
if [ ${rpcNotWorking} -gt 0 ]; then |
|||
|
|||
# this can happen for a long time when LND is starting fresh sync |
|||
# on first startup - check if logs since start signaled RPC ready before |
|||
if [ ${lndRPCReady} -eq 0 ]; then |
|||
# nullify error - this is normal |
|||
lndErrorFull="" |
|||
errorResolved=1 |
|||
# oputput basic data because no error |
|||
echo "# LND RPC is still warming up - no scan progress: prepare scan" |
|||
echo "scanTimestamp=-2" |
|||
echo "syncedToChain=0" |
|||
else |
|||
echo "# LND RPC was started - some other problem going on" |
|||
lndErrorShort='LND RPC not responding' |
|||
lndErrorFull=$(echo "LND RPC is not responding. LND may have problems starting up. Check logs, config files and systemd service. Org-Error: ${lndErrorFull}" | tr -d "'") |
|||
fi |
|||
fi |
|||
|
|||
# if not known error and not resolved before - keep generic |
|||
if [ ${#lndErrorShort} -eq 0 ] && [ ${errorResolved} -eq 0 ]; then |
|||
lndErrorShort='Unkown Error - see logs' |
|||
lndErrorFull=$(echo ${lndErrorFull} | tr -d "'") |
|||
fi |
|||
|
|||
# write to results |
|||
if [ ${#lndErrorFull} -gt 0 ]; then |
|||
echo "lndErrorShort='${lndErrorShort}'" |
|||
echo "lndErrorFull='${lndErrorFull}'" |
|||
/home/admin/config.scripts/blitz.systemd.sh log lightning "ERROR: ${lndErrorFull}" |
|||
fi |
|||
|
|||
fi |
|||
|
|||
else |
|||
|
|||
# check if wallet is locked |
|||
locked=$(echo ${lndinfo} | grep -c unlock) |
|||
if [ ${locked} -gt 0 ]; then |
|||
echo "walletLocked=1" |
|||
else |
|||
echo "walletLocked=0" |
|||
fi |
|||
|
|||
# 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') |
|||
if [ ${#scanTimestamp} -gt 0 ]; then |
|||
echo "scanTimestamp=${scanTimestamp}" |
|||
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}" |
|||
else |
|||
echo "# was not able to parse 'best_header_timestamp' from: lncli getinfo" |
|||
echo "scanTimestamp=-1" |
|||
fi |
|||
|
|||
fi |
|||
|
|||
# output if lnd-RPC is ready |
|||
echo "lndRPCReady=${lndRPCReady}" |
|||
|
|||
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,104 @@ |
|||
#!/bin/bash |
|||
|
|||
# command info |
|||
if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then |
|||
echo "run stress test to measure heat and voltage" |
|||
echo "blitz.stresstest.sh [?filenameForReport]" |
|||
exit 1 |
|||
fi |
|||
|
|||
# Based on https://github.com/bamarni/pi64/issues/4#issuecomment-292707581 |
|||
# sysbench manual: http://imysql.com/wp-content/uploads/2014/10/sysbench-manual.pdf |
|||
|
|||
# get parameter |
|||
filenameForReport=$1 |
|||
|
|||
# check if bechmarking tool is installed |
|||
sysbenchInstalled=$(sysbench --version 2>/dev/null | grep -c 'sysbench 0.') |
|||
if [ ${sysbenchInstalled} -eq 0 ];then |
|||
sudo apt install -y sysbench |
|||
fi |
|||
|
|||
# do debug outputs to the STDERR - so that the STDOUT is just the results in the end |
|||
echo "RaspiBlitz Hardwaretest v0.1" >&2 |
|||
echo "Starting sysbench to run for 60 seconds (--max-time=60 --cpu-max-prime=10000)" >&2 |
|||
|
|||
# result values |
|||
powerWARN=0 |
|||
powerFAIL=0 |
|||
powerMIN=9999999 |
|||
tempWARN=0 |
|||
tempFAIL=0 |
|||
tempMAX=0 |
|||
|
|||
# starting bench mark |
|||
sysbench --max-time=60 --test=cpu --cpu-max-prime=10000 --num-threads=4 run 1>/dev/null 2>&1 & |
|||
|
|||
# keep monitoring in the background |
|||
Maxfreq=$(( $(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq) -15 )) |
|||
for (( n=0; n<15; ++n )); do |
|||
|
|||
# make measurements |
|||
Temp=$(sudo vcgencmd measure_temp | cut -f2 -d=) |
|||
RealClockspeed=$(sudo vcgencmd measure_clock arm | awk -F"=" '{printf ("%0.0f",$2/1000000); }' ) |
|||
SysFSClockspeed=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq) |
|||
CoreVoltage=$(sudo vcgencmd measure_volts | cut -f2 -d= | sed 's/000//') |
|||
|
|||
# debug output |
|||
if [ ${RealClockspeed} -ge ${Maxfreq} ]; then |
|||
echo "${Temp}$(printf "%5s" ${SysFSClockspeed}) MHz ${CoreVoltage}" >&2 |
|||
else |
|||
echo "${Temp}$(printf "%5s" ${RealClockspeed})/$(printf "%4s" ${SysFSClockspeed}) MHz ${CoreVoltage}" >&2 |
|||
fi |
|||
|
|||
# analyse Voltage |
|||
voltFloat=$(echo "${CoreVoltage/V/}*1000000" | bc) |
|||
voltInt=${voltFloat/.*} |
|||
#echo "V -> ${voltFloat}/${voltInt}" |
|||
if [ ${voltInt} -lt 1200100 ] && [ ${powerWARN} -gt 1 ]; then |
|||
((powerFAIL=powerFAIL+1)) |
|||
echo "--> Power CRITICAL detected" >&2 |
|||
fi |
|||
if [ ${voltInt} -lt 1250000 ]; then |
|||
((powerWARN=powerWARN+1)) |
|||
echo "--> Power WARN detected" >&2 |
|||
fi |
|||
if [ ${voltInt} -lt ${powerMIN} ]; then |
|||
powerMIN=${voltInt} |
|||
fi |
|||
|
|||
# analyse Temp |
|||
tempFloat=$(echo "${Temp/\'C/}*100" | bc) |
|||
tempInt=${tempFloat/.*} |
|||
#echo "T -> ${tempFloat}/${tempInt}" |
|||
if [ ${tempInt} -gt 6999 ]; then |
|||
((tempFAIL=tempFAIL+1)) |
|||
echo "--> Temp CRITICAL detected" >&2 |
|||
fi |
|||
if [ ${tempInt} -gt 6500 ]; then |
|||
((tempWARN=tempWARN+1)) |
|||
echo "--> Temp WARN detected" >&2 |
|||
fi |
|||
if [ ${tempInt} -gt ${tempMAX} ]; then |
|||
tempMAX=${tempInt} |
|||
fi |
|||
|
|||
sleep 5 |
|||
done |
|||
|
|||
if [ ${#filenameForReport} -eq 0 ]; then |
|||
echo "powerFAIL=${powerFAIL}" |
|||
echo "powerWARN=${powerWARN}" |
|||
echo "powerMIN='${powerMIN} microVolt'" |
|||
echo "tempFAIL=${tempFAIL}" |
|||
echo "tempWARN=${tempWARN}" |
|||
echo "tempMAX='${tempMAX} centiGrad'" |
|||
else |
|||
echo "powerFAIL=${powerFAIL}" >${filenameForReport} |
|||
echo "powerWARN=${powerWARN}" >>${filenameForReport} |
|||
echo "powerMIN='${powerMIN} microVolt'" >>${filenameForReport} |
|||
echo "tempFAIL=${tempFAIL}" >>${filenameForReport} |
|||
echo "tempWARN=${tempWARN}" >>${filenameForReport} |
|||
echo "tempMAX='${tempMAX} centiGrad'" >>${filenameForReport} |
|||
sudo chmod 744 ${filenameForReport} |
|||
fi |
@ -0,0 +1,19 @@ |
|||
#!/bin/bash |
|||
|
|||
# command info |
|||
if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then |
|||
echo "additional systemd services" |
|||
echo "blitz.systemd.sh log blockchain STARTED" |
|||
echo "blitz.systemd.sh log loghtning STARTED" |
|||
exit 1 |
|||
fi |
|||
|
|||
# check parameter |
|||
if [ "${1}" != "log" ]; then |
|||
echo "# FAIL: unkown parameter" |
|||
fi |
|||
|
|||
# writing log file entry |
|||
logFile="/home/admin/systemd.${2}.log" |
|||
echo "$(date +%s) ${3}" >> ${logFile} |
|||
echo "# OK: log '${3}' written to ${logFile}" |
@ -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 set a the DNS server that should be used" |
|||
echo "internet.dns.sh [DNS-SERVER]" |
|||
exit 1 |
|||
fi |
|||
|
|||
# 1. parameter |
|||
DNSSERVER="$1" |
|||
echo "The DNS server you want to set is: ${DNSSERVER}" |
|||
|
|||
# checking for IP address |
|||
if [[ $DNSSERVER =~ ^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$ ]]; then |
|||
echo "OK IPv6" |
|||
elif [[ $DNSSERVER =~ ^([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$ ]]; then |
|||
echo "OK IPv4" |
|||
else |
|||
echo "FAIL - not an IPv4 or IPv6 address" |
|||
exit 1 |
|||
fi |
|||
echo "" |
|||
|
|||
# setting DNS address |
|||
echo "Setting DNS server in /etc/dhcpcd.conf ..." |
|||
sudo sed -i "s/^static domain_name_servers=.*/static domain_name_servers=${DNSSERVER}/g" /etc/dhcpcd.conf |
|||
echo "OK" |
|||
echo "" |
|||
|
|||
# make sure entry in raspiblitz.conf exists |
|||
source /mnt/hdd/raspiblitz.conf |
|||
if [ ${#dnsServer} -eq 0 ]; then |
|||
echo "Adding value to /mnt/hdd/raspiblitz.conf" |
|||
echo "dnsServer=${DNSSERVER}" >> /mnt/hdd/raspiblitz.conf |
|||
else |
|||
echo "Updating value in /mnt/hdd/raspiblitz.conf" |
|||
sudo sed -i "s/^dnsServer=.*/dnsServer=${DNSSERVER}/g" /mnt/hdd/raspiblitz.conf |
|||
fi |
|||
echo "OK" |
|||
echo "" |
|||
|
|||
echo "DNS Server is set - reboot needed before active" |
@ -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 "# -> return pubkey (and will init if needed):" |
|||
echo "# internet.sshpubkey.sh get" |
|||
echo "# -> 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 |
|||
|
|||
|
@ -0,0 +1,245 @@ |
|||
#!/usr/bin/python3 |
|||
|
|||
import sys, subprocess, re |
|||
from pathlib import Path |
|||
|
|||
# IDEA: At the momemt its just Reverse-SSh Tunnels thats why [INTERNAL-PORT]<[EXTERNAL-PORT] |
|||
# For the future also just local ssh tunnels could be added with [INTERNAL-PORT]-[EXTERNAL-PORT] |
|||
# for the use case when a server wants to use a RaspiBlitz behind a NAT as Lightning backend |
|||
|
|||
# display config script info |
|||
if len(sys.argv) <= 1 or sys.argv[1] == "-h" or sys.argv[1] == "help": |
|||
print("forward ports from another server to raspiblitz with reverse SSH tunnel") |
|||
print("internet.sshtunnel.py [on|off|restore] [USER]@[SERVER] \"[INTERNAL-PORT]<[EXTERNAL-PORT]\"") |
|||
print("note that [INTERNAL-PORT]<[EXTERNAL-PORT] can one or multiple forwardings") |
|||
sys.exit(1) |
|||
|
|||
# |
|||
# CONSTANTS |
|||
# sudo journalctl -f -u autossh-tunnel |
|||
# |
|||
|
|||
SERVICENAME="autossh-tunnel.service" |
|||
SERVICEFILE="/etc/systemd/system/"+SERVICENAME |
|||
SERVICETEMPLATE="""# see config script internet.sshtunnel.py |
|||
[Unit] |
|||
Description=AutoSSH tunnel service |
|||
After=network.target |
|||
|
|||
[Service] |
|||
User=root |
|||
Group=root |
|||
Environment="AUTOSSH_GATETIME=0" |
|||
ExecStart=/usr/bin/autossh -M 0 -N -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" [PLACEHOLDER] |
|||
StandardOutput=journal |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
|||
""" |
|||
|
|||
# get LND port form lnd.conf |
|||
LNDPORT = subprocess.getoutput("sudo cat /mnt/hdd/lnd/lnd.conf | grep '^listen=*' | cut -f2 -d':'") |
|||
if len(LNDPORT) == 0: |
|||
LNDPORT="9735" |
|||
|
|||
|
|||
|
|||
# |
|||
# RESTORE = SWITCHING ON with restore flag on |
|||
# on restore other external scripts dont need calling |
|||
# |
|||
|
|||
forwardingLND = False |
|||
restoringOnUpdate = False |
|||
if sys.argv[1] == "restore": |
|||
print("internet.sshtunnel.py -> running with restore flag") |
|||
sys.argv[1] = "on" |
|||
restoringOnUpdate = True |
|||
|
|||
# |
|||
# SWITCHING ON |
|||
# |
|||
|
|||
if sys.argv[1] == "on": |
|||
|
|||
# check if already running |
|||
isRunning = subprocess.getoutput("sudo systemctl --no-pager | grep -c '%s'" % (SERVICENAME)) |
|||
if int(isRunning) > 0: |
|||
print("SSH TUNNEL SERVICE IS RUNNING - run 'internet.sshtunnel.py off' first to set new tunnel") |
|||
sys.exit(1) |
|||
|
|||
# check server address |
|||
if len(sys.argv) < 3: |
|||
print("[USER]@[SERVER] missing - use 'internet.sshtunnel.py -h' for help") |
|||
sys.exit(1) |
|||
if sys.argv[2].count("@") != 1: |
|||
print("[USER]@[SERVER] wrong - use 'internet.sshtunnel.py -h' for help") |
|||
sys.exit(1) |
|||
ssh_server = sys.argv[2] |
|||
|
|||
# genenate additional parameter for autossh (forwarding ports) |
|||
if len(sys.argv) < 4: |
|||
print("[INTERNAL-PORT]<[EXTERNAL-PORT] missing") |
|||
sys.exit(1) |
|||
ssh_ports="" |
|||
additional_parameters="" |
|||
i = 3 |
|||
while i < len(sys.argv): |
|||
|
|||
# check forwarding format |
|||
if sys.argv[i].count("<") != 1: |
|||
print("[INTERNAL-PORT]<[EXTERNAL-PORT] wrong format '%s'" % (sys.argv[i])) |
|||
sys.exit(1) |
|||
|
|||
# get ports |
|||
sys.argv[i] = re.sub('"','', sys.argv[i] ) |
|||
ports = sys.argv[i].split("<") |
|||
port_internal = ports[0] |
|||
port_external = ports[1] |
|||
if port_internal.isdigit() == False: |
|||
print("[INTERNAL-PORT]<[EXTERNAL-PORT] internal not number '%s'" % (sys.argv[i])) |
|||
sys.exit(1) |
|||
if port_external.isdigit() == False: |
|||
print("[INTERNAL-PORT]<[EXTERNAL-PORT] external not number '%s'" % (sys.argv[i])) |
|||
sys.exit(1) |
|||
if port_internal == LNDPORT: |
|||
print("Detected LND Port Forwarding") |
|||
forwardingLND = True |
|||
if port_internal != port_external: |
|||
print("FAIL: When tunneling your local LND port '%s' it needs to be the same on the external server, but is '%s'" % (LNDPORT,port_external)) |
|||
print("Try again by using the same port. If you cant change the external port, change local LND port with: /home/admin/config.scripts/lnd.setport.sh") |
|||
sys.exit(1) |
|||
|
|||
ssh_ports = ssh_ports + "\"%s\" " % (sys.argv[i]) |
|||
additional_parameters= additional_parameters + "-R %s:localhost:%s " % (port_external,port_internal) |
|||
i=i+1 |
|||
|
|||
# genenate additional parameter for autossh (server) |
|||
ssh_ports = ssh_ports.strip() |
|||
additional_parameters= additional_parameters + ssh_server |
|||
|
|||
# generate custom service config |
|||
service_data = SERVICETEMPLATE.replace("[PLACEHOLDER]", additional_parameters) |
|||
|
|||
# debug print out service |
|||
print() |
|||
print("*** New systemd service: %s" % (SERVICENAME)) |
|||
print(service_data) |
|||
|
|||
# write service file |
|||
service_file = open("/home/admin/temp.service", "w") |
|||
service_file.write(service_data) |
|||
service_file.close() |
|||
subprocess.call("sudo mv /home/admin/temp.service %s" % (SERVICEFILE), shell=True) |
|||
|
|||
# check if SSH keys for root user need to be created |
|||
print() |
|||
print("*** Checking root SSH pub keys") |
|||
ssh_pubkey="" |
|||
try: |
|||
ssh_pubkey = subprocess.check_output("sudo cat /root/.ssh/id_rsa.pub", shell=True, universal_newlines=True) |
|||
print("OK - root id_rsa.pub file exists") |
|||
except subprocess.CalledProcessError as e: |
|||
print("Generating root SSH keys ...") |
|||
subprocess.call("sudo sh -c 'yes y | sudo -u root ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N \"\"'", shell=True) |
|||
ssh_pubkey = subprocess.check_output("sudo cat /root/.ssh/id_rsa.pub", shell=True, universal_newlines=True) |
|||
|
|||
# copy SSH keys for backup (for update with new sd card) |
|||
print("making backup copy of SSH keys") |
|||
subprocess.call("sudo cp -r /root/.ssh /mnt/hdd/ssh/root_backup", shell=True) |
|||
print("DONE") |
|||
|
|||
# write ssh tunnel data to raspiblitz config (for update with new sd card) |
|||
print("*** Updating RaspiBlitz Config") |
|||
with open('/mnt/hdd/raspiblitz.conf') as f: |
|||
file_content = f.read() |
|||
if file_content.count("sshtunnel=") == 0: |
|||
file_content = file_content+"\nsshtunnel=''" |
|||
file_content = re.sub("sshtunnel=.*", "sshtunnel='%s %s'" % (ssh_server, ssh_ports), file_content) |
|||
if restoringOnUpdate == False: |
|||
serverdomain=ssh_server.split("@")[1] |
|||
|
|||
# make sure serverdomain is set as tls alias |
|||
print("Setting server as tls alias") |
|||
oldConfigHash=subprocess.getoutput("sudo shasum -a 256 /mnt/hdd/lnd/lnd.conf") |
|||
subprocess.call("sudo sed -i \"s/^#tlsextradomain=.*/tlsextradomain=/g\" /mnt/hdd/lnd/lnd.conf", shell=True) |
|||
subprocess.call("sudo sed -i \"s/^tlsextradomain=.*/tlsextradomain=%s/g\" /mnt/hdd/lnd/lnd.conf" % (serverdomain), shell=True) |
|||
newConfigHash=subprocess.getoutput("sudo shasum -a 256 /mnt/hdd/lnd/lnd.conf") |
|||
if oldConfigHash != newConfigHash: |
|||
print("lnd.conf changed ... generating new TLS cert") |
|||
subprocess.call("sudo /home/admin/config.scripts/lnd.newtlscert.sh", shell=True) |
|||
else: |
|||
print("lnd.conf unchanged... keep TLS cert") |
|||
|
|||
if forwardingLND: |
|||
# setting server explicitly on LND if LND port is forwarded |
|||
print("Setting fixed address for LND with raspiblitz lndAddress") |
|||
file_content = re.sub("lndAddress=.*", "lndAddress='%s'" % (serverdomain), file_content) |
|||
else: |
|||
print("No need to set fixed address for LND with raspiblitz lndAddress") |
|||
file_content = "".join([s for s in file_content.splitlines(True) if s.strip("\r\n")]) + "\n" |
|||
print(file_content) |
|||
with open("/mnt/hdd/raspiblitz.conf", "w") as text_file: |
|||
text_file.write(file_content) |
|||
print("DONE") |
|||
|
|||
# make sure autossh is installed |
|||
# https://www.everythingcli.org/ssh-tunnelling-for-fun-and-profit-autossh/ |
|||
print() |
|||
print("*** Install autossh") |
|||
subprocess.call("sudo apt-get install -y autossh", shell=True) |
|||
|
|||
# enable service |
|||
print() |
|||
print("*** Enabling systemd service: %s" % (SERVICENAME)) |
|||
subprocess.call("sudo systemctl daemon-reload", shell=True) |
|||
subprocess.call("sudo systemctl enable %s" % (SERVICENAME), shell=True) |
|||
|
|||
# final info (can be ignored if run by other script) |
|||
print() |
|||
print("**************************************") |
|||
print("*** WIN - SSH TUNNEL SERVICE SETUP ***") |
|||
print("**************************************") |
|||
print("See chapter 'How to setup port-forwarding with a SSH tunnel?' in:") |
|||
print("https://github.com/rootzoll/raspiblitz/blob/master/FAQ.md") |
|||
print("- Tunnel service needs final reboot to start.") |
|||
print("- After reboot check logs: sudo journalctl -f -u %s" % (SERVICENAME)) |
|||
print("- Make sure the SSH pub key of this RaspiBlitz is in 'authorized_keys' of %s :" % (ssh_server)) |
|||
print(ssh_pubkey) |
|||
print() |
|||
|
|||
# |
|||
# SWITCHING OFF |
|||
# |
|||
|
|||
elif sys.argv[1] == "off": |
|||
|
|||
print("*** Disabling systemd service: %s" % (SERVICENAME)) |
|||
subprocess.call("sudo systemctl stop %s" % (SERVICENAME), shell=True) |
|||
subprocess.call("sudo systemctl disable %s" % (SERVICENAME), shell=True) |
|||
subprocess.call("sudo systemctl reset-failed", shell=True) |
|||
subprocess.call("sudo rm %s" % (SERVICEFILE), shell=True) |
|||
subprocess.call("sudo systemctl daemon-reload", shell=True) |
|||
print("OK Done") |
|||
print() |
|||
|
|||
print("*** Removing LND Address") |
|||
subprocess.call("sudo /home/admin/config.scripts/lnd.setaddress.sh off", shell=True) |
|||
print() |
|||
|
|||
print("*** Removing SSH Tunnel data from RaspiBlitz config") |
|||
with open('/mnt/hdd/raspiblitz.conf') as f: |
|||
file_content = f.read() |
|||
file_content = re.sub("sshtunnel=.*", "", file_content) |
|||
file_content = re.sub("\n\n", "\n", file_content) |
|||
print(file_content) |
|||
with open("/mnt/hdd/raspiblitz.conf", "w") as text_file: |
|||
text_file.write(file_content) |
|||
print("OK Done") |
|||
|
|||
# |
|||
# UNKOWN PARAMETER |
|||
# |
|||
|
|||
else: |
|||
print ("unkown parameter - use 'internet.sshtunnel.py -h' for help") |
@ -0,0 +1,178 @@ |
|||
#!/bin/bash |
|||
|
|||
if [ $# -eq 0 ]; then |
|||
echo "# script to check LND states" |
|||
echo "# lnd.check.sh basic-setup" |
|||
exit 1 |
|||
fi |
|||
|
|||
# load raspiblitz conf |
|||
source /mnt/hdd/raspiblitz.conf |
|||
|
|||
# check basic LND setup |
|||
if [ "$1" == "basic-setup" ]; then |
|||
|
|||
# check TLS exits |
|||
tlsExists=$(sudo ls /mnt/hdd/lnd/tls.cert 2>/dev/null | grep -c 'tls.cert') |
|||
if [ ${tlsExists} -gt 0 ]; then |
|||
echo "tls=1" |
|||
else |
|||
echo "tls=0" |
|||
echo "err='tls.cert is missing in /mnt/hdd/lnd'" |
|||
fi |
|||
# check TLS exits (on SD card for admin) |
|||
tlsExists=$(sudo ls /home/admin/.lnd/tls.cert 2>/dev/null | grep -c 'tls.cert') |
|||
if [ ${tlsExists} -gt 0 ]; then |
|||
echo "tlsCopy=1" |
|||
# check if the same |
|||
orgChecksum=$(sudo shasum -a 256 /mnt/hdd/lnd/tls.cert 2>/dev/null | cut -d " " -f1) |
|||
cpyChecksum=$(sudo shasum -a 256 /home/admin/.lnd/tls.cert 2>/dev/null | cut -d " " -f1) |
|||
if [ "${orgChecksum}" == "${cpyChecksum}" ]; then |
|||
echo "tlsMismatch=0" |
|||
else |
|||
echo "tlsMismatch=1" |
|||
echo "err='tls.cert for user admin is old'" |
|||
fi |
|||
else |
|||
echo "tlsCopy=0" |
|||
echo "tlsMismatch=0" |
|||
echo "err='tls.cert is missing for user admin'" |
|||
fi |
|||
|
|||
# check lnd.conf exits |
|||
lndConfExists=$(sudo ls /mnt/hdd/lnd/lnd.conf 2>/dev/null | grep -c 'lnd.conf') |
|||
if [ ${lndConfExists} -gt 0 ]; then |
|||
echo "config=1" |
|||
else |
|||
echo "config=0" |
|||
echo "err='lnd.conf is missing in /mnt/hdd/lnd'" |
|||
fi |
|||
# check lnd.conf exits (on SD card for admin) |
|||
lndConfExists=$(sudo ls /home/admin/.lnd/lnd.conf 2>/dev/null | grep -c 'lnd.conf') |
|||
if [ ${lndConfExists} -gt 0 ]; then |
|||
echo "configCopy=1" |
|||
# check if the same |
|||
orgChecksum=$(sudo shasum -a 256 /mnt/hdd/lnd/lnd.conf 2>/dev/null | cut -d " " -f1) |
|||
cpyChecksum=$(sudo shasum -a 256 /home/admin/.lnd/lnd.conf 2>/dev/null | cut -d " " -f1) |
|||
if [ "${orgChecksum}" == "${cpyChecksum}" ]; then |
|||
echo "configMismatch=0" |
|||
else |
|||
echo "configMismatch=1" |
|||
echo "err='lnd.conf for user admin is old'" |
|||
fi |
|||
else |
|||
echo "configCopy=0" |
|||
echo "configMismatch=0" |
|||
echo "err='lnd.conf is missing for user admin'" |
|||
fi |
|||
|
|||
# get network from config (BLOCKCHAIN) |
|||
lndNetwork="" |
|||
source <(sudo cat /mnt/hdd/lnd/lnd.conf 2>/dev/null | grep 'bitcoin.active' | sed 's/^[a-z]*\./bitcoin_/g') |
|||
source <(sudo cat /mnt/hdd/lnd/lnd.conf 2>/dev/null | grep 'litecoin.active' | sed 's/^[a-z]*\./litecoin_/g') |
|||
if [ "${bitcoin_active}" == "1" ] && [ "${litecoin_active}" == "1" ]; then |
|||
echo "err='lnd.conf: bitcoin and litecoin are set active at the same time'" |
|||
elif [ "${bitcoin_active}" == "1" ]; then |
|||
lndNetwork="bitcoin" |
|||
elif [ "${litecoin_active}" == "1" ]; then |
|||
lndNetwork="litecoin" |
|||
else |
|||
echo "err='lnd.conf: no blockchain network is set'" |
|||
fi |
|||
echo "network='${lndNetwork}'" |
|||
|
|||
# check if network is same the raspiblitz config |
|||
if [ "${network}" != "${lndNetwork}" ]; then |
|||
echo "err='lnd.conf: blockchain network in lnd.conf (${lndNetwork}) is different from raspiblitz.conf (${network})'" |
|||
fi |
|||
|
|||
# get chain from config (TESTNET / MAINNET) |
|||
lndChain="" |
|||
source <(sudo cat /mnt/hdd/lnd/lnd.conf 2>/dev/null | grep "${lndNetwork}.mainnet" | sed 's/^[a-z]*\.//g') |
|||
source <(sudo cat /mnt/hdd/lnd/lnd.conf 2>/dev/null | grep "${lndNetwork}.testnet" | sed 's/^[a-z]*\.//g') |
|||
if [ "${mainnet}" == "1" ] && [ "${testnet}" == "1" ]; then |
|||
echo "err='lnd.conf: mainnet and testnet are set active at the same time'" |
|||
elif [ "${mainnet}" == "1" ]; then |
|||
lndChain="main" |
|||
elif [ "${testnet}" == "1" ]; then |
|||
lndChain="test" |
|||
else |
|||
echo "err='lnd.conf: neither testnet or mainnet is set active (raspiblitz needs one of them active in lnd.conf)'" |
|||
fi |
|||
echo "chain='${lndChain}'" |
|||
|
|||
# check if chain is same the raspiblitz config |
|||
if [ "${chain}" != "${lndChain}" ]; then |
|||
echo "err='lnd.conf: testnet/mainnet in lnd.conf (${lndChain}) is different from raspiblitz.conf (${chain})'" |
|||
fi |
|||
|
|||
# check for admin macaroon exist (on HDD) |
|||
adminMacaroonExists=$(sudo ls /mnt/hdd/lnd/data/chain/${network}/${chain}net/admin.macaroon 2>/dev/null | grep -c 'admin.macaroon') |
|||
if [ ${adminMacaroonExists} -gt 0 ]; then |
|||
echo "macaroon=1" |
|||
else |
|||
echo "macaroon=0" |
|||
echo "err='admin.macaroon is missing in /mnt/hdd/lnd/data/chain/${network}/${chain}net'" |
|||
fi |
|||
# check for admin macaroon exist (on SD card for admin) |
|||
adminMacaroonExists=$(sudo ls /home/admin/.lnd/data/chain/${network}/${chain}net/admin.macaroon 2>/dev/null | grep -c 'admin.macaroon') |
|||
if [ ${adminMacaroonExists} -gt 0 ]; then |
|||
echo "macaroonCopy=1" |
|||
# check if the same |
|||
orgChecksum=$(sudo shasum -a 256 /mnt/hdd/lnd/data/chain/${network}/${chain}net/admin.macaroon 2>/dev/null | cut -d " " -f1) |
|||
cpyChecksum=$(sudo shasum -a 256 /home/admin/.lnd/data/chain/${network}/${chain}net/admin.macaroon 2>/dev/null | cut -d " " -f1) |
|||
if [ "${orgChecksum}" == "${cpyChecksum}" ]; then |
|||
echo "macaroonMismatch=0" |
|||
else |
|||
echo "macaroonMismatch=1" |
|||
echo "err='admin.macaroon for user admin is old'" |
|||
fi |
|||
else |
|||
echo "macaroonCopy=0" |
|||
echo "macaroonMismatch=0" |
|||
echo "err='admin.macaroon is missing for user admin" |
|||
fi |
|||
|
|||
# check for walletDB exist |
|||
walletExists=$(sudo ls /mnt/hdd/lnd/data/chain/${network}/${chain}net/wallet.db 2>/dev/null | grep -c 'wallet.db') |
|||
if [ ${walletExists} -gt 0 ]; then |
|||
echo "wallet=1" |
|||
else |
|||
echo "wallet=0" |
|||
fi |
|||
|
|||
# check that RPC USER between Bitcoin and LND is correct |
|||
rpcusercorrect=0 |
|||
source <(sudo cat /mnt/hdd/lnd/lnd.conf 2>/dev/null | grep "${lndNetwork}d.rpcuser" | sed 's/^[a-z]*\./lnd/g') |
|||
source <(sudo cat /mnt/hdd/${lndNetwork}/${lndNetwork}.conf 2>/dev/null | grep "rpcuser" | sed 's/^[a-z]*\./lnd/g') |
|||
if [ ${#lndrpcuser} -eq 0 ]; then |
|||
echo "err='lnd.conf: missing ${lndNetwork}d.rpcuser (needs to be same as set in ${lndNetwork}.conf)'" |
|||
elif [ ${#rpcuser} -eq 0 ]; then |
|||
echo "err='${lndNetwork}.conf: missing rpcuser (needs to be same as set in lnd.conf)'" |
|||
elif [ "${rpcuser}" != "${lndrpcuser}" ]; then |
|||
echo "err='${lndNetwork}.conf (${rpcuser}) & lnd.conf (${lndrpcuser}): RPC user missmatch! - LND cannot connect to blockchain RPC'" |
|||
else |
|||
# OK looks good |
|||
rpcusercorrect=1 |
|||
fi |
|||
echo "rpcusercorrect=${rpcusercorrect}" |
|||
|
|||
# check that RPC PASSWORD between Bitcoin and LND is correct |
|||
rpcpasscorrect=0 |
|||
source <(sudo cat /mnt/hdd/lnd/lnd.conf 2>/dev/null | grep "${lndNetwork}d.rpcpass" | sed 's/^[a-z]*\./lnd/g') |
|||
source <(sudo cat /mnt/hdd/${lndNetwork}/${lndNetwork}.conf 2>/dev/null | grep "rpcpassword" | sed 's/^[a-z]*\./lnd/g') |
|||
if [ ${#lndrpcpass} -eq 0 ]; then |
|||
echo "err='lnd.conf: missing ${lndNetwork}d.rpcpass (needs to be same as set in ${lndNetwork}.conf)'" |
|||
elif [ ${#rpcpassword} -eq 0 ]; then |
|||
echo "err='${lndNetwork}.conf: missing rpcpassword (needs to be same as set in lnd.conf)'" |
|||
elif [ "${rpcpassword}" != "${lndrpcpass}" ]; then |
|||
echo "err='${lndNetwork}.conf (${rpcpassword}) & lnd.conf (${lndrpcpass}): RPC password missmatch! - should autofix on reboot'" |
|||
else |
|||
# OK looks good |
|||
rpcpasscorrect=1 |
|||
fi |
|||
echo "rpcpasscorrect=${rpcpasscorrect}" |
|||
|
|||
else |
|||
echo "# FAIL: parameter not known" |
|||
fi |
@ -0,0 +1,204 @@ |
|||
#!/usr/bin/python |
|||
import codecs, os, sys, base64 |
|||
|
|||
# display config script info |
|||
if len(sys.argv) <= 1 or sys.argv[1] == "-h" or sys.argv[1] == "help": |
|||
print("# ! always activate virtual env first: source /home/admin/python-env-lnd/bin/activate") |
|||
print("# ! and run with with: python /home/admin/config.scripts/lnd.initwallet.py") |
|||
print("# creating or recovering the LND wallet") |
|||
print("# lnd.winitwallet.py new [walletpassword] [?seedpassword]") |
|||
print("# lnd.winitwallet.py seed [walletpassword] [\"seeds-words-seperated-spaces\"] [?seedpassword]") |
|||
print("# lnd.winitwallet.py scb [walletpassword] [\"seeds-words-seperated-spaces\"] [filepathSCB] [?seedpassword]") |
|||
print("err='missing parameters'") |
|||
sys.exit(1) |
|||
|
|||
import grpc |
|||
from lndlibs import rpc_pb2 as ln |
|||
from lndlibs import rpc_pb2_grpc as lnrpc |
|||
from pathlib2 import Path |
|||
|
|||
walletpassword="" |
|||
seedwords="" |
|||
seedpassword="" |
|||
filepathSCB="" |
|||
|
|||
mode=sys.argv[1] |
|||
|
|||
if mode=="new": |
|||
|
|||
print("# *** CREATING NEW LND WALLET ***") |
|||
|
|||
if len(sys.argv)>2: |
|||
walletpassword=sys.argv[2] |
|||
if len(walletpassword)<8: |
|||
print("err='wallet password is too short'") |
|||
sys.exit(1) |
|||
else: |
|||
print("err='wallet password is too short'") |
|||
sys.exit(1) |
|||
|
|||
if len(sys.argv)>3: |
|||
seedpassword=sys.argv[3] |
|||
|
|||
elif mode=="seed" or mode=="scb": |
|||
|
|||
if len(sys.argv)>2: |
|||
walletpassword=sys.argv[2] |
|||
if len(walletpassword)<8: |
|||
print("err='wallet password is too short'") |
|||
sys.exit(1) |
|||
else: |
|||
print("err='not correct amount of parameter - missing wallet password'") |
|||
sys.exit(1) |
|||
|
|||
if len(sys.argv)>3: |
|||
seedwordString=sys.argv[3] |
|||
seedwords=seedwordString.split(" ") |
|||
if len(seedwords)<24: |
|||
print("err='not 24 seed words seperated by just spaces (surrounded with \")'") |
|||
sys.exit(1) |
|||
else: |
|||
print("err='not correct amount of parameter - missing seed string'") |
|||
sys.exit(1) |
|||
|
|||
if mode=="seed": |
|||
|
|||
if len(sys.argv)>4: |
|||
seedpassword=sys.argv[4] |
|||
|
|||
elif mode=="scb": |
|||
|
|||
if len(sys.argv)>4: |
|||
filepathSCB=sys.argv[4] |
|||
scbFile = Path(filepathSCB) |
|||
if scbFile.is_file(): |
|||
print("# OK SCB file exists") |
|||
else: |
|||
print("err='the given filepathSCB - file does not exists or no permission'") |
|||
sys.exit(1) |
|||
else: |
|||
print("err='not correct amount of parameter - missing seed filepathSCB'") |
|||
sys.exit(1) |
|||
|
|||
if len(sys.argv)>5: |
|||
seedpassword=sys.argv[4] |
|||
|
|||
else: |
|||
|
|||
print("err='unkown mode parameter - run without any parameters to see options'") |
|||
sys.exit(1) |
|||
|
|||
os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA' |
|||
cert = open('/mnt/hdd/lnd/tls.cert', 'rb').read() |
|||
ssl_creds = grpc.ssl_channel_credentials(cert) |
|||
channel = grpc.secure_channel('localhost:10009', ssl_creds) |
|||
stub = lnrpc.WalletUnlockerStub(channel) |
|||
if mode=="new": |
|||
|
|||
request = ln.GenSeedRequest() |
|||
try: |
|||
response = stub.GenSeed(request) |
|||
seedwords = response.cipher_seed_mnemonic |
|||
seedwordsString=', '.join(seedwords) |
|||
print("seedwords='"+seedwordsString+"'") |
|||
|
|||
# add a 6x4 formatted version to the output |
|||
seedwords6x4="" |
|||
for i in range(0,len(seedwords)): |
|||
if i % 6 == 0 and i != 0: |
|||
seedwords6x4=seedwords6x4+"\n" |
|||
singleWord=str(i+1)+":"+seedwords[i] |
|||
while len(singleWord)<12: |
|||
singleWord=singleWord+" " |
|||
seedwords6x4=seedwords6x4+singleWord |
|||
print("seedwords6x4='"+seedwords6x4+"'") |
|||
|
|||
except grpc.RpcError as rpc_error_call: |
|||
code = rpc_error_call.code() |
|||
print >> sys.stderr, code |
|||
details = rpc_error_call.details() |
|||
print("err='RPCError GenSeedRequest'") |
|||
print("errMore='"+details+"'") |
|||
sys.exit(1) |
|||
except: |
|||
e = sys.exc_info()[0] |
|||
print >> sys.stderr, e |
|||
print("err='GenSeedRequest'") |
|||
sys.exit(1) |
|||
|
|||
request = ln.InitWalletRequest( |
|||
wallet_password=walletpassword, |
|||
cipher_seed_mnemonic=seedwords |
|||
) |
|||
try: |
|||
response = stub.InitWallet(request) |
|||
except grpc.RpcError as rpc_error_call: |
|||
code = rpc_error_call.code() |
|||
print >> sys.stderr, code |
|||
details = rpc_error_call.details() |
|||
print("err='RPCError InitWallet'") |
|||
print("errMore='"+details+"'") |
|||
sys.exit(1) |
|||
except: |
|||
e = sys.exc_info()[0] |
|||
print >> sys.stderr, e |
|||
print("err='InitWallet'") |
|||
sys.exit(1) |
|||
|
|||
elif mode=="seed": |
|||
|
|||
request = ln.InitWalletRequest( |
|||
wallet_password=walletpassword, |
|||
cipher_seed_mnemonic=seedwords, |
|||
recovery_window=250, |
|||
aezeed_passphrase=seedpassword |
|||
) |
|||
|
|||
try: |
|||
response = stub.InitWallet(request) |
|||
except grpc.RpcError as rpc_error_call: |
|||
code = rpc_error_call.code() |
|||
print >> sys.stderr, code |
|||
details = rpc_error_call.details() |
|||
print("err='RPCError InitWallet'") |
|||
print("errMore='"+details+"'") |
|||
sys.exit(1) |
|||
except: |
|||
e = sys.exc_info()[0] |
|||
print >> sys.stderr, e |
|||
print("err='InitWallet'") |
|||
sys.exit(1) |
|||
|
|||
elif mode=="scb": |
|||
|
|||
import binascii |
|||
with open(filepathSCB, 'rb') as f: |
|||
content = f.read() |
|||
scbHexString=binascii.hexlify(content) |
|||
print(scbHexString) |
|||
|
|||
request = ln.InitWalletRequest( |
|||
wallet_password=walletpassword, |
|||
cipher_seed_mnemonic=seedwords, |
|||
recovery_window=250, |
|||
aezeed_passphrase=seedpassword, |
|||
channel_backups=scbHexString |
|||
) |
|||
|
|||
try: |
|||
response = stub.InitWallet(request) |
|||
except grpc.RpcError as rpc_error_call: |
|||
code = rpc_error_call.code() |
|||
print >> sys.stderr, code |
|||
details = rpc_error_call.details() |
|||
print("err='RPCError InitWallet'") |
|||
print("errMore='"+details+"'") |
|||
sys.exit(1) |
|||
except: |
|||
e = sys.exc_info()[0] |
|||
print >> sys.stderr, e |
|||
print("err='InitWallet'") |
|||
sys.exit(1) |
|||
|
|||
print("err='TODO: implement creating from seed/scb'") |
|||
sys.exit(1) |
@ -0,0 +1,98 @@ |
|||
#!/bin/bash |
|||
|
|||
# INFO : Does not need to be part of update/provision, because |
|||
# all data is already on HDD ready |
|||
|
|||
# command info |
|||
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then |
|||
echo "small config script to set a fixed domain or IP for LND" |
|||
echo "internet.setaddress.sh [on|off] [?address]" |
|||
exit 1 |
|||
fi |
|||
|
|||
# 1. parameter [on|off] |
|||
mode="$1" |
|||
|
|||
echo "number of args($#)" |
|||
|
|||
# config file |
|||
configFile="/mnt/hdd/raspiblitz.conf" |
|||
|
|||
# lnd conf file |
|||
lndConfig="/mnt/hdd/lnd/lnd.conf" |
|||
|
|||
# check if config file exists |
|||
configExists=$(ls ${configFile} | grep -c '.conf') |
|||
if [ ${configExists} -eq 0 ]; then |
|||
echo "FAIL - missing ${configFile}" |
|||
exit 1 |
|||
fi |
|||
|
|||
# get hash of lnd.conf before edit (to detect if changed later) |
|||
md5HashBefore=$(sudo shasum -a 256 /mnt/hdd/lnd/lnd.conf) |
|||
|
|||
# FIXED DOMAIN/IP |
|||
if [ "${mode}" = "on" ]; then |
|||
|
|||
address=$2 |
|||
if [ ${#address} -eq 0 ]; then |
|||
echo "missing parameter" |
|||
exit 1 |
|||
fi |
|||
|
|||
echo "switching fixed LND Domain ON" |
|||
echo "address(${address})" |
|||
|
|||
# setting value in raspi blitz config |
|||
sudo sed -i "s/^lndAddress=.*/lndAddress='${address}'/g" /mnt/hdd/raspiblitz.conf |
|||
|
|||
echo "changing lnd.conf" |
|||
|
|||
# lnd.conf: uncomment tlsextradomain (just if it is still uncommented) |
|||
sudo sed -i "s/^#tlsextradomain=.*/tlsextradomain=/g" /mnt/hdd/lnd/lnd.conf |
|||
|
|||
# lnd.conf: domain value |
|||
sudo sed -i "s/^tlsextradomain=.*/tlsextradomain=${address}/g" /mnt/hdd/lnd/lnd.conf |
|||
|
|||
# refresh TLS cert |
|||
md5HashAfter=$(sudo shasum -a 256 /mnt/hdd/lnd/lnd.conf) |
|||
if [ "${md5HashAfter}" != "${md5HashBefore}" ]; then |
|||
echo "# lnd.conf changed - TLS certs need refreshing" |
|||
sudo /home/admin/config.scripts/lnd.newtlscert.sh |
|||
else |
|||
echo "# lnd.conf NOT changed - keep TLS certs" |
|||
fi |
|||
|
|||
echo "fixedAddress is now ON" |
|||
fi |
|||
|
|||
# switch off |
|||
if [ "${mode}" = "off" ]; then |
|||
echo "switching fixedAddress OFF" |
|||
|
|||
# stop services |
|||
echo "making sure services are not running" |
|||
sudo systemctl stop lnd 2>/dev/null |
|||
|
|||
# setting value in raspi blitz config |
|||
sudo sed -i "s/^lndAddress=.*/lndAddress=''/g" /mnt/hdd/raspiblitz.conf |
|||
|
|||
echo "changing lnd.conf" |
|||
|
|||
# lnd.conf: comment tlsextradomain out |
|||
sudo sed -i "s/^tlsextradomain=.*/#tlsextradomain=/g" /mnt/hdd/lnd/lnd.conf |
|||
|
|||
# refresh TLS cert |
|||
md5HashAfter=$(sudo shasum -a 256 /mnt/hdd/lnd/lnd.conf) |
|||
if [ "${md5HashAfter}" != "${md5HashBefore}" ]; then |
|||
echo "# lnd.conf changed - TLS certs need refreshing" |
|||
sudo /home/admin/config.scripts/lnd.newtlscert.sh |
|||
else |
|||
echo "# lnd.conf NOT changed - keep TLS certs" |
|||
fi |
|||
|
|||
echo "fixedAddress is now OFF" |
|||
fi |
|||
|
|||
echo "may needs reboot to run normal again" |
|||
exit 0 |
@ -0,0 +1,28 @@ |
|||
For every new LND version the LND RPC libs need to be compiled from the matching protobuff files. |
|||
Do this on a raspberrypi with the exact same python version the scripts will be are running on. |
|||
See https://dev.lightning.community/guides/python-grpc/ |
|||
|
|||
Make sure Virtual Environment is setup: |
|||
``` |
|||
sudo apt-get -f -y install virtualenv |
|||
virtualenv lnd |
|||
source lnd/bin/activate |
|||
pip install grpcio grpcio-tools googleapis-common-protos |
|||
``` |
|||
|
|||
Normally that is already done by build_sdcard.sh for user admin user. So just run: |
|||
``` |
|||
source lnd/bin/activate |
|||
```` |
|||
|
|||
Now to generate the lnd RPC libs: |
|||
``` |
|||
git clone https://github.com/googleapis/googleapis.git |
|||
curl -o rpc.proto -s https://raw.githubusercontent.com/lightningnetwork/lnd/master/lnrpc/rpc.proto |
|||
python -m grpc_tools.protoc --proto_path=googleapis:. --python_out=. --grpc_python_out=. rpc.proto |
|||
```` |
|||
|
|||
*NOTE: If LND master branch is already a version ahead .. use the rpc.proto from the version tagged branch.* |
|||
|
|||
Now copy the generated RPC libs per SCP over to your Laptop and add them to the `/home/admin/config.scripts/lndlibs`. |
|||
|
After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 2.8 MiB After Width: | Height: | Size: 2.6 MiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 59 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 56 KiB |
After Width: | Height: | Size: 63 KiB |