diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c4677f0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2018 The RaspiBlitz developers + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 8cb735a..7aa7baf 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ -[ [Hardware](#hardware-needed-amazon-shopping-list) ] -- [ [Setup](#boot-your-raspiblitz) ] -- [ [Documentation](#documentation) ] -- [ [Education](#educational-tutorials) ] -- [ [Development](#further-development-of-raspiblitz) ] +[ [Hardware](#hardware-needed-amazon-shopping-list) ] -- [ [Setup](#boot-your-raspiblitz) ] -- [ [Documentation](#documentation) ] -- [ [Development](#further-development-of-raspiblitz) ] ----- # RaspiBlitz Fastest and cheapest way to get your own Lightning Node running - on a RaspberryPi with a nice LCD. +`Latest Version with lnd 0.5 and bitcoin 0.17.0rc4 & litecoin 0.16.3 (both with dos bugfix).` + ![RaspiBlitz](pictures/raspiblitz.jpg) *This tutorial is based on the RaspiBolt project - you can find in detail here: https://github.com/Stadicus/guides/blob/master/raspibolt The RaspiBlitz serves as a shortcut through this setup process with some changes and an additional LCD display so that you can quickly experiment with a Lightning node and start working on your LApps on a hacking event (or at home). This shortcut is fine for testnet usage and maybe trying some small things on mainnet. But if you choose to go full reckless afterwards … please consider taking the time and work thru the original RaspiBolt project. Don’t trust us, verify.* @@ -13,28 +15,37 @@ Fastest and cheapest way to get your own Lightning Node running - on a Raspberry * [ [Hardware](#hardware-needed-amazon-shopping-list) ] Shopping Lists and Putting all together * [ [Setup](#boot-your-raspiblitz) ] Init and Setup your RaspiBlitz Lightning Node * [ [Documentation](#documentation) ] Features and Usecases -* [ [Education](#educational-tutorials) ] Tutorials with the RaspiBlitz to learn about Lightning * [ [Development](#further-development-of-raspiblitz) ] Lets work together on the RaspiBlitz ## Hardware Needed (Amazon Shopping List) *The RaspiBlitz software is build and tested for the following Hardware set that you can buy cheap on Amazon.de:* -* RaspBerry Pi 3 (31,99 EUR) https://www.amazon.de/dp/B01CD5VC92 -* Micro SD-Card 16GB (7,11 EUR) https://www.amazon.de/dp/B0162YQEIE -* Power >=3A (9,29 EUR) https://www.amazon.de/dp/B01E75SB2C -* 1TB Hard Drive (49,99 EUR) https://www.amazon.de/dp/B00KWHJY7Q +* RaspBerry Pi 3 (34,99 EUR) https://www.amazon.de/dp/B07BDR5PDW +* Micro SD-Card 16GB (7,99 EUR) https://www.amazon.de/gp/product/B073K14CVB/ +* Power >=3A (9,99 EUR) https://www.amazon.de/gp/product/B078567K85 +* 1TB Hard Drive (44,98 EUR) https://www.amazon.de/dp/B07997KKSK?th=1 * Case (9,36 EUR) https://www.amazon.de/dp/B0173GQF8Y -* LCD-Display (19,58 EUR) https://www.amazon.de/dp/B01JRUH0CY +* LCD-Display (16,88 EUR) https://www.amazon.de/gp/product/B06X191RX7 -**Total Price: 127,31 EUR** (thats under 150 USD) +**Total Price: 124,19 EUR** (thats under 150 USD) Amazon shopping lists for different countries: -[ [USA](shoppinglist_usa.md) ] [ [UK](shoppinglist_uk.md) ] [ [FR](shoppinglist_fr.md) ] +[ [USA](shoppinglist_usa.md) ] [ [UK](shoppinglist_uk.md) ] [ [FR](shoppinglist_fr.md) ] [ [China](shoppinglist_cn.md) ] You can even pay your RaspiBlitz Amazon Shopping with Bitcoin & Lightning thru [Bitrefill](https://blog.bitrefill.com/its-here-buy-amazon-vouchers-with-bitcoin-on-bitrefill-bb2a4449724a). -### Optional Hardware +The shopping list for China refers to Taobao/T-Mall. + +### 3D Printed Case (optional) + +You can replace the generic case in the shopping lists above with a customized 3D printed for the RaspiBlitz called "Lightning Shell" - great work by @CryptoCloaks + +https://thecryptocloak.com/product/lightningshell/ + +![LightningShell](pictures/lightningshell.png) + +### More optional Hardware *Some optional goodies to consider to add to your shopping list for your RaspiBlitz (Amazon DE/US):* @@ -46,8 +57,6 @@ You can even pay your RaspiBlitz Amazon Shopping with Bitcoin & Lightning thru [ If you organizing an educational event where you want to support people learning on and with multiple RaspiBlitz, here is a package list of useful hardware to have at that event: [ [Event Package List](shoppinglist_event.md) ] - - ## Prepare your Hardware *There are two ways to start:* @@ -59,7 +68,7 @@ If you are at an event, ask for a ready-2-go set or if you have your own hardwar You got all the hardware of the shopping list above and you have no further assistance. Then you need to prepare your SD-Card yourself .. this scenario is still experimental, feedback needed and can take some time. 1. Download SD-Card image: -http://wiki.fulmo.org/downloads/raspiblitz-2018-08-02.img.gz +https://wiki.fulmo.org/downloads/raspiblitz-2018-09-22.img.gz (or [build your own](#build-the-sd-card-image)) 2. Write the SD-Card image to your SD Card - if you need details, see here: https://www.raspberrypi.org/documentation/installation/installing-images/README.md @@ -147,7 +156,9 @@ The option "SYNC" should just be use as a fallback. So normally you have the fol #### Download the Blockchain -This is the recommended way for users that are making the setup at home without any further assistance but can take quite some time. You can choose to download over TORRENT or FTP-DOWNLOAD. Choose the FTP is the torrent if not working for you. To stop torrent and choose another option use CTRL+z and then start './10setupBlitz.sh' from terminal. +This is the recommended way for users that are making the setup at home without any further assistance but can take quite some time. You can choose to download over TORRENT or FTP-DOWNLOAD. Choose the FTP if the torrent is not working for you. + +For more details: [Background on Download Blockchain](background_downloadBlockchain.md) #### Copy the Blockchain @@ -167,7 +178,7 @@ To connect the 2nd HDD to the RaspiBlitz, the use of a Y cable to provide extra ![ExtraPower](pictures/extrapower.png) -**Background: If the blockchain was already on the HDD or was acquired successfully, the script `60finsihHDD.sh` will be called. It will further prepare the HDD and start the bitcoin service.* +**Background: If the blockchain was already on the HDD or was acquired successfully, the script `60finishHDD.sh` will be called. It will further prepare the HDD and start the bitcoin service.* #### Lightning @@ -201,15 +212,19 @@ After SSH back in as admin the main menu shows the unlock option: Once the wallet is unlocked the setup is finally over and the main menu shows the option and features of the RaspiBlitz: -![SSH9e](pictures/ssh9e-mainmenu.png) +![SSH9e1](pictures/ssh9e-mainmenu1.png) + +And if you scroll down .. you see even more feature options: + +![SSH9e2](pictures/ssh9e-mainmenu2.png) *Background: The script `00mainMenu.sh` is now the place to offer further features und extend the possibilities of the RaspiBlitz. Feel free to come up with ideas. Check out the developer section at the end of this page.* ### Features -But you manually extened your RaspiBlitz with features listed in the RaspiBlot Guide: https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_60_bonus.md +But you manually extened your RaspiBlitz with features listed in the RaspiBolt Guide: https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_60_bonus.md -Already integrated features of the RaspiBlitz are/willbe listed as part of the main menu after connecting per ssh with the admin user. +Already integrated features of the RaspiBlitz are/will be listed as part of the main menu after connecting via ssh as admin user. *Background: The script `91addBonus.sh` is the place to put your setup of features you want to add to RaspiBlitz. Its run at the end of the automated setup process before final reboot. To make the feature executable for the user, add a new option to the `00mainMenu.sh`* @@ -223,11 +238,76 @@ Already integrated features of the RaspiBlitz are/willbe listed as part of the m bonus-lnchannels -## Educational Tutorials +#### TOR Integration (experimental) + +You can use the Switch to TOR option from the main menu to make the node reachable thru TOR. This way you can get thru a NAT without needed to open/forward ports on your router. Bitcoin and LND will have a seperate onion-address displayed on LCD and the Status Info Screen option in menu. + +![tor1](pictures/tor1.png) + +The TOR integration is experimental and at the moment there is no way to switch off TOR again. + +#### Connect to Mobile Wallet + +There is now the option to connect and control your LND node with the mobile app called "Shango" - choose option in the main menu. + +![shango1](pictures/shango1.png) + +#### RaspiBlitz as Backend for BTCPayServer (experimental) + +BTCPay Server is a solution to be your own payment processor to accept Lightning Payments for your online store: https://github.com/btcpayserver/btcpayserver + +You can find setup instructions here: https://goo.gl/KnTzLu + +Thanks to @RobEdb (ask on twitter for more details) running his demo store with RaspiBlitz: https://store.edberg.eu - buy a picture of [him and Andreas](https://store.edberg.eu/produkt/jag-andreas/) :) + +## Build the SD Card Image + +A ready to use SD card image of the RaspiBlitz for your RaspberryPi is provided as download by us to get everbody started quickly. But if you want to build that image yourself - here is a quick guide: + +* Get a fresh Rasbian RASPBIAN STRETCH WITH DESKTOP card image: [DOWNLOAD](https://www.raspberrypi.org/downloads/raspbian/) +* Write image to a SD card: [TUTORIAL](https://www.raspberrypi.org/documentation/installation/installing-images/README.md) +* Add a file called `ssh` to the root of the SD card when mounted to enable SSH login +* Start card in Raspi and login per SSH with `ssh pi@[IP-OF-YOUR-RASPI]` password is `raspberry` + +Now you are ready to start the SD card build script - copy the following command into your terminal and execute: + +`wget https://raw.githubusercontent.com/rootzoll/raspiblitz/master/build.sdcard/raspbianStretchDesktop.sh && sudo bash raspbianStretchDesktop.sh` + +As you can see from the URL you find the build script in this Git repo under `build.sdcard/raspbianStretchDesktop.sh`- there you can check what gets installed and configured in detail. Feel free to post improvements as pull requests. + +The whole build process takes a while. And the end the LCD drives get installed and a reboot is needed. Remember the default password is now `raspiblitz`. You can login per SSH again - this time use root: `ssh root@[IP-OF-YOUR-RASPI]` and simply shutdown with `sudo shutdown now`. Once you see the LCD going white and the actovity LED of the pi starts going dark. You can unplug power and remove the SD card. You have now build your own RaspiBlitz sd card image. + +*Note: If you plan to use your self build sd card as a MASTER copy to backup image and distribute it. Use a smaller 8GB card for that. This way its ensured that it will fit on every 16 GB card recommended for RaspiBlitz later on.* + +## Update to a new SD Card Release + +At the beginning of this README you can find the newest SD card we provide. Or you can build the newest SD card image yourself like in the chapter above. The SD card image is used to setup a fresh install of the RaspiBlitz. So what to do if you already have an older version running and you want to upgrade? + +Until we reach version 1.0 the update process will be a bit rough .. so what you do is: +* close all open lightning channels you have (`lncli closeallchannels --force`) +* wait until all closing transactions are done +* move all on-chain funds to a wallet outside raspiblitz (`lncli --conf_target 3 sendcoins [ADDRESS]`) +* run the script `./XXcleanHDD.sh` in admin home directory (Blockchain will stay on HDD) +* shutdown RaspiBlitz (`sudo shutdown now`) +* flash SD card with new image +* Redo a fresh setup of RaspiBlitz +* Move your funds back in +* Re-Open your channels + +We know that this is not optimal yet. But until version 1.0 we will change too much stuff to garantue any other save update mechanism. Also by redoing all the setup you help out on testing the lastest setup process. + +From the upcomming version 1.0 onwards the goal is to make it easier to keep up with the lastest RaspiBlitz updates. + +## Mobile Development: Connect RaspiBlitz without a Router/Switch -*Once the Setup Process is done, the learning and building should begin ... more detailed educational content should be added in this section in the future.* +To connect a RaspiBlitz directly (without a router/switch) to your laptop and share the WIFI internet connection, you can follow this [guide for OSX](https://medium.com/@tzhenghao/how-to-ssh-into-your-raspberry-pi-with-a-mac-and-ethernet-cable-636a197d055). In short: -A good way to start for now is to get some Testnet coins, connect to other peers and make your first transactions. You find tutorials for this at the original RaspiBolt guide: https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_40_lnd.md#get-some-testnet-bitcoin +* connect with LAN directly +* Settings > Sharing/Freigaben > activate "internet sharing" from WLAN to Ethernet +* Settings > Network > Ethernet-Adapter > set to DHCP +* in terminal > `ifconfig` there you should the the IP of the bridge100 +* in terminal > `arp -a` and check for an IP of a client to the bridge +* in terminal > ssh admin@[clientIP] ## Further Development of RaspiBlitz @@ -239,4 +319,4 @@ Everybody is welcome to join, improve and extend the RaspiBlitz - its a work in Join me on twitter [@rootzoll](https://twitter.com/rootzoll), visit us at a [#lightninghackday](https://twitter.com/hashtag/LightningHackday?src=hash) in Berlin or drop by the Bitcoin Assembly at the [#35C3](https://twitter.com/hashtag/35C3). -IRC channel on Freenode `irc://irc.freenode.net/raspiblitz` +IRC channel on Freenode `irc://irc.freenode.net/raspiblitz` (unmoderated) diff --git a/background_downloadBlockchain.md b/background_downloadBlockchain.md new file mode 100644 index 0000000..c9f9bd4 --- /dev/null +++ b/background_downloadBlockchain.md @@ -0,0 +1,150 @@ +# Background: Blockchain Download + +## Why do we need to download the blockchain and not syncing it? + +The RaspiBlitz is powered by the RaspberryPi. The processing power of this SingleBoardComputer is too low to make a fast sync of the blockchain from the bitcoin peer to peer network during setup process (validation). To sync and index the complete blockchain could take weeks or even longer. Thats why the RaspiBlitz needs to download a prepared blockchain from another source. + +## Is downloading the blockchain secure? + +The downloaded Blockchain is pre-indexed and pre-validated. That is secure enough because if the user gets a "manipulated" blockchain it would not work after setup. The beginning of the downloaded blockchain needs to fit the genesis block (in bitcoind software) and the end of the downloaded blockchain needs not match with the rest of the bitcoin network state - hashes of new block distrubuted within the peer-2-peer network need to match the downloaded blockchain head. So if you downloaded a manipulated blockchain it would simply just dont work in practice. + +There might be theoretical scenarios why it would be bad for the whole network if anybody is downloading a prepared blockchain and not syncing and self-validating every block, but with a lot of self-validating full nodes already out there, just putting some RaspiBlitz with a downloaded blockchain into the mix and runnig as a self-valifating full node from that point on, is practically just strengthening the the overall network. And dont forget, the most important part of running a full node is to validate the new blocks summited by the miners - to balance out there power and to keep the Bitcoin network running by our rules. + +If you have any link to a more detailed discussion of this topic, please add it here for people to do their own research. + +## Blockchain Data + +The RaspiBlitz needs the following files from a bitcoind (>=0.17.0) that is fully sync and has indexing switched on (txindex=1) - all files from the directories: +``` +/blocks +/chainstate +/indexes +``` + +Make sure not to add other files like wallet data or lock files to a prepared download. + +You might want to include the testnet data also - then add the testnet3 folder that just contains the same three folders from the testnet blockchain. + +On download all those files need to be placed finally in the /mnt/hdd/bitcoin folder of the RaspiBlitz. + +## Download Process + +At the moment the RaspiBlitz offers two technical ways to download the blockchain: + +### FTP Download (fallback) + +The easiest way is to put the blockchain data on a FTP server and let people download it. FTP is able to download complete directories - HTTP can just handle single file. FTP clients and server hosting is widly available. + +The downside that this is a central point solution and is hard to scale up (without spending a lot of money). But it is available as a backup, if other solutions do not work. + +### Torrent Download (default) + +The preferred way is to to download the blockchain data thru the peer2peer torrent network. This way the community can help to seed the torrents (at least while downloading). Supporters of the project can setup constant seeding. There is no single point of failure within the download structure. + +In the beginning we used just on torrent file - containing all the directories and data like mentioned above. But this had the downside, that everytime when we update the torrent the seeding is bad in the beginning and downloads are slow. Good seeding needs time to build up. + +Thats why there are two torrent files now: + +#### Base Torrent File + +Inspired by the website getbitcoinblockchain.com we use one of their base torrent files to have a basic set of blocks - that will not change for the future. This torrent contains most of the data (the big file) and we dont need to change the torrent for a long time. This way the torrent can get establish a wide spread seeding and the torrent network can take the heavy load. + +At the moment this is just the blk and rev files up to the number: +- /blocks : 01385 +- /testnet3/blocks: 00152 + +#### Update Torrent File (Description) + +All the rest of the files get packaged into a second torrent file. This file will be updated much more often. The seeding is expected to be not that good and download may be slower, but thats OK because its a much smaller file. + +This way a good balance between good seeding and up-to-date blockchain can be reached. + +#### Update Torrent File (Creation) + +To create the Update Torrent file, follow the following step ... + +Have a almost 100% synced bitcoind MAINNET with txindex=1 on a RaspiBlitz + +Stop bitcoind with: +``` +sudo systemctl stop bitcoind +``` + +Delete base torrent blk-files with: +``` +sudo rm /mnt/hdd/bitcoin/blocks/blk00*.dat +sudo rm /mnt/hdd/bitcoin/blocks/blk0{1000..1390}.dat +``` + +Delete base torrent rev-files with: +``` +sudo rm /mnt/hdd/bitcoin/blocks/rev00*.dat +sudo rm /mnt/hdd/bitcoin/blocks/rev0{1000..1390}.dat +``` + +Now change to your computer where you package the torrent files and transfere the three directories into your torrent base directory (should be your current working directory): +``` +scp -r bitcoin@[RaspiBlitzIP]:/mnt/hdd/bitcoin/blocks ./blocks +scp -r bitcoin@[RaspiBlitzIP]:/mnt/hdd/bitcoin/chainstate ./chainstate +scp -r bitcoin@[RaspiBlitzIP]:/mnt/hdd/bitcoin/indexes ./indexes +``` + +Also have a almost 100% synced bitcoind TESTNET with txindex=1 on a RaspiBlitz + +Stop bitcoind with: +``` +sudo systemctl stop bitcoind +``` + +Delete base torrent blk-files with: +``` +sudo rm /mnt/hdd/bitcoin/testnet3/blocks/blk000*.dat +sudo rm /mnt/hdd/bitcoin/testnet3/blocks/blk00{100..152}.dat +``` + +Delete base torrent rev-files with: +``` +sudo rm /mnt/hdd/bitcoin/testnet3/blocks/rev000*.dat +sudo rm /mnt/hdd/bitcoin/testnet3/blocks/rev00{100..152}.dat +``` + +Now change again to your computer where you package the torrent files and transfere the three directories into your torrent base directory (should be your current working directory): +``` +mkdir testnet3 +scp -r bitcoin@[RaspiBlitzIP]:/mnt/hdd/bitcoin/testnet3/blocks ./testnet3/blocks +scp -r bitcoin@[RaspiBlitzIP]:/mnt/hdd/bitcoin/testnet3/chainstate ./testnet3/chainstate +scp -r bitcoin@[RaspiBlitzIP]:/mnt/hdd/bitcoin/testnet3/indexes ./testnet3/indexes +``` + +(Re-)name the "torrent base directory" to the same name as the torrent UPDATE file itself later (without the .torrent ending). For the correct naming see the chapter "Torrent Files Naming Schema" below. + +Now open your torrent client (e.g. qTorrent for OSX) and create a new torrent-file with the freshly renamed "torrent base directory" as source directory. + +Add this list of trackers to your torrent and start seeding (keep a free/empty line between the three single trackers): +``` +udp://tracker.justseed.it:1337 + +udp://tracker.coppersurfer.tk:6969/announce + +udp://open.demonii.si:1337/announce + +udp://denis.stalker.upeer.me:6969/announce +``` + +Name the new torrent file + +To create the torrent file can take some time. Finally add the generated torrent file to the /home.admin/assets/ of the github and change the name of the updateTorrent varibale file in the script 50torrentHDD.bitcoin.sh + +#### Torrent Files Naming Schema + +The base torrent file should always have the following naming scheme: + +`raspiblitz-[CHAINNETWORK][BASEITERATIONNUMBER]-[YEAR]-[MONTH]-[DAY]-base.torrent` + +So for example the second version of the base torrent for litecoin created on 2018-10-31 would have this name: raspiblitz-litecoin2-2018-10-31-base.torrent + +The update torrentfile should always have the following naming schema: + +`raspiblitz-[CHAINNETWORK][BASEITERATIONNUMBER]-[YEAR]-[MONTH]-[DAY]-update.torrent` + +So for exmaple an update torrent created on 2018-12-24 for litecoin that is an update to the second base torrent version would have this name: raspiblitz-litecoin2-2018-12-24-update.torrent \ No newline at end of file diff --git a/background_raspiblitzSettings.md b/background_raspiblitzSettings.md new file mode 100644 index 0000000..e17272e --- /dev/null +++ b/background_raspiblitzSettings.md @@ -0,0 +1,43 @@ +# Background: RaspiBlitz Settings + +## Before Version 1.0 + +The RaspiBlitz started as small collection of shell scripts to setup a bitcoin+lightning node. At this time it was not needed to have settings file. The idea was that the scripts analyse the system state and make the changes required - automatically trying to catch up. That was OK as long RaspiBlitz was just a helper to setup your Lightning node and the rest was up to you. + +Over time users that are running a RaspiBlitz expected that it can handle more complex setup and customization. Also it should be easy to update the system (exchange sd card with a newer image) and should be able to have the same configuration afterwards - keeping its state. Thats why starting from version 1.0 there will be a raspiblitz config file stored on the HDD that stores stores the config state. + +## The Config File + +The RaspiBlitz config file is stored on the HDD root: + +`/mnt/hdd/raspiblitz.conf` + +Its simple structure is: one key-value pair per line. In the end its bash-script syntax to define varibales. The RaspiBlitz shell scripts can import this file with: + +`source /mnt/hdd/raspiblitz.conf` + +After this line all the config values are available and can be worked with. I prefer to call this line in scripts explicitly and not setting this values as environment variables, because when you read as a newbie such a script, you get an idea where the config file is stored. + +## The Config Values + +So see what config parameters are available check the comments in the following script: + +`/home/admin/_bootstrap.sh` + +## Adding new Config Values + +If you extend the RaspiBlitz scripts and you have the need to add a new config key-value add it to the `/home/admin/00enforceConfig.sh` script. There is a section for default values and setting them in the config file, if they dont exist there yet. Because this script runs on every startup, you can be sure that the default value is then available to your extended script - especially if people update their system. + +## Bootstrap Service: Enforcing the Config + +On every start of the RaspiBlitz take the config file and check if the system is running as stated in the config file and when needed make changes to the system. This is done by calling this script on startup with systemd: + +`/home/admin/_bootstrap.sh` + +So if you change the config by hand or you write a script that changes the config, then simply trigger a restart the RaspiBliz. + +Having this script checking the system on every startup, the user can easily update the SD card with a fresh image and the system will automatically establish the old state. + +## What to put into the config file and what not + +All values users put into setup or setting dialogs and that is not stored on the HDD (for example in the config files of lnd or bitcoin) is a hot cadidate to put into the raspi config file. Some values make sense to get stored as a duplicate (for performance or easy of access) - but dont get to wild. \ No newline at end of file diff --git a/build.sdcard/raspbianStretchDesktop.sh b/build.sdcard/raspbianStretchDesktop.sh new file mode 100644 index 0000000..dfaa622 --- /dev/null +++ b/build.sdcard/raspbianStretchDesktop.sh @@ -0,0 +1,422 @@ +#!/bin/bash +######################################################################### +# Build your SD card image based on: +# RASPBIAN STRETCH WITH DESKTOP (2018-06-27) +# https://www.raspberrypi.org/downloads/raspbian/ +# SHA256: 8636ab9fdd8f58a8ec7dde33b83747696d31711d17ef68267dbbcd6cfb968c24 +########################################################################## +# setup fresh SD card with image above - login per SSH and run this script: +########################################################################## + +echo "" +echo "****************************************" +echo "* RASPIBLITZ SD CARD IMAGE SETUP v0.95 *" +echo "****************************************" +echo "" + +echo "" +echo "*** CHECK BASE IMAGE ***" + +# armv7=32Bit , armv8=64Bit +echo "Check if Linux ARM based ..." +isARM=$(uname -m | grep -c 'arm') +if [ ${isARM} -eq 0 ]; then + echo "!!! FAIL !!!" + echo "Can just build on ARM Linux, not on:" + uname -m + exit 1 +fi +echo "OK running on Linux ARM architecture." + +# keep in mind thet 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 + +# update debian +echo "" +echo "*** UPDATE DEBIAN ***" +sudo apt-get update +sudo apt-get upgrade -f -y --allow-change-held-packages + +# special prepare when DietPi +if [ "${baseImage}" = "dietpi" ]; then + echo "" + echo "*** PREPARE DietPi ***" + echo "renaming dietpi user ti pi" + sudo usermod -l pi dietpi + echo "install pip" + sudo apt-get update + sudo apt-get remove -y fail2ban + sudo apt-get install -y build-essential + sudp apt-get install -y python-pip +fi + +# special prepare when Raspbian +if [ "${baseImage}" = "raspbian" ]; then + echo "" + echo "*** PREPARE Raspbian ***" + # do memory split (16MB) + sudo raspi-config nonint do_memory_split 16 + # set to wait until network is available on boot (0 seems to yes) + sudo raspi-config nonint do_boot_wait 0 + # set WIFI country so boot does not block + sudo raspi-config nonint do_wifi_country US + # extra: remove some big packages not needed + sudo apt-get remove -y --purge libreoffice* + sudo apt-get clean + sudo apt-get -y autoremove +fi + +echo "" +echo "*** CONFIG ***" +# based on https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_20_pi.md#raspi-config + +# set new default passwort for root user +echo "root:raspiblitz" | sudo chpasswd +echo "pi:raspiblitz" | sudo chpasswd + +# set Raspi to boot up automatically with user pi (for the LCD) +# https://www.raspberrypi.org/forums/viewtopic.php?t=21632 +sudo raspi-config nonint do_boot_behaviour B2 +sudo bash -c "echo '[Service]' >> /etc/systemd/system/getty@tty1.service.d/autologin.conf" +sudo bash -c "echo 'ExecStart=' >> /etc/systemd/system/getty@tty1.service.d/autologin.conf" +sudo bash -c "echo 'ExecStart=-/sbin/agetty --autologin pi --noclear %I 38400 linux' >> /etc/systemd/system/getty@tty1.service.d/autologin.conf" + +echo "" +echo "*** SOFTWARE UPDATE ***" +# based on https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_20_pi.md#software-update + +# installs like on RaspiBolt +sudo apt-get install -y htop git curl bash-completion jq dphys-swapfile + +echo "" +echo "*** ADDING MAIN USER admin ***" +# based on https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_20_pi.md#adding-main-user-admin +# using the default password 'raspiblitz' + +sudo adduser --disabled-password --gecos "" admin +echo "admin:raspiblitz" | sudo chpasswd +sudo adduser admin sudo +sudo chsh admin -s /bin/bash + +# configure sudo for usage without password entry +echo '%sudo ALL=(ALL) NOPASSWD:ALL' | sudo EDITOR='tee -a' visudo + +echo "*** ADDING SERVICE USER bitcoin" +# based on https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_20_pi.md#adding-the-service-user-bitcoin + +# create user and set default password for user +sudo adduser --disabled-password --gecos "" bitcoin +echo "bitcoin:raspiblitz" | sudo chpasswd + +echo "" +echo "*** SWAP FILE ***" +# based on https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_20_pi.md#moving-the-swap-file +# but just deactivating and deleting old (will be created alter when user adds HDD) + +sudo dphys-swapfile swapoff +sudo dphys-swapfile uninstall + +echo "" +echo "*** INCREASE OPEN FILE LIMIT ***" +# based on https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_20_pi.md#increase-your-open-files-limit + +sudo sed --in-place -i "56s/.*/* soft nofile 128000/" /etc/security/limits.conf +sudo bash -c "echo '* hard nofile 128000' >> /etc/security/limits.conf" +sudo bash -c "echo 'root soft nofile 128000' >> /etc/security/limits.conf" +sudo bash -c "echo 'root hard nofile 128000' >> /etc/security/limits.conf" +sudo bash -c "echo '# End of file' >> /etc/security/limits.conf" + +sudo sed --in-place -i "23s/.*/session required pam_limits.so/" /etc/pam.d/common-session + +sudo sed --in-place -i "25s/.*/session required pam_limits.so/" /etc/pam.d/common-session-noninteractive +sudo bash -c "echo '# end of pam-auth-update config' >> /etc/pam.d/common-session-noninteractive" + +echo "" +echo "*** BITCOIN ***" +# based on https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_30_bitcoin.md#installation + +# set version (change if update is available) +bitcoinVersion="0.17.0" +laanwjPGP="01EA5486DE18A882D4C2684590C8019E36C2E964" + +# prepare directories +sudo -u admin mkdir /home/admin/download +cd /home/admin/download + +# download resources +sudo -u admin wget https://bitcoin.org/bin/bitcoin-core-${bitcoinVersion}/bitcoin-${bitcoinVersion}-arm-linux-gnueabihf.tar.gz +if [ ! -f "./bitcoin-${bitcoinVersion}-arm-linux-gnueabihf.tar.gz" ] +then + echo "!!! FAIL !!! Download BITCOIN BINARY not success." + exit 1 +fi +sudo -u admin wget https://bitcoin.org/bin/bitcoin-core-${bitcoinVersion}/SHA256SUMS.asc +if [ ! -f "./SHA256SUMS.asc" ] +then + echo "!!! FAIL !!! Download SHA256SUMS.asc not success." + exit 1 +fi +sudo -u admin wget https://bitcoin.org/laanwj-releases.asc +if [ ! -f "./laanwj-releases.asc" ] +then + echo "!!! FAIL !!! Download laanwj-releases.asc not success." + exit 1 +fi + +# test checksum +checksum=$(sha256sum --check SHA256SUMS.asc --ignore-missing 2>/dev/null | grep '.tar.gz: OK' -c) +if [ ${checksum} -lt 1 ]; then + echo "" + echo "!!! BUILD FAILED --> Bitcoin download checksum not OK" + exit 1 +fi + +# check gpg finger print +fingerprint=$(gpg ./laanwj-releases.asc 2>/dev/null | grep "${laanwjPGP}" -c) +if [ ${fingerprint} -lt 1 ]; then + echo "" + echo "!!! BUILD FAILED --> Bitcoin download PGP author not OK" + exit 1 +fi +gpg --import ./laanwj-releases.asc +verifyResult=$(gpg --verify SHA256SUMS.asc 2>&1) +goodSignature=$(echo ${verifyResult} | grep 'Good signature' -c) +echo "goodSignature(${goodSignature})" +correctKey=$(echo ${verifyResult} | grep "using RSA key ${laanwjPGP: -16}" -c) +echo "correctKey(${correctKey})" +if [ ${correctKey} -lt 1 ] || [ ${goodSignature} -lt 1 ]; then + echo "" + echo "!!! BUILD FAILED --> LND PGP Verify not OK / signatute(${goodSignature}) verify(${correctKey})" + exit 1 +fi + +# install +sudo -u admin tar -xvf bitcoin-${bitcoinVersion}-arm-linux-gnueabihf.tar.gz +sudo install -m 0755 -o root -g root -t /usr/local/bin bitcoin-${bitcoinVersion}/bin/* +sleep 3 +installed=$(sudo -u admin bitcoind --version | grep "${bitcoinVersion}" -c) +if [ ${installed} -lt 1 ]; then + echo "" + echo "!!! BUILD FAILED --> Was not able to install bitcoind version(${bitcoinVersion})" + exit 1 +fi + +echo "" +echo "*** LITECOIN ***" +# based on https://medium.com/@jason.hcwong/litecoin-lightning-with-raspberry-pi-3-c3b931a82347 + +# set version (change if update is available) +litecoinVersion="0.16.3" +cd /home/admin/download +sudo -u admin wget https://download.litecoin.org/litecoin-${litecoinVersion}/linux/litecoin-${litecoinVersion}-arm-linux-gnueabihf.tar.gz +sudo -u admin tar -xvf litecoin-${litecoinVersion}-arm-linux-gnueabihf.tar.gz +sudo install -m 0755 -o root -g root -t /usr/local/bin litecoin-${litecoinVersion}/bin/* +installed=$(sudo -u admin litecoind --version | grep "${litecoinVersion}" -c) +if [ ${installed} -lt 1 ]; then + echo "" + echo "!!! BUILD FAILED --> Was not able to install litecoind version(${litecoinVersion})" + exit 1 +fi + +echo "" +echo "*** LND ***" + +## based on https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_40_lnd.md#lightning-lnd +#lndVersion="0.5-beta-rc1" +#olaoluwaPGP="65317176B6857F98834EDBE8964EA263DD637C21" +# +# get LND resources +#cd /home/admin/download +#sudo -u admin wget https://github.com/lightningnetwork/lnd/releases/download/v${lndVersion}/lnd-linux-arm-v${lndVersion}.tar.gz +#sudo -u admin wget https://github.com/lightningnetwork/lnd/releases/download/v${lndVersion}/manifest-v${lndVersion}.txt +#sudo -u admin wget https://github.com/lightningnetwork/lnd/releases/download/v${lndVersion}/manifest-v${lndVersion}.txt.sig +#sudo -u admin wget https://keybase.io/roasbeef/pgp_keys.asc +## test checksum +#checksum=$(sha256sum --check manifest-v${lndVersion}.txt --ignore-missing 2>/dev/null | grep '.tar.gz: OK' -c) +#if [ ${checksum} -lt 1 ]; then +# echo "" +# echo "!!! BUILD FAILED --> LND download checksum not OK" +# exit 1 +#fi +## check gpg finger print +#fingerprint=$(gpg ./pgp_keys.asc 2>/dev/null | grep "${olaoluwaPGP}" -c) +#if [ ${fingerprint} -lt 1 ]; then +# echo "" +# echo "!!! BUILD FAILED --> LND download author PGP not OK" +# exit 1 +#fi +#gpg --import ./pgp_keys.asc +#sleep 2 +#verifyResult=$(gpg --verify manifest-v${lndVersion}.txt.sig manifest-v${lndVersion}.txt 2>&1) +#goodSignature=$(echo ${verifyResult} | grep 'Good signature' -c) +#echo "goodSignature(${goodSignature})" +#correctKey=$(echo ${verifyResult} | grep "using RSA key ${olaoluwaPGP: -16}" -c) +#echo "correctKey(${correctKey})" +#if [ ${correctKey} -lt 1 ] || [ ${goodSignature} -lt 1 ]; then +# echo "" +# echo "!!! BUILD FAILED --> LND PGP Verify not OK / signatute(${goodSignature}) verify(${correctKey})" +# exit 1 +#fi +## install +#sudo -u admin tar -xzf lnd-linux-arm-v${lndVersion}.tar.gz +#sudo install -m 0755 -o root -g root -t /usr/local/bin lnd-linux-arm-v${lndVersion}/* +#sleep 3 +#installed=$(sudo -u admin lnd --version | grep "${lndVersion}" -c) +#if [ ${installed} -lt 1 ]; then +# echo "" +# echo "!!! BUILD FAILED --> Was not able to install LND version(${lndVersion})" +# exit 1 +#fi + +##### Build from Source +# To quickly catch up get latest patches if needed +repo="github.com/lightningnetwork/lnd" +commit="61e867741926bcb318432a6344b80161fabd1455" +# BUILDING LND FROM SOURCE +echo "*** Installing Go ***" +wget https://storage.googleapis.com/golang/go1.11.linux-armv6l.tar.gz +if [ ! -f "./go1.11.linux-armv6l.tar.gz" ] +then + echo "!!! FAIL !!! Download not success." + exit 1 +fi +sudo tar -C /usr/local -xzf go1.11.linux-armv6l.tar.gz +sudo rm *.gz +sudo mkdir /usr/local/gocode +sudo chmod 777 /usr/local/gocode +export GOROOT=/usr/local/go +export PATH=$PATH:$GOROOT/bin +export GOPATH=/usr/local/gocode +export PATH=$PATH:$GOPATH/bin +echo "*** Build LND from Source ***" +go get -d $repo +# make sure to always have the same code (commit) to build +# TODO: To update lnd -> change to latest commit +cd $GOPATH/src/$repo +sudo git checkout $commit +make && make install +sudo chmod 555 /usr/local/gocode/bin/lncli +sudo chmod 555 /usr/local/gocode/bin/lnd +sudo bash -c "echo 'export PATH=$PATH:/usr/local/gocode/bin/' >> /home/admin/.bashrc" +sudo bash -c "echo 'export PATH=$PATH:/usr/local/gocode/bin/' >> /home/pi/.bashrc" +sudo bash -c "echo 'export PATH=$PATH:/usr/local/gocode/bin/' >> /home/bitcoin/.bashrc" +lndVersionCheck=$(lncli --version) +echo "LND VERSION: ${lndVersionCheck}" +if [ ${#lndVersionCheck} -eq 0 ]; then + echo "FAIL - Something went wrong with building LND from source." + echo "Sometimes it may just be a connection issue. Reset to fresh Rasbian and try again?" + exit 1 +fi +echo "" +echo "** Link to /usr/local/bin ***" +sudo ln -s /usr/local/gocode/bin/lncli /usr/local/bin/lncli +sudo ln -s /usr/local/gocode/bin/lnd /usr/local/bin/lnd + +echo "" +echo "*** RASPIBLITZ EXTRAS ***" + +# for setup schell scripts +sudo apt-get -y install dialog bc + +# enable copy of blockchain from 2nd HDD formatted with exFAT +sudo apt-get -y install exfat-fuse + +# for blockchain torrent download +sudo apt-get -y install transmission-cli + +# for background downloading +sudo apt-get -y install screen + +# optimization for torrent download +sudo bash -c "echo 'net.core.rmem_max = 4194304' >> /etc/sysctl.conf" +sudo bash -c "echo 'net.core.wmem_max = 1048576' >> /etc/sysctl.conf" + +# *** SHELL SCRIPTS AND ASSETS + +# move files from gitclone +cd /home/admin/ +sudo -u admin git clone https://github.com/rootzoll/raspiblitz.git +sudo -u admin cp /home/admin/raspiblitz/home.admin/*.* /home/admin +sudo -u admin chmod +x *.sh +sudo -u admin cp -r /home/admin/raspiblitz/home.admin/assets /home/admin/ + +# bash aoutstart for admin +sudo bash -c "echo '# automatically start main menu for admin' >> /home/admin/.bashrc" +sudo bash -c "echo './00mainMenu.sh' >> /home/admin/.bashrc" + +# bash aoutstart for pi +# run as exec to dont allow easy physical access by keyboard +# see https://github.com/rootzoll/raspiblitz/issues/54 +sudo bash -c 'echo "# automatic start the LCD info loop" >> /home/pi/.bashrc' +sudo bash -c 'echo "SCRIPT=/home/admin/00infoLCD.sh" >> /home/pi/.bashrc' +sudo bash -c 'echo "# replace shell with script => logout when exiting script" >> /home/pi/.bashrc' +sudo bash -c 'echo "exec \$SCRIPT" >> /home/pi/.bashrc' + +# create /home/admin/setup.sh - which will get executed after reboot by autologin pi user +cat > /home/admin/setup.sh </dev/null | grep "#testnet=1" -c) +if [ ${isMainChain} -gt 0 ];then + chain="main" +fi + # set datadir bitcoin_dir="/home/bitcoin/.${network}" lnd_dir="/home/bitcoin/.lnd" +lnd_macaroon_dir="/home/bitcoin/.lnd/data/chain/${network}/${chain}net" # get uptime & load -load=$(w | grep "load average:" | cut -c11-) +load=$(w | head -n 1 | cut -d 'v' -f2 | cut -d ':' -f2) # get CPU temp cpu=$(cat /sys/class/thermal/thermal_zone0/temp) @@ -35,16 +41,8 @@ else color_ram=${color_green} fi -# get storage -sd_free_ratio=$(printf "%d" "$(df -h | grep "/$" | awk '{ print $4/$2*100 }')") 2>/dev/null -sd=$(printf "%s (%s%%)" "$(df -h | grep '/$' | awk '{ print $4 }')" "${sd_free_ratio}") -if [ ${sd_free_ratio} -lt 10 ]; then - color_sd="${color_red}" -else - color_sd=${color_green} -fi - -hdd_free_ratio=$(printf "%d" "$(df -h | grep '/mnt/hdd$' | awk '{ print $4/$2*100 }')") 2>/dev/null +# get free HDD ratio +hdd_free_ratio=$(printf "%d" "$(df -h | grep '/mnt/hdd$' | awk '{ print $4/$2*100 }')" 2>/dev/null) hdd=$(printf "%s (%s%%)" "$(df -h | grep '/mnt/hdd$' | awk '{ print $4 }')" "${hdd_free_ratio}") if [ ${hdd_free_ratio} -lt 10 ]; then @@ -61,16 +59,16 @@ network_tx=$(ifconfig eth0 | grep 'TX packets' | awk '{ print $6$7 }' | sed 's/[ btc_path=$(command -v ${network}-cli) if [ -n ${btc_path} ]; then btc_title=$network - chain="$(${network}-cli -datadir=${bitcoin_dir} getblockchaininfo | jq -r '.chain')" - if [ -n $chain ]; then + blockchaininfo="$(${network}-cli -datadir=${bitcoin_dir} getblockchaininfo 2>/dev/null)" + if [ ${#blockchaininfo} -gt 0 ]; then btc_title="${btc_title} (${chain}net)" # get sync status - block_chain="$(${network}-cli -datadir=${bitcoin_dir} getblockcount)" - block_verified="$(${network}-cli -datadir=${bitcoin_dir} getblockchaininfo | jq -r '.blocks')" + block_chain="$(${network}-cli -datadir=${bitcoin_dir} getblockcount 2>/dev/null)" + block_verified="$(echo "${blockchaininfo}" | jq -r '.blocks')" block_diff=$(expr ${block_chain} - ${block_verified}) - progress="$(${network}-cli -datadir=${bitcoin_dir} getblockchaininfo | jq -r '.verificationprogress')" + progress="$(echo "${blockchaininfo}" | jq -r '.verificationprogress')" sync_percentage=$(printf "%.2f%%" "$(echo $progress | awk '{print 100 * $1}')") if [ ${block_diff} -eq 0 ]; then # fully synced @@ -92,13 +90,13 @@ if [ -n ${btc_path} ]; then fi # get last known block - last_block="$(${network}-cli -datadir=${bitcoin_dir} getblockcount)" + last_block="$(${network}-cli -datadir=${bitcoin_dir} getblockcount 2>/dev/null)" if [ ! -z "${last_block}" ]; then btc_line2="${btc_line2} ${color_gray}(block ${last_block})" fi # get mem pool transactions - mempool="$(${network}-cli -datadir=${bitcoin_dir} getmempoolinfo | jq -r '.size')" + mempool="$(${network}-cli -datadir=${bitcoin_dir} getmempoolinfo 2>/dev/null | jq -r '.size')" else btc_line2="${color_red}NOT RUNNING\t\t" @@ -106,77 +104,105 @@ if [ -n ${btc_path} ]; then fi # get IP address & port +networkInfo=$(${network}-cli -datadir=${bitcoin_dir} getnetworkinfo 2>/dev/null) local_ip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') -public_ip=$(curl -s http://v4v6.ipv6-test.com/api/myip.php) -public_port=$(cat ${bitcoin_dir}/${network}.conf 2>/dev/null | grep port= | awk -F"=" '{print $2}') -if [ "${public_port}" = "" ]; then - if [ $chain = "test" ]; then - public_port=18333 - else - public_port=8333 - fi +public_ip=$(curl -s http://v4.ipv6-test.com/api/myip.php) +public_port="$(echo ${networkInfo} | jq -r '.localaddresses [0] .port')" +if [ "${public_port}" = "null" ]; then + public_port="8333" fi -public_check=$(curl -s https://bitnodes.earn.com/api/v1/nodes/me-${public_port}/ | jq .success) - -if [ $public_check = "true" ]; then - public="Yes" +# CHAIN NETWORK +public_addr="??" +torInfo="" +# Version +networkVersion=$(${network}-cli -datadir=${bitcoin_dir} -version 2>/dev/null | cut -d ' ' -f6) +# TOR or IP +onionAddress=$(echo ${networkInfo} | jq -r '.localaddresses [0] .address') +if [ "${onionAddress}" != "null" ]; then + # TOR address + public_addr="${onionAddress}:${public_port}" + public="" public_color="${color_green}" + torInfo="+ TOR" else - public="Not reachable" - public_color="${color_red}" + # IP address + public_addr="${public_ip}:${public_port}" + public_check=$(timeout 2s nc -z ${public_ip} ${public_port} 2>/dev/null; echo $?) + if [ $public_check = "0" ]; then + public="Yes" + public_color="${color_green}" + else + public="Not reachable" + public_color="${color_red}" + fi fi -public_addr="${public_ip}:${public_port}" -# get LND info -/usr/local/bin/lncli --macaroonpath=${lnd_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert getinfo 2>&1 | grep "Please unlock" >/dev/null -wallet_unlocked=$? -if [ "$wallet_unlocked" -eq 0 ] ; then +#IP + + +# LIGHTNING NETWORK + +ln_baseInfo="-" +ln_channelInfo="\n" +ln_external="\n" + +wallet_unlocked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2> /dev/null | grep -c unlock) +if [ "$wallet_unlocked" -gt 0 ] ; then alias_color="${color_red}" ln_alias="Wallet Locked" else + ln_getInfo=$(sudo -u bitcoin /usr/local/bin/lncli --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert getinfo 2>/dev/null) + ln_external=$(echo "${ln_getInfo}" | grep "uris" -A 1 | tr -d '\n' | cut -d '"' -f4) alias_color="${color_grey}" -ln_alias="$(/usr/local/bin/lncli --macaroonpath=${lnd_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert getinfo | jq -r '.alias')" 2>/dev/null - ln_walletbalance="$(/usr/local/bin/lncli --macaroonpath=${lnd_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert walletbalance | jq -r '.confirmed_balance')" 2>/dev/null - ln_channelbalance="$(/usr/local/bin/lncli --macaroonpath=${lnd_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert channelbalance | jq -r '.balance')" 2>/dev/null - -fi -ln_channels_online="$(/usr/local/bin/lncli --macaroonpath=${lnd_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert getinfo | jq -r '.num_active_channels')" 2>/dev/null -ln_channels_total="$(/usr/local/bin/lncli --macaroonpath=${lnd_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert listchannels | jq '.[] | length')" 2>/dev/null -ln_external="$(/usr/local/bin/lncli --macaroonpath=${lnd_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert getinfo | jq -r '.uris[0]' | tr "@" " " | awk '{ print $2 }')" 2>/dev/null -ln_external_ip="$(echo $ln_external | tr ":" " " | awk '{ print $1 }' )" 2>/dev/null -if [ "$ln_external_ip" = "$public_ip" ]; then - external_color="${color_grey}" -else - external_color="${color_red}" + ln_alias=$(echo "${ln_getInfo}" | grep "alias" | cut -d '"' -f4) + ln_sync=$(echo "${ln_getInfo}" | grep "synced_to_chain" | grep "true" -c) + if [ ${ln_sync} -eq 0 ]; then + if [ ${#ln_getInfo} -eq 0 ]; then + ln_baseInfo="${color_red} Not Started | Not Ready Yet" + else + item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2> /dev/null | grep "(height" | tail -n1 | awk '{print $10} {print $11} {print $12}' | tr -dc '0-9') + total=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 2>/dev/null | jq -r '.blocks') + ln_baseInfo="${color_red} waiting for chain sync" + if [ ${#item} -gt 0 ]; then + ln_channelInfo="scanning ${item}/${total}" + fi + fi + else + ln_walletbalance="$(sudo -u bitcoin /usr/local/bin/lncli --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert walletbalance | jq -r '.confirmed_balance')" 2>/dev/null + ln_channelbalance="$(sudo -u bitcoin /usr/local/bin/lncli --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert channelbalance | jq -r '.balance')" 2>/dev/null + ln_channels_online="$(echo "${ln_getInfo}" | jq -r '.num_active_channels')" 2>/dev/null + ln_channels_total="$(sudo -u bitcoin /usr/local/bin/lncli --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert listchannels | jq '.[] | length')" 2>/dev/null + ln_baseInfo="${color_gray}wallet ${ln_walletbalance} sat" + ln_channelInfo="${ln_channels_online}/${ln_channels_total} Channels ${ln_channelbalance} sat" + fi fi -networkVersion=$(${network}-cli -datadir=${bitcoin_dir} -version | cut -d ' ' -f6) -ln_alias=`sudo -u admin cat /home/admin/.hostname` - -printf " +sleep 5 +printf " ${color_yellow} ${color_yellow} ${color_yellow} ${color_yellow} ${color_yellow}%s ${color_green} ${ln_alias} -${color_yellow} ${color_gray}${network} Fullnode + Lightning Network -${color_yellow} ${color_yellow}%s -${color_yellow} ,/ ${color_yellow} +${color_yellow} ${color_gray}${network} Fullnode + Lightning Network ${torInfo} +${color_yellow} ,/ ${color_yellow}%s ${color_yellow} ,'/ ${color_gray}%s, CPU %s°C ${color_yellow} ,' / ${color_gray}Free Mem ${color_ram}${ram} ${color_gray} Free HDD ${color_hdd}%s -${color_yellow} ,' /_____, ${color_gray} -${color_yellow} .'____ ,' ${color_gray}Local ${color_green}${local_ip}${color_gray} ▼ ${network_rx} ▲ ${network_tx} -${color_yellow} / ,' ${color_gray}Public ${public_color}${public_addr} ${public} -${color_yellow} / ,' ${color_gray} -${color_yellow} /,' ${color_gray}${network} ${color_green}${networkVersion} ${chain}net ${color_gray}Sync ${sync_color}${sync} (%s) -${color_yellow} /' ${color_gray}LND ${color_green}v0.4.2 ${color_gray}wallet ${ln_walletbalance} sat -${color_yellow} ${color_gray}${ln_channels_online}/${ln_channels_total} Channels ${ln_channelbalance} sat -${color_yellow} ${ln_external} +${color_yellow} ,' /_____, ${color_gray}ssh admin@${color_green}${local_ip}${color_gray} ▼${network_rx} ▲${network_tx} +${color_yellow} .'____ ,' ${color_gray} +${color_yellow} / ,' ${color_gray}${network} ${color_green}${networkVersion} ${chain}net ${color_gray}Sync ${sync_color}${sync} (%s) +${color_yellow} / ,' ${color_gray}Public ${public_color}${public_addr} ${public} +${color_yellow} /,' ${color_gray} +${color_yellow} /' ${color_gray}LND ${color_green}v0.5-beta ${ln_baseInfo} +${color_yellow} ${color_gray}${ln_channelInfo} ${color_yellow} +${color_yellow}${ln_external} " \ -"RaspiBlitz v0.4" \ +"RaspiBlitz v${codeVersion}" \ "-------------------------------------------" \ -"${load##up*, }" "${temp}" \ +"load average:${load##up*, }" "${temp}" \ "${hdd}" "${sync_percentage}" - -echo "$(tput -T xterm sgr0)" +if [ ${#onionAddress} -eq 0 ]; then + # one extra space line at the end if nodeaddress is not TOR + echo "" +fi diff --git a/home.admin/00infoLCD.sh b/home.admin/00infoLCD.sh index 40bfc28..421f8e1 100755 --- a/home.admin/00infoLCD.sh +++ b/home.admin/00infoLCD.sh @@ -1,115 +1,147 @@ #!/bin/sh -if [ "$USER" = "pi" ]; then - # load network - network=`sudo cat /home/admin/.network` +### USER PI AUTOSTART (LCD Display) +# this script gets started by the autologin of the pi user and +# and its output is gets displayed on the LCD or the RaspiBlitz - ### USER PI AUTOSTART (LCD Display) - localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') - - # check if bitcoin service is configured - bitcoinInstalled=$(sudo -u bitcoin ls /mnt/hdd/${network}/ 2>/dev/null | grep -c ${network}.conf) - if [ ${bitcoinInstalled} -eq 1 ]; then - # wait enough secs to let bitcoind init - dialog --pause " Waiting for ${network} to startup and init ..." 8 58 130 - fi - - # show updating status in loop - while : - do - - # refresh network - network=`sudo cat /home/admin/.network` +# check that user is pi +if [ "$USER" != "pi" ]; then + echo "plz run as user pi --> su pi" + exit 1 +fi - # get the setup state - setupStepExists=$(sudo -u admin ls -la /home/admin/.setup | grep -c .setup) - if [ ${setupStepExists} -eq 1 ]; then - setupStep=$(sudo -u admin cat /home/admin/.setup) - else - setupStep=0 +# get the local network IP to be displayed on the lCD +localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') + +# DISPLAY LOOP +chain="" +freshstart=1 +while : + do + + # refresh network (if information is already available) + network=`sudo cat /home/admin/.network 2>/dev/null` + + # get the actual step number of setup process + setupStep=$(sudo -u admin cat /home/admin/.setup 2>/dev/null) + if [ ${#setupStep} -eq 0 ]; then + setupStep=0 + fi + + # before initial setup + if [ ${setupStep} -eq 0 ]; then + + # setup process has not started yet + l1="Login to your RaspiBlitz with:\n" + l2="ssh admin@${localip}\n" + l3="Use password: raspiblitz\n" + boxwidth=$((${#localip} + 24)) + sleep 3 + dialog --backtitle "RaspiBlitz ${localip} - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth} + sleep 5 + + # during basic setup + elif [ ${setupStep} -lt 65 ]; then + + # setup process has not started yet + l1="Login to your RaspiBlitz with:\n" + l2="ssh admin@${localip}\n" + l3="Use your password A\n" + boxwidth=$((${#localip} + 24)) + sleep 3 + dialog --backtitle "RaspiBlitz ${localip} - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth} + sleep 5 + + # when blockchain and lightning are running + elif [ ${setupStep} -lt 100 ]; then + + # when entering first time after boot - display a delay + if [ ${freshstart} -eq 1 ]; then + dialog --pause " Waiting for ${network} to startup and init ..." 8 58 130 + freshstart=0 fi - if [ ${setupStep} -eq 0 ]; then - - # setup process has not started yet - l1="Login to your RaspiBlitz with:\n" - l2="ssh admin@${localip}\n" - l3="Use password: raspiblitz\n" - boxwidth=$((${#localip} + 20)) - dialog --backtitle "RaspiBlitz - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth} - sleep 5 - - elif [ ${setupStep} -lt 100 ]; then - - # setup process init is done and not finished - lndSyncing=$(sudo -u bitcoin lncli getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c false) + # get state of system + if [ ${#chain} -eq 0 ];then + # get chain if not available before chain=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 2>/dev/null | jq -r '.chain') - locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2>/dev/null | grep -c unlock) + fi + lndSynced=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true) + locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2>/dev/null | grep -c unlock) - if [ ${locked} -gt 0 ]; then + if [ ${locked} -gt 0 ]; then - # special case: LND wallet is locked ---> show unlock info - l1="!!! LND WALLET IS LOCKED !!!\n" - l2="Login: ssh admin@${localip}\n" - l3="Use your Password A\n" - boxwidth=$((${#localip} + 20)) - dialog --backtitle "RaspiBlitz - Action Required" --infobox "$l1$l2$l3" 5 ${boxwidth} - sleep 5 - - elif [ ${lndSyncing} -gt 0 ]; then + # special case: LND wallet is locked ---> show unlock info + l1="!!! LND WALLET IS LOCKED !!!\n" + l2="Login: ssh admin@${localip}\n" + l3="Use your Password A\n" + boxwidth=$((${#localip} + 24)) + dialog --backtitle "RaspiBlitz ${localip} - Action Required" --infobox "$l1$l2$l3" 5 ${boxwidth} + sleep 5 - # special case: LND is syncing - /home/admin/80scanLND.sh - sleep 5 + elif [ ${lndSynced} -eq 0 ]; then - else + # special case: LND is syncing + /home/admin/80scanLND.sh + sleep 20 - # setup in progress without special case - password has been changed - l1="Login to your RaspiBlitz with:\n" - l2="ssh admin@${localip}\n" - l3="Use your Password A\n" - boxwidth=$((${#localip} + 20)) + else - if [ ${setupStep} -eq 50 ]; then - l1="Blockhain Setup - monitor progress:\n" - boxwidth=45 - fi + # setup in progress without special case - password has been changed + l1="Login to your RaspiBlitz with:\n" + l2="ssh admin@${localip}\n" + l3="Use your Password A\n" + boxwidth=$((${#localip} + 24)) + sleep 3 + dialog --backtitle "RaspiBlitz ${localip} - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth} + sleep 10 - sleep 3 - dialog --backtitle "RaspiBlitz - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth} - sleep 10 + fi + else + + # RASPIBLITZ iS FULL SETUP + + # check if bitcoin is ready + sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 1>/dev/null 2>error.tmp + clienterror=`cat error.tmp` + rm error.tmp + if [ ${#clienterror} -gt 0 ]; then + l1="Waiting for ${network}d to get ready.\n" + l2="---> Starting Up\n" + l3="Can take longer if devcie was off." + isVerifying=$(echo "${clienterror}" | grep -c 'Verifying blocks') + if [ ${isVerifying} -gt 0 ]; then + l2="---> Verifying Blocks\n" fi - + boxwidth=40 + dialog --backtitle "RaspiBlitz ${localip} - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth} + sleep 5 else - # RaspiBlitz is full Setup + # check if locked + locked=$(sudo -u admin lncli --chain=${network} getinfo 2>&1 | grep -c unlock) + if [ "${locked}" -gt 0 ]; then - chain=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain') - locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c unlock) - if [ ${locked} -gt 0 ]; then - # special case: LND wallet is locked ---> show unlock info l1="!!! LND WALLET IS LOCKED !!!\n" l2="Login: ssh admin@${localip}\n" l3="Use your Password A\n" - boxwidth=$((${#localip} + 22)) - dialog --backtitle "RaspiBlitz - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth} + boxwidth=$((${#localip} + 24)) + dialog --backtitle "RaspiBlitz ${localip} - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth} sleep 5 - + else # no special case - show status display /home/admin/00infoBlitz.sh sleep 5 - + fi fi - done -else - - echo "plz run as user pi --> su pi" + fi + done fi diff --git a/home.admin/00mainMenu.sh b/home.admin/00mainMenu.sh index f395baa..427d890 100755 --- a/home.admin/00mainMenu.sh +++ b/home.admin/00mainMenu.sh @@ -9,11 +9,20 @@ TITLE="" MENU="Choose one of the following options:" OPTIONS=() -# default config values (my get changed later) -if [ ! -f ./.network ]; then - echo "bitcoin" > /home/admin/.network +## get basic info (its OK if not set yet) + +# get name +name=`sudo cat /home/admin/.hostname` + +# get network +network=`sudo cat /home/admin/.network` + +# get chain +chain="test" +isMainChain=$(sudo cat /mnt/hdd/${network}/${network}.conf 2>/dev/null | grep "#testnet=1" -c) +if [ ${isMainChain} -gt 0 ];then + chain="main" fi -network=`cat .network` ## get actual setup state setupState=0; @@ -32,10 +41,17 @@ if [ ${setupState} -eq 0 ]; then elif [ ${setupState} -lt 100 ]; then + # make sure to have a init pause aufter fresh boot + uptimesecs=$(awk '{print $1}' /proc/uptime | awk '{print int($1)}') + waittimesecs=$(expr 150 - $uptimesecs) + if [ ${waittimesecs} -gt 0 ]; then + dialog --pause " Waiting for ${network} to startup and init ..." 8 58 ${waittimesecs} + fi + # continue setup - BACKTITLE="RaspiBlitz - Setup" + BACKTITLE="${name} / ${network} / ${chain}" TITLE="⚡ Welcome to your RaspiBlitz ⚡" - MENU="\nThe setup process in snot finished yet: \n " + MENU="\nThe setup process is not finished yet: \n " OPTIONS+=(CONTINUE "Continue Setup of your RaspiBlitz") HEIGHT=10 @@ -50,23 +66,53 @@ else # MAIN MENU AFTER SETUP - chain=$(${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain') + BACKTITLE="${name} / ${network} / ${chain}" + locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c unlock) if [ ${locked} -gt 0 ]; then # LOCK SCREEN MENU="!!! YOUR WALLET IS LOCKED !!!" - OPTIONS+=(X "Unlock your Lightning Wallet with 'lncli unlock'") + OPTIONS+=(U "Unlock your Lightning Wallet with 'lncli unlock'") else - # REGULAR MENU + switchOption="to MAINNET" + if [ "${chain}" = "main" ]; then + switchOption="back to TESTNET" + fi + + # Basic Options OPTIONS+=(INFO "RaspiBlitz Status Screen" \ - FUNDING "Fund your Wallet" \ + FUNDING "Fund your on-chain Wallet" \ + CASHOUT "Remove Funds from on-chain Wallet" \ CONNECT "Connect to a Peer" \ + CHANNEL "Open a Channel with Peer" \ + SEND "Pay an Invoice/PaymentRequest" \ + RECEIVE "Create Invoice/PaymentRequest" \ + SERVICES "Activate/Deactivate Services" \ lnbalance "Detailed Wallet Balances" \ lnchannels "Lightning Channel List" \ - RECKLES "Console / Terminal") + MOBILE "Connect Mobile Wallet") + + # Depending Options + openChannels=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} listchannels 2>/dev/null | grep chan_id -c) + if [ ${openChannels} -gt 0 ]; then + OPTIONS+=(CLOSEALL "Close all open Channels") + fi + if [ "${network}" = "bitcoin" ]; then + OPTIONS+=(SWITCH "Switch ${switchOption}") + fi + torInstalled=$(sudo ls /mnt/hdd/tor/lnd9735/hostname 2>/dev/null | grep 'hostname' -c) + if [ ${torInstalled} -eq 0 ]; then + OPTIONS+=(TOR "Make reachable thru TOR") + else + OPTIONS+=(NYX "Monitor TOR") + fi + + # final Options + OPTIONS+=(OFF "PowerOff RaspiBlitz") + OPTIONS+=(X "Console / Terminal") fi @@ -106,13 +152,17 @@ case $CHOICE in ./00mainMenu.sh ;; lnbalance) - lnbalance + lnbalance ${network} echo "Press ENTER to return to main menu." read key ./00mainMenu.sh ;; + NYX) + sudo nyx + ./00mainMenu.sh + ;; lnchannels) - lnchannels + lnchannels ${network} echo "Press ENTER to return to main menu." read key ./00mainMenu.sh @@ -129,12 +179,71 @@ case $CHOICE in read key ./00mainMenu.sh ;; - RECKLES) + CASHOUT) + ./BBcashoutWallet.sh + echo "Press ENTER to return to main menu." + read key + ./00mainMenu.sh + ;; + CHANNEL) + ./BBopenChannel.sh + echo "Press ENTER to return to main menu." + read key + ./00mainMenu.sh + ;; + SEND) + ./BBpayInvoice.sh + echo "Press ENTER to return to main menu." + read key + ./00mainMenu.sh + ;; + RECEIVE) + ./BBcreateInvoice.sh + echo "Press ENTER to return to main menu." + read key + ./00mainMenu.sh + ;; + SERVICES) + ./00settingsMenuServices.sh + ./00mainMenu.sh + ;; + CLOSEALL) + ./BBcloseAllChannels.sh + echo "Press ENTER to return to main menu." + read key + ./00mainMenu.sh + ;; + SWITCH) + sudo ./95switchMainTest.sh + echo "Press ENTER to return to main menu." + read key + ./00mainMenu.sh + ;; + MOBILE) + ./97addMobileWallet.sh + echo "Press ENTER to return to main menu." + read key + ./00mainMenu.sh + ;; + TOR) + sudo ./96addTorService.sh + echo "Press ENTER to return to main menu." + read key + ./00mainMenu.sh + ;; + OFF) + echo "After Shutdown remove power from RaspiBlitz." + echo "Press ENTER to start shutdown - then wait some seconds." + read key + sudo shutdown now + exit 0 + ;; + X) lncli -h echo "SUCH WOW come back with ./00mainMenu.sh" - ;; - X) # unlock + ;; + U) # unlock ./AAunlockLND.sh ./00mainMenu.sh ;; -esac +esac \ No newline at end of file diff --git a/home.admin/00settingsMenuServices.sh b/home.admin/00settingsMenuServices.sh new file mode 100644 index 0000000..a8e68e9 --- /dev/null +++ b/home.admin/00settingsMenuServices.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# get raspiblitz config +source /mnt/hdd/raspiblitz.conf + +# show select dialog +CHOICES=$(dialog --checklist "Activate/Deactivate Services:" 15 40 5 \ +1 "Channel Autopilot" ${autoPilot} \ +2>&1 >/dev/tty) +#CHOICES=$(dialog --checklist "Activate/Deactivate Services:" 15 40 5 \ +#1 "Channel Autopilot" ${autoPilot} \ +#2 "UPnP Router-Portforwarding" ${natUPnP} \ +#3 "Auto Unlock on Start" ${autoUnlock} \ +#4 "Seed Torrent Blockchain" ${torrentSeed} \ +#4 "RTL Webinterface" ${rtlWebinterface} \ +#2>&1 >/dev/tty) +dialogcancel=$? +clear + +# check if user canceled dialog +if [ ${dialogcancel} -eq 1 ]; then + echo "user canceled" + exit 1 +fi + +# AUTOPILOT process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "1") +if [ ${check} -eq 1 ]; then choice="on"; fi +sudo sed -i "s/^autoPilot=.*/autoPilot=${choice}/g" /mnt/hdd/raspiblitz.conf + +# confirm reboot to activate new settings with bootstrap.service +dialog --backtitle "Rebooting" --yesno "To activate the settings a reboot is needed." 6 52 +if [ $? -eq 0 ];then + echo "Starting Reboot .." + sudo shutdown -r now +else + echo "No Reboot - changes stored, but maybe not active." + sleep 3 +fi \ No newline at end of file diff --git a/home.admin/10setupBlitz.sh b/home.admin/10setupBlitz.sh index 8550fbb..691eb4e 100755 --- a/home.admin/10setupBlitz.sh +++ b/home.admin/10setupBlitz.sh @@ -4,32 +4,95 @@ echo "" # load network network=`cat .network` +# check chain +chain="test" +isMainChain=$(sudo cat /mnt/hdd/${network}/${network}.conf 2>/dev/null | grep "#testnet=1" -c) +if [ ${isMainChain} -gt 0 ];then + chain="main" +fi + +# get setup progress +setupStep=$(sudo -u admin cat /home/admin/.setup) +if [ ${#setupStep} -eq 0 ];then + setupStep=0 +fi + +# if setup if ready --> REBOOT +if [ ${setupStep} -gt 89 ];then + echo "FINISH by setupstep(${setupStep})" + sleep 3 + ./90finishSetup.sh + exit 0 +fi + # CHECK WHAT IS ALREADY WORKING # check list from top down - so ./10setupBlitz.sh # and re-enters the setup process at the correct spot # in case it got interrupted # check if lightning is running -lndRunning=$(systemctl status lnd.service | grep -c running) +lndRunning=$(systemctl status lnd.service 2>/dev/null | grep -c running) if [ ${lndRunning} -eq 1 ]; then - - chain=$(${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 2>/dev/null | jq -r '.chain') - locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2>/dev/null | grep -c unlock) - lndSyncing=$(sudo -u bitcoin lncli getinfo | jq -r '.synced_to_chain' 2>/dev/null | grep -c false) + + echo "LND is running ..." + sleep 1 + + # check if LND is locked + walletExists=$(sudo ls /mnt/hdd/lnd/data/chain/${network}/${chain}net/wallet.db 2>/dev/null | grep wallet.db -c) + locked=0 + # only when a wallet exists - it can be locked + if [ ${walletExists} -eq 1 ];then + echo "lnd wallet exists ... checking if locked" + sleep 2 + locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2>/dev/null | grep -c unlock) + fi if [ ${locked} -gt 0 ]; then # LND wallet is locked ./AAunlockLND.sh ./10setupBlitz.sh - elif [ ${lndSyncing} -gt 0 ]; then + exit 0 + fi + + # check if blockchain still syncing (during sync sometimes CLI returns with error at this point) + chainInfo=$(sudo -u bitcoin ${network}-cli getblockchaininfo 2>/dev/null | grep 'initialblockdownload') + chainSyncing=1 + if [ ${#chainInfo} -gt 0 ];then + chainSyncing=$(echo "${chainInfo}" | grep "true" -c) + fi + if [ ${chainSyncing} -eq 1 ]; then + echo "Sync Chain ..." + sleep 3 ./70initLND.sh - else - ./90finishSetup.sh + exit 0 fi - exit 1 + + # check if lnd is scanning blockchain + lndInfo=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} getinfo | grep "synced_to_chain") + lndSyncing=1 + if [ ${#lndInfo} -gt 0 ];then + lndSyncing=$(echo "${chainInfo}" | grep "false" -c) + fi + if [ ${lndSyncing} -eq 1 ]; then + echo "Sync LND ..." + sleep 3 + ./70initLND.sh + exit 0 + fi + + # if unlocked, blockchain synced and LND synced to chain .. finisch Setup + echo "FINSIH ... " + sleep 3 + ./90finishSetup.sh + exit 0 + fi # check if bitcoin is running -bitcoinRunning=$(sudo -u bitcoin ${network}-cli getblockchaininfo 2>/dev/null | grep -c blocks) +bitcoinRunning=$(systemctl status ${network}d.service 2>/dev/null | grep -c running) +if [ ${bitcoinRunning} -eq 0 ]; then + # double check + bitcoinRunning=$(${network}-cli getblockchaininfo | grep "initialblockdownload" -c) +fi if [ ${bitcoinRunning} -eq 1 ]; then echo "OK - ${network}d is running" echo "Next step run Lightning" @@ -43,10 +106,15 @@ if [ ${mountOK} -eq 1 ]; then # are there any signs of blockchain data if [ -d "/mnt/hdd/${network}" ]; then + + echo "TAIL Chain Network Log" + sudo tail /mnt/hdd/${network}/debug.log + echo "" + echo "UNKOWN STATE - there is blockain data folder, but blockchaind is not running" echo "It seems that something went wrong during sync/download/copy of the blockchain." - echo "Maybe try --> ./60finishHDD.sh" - echo "If this sill is not working reboot after running --> sudo rm -r /mnt/hdd/${network}" + echo "If you want start fresh --> sudo rm -r /mnt/hdd/${network}" + echo "Or something with the config is not correct." exit 1 fi @@ -125,7 +193,7 @@ if [ ! -f "home/admin/.setup" ]; then echo "*** Update System ***" sudo apt-mark hold raspberrypi-bootloader sudo apt-get update - sudo apt-get upgrade -f -y --force-yes + sudo apt-get upgrade -f -y --allow-change-held-packages echo "OK - System is now up to date" fi diff --git a/home.admin/20initDialog.sh b/home.admin/20initDialog.sh index 071d9a2..e411f4d 100755 --- a/home.admin/20initDialog.sh +++ b/home.admin/20initDialog.sh @@ -11,12 +11,12 @@ while [ ${#result} -eq 0 ] l1="Please enter the name of your new RaspiBlitz:\n" l2="one word, keep characters basic & not too long" dialog --backtitle "RaspiBlitz - Setup" --inputbox "$l1$l2" 11 52 2>$_temp - result=`cat $_temp` + result=$( cat $_temp | tr -d [:space:] ) shred $_temp done # set lightning alias -sed -i "7s/.*/alias=${result}/" /home/admin/assets/lnd.${network}.conf +sed -i "s/^alias=.*/alias=${result}/g" /home/admin/assets/lnd.${network}.conf # store hostname for later - to be set right before the next reboot # work around - because without a reboot the hostname seems not updates in the whole system @@ -40,7 +40,7 @@ dialog --backtitle "RaspiBlitz - Setup"\ --inputbox "Please enter your Master/Admin Password A:\n!!! This is new password to login per SSH !!!" 10 52 2>$_temp # get user input -result=`cat $_temp` +result=$( cat $_temp ) shred $_temp # check input (check for more later) @@ -67,13 +67,13 @@ while [ ${#result} -lt 8 ] do dialog --backtitle "RaspiBlitz - Setup"\ --inputbox "Enter your RPC Password B (min 8 chars):" 9 52 2>$_temp - result=`cat $_temp` + result=$( cat $_temp ) shred $_temp done # set Blockchain RPC Password (for admin cli & template for user bitcoin) -sed -i "14s/.*/rpcpassword=$result/" /home/admin/assets/${network}.conf - +sed -i "s/^rpcpassword=.*/rpcpassword=${result}/g" /home/admin/assets/${network}.conf +sed -i "s/^${network}d.rpcpass=.*/${network}d.rpcpass=${result}/g" /home/admin/assets/lnd.${network}.conf # success info dialog dialog --backtitle "RaspiBlitz - SetUP" --msgbox "OK - RPC password changed to '$result'\n\nNow starting the Setup of your RaspiBlitz." 7 52 diff --git a/home.admin/40addHDD.sh b/home.admin/40addHDD.sh index d0e3ced..9d58754 100755 --- a/home.admin/40addHDD.sh +++ b/home.admin/40addHDD.sh @@ -49,6 +49,8 @@ if [ ${existsHDD} -gt 0 ]; then echo "*** Analysing HDD Content ***" if [ -d "/mnt/hdd/${network}" ]; then + sudo chown -R bitcoin:bitcoin /mnt/hdd/bitcoin 2>/dev/null + sudo chown -R bitcoin:bitcoin /mnt/hdd/litecoin 2>/dev/null echo "Looks like the HDD is prepared with the Blockchain." echo "Continuing with finishing the system setup ..." ./60finishHDD.sh diff --git a/home.admin/50downloadHDD.sh b/home.admin/50downloadHDD.sh index 7cc9f6f..c8704f8 100755 --- a/home.admin/50downloadHDD.sh +++ b/home.admin/50downloadHDD.sh @@ -1,10 +1,11 @@ #!/bin/bash echo "" -# *** BITCOIN *** +# *** BITCOIN (just mainnet) *** bitcoinList="" # url to list with other sources -bitcoinUrl="ftp://anonymous:anonymous@tll9xsfkjht8j26z.myfritz.net/raspiblitz-bitcoin-2018-07-16" -bitcoinSize=231000000 # 231235816-tolerance +#bitcoinUrl="ftp://anonymous:anonymous@91.83.237.185:21/raspiblitz-bitcoin-2018-07-16" +bitcoinUrl="ftp://f00f39c4:download@w0189aba.kasserver.com/" +bitcoinSize=253000000 # 253827180-tolerance # *** LITECOIN *** litecoinList="" # url to list with other sources @@ -28,7 +29,6 @@ fi name="Download" targetDir="/mnt/hdd/download/" targetSize=$size -maxTimeoutLoops=500 command="sudo wget -c -r -P ${targetDir} -q --show-progress ${url}" # starting session if needed @@ -48,8 +48,6 @@ sleep 3 # monitor session screenDump="... started ..." actualSize=0 -timeout=1 -timeoutInfo="-" while : do @@ -57,7 +55,6 @@ while : screen -wipe 1>/dev/null isRunning=$( screen -S ${name} -ls | grep "${name}" -c ) if [ ${isRunning} -eq 0 ]; then - timeout=0 echo "OK - session finished" break fi @@ -68,35 +65,21 @@ while : freshSize=0 fi progress=$(echo "scale=2; $freshSize*100/$targetSize" | bc) - echo $progress > '.${name}.progress' - - # detect if since last loop any progress occured - if [ ${actualSize} -eq ${freshSize} ]; then - timeoutInfo="${timeout}/${maxTimeoutLoops}" - timeout=$(( $timeout + 1 )) - else - timeout=1 - timeoutInfo="no timeout detected" - fi - actualSize=$freshSize + echo $progress > ".${name}.progress" - # detect if mx timeout loop limit is reached - if [ ${timeout} -gt ${maxTimeoutLoops} ]; then - echo "FAIL - download hit timeout" - break - fi + actualSize=$freshSize # display info screen clear echo "****************************************************" echo "Monitoring Screen Session: ${name}" echo "Progress: ${progress}% (${actualSize} of ${targetSize})" - echo "Timeout: ${timeoutInfo}" echo "If needed press key x to stop ${name}" + echo "NOTICE: This can take multiple hours or days !!" echo "Its OK to close terminal now and SSH back in later." echo "****************************************************" screen -S ${name} -X hardcopy .${name}.out - newScreenDump=$(cat .Download.out | grep . | tail -10) + newScreenDump=$(cat .${name}.out | grep . | tail -8) if [ ${#newScreenDump} -gt 0 ]; then screenDump=$newScreenDump fi @@ -152,10 +135,10 @@ if [ ${finalSize} -lt ${targetSize} ]; then # Download failed sleep 3 echo -ne '\007' - dialog --title " WARNING " --yesno "The download failed or is not complete. Maybe try again (later). Do you want keep already downloaded data for next try?" 6 57 + dialog --title " WARNING " --yesno "The download failed or is not complete. Maybe try again (later). Do you want keep already downloaded data for next try?" 8 57 response=$? case $response in - 1) sudo rm -rf ${targetDir}${targetPath} ;; + 1) sudo rm -rf ${targetDir} ;; esac ./00mainMenu.sh exit 1; diff --git a/home.admin/50torrentHDD.bitcoin.sh b/home.admin/50torrentHDD.bitcoin.sh new file mode 100755 index 0000000..ea2cc55 --- /dev/null +++ b/home.admin/50torrentHDD.bitcoin.sh @@ -0,0 +1,234 @@ +#!/bin/bash +echo "" + +# see background_downloadBlockchain.md for info +# why there are two torrent files + +# torrent files that are available +# in directory /home.admin/assets/ +# WITHOUT THE '.torrent' ENDING +baseTorrentFile="raspiblitz-bitcoin1-2018-10-13-base" +updateTorrentFile="raspiblitz-bitcoin1-2018-10-13-update" + +# make sure rtorrent is available +sudo apt-get install rtorrent -y +echo "" + +targetDir="/mnt/hdd/torrent" +sessionDir="/home/admin/.rtorrent.session" +sudo mkdir ${sessionDir} 2>/dev/null + +############################## +# CHECK TORRENT 1 "BLOCKCHAIN" +############################## + +echo "*** checking torrent 1: base blockchain" +torrentComplete1=$(cat ${sessionDir}/blockchain/*.torrent.rtorrent | grep ':completei1' -c) +echo "torrentComplete1(${torrentComplete1})" +if [ ${torrentComplete1} -eq 0 ]; then + + # check if screen session for this torrent + isRunning1=$( screen -S blockchain -ls | grep "blockchain" -c ) + echo "isRunning1(${isRunning1})" + if [ ${isRunning1} -eq 0 ]; then + + # start torrent download in screen session + echo "starting torrent: blockchain" + command1="sudo rtorrent -n -d ${targetDir} -s ${sessionDir}/blockchain/ /home/admin/assets/${baseTorrentFile}.torrent" + sudo mkdir ${targetDir} 2>/dev/null + sudo mkdir ${sessionDir}/blockchain/ 2>/dev/null + screenCommand="screen -S blockchain -L screen.log -dm ${command1}" + echo "${screenCommand}" + bash -c "${screenCommand}" + fi +fi +sleep 2 + +############################## +# CHECK TORRENT 2 "UPDATE" +############################## + +echo "*** checking torrent 2: update blockchain" +torrentComplete2=$(cat ${sessionDir}/update/*.torrent.rtorrent | grep ':completei1' -c) +echo "torrentComplete2(${torrentComplete2})" +if [ ${torrentComplete2} -eq 0 ]; then + + # check if screen session for this torrent + isRunning2=$( screen -S update -ls | grep "update" -c ) + echo "isRunning2(${isRunning2})" + if [ ${isRunning2} -eq 0 ]; then + + # start torrent download in screen session + echo "starting torrent: update" + command2="sudo rtorrent -n -d ${targetDir} -s ${sessionDir}/update/ /home/admin/assets/${updateTorrentFile}.torrent" + sudo mkdir ${targetDir} 2>/dev/null + sudo mkdir ${sessionDir}/update/ 2>/dev/null + screenCommand="screen -S update -L screen.log -dm ${command2}" + echo "${screenCommand}" + bash -c "${screenCommand}" + + fi +fi +sleep 2 + +############################## +# MONITOR PROGRESS +############################## + +sleep 3 + +# monitor screen session +screenDump1="... started ..." +screenDump2="... started ..." +torrentComplete1=0 +torrentComplete2=0 +while : + do + + # display info screen + clear + echo "****************************************************" + echo "Monitoring Screen Session: Torrent base+update" + echo "If needed press key x to stop TORRENT download" + echo "NOTICE: This can take multiple hours or days !!" + echo "Its OK to close terminal now and SSH back in later." + echo "****************************************************" + echo "" + + # display torrent 1 info + echo "*** 1) Status Torrent 'blockchain':" + torrentComplete1=$(cat ${sessionDir}/blockchain/*.torrent.rtorrent | grep ':completei1' -c) + if [ ${torrentComplete1} -eq 0 ]; then + screen -S blockchain -X hardcopy .blockchain.out + newScreenDump=$(cat .blockchain.out | head -6 | tail -3 ) + if [ ${#newScreenDump} -gt 0 ]; then + screenDump1=$newScreenDump + fi + echo "$screenDump1" + else + echo "Completed" + fi + echo "" + + # display torrent 2 info + echo "*** 2) Status Torrent 'update':" + torrentComplete2=$(cat ${sessionDir}/update/*.torrent.rtorrent | grep ':completei1' -c) + if [ ${torrentComplete2} -eq 0 ]; then + screen -S update -X hardcopy .update.out + newScreenDump=$(cat .update.out| head -6 | tail -3 ) + if [ ${#newScreenDump} -gt 0 ]; then + screenDump2=$newScreenDump + fi + echo "$screenDump2" + else + echo "Completed" + fi + echo "" + + # check if both torrents completed + if [ ${torrentComplete1} -eq 1 ]; then + if [ ${torrentComplete2} -eq 1 ]; then + echo "OK - all torrents finished" + break + fi + fi + + # wait 2 seconds for key input + read -n 1 -t 2 keyPressed + + # check if user wants to abort session + if [ "${keyPressed}" = "x" ]; then + echo "" + echo "Aborting getbitcoinblockchain.com" + break + fi + + done + +# clean up +rm -f .blockchain.out +rm -f .update.out + +############################## +# AFTER PARTY & CLEAN UP +############################## + +# quit session1 +isRunning=$( screen -S blockchain -ls | grep "blockchain" -c ) +if [ ${isRunning} -eq 1 ]; then + # get the PID of screen session + sessionPID=$(screen -ls | grep "blockchain" | cut -d "." -f1 | xargs) + echo "killing screen session PID(${sessionPID})" + # kill all child processes of screen sceesion + sudo pkill -P ${sessionPID} + echo "proccesses killed" + sleep 3 + # tell the screen session to quit and wait a bit + screen -S blockchain -X quit 1>/dev/null + sleep 3 + echo "cleaning screen" + screen -wipe 1>/dev/null + sleep 3 +fi + +# quit session2 +isRunning=$( screen -S update -ls | grep "update" -c ) +if [ ${isRunning} -eq 1 ]; then + # get the PID of screen session + sessionPID=$(screen -ls | grep "update" | cut -d "." -f1 | xargs) + echo "killing screen session PID(${sessionPID})" + # kill all child processes of screen sceesion + sudo pkill -P ${sessionPID} + echo "proccesses killed" + sleep 3 + # tell the screen session to quit and wait a bit + screen -S update -X quit 1>/dev/null + sleep 3 + echo "cleaning screen" + screen -wipe 1>/dev/null + sleep 3 +fi + +# check result +torrentComplete=0 +torrentComplete1=$(cat ${sessionDir}/blockchain/*.torrent.rtorrent | grep ':completei1' -c) +torrentComplete2=$(cat ${sessionDir}/update/*.torrent.rtorrent | grep ':completei1' -c) +if [ ${torrentComplete1} -eq 1 ]; then + if [ ${torrentComplete2} -eq 1 ]; then + torrentComplete=1 + fi +fi +if [ ${torrentComplete} -eq 0 ]; then + + # User Cancel --> Torrent incomplete + sleep 3 + echo -ne '\007' + dialog --title " WARNING " --yesno "The download failed or is not complete. Maybe try again (later). Do you want keep already downloaded data for next try?" 8 57 + response=$? + case $response in + 1) sudo rm -rf ${targetDir} ;; + esac + ./00mainMenu.sh + exit 1; + +fi + +# the path torrent will download to +targetPath1="${targetDir}/${baseTorrentFile}" +targetPath2="${targetDir}/${updateTorrentFile}" + +# Download worked / just move, copy on USB2 >4h +echo "" +echo "*** Moving Files ***" +date +%s +echo "can take some minutes ... öease wait" + +sudo mkdir /mnt/hdd/bitcoin 2>/dev/null +sudo mv ${targetPath1}/* /mnt/hdd/bitcoin/ +sudo cp -r ${targetPath2}/* /mnt/hdd/bitcoin/ +sudo rm -r ${targetDir} +echo "OK" +date +%s + +# continue setup +./60finishHDD.sh diff --git a/home.admin/50torrentHDD.sh b/home.admin/50torrentHDD.sh index 0118d34..6b2428b 100755 --- a/home.admin/50torrentHDD.sh +++ b/home.admin/50torrentHDD.sh @@ -1,9 +1,12 @@ -#!/bin/sh +#!/bin/bash +echo "" + +# --> TODO: Check https://getbitcoinblockchain.com/ # *** BITCOIN Torrent *** -bitcoinTorrent="raspiblitz-bitcoin-2018-07-16" -bitcoinTorrentsize=231230512 - +bitcoinTorrent="raspiblitz-bitcoin-2018-10-06" +bitcoinTorrentsize=259000000 + # *** LITECOIN Torrent *** litecoinTorrent="raspiblitz-litecoin-2018-07-29" litecoinTorrentsize=10240000 @@ -11,58 +14,161 @@ litecoinTorrentsize=10240000 # load network network=`cat .network` +## experimental redirect if bitcoin +if [ "$network" = "bitcoin" ]; then + ./50torrentHDD.bitcoin.sh + exit 1 +fi + +# make sure rtorrent is available +sudo apt-get install rtorrent -y +echo "" + # settings based on network torrent=$bitcoinTorrent -torrentsize=$bitcoinTorrentsize +size=$bitcoinTorrentsize if [ "$network" = "litecoin" ]; then torrent=$litecoinTorrent - torrentsize=$litecoinTorrentsize + size=$litecoinTorrentsize fi -echo "" -echo "torrentFile: ${torrent}" -echo "" -echo "*** Downloading TORRENT ***" -echo "IN CASE DOWNLOAD DOES NOT START OR TOO SLOW:" -echo "CTRL+z start ./10setupBlitz.sh choose other option" -echo "***************************" -echo "" -tmpfile=$(mktemp) -chmod a+x $tmpfile -echo "killall transmission-cli" > $tmpfile -sudo transmission-cli ./assets/$torrent.torrent -D -et -w /mnt/hdd -f $tmpfile -echo "OK - Download closed" -echo "" +# screen background monitoring settings +name="Torrent" +targetDir="/mnt/hdd/torrent" +targetSize=$size +sessionDir="/home/admin/.rtorrent.session/" +command="sudo rtorrent -n -d ${targetDir} -s ${sessionDir} /home/admin/assets/${torrent}.torrent" +# 2 screen sessions - differnt rtorrent session dir? +#sudo rtorrent -n -d /mnt/hdd/torrent -s /home/admin/.rtorrent.session/ https://getbitcoinblockchain.com/blockchain.torrent +#sudo rtorrent -n -d /mnt/hdd/torrent -s /home/admin/.rtorrent.session/ https://getbitcoinblockchain.com/update.torrent -echo "*** Checking TORRENT ***" -echo "wait a moment" -sleep 5 -downloadsize=$(sudo du -s /mnt/hdd/$torrent/ | awk '{print $1}' | tr -dc '0-9') -if [ ${#downloadsize} -eq 0 ]; then - downloadsize=0 +# starting screen session if needed +echo "checking if ${name} has a running screen session" +screen -wipe 1>/dev/null +isRunning=$( screen -S ${name} -ls | grep "${name}" -c ) +echo "isRunning(${isRunning})" +if [ ${isRunning} -eq 0 ]; then + echo "Starting screen session" + sudo mkdir ${targetDir} 2>/dev/null + sudo mkdir ${sessionDir} 2>/dev/null + screenCommand="screen -S ${name} -L screen.log -dm ${command}" + echo "${screenCommand}" + bash -c "${screenCommand}" +else + echo "Continue screen session" fi -# add some tolerance for checking -size="$(($size-1024000))" -echo "download size is(${downloadsize}) needs to be minimum(${size})" -if [ ${downloadsize} -lt ${size} ]; then +sleep 3 + +# monitor screen session +screenDump="... started ..." +actualSize=0 +torrentComplete=0 +while : + do + + # check if completed by inspecting rtorrent session files + torrentComplete=$(cat /home/admin/.rtorrent.session/*.torrent.rtorrent | grep ':completei1' -c) + if [ ${torrentComplete} -eq 1 ]; then + echo "OK - torrent finished" + break + fi + + # calculate progress and write it to file for LCD to read + freshSize=$( du -s ${targetDir} | head -n1 | awk '{print $1;}' ) + if [ ${#actualSize} -eq 0 ]; then + freshSize=0 + fi + progress=$(echo "scale=2; $freshSize*100/$targetSize" | bc) + echo $progress > ".${name}.progress" + + actualSize=$freshSize + + # display info screen + clear + echo "****************************************************" + echo "Monitoring Screen Session: ${name}" + echo "Progress: ${progress}% (${actualSize} of ${targetSize})" + echo "If needed press key x to stop ${name}" + echo "NOTICE: This can take multiple hours or days !!" + echo "Its OK to close terminal now and SSH back in later." + echo "****************************************************" + screen -S ${name} -X hardcopy .${name}.out + newScreenDump=$(cat .${name}.out | grep . | tail -8) + if [ ${#newScreenDump} -gt 0 ]; then + screenDump=$newScreenDump + fi + echo "$screenDump" + + # wait 2 seconds for key input + read -n 1 -t 2 keyPressed + + # check if user wants to abort session + if [ "${keyPressed}" = "x" ]; then + echo "" + echo "Aborting ${name}" + break + fi + + done + +# clean up +rm -f .${name}.out +rm -f .${name}.progress + +# quit session if still running +isRunning=$( screen -S ${name} -ls | grep "${name}" -c ) +if [ ${isRunning} -eq 1 ]; then + # get the PID of screen session + sessionPID=$(screen -ls | grep "${name}" | cut -d "." -f1 | xargs) + echo "killing screen session PID(${sessionPID})" + # kill all child processes of screen sceesion + sudo pkill -P ${sessionPID} + echo "proccesses killed" + sleep 3 + # tell the screen session to quit and wait a bit + screen -S ${name} -X quit 1>/dev/null + sleep 3 + echo "cleaning screen" + screen -wipe 1>/dev/null + sleep 3 +fi + +# the path torrent will download to +targetPath="${targetDir}/${torrent}" +echo "path to downloaded data is ${targetPath}" + +# calculate progress and write it to file for LCD to read +finalSize=$( du -s ${targetDir} 2>/dev/null | head -n1 | awk '{print $1;}' ) +if [ ${#finalSize} -eq 0 ]; then + finalSize=0 +fi +echo "final size is ${finalSize} of targeted size ${targetSize}" + +# check result +if [ ${finalSize} -lt ${targetSize} ]; then + + # Download failed sleep 3 echo -ne '\007' - dialog --title " WARNING " --yesno "The download failed or is not complete. Do you want keep already downloaded data?" 6 57 + dialog --title " WARNING " --yesno "The download failed or is not complete. Maybe try again (later). Do you want keep already downloaded data for next try?" 8 57 response=$? case $response in - 1) sudo rm -rf /mnt/hdd/$torrent ; sudo rm -rf /root/.config/transmission ;; + 1) sudo rm -rf ${targetDir} ;; esac ./00mainMenu.sh exit 1; -fi + +else -echo "*** Moving Files ***" -echo "moving files ..." -sudo mv /mnt/hdd/$torrent /mnt/hdd/${network} -echo "" + # Download worked / just move, copy on USB2 >4h + echo "*** Moving Files ***" + echo "START" + date +%s + sudo mv ${targetPath} /mnt/hdd/${network} + echo "OK" + date +%s -# set SetupState -echo "50" > /home/admin/.setup + # continue setup + ./60finishHDD.sh -# continue setup -./60finishHDD.sh \ No newline at end of file +fi \ No newline at end of file diff --git a/home.admin/60finishHDD.sh b/home.admin/60finishHDD.sh index 583900f..0998a8d 100755 --- a/home.admin/60finishHDD.sh +++ b/home.admin/60finishHDD.sh @@ -17,14 +17,14 @@ if [ ${mountOK} -eq 1 ]; then echo "*** Prepare ${network} ***" sudo killall -u bitcoin sleep 5 - sudo rm -r /home/bitcoin/.${network} + sudo rm -r /home/bitcoin/.${network} 2>/dev/null sleep 2 if [ -d /home/bitcoin/.${network} ]; then echo "FAIL - /home/bitcoin/.${network} exists and cannot be removed!" exit 1 fi sudo cp /home/admin/assets/${network}.conf /mnt/hdd/${network}/${network}.conf - sudo mkdir /home/admin/.${network} + sudo mkdir /home/admin/.${network} 2>/dev/null sudo cp /home/admin/assets/${network}.conf /home/admin/.${network}/${network}.conf sudo ln -s /mnt/hdd/${network} /home/bitcoin/.${network} sudo mkdir /mnt/hdd/lnd @@ -40,6 +40,8 @@ if [ ${mountOK} -eq 1 ]; then echo "*** Start ${network} ***" echo "This can take a while .." sudo cp /home/admin/assets/${network}d.service /etc/systemd/system/${network}d.service + sudo chmod +x /etc/systemd/system/${network}d.service + sudo systemctl daemon-reload sudo systemctl enable ${network}d.service sudo systemctl start ${network}d.service echo "Giving ${network}d service 180 seconds to init - please wait ..." diff --git a/home.admin/70initLND.sh b/home.admin/70initLND.sh index 2c285ad..9504f1a 100755 --- a/home.admin/70initLND.sh +++ b/home.admin/70initLND.sh @@ -4,9 +4,20 @@ echo "" # load network network=`cat .network` +# get chain +chain="test" +isMainChain=$(sudo cat /mnt/hdd/${network}/${network}.conf 2>/dev/null | grep "#testnet=1" -c) +if [ ${isMainChain} -gt 0 ];then + chain="main" +fi + # verify that bitcoin is running echo "*** Checking ${network} ***" -bitcoinRunning=$(sudo -u bitcoin ${network}-cli getblockchaininfo | grep -c blocks) +bitcoinRunning=$(systemctl status ${network}d.service 2>/dev/null | grep -c running) +if [ ${bitcoinRunning} -eq 0 ]; then + #doublecheck + bitcoinRunning=$(${network}-cli getblockchaininfo | grep -c verificationprogress) +fi if [ ${bitcoinRunning} -eq 0 ]; then # HDD is not available yet echo "FAIL - ${network}d is not running" @@ -16,34 +27,32 @@ fi echo "OK - ${network}d is running" echo "" -###### Wait for Blochain Sync -echo "*** Syncing Blockchain ***" -ready=0 -while [ ${ready} -eq 0 ] +# verify that chainnetwork is ready +chainIsReady=0 +while [ ${chainIsReady} -eq 0 ] do - progress="$(sudo -u bitcoin ${network}-cli getblockchaininfo | jq -r '.verificationprogress')" - verySmallProgress=$(echo $progress | grep -c 'e-'); - if [ ${verySmallProgress} -eq 1 ]; then - progress="0.00"; - fi - ready=$(echo $progress'>0.99' | bc -l) - sync_percentage=$(printf "%.2f%%" "$(echo $progress | awk '{print 100 * $1}')") - #echo "progress($progress) verySmallProgress($verySmallProgress) ready($ready) sync_percentage($sync_percentage)" - if [ ${#ready} -eq 0 ]; then - echo "waiting for init ... can take a while" - ready=0 - elif [ "$sync_percentage" = "0.00%" ]; then - echo "waiting for network ... can take a while" - ready=0 - elif [ ${ready} -eq 0 ]; then - echo "${sync_percentage}" + echo "*** Test if chainnetwork is ready ..." + date +%s + result=$(${network}-cli getblockchaininfo 2>error.out) + error=`cat error.out` + rm error.out + echo "result(${result})" + echo "error(${error})" + if [ ${#error} -gt 0 ]; then + testnetAdd="" + if [ "${chain}" = "test" ]; then + testnetAdd="testnet3/" + fi + sudo tail -n 5 /mnt/hdd/bitcoin/${testnetAdd}debug.log + echo "Waiting 1 minute and then trying again ..." + sleep 60 + echo "" else - echo "finishing sync ... can take a while" + echo "OK - chainnetwork is working" + chainIsReady=1 + break fi - sleep 3 done -echo "OK - Blockchain is synced" -echo "" ###### LND Config echo "*** LND Config ***" @@ -64,42 +73,47 @@ echo "" ###### Start LND echo "*** Starting LND ***" -lndRunning=$(systemctl status lnd.service | grep -c running) +lndRunning=$(systemctl status lnd.service 2>/dev/null | grep -c running) if [ ${lndRunning} -eq 0 ]; then sed -i "5s/.*/Wants=${network}d.service/" ./assets/lnd.service sed -i "6s/.*/After=${network}d.service/" ./assets/lnd.service sudo cp /home/admin/assets/lnd.service /etc/systemd/system/lnd.service + sudo chmod +x /etc/systemd/system/lnd.service sudo systemctl enable lnd sudo systemctl start lnd - echo "Started LND .. waiting 30 seconds for init ..." - sleep 30 + echo "Starting LND ... give 120 seconds to init." + sleep 120 fi ###### Check LND is running -lndRunning=$(systemctl status lnd.service | grep -c running) -if [ ${lndRunning} -eq 0 ]; then - echo "!!!!!!!!!!!!!!!!!!!!!!!!!" - echo "FAIL - LND is not running" - echo "recheck with original tutorial -->" - echo "https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_40_lnd.md" - exit 1 -fi +lndRunning=0 +while [ ${lndRunning} -eq 0 ] +do + lndRunning=$(systemctl status lnd.service | grep -c running) + if [ ${lndRunning} -eq 0 ]; then + date +%s + echo "LND not ready yet ... waiting another 60 seconds." + echo "If this takes too long (more then 10min total) --> CTRL+c and report Problem" + sleep 60 + fi +done echo "OK - LND is running" echo "" ###### Instructions on Creating LND Wallet -setupStep=0 -setupStep=$(sudo cat "/home/admin/.setup") -if [ ${setupStep} -lt 65 ]; then +walletExists=$(sudo ls /mnt/hdd/lnd/data/chain/${network}/${chain}net/wallet.db 2>/dev/null | grep wallet.db -c) +echo "walletExists(${walletExists})" +sleep 2 +if [ ${walletExists} -eq 0 ]; then + # setup state signals, that no wallet has been created yet - dialog --backtitle "RaspiBlitz - LND Lightning Wallet" --msgbox " + dialog --backtitle "RaspiBlitz - LND Lightning Wallet (${network}/${chain})" --msgbox " ${network} and Lighthing Services are installed. You now need to setup your Lightning Wallet: We will now call the command: lncli create lncli = Lightning Network Command Line Interface Learn more: https://api.lightning.community - Press OK and follow the 'Helping Instructions'. " 14 52 clear @@ -111,37 +125,67 @@ Press OK and follow the 'Helping Instructions'. echo "C) For 'passphrase' to encrypt your 'cipher seed' use PASSWORD D (optional)" echo "****************************************************************************" echo "" - echo "lncli create" - sudo -u bitcoin lncli create + echo "lncli --chain=${network} create" + + # execute command and monitor error + _error="./.error.out" + sudo -u bitcoin /usr/local/bin/lncli --chain=${network} create 2>$_error + error=`cat ${_error}` + + if [ ${#error} -gt 0 ]; then + echo "" + echo "!!! FAIL !!! SOMETHING WENT WRONG:" + echo "${error}" + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + echo "" + echo "Press ENTER to retry ... or CTRL-c to EXIT" + read key + echo "Starting RETRY ..." + ./70initLND.sh + exit 1 + fi + echo "" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "!!! Make sure to write down the 24 words (cipher seed mnemonic) !!!" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "If you are ready. Press ENTER." read key - # set SetupState to 75 (mid thru this process) + echo "65" > /home/admin/.setup fi -echo "--> lets wait 30 seconds for LND to get ready" -sleep 30 + +echo "--> lets wait 60 seconds for LND to get ready" +sleep 60 ###### Copy LND macaroons to admin echo "" echo "*** Copy LND Macaroons to user admin ***" -macaroonExists=$(sudo -u bitcoin ls -la /mnt/hdd/lnd/admin.macaroon | grep -c admin.macaroon) +macaroonExists=$(sudo -u bitcoin ls -la /home/bitcoin/.lnd/data/chain/${network}/${chain}net/admin.macaroon | grep -c admin.macaroon) if [ ${macaroonExists} -eq 0 ]; then + ./AAunlockLND.sh + sleep 3 +fi +macaroonExists=$(sudo -u bitcoin ls -la /home/bitcoin/.lnd/data/chain/${network}/${chain}net/admin.macaroon | grep -c admin.macaroon) +if [ ${macaroonExists} -eq 0 ]; then + sudo -u bitcoin ls -la /home/bitcoin/.lnd/data/chain/${network}/${chain}net/admin.macaroon echo "" echo "FAIL - LND Macaroons not created" echo "Please check the following LND issue:" echo "https://github.com/lightningnetwork/lnd/issues/890" + echo "You may want try again with starting ./70initLND.sh" exit 1 fi -sudo mkdir /home/admin/.lnd -macaroonExists=$(sudo ls -la /home/admin/.lnd/ | grep -c admin.macaroon) +macaroonExists=$(sudo ls -la /home/admin/.lnd/data/chain/${network}/${chain}net/ | grep -c admin.macaroon) if [ ${macaroonExists} -eq 0 ]; then sudo mkdir /home/admin/.lnd + sudo mkdir /home/admin/.lnd/data + sudo mkdir /home/admin/.lnd/data/chain + sudo mkdir /home/admin/.lnd/data/chain/${network} + sudo mkdir /home/admin/.lnd//data/chain/${network}/${chain}net sudo cp /home/bitcoin/.lnd/tls.cert /home/admin/.lnd - sudo cp /home/bitcoin/.lnd/admin.macaroon /home/admin/.lnd + sudo cp /home/bitcoin/.lnd/lnd.conf /home/admin/.lnd + sudo cp /home/bitcoin/.lnd/data/chain/${network}/${chain}net/admin.macaroon /home/admin/.lnd/data/chain/${network}/${chain}net sudo chown -R admin:admin /home/admin/.lnd/ echo "OK - LND Macaroons created" else @@ -150,11 +194,10 @@ fi ###### Unlock Wallet (if needed) echo "*** Check Wallet Lock ***" -chain=$(${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain') locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c unlock) if [ ${locked} -gt 0 ]; then echo "OK - Wallet is locked ... starting unlocking dialog" - ./unlockLND.sh + ./AAunlockLND.sh else echo "OK - Wallet is already unlocked" fi @@ -163,8 +206,7 @@ fi echo "" echo "*** Check LND Sync ***" item=0 -chain="$(${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain')" -lndSyncing=$(sudo -u bitcoin lncli getinfo | jq -r '.synced_to_chain' | grep -c true) +lndSyncing=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true) if [ ${lndSyncing} -eq 0 ]; then echo "OK - wait for LND to be synced" while : @@ -172,10 +214,10 @@ if [ ${lndSyncing} -eq 0 ]; then # show sync status ./80scanLND.sh - sleep 3 + sleep 15 # break loop when synced - lndSyncing=$(sudo -u bitcoin lncli getinfo | jq -r '.synced_to_chain' | grep -c true) + lndSyncing=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true) if [ ${lndSyncing} -eq 1 ]; then break fi @@ -186,6 +228,8 @@ if [ ${lndSyncing} -eq 0 ]; then break fi + sleep 15 + done clear else diff --git a/home.admin/80scanLND.sh b/home.admin/80scanLND.sh index f7a3313..962676e 100755 --- a/home.admin/80scanLND.sh +++ b/home.admin/80scanLND.sh @@ -1,34 +1,66 @@ # load network network=`sudo cat /home/admin/.network` +# load name of Blitz +name=`sudo cat /home/admin/.hostname` + ### USER PI AUTOSTART (LCD Display) localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') # parse the actual scanned height progress from LND logs item=0 -chain="$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain')" -gotData=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c height) -if [ ${gotData} -gt 0 ]; then - item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep height | tail -n1 | awk '{print $9} {print $10} {print $11} {print $12}' | tr -dc '0-9') -fi +blockchaininfo=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo) +chain="$(echo "${blockchaininfo}" | jq -r '.chain')" -# get total number of blocks -total=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.blocks') +## TRY to get the actual progress height of scanning -# calculate progress in percent -percent=$(awk "BEGIN { pc=100*${item}/${total}; i=int(pc); print (pc-i<0.5)?i:i+1 }") -if [ ${percent} -eq 100 ]; then - # normally if 100% gets calculated, item parsed the wrong height - percent=0 +# 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') + +# 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') fi -infoStr=$(echo " Lightning Rescanning Blockchain ${percent}%\nplease wait - this can take some time") +# TODO next fallback try later here if necessary +if [ ${#item} -eq 0 ]; then + item="?" +fi + +# get total number of blocks +total=$(echo "${blockchaininfo}" | jq -r '.blocks') +# put scanstate +scanstate="${item}/${total}" + +# get blockchain sync progress +progress="$(echo "${blockchaininfo}" | jq -r '.verificationprogress')" # 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 - infoStr=" Waiting for final Blockchain Sync\nplease wait - this can take some time" + isInitialChainSync=1 +fi +if [ ${isInitialChainSync} -gt 0 ]; then + heigh=7 + infoStr=" Waiting for final Blockchain Sync\n Progress: ${progress}\n Please wait - this can take some time.\n ssh admin@${localip}\n Password A" + if [ "$USER" = "admin" ]; then + heigh=6 + width=53 + infoStr=$(echo " Waiting for final Blockchain Sync\n Progress: ${progress}\n Please wait - this can take some long time.\n Its OK to close terminal and ssh back in later.") + fi +else + heigh=7 + infoStr=$(echo " Lightning Rescanning 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 Rescanning Blockchain\n Progress: ${scanstate}\n Please wait - this can take some long time.\n Its OK to close terminal and ssh back in later.") + fi fi # display progress to user -dialog --backtitle "RaspiBlitz (${localip} / ${network} / ${chain})" --infobox "${infoStr}" 4 42 \ No newline at end of file +sleep 3 +dialog --title " ${network} / ${chain} " --backtitle "RaspiBlitz (${name})" --infobox "${infoStr}" ${heigh} ${width} \ No newline at end of file diff --git a/home.admin/90finishSetup.sh b/home.admin/90finishSetup.sh index 66c4764..67724b4 100755 --- a/home.admin/90finishSetup.sh +++ b/home.admin/90finishSetup.sh @@ -4,7 +4,7 @@ echo "" # add bonus scripts ./91addBonus.sh -###### SWAP +###### SWAP & FS echo "*** SWAP file ***" swapExists=$(swapon -s | grep -c /mnt/hdd/swapfile) if [ ${swapExists} -eq 1 ]; then @@ -20,7 +20,13 @@ else sudo dphys-swapfile setup sudo chmod 0600 /mnt/hdd/swapfile sudo dphys-swapfile swapon + + # expand FS of SD + echo "*** Expand RootFS ***" + sudo raspi-config --expand-rootfs + echo "" fi + swapExists=$(swapon -s | grep -c /mnt/hdd/swapfile) if [ ${swapExists} -eq 1 ]; then echo "OK - SWAP is working" @@ -32,9 +38,36 @@ else sleep 60 fi -# expand FS of SD -echo "*** Expand RootFS ***" -sudo raspi-config --expand-rootfs +# firewall - just install (not configure) +echo "" +echo "*** Setting and Activating Firewall ***" +sudo apt-get install -y ufw +echo "deny incoming connection on other ports" +sudo ufw default deny incoming +echo "allow outgoing connections" +sudo ufw default allow outgoing +echo "allow: ssh" +sudo ufw allow ssh +echo "allow: bitcoin testnet" +sudo ufw allow 18333 comment 'bitcoin testnet' +echo "allow: bitcoin mainnet" +sudo ufw allow 8333 comment 'bitcoin mainnet' +echo "allow: litecoin mainnet" +sudo ufw allow 9333 comment 'litecoin mainnet' +echo 'allow: lightning testnet' +sudo ufw allow 19735 comment 'lightning testnet' +echo "allow: lightning mainnet" +sudo ufw allow 9735 comment 'lightning mainnet' +echo "allow: lightning gRPC" +sudo ufw allow 10009 comment 'lightning gRPC' +echo "allow: trasmission" +sudo ufw allow 51413 comment 'transmission' +echo "allow: local web admin" +sudo ufw allow from 192.168.0.0/24 to any port 80 comment 'allow local LAN web' +echo "open firewall for auto nat discover (see issue #129)" +sudo ufw allow proto udp from 192.168.0.0/24 port 1900 to any comment 'allow local LAN SSDP for UPnP discovery' +echo "enable lazy firewall" +sudo ufw --force enable echo "" # mark setup is done @@ -56,4 +89,6 @@ sudo raspi-config nonint do_hostname ${hostname} # mark setup is done (100%) echo "100" > /home/admin/.setup +clear +echo "Setup done. Rebooting now." sudo shutdown -r now \ No newline at end of file diff --git a/home.admin/91addBonus.sh b/home.admin/91addBonus.sh index ca380d2..21d6be8 100755 --- a/home.admin/91addBonus.sh +++ b/home.admin/91addBonus.sh @@ -13,5 +13,11 @@ chmod +x lnchannels sudo cp lnchannels /usr/local/bin sudo cp lnbalance /usr/local/bin echo "OK" +echo "installing bash completion for bitcoin-cli and lncli" +wget https://raw.githubusercontent.com/bitcoin/bitcoin/master/contrib/bitcoin-cli.bash-completion +wget https://raw.githubusercontent.com/lightningnetwork/lnd/master/contrib/lncli.bash-completion +sudo cp *.bash-completion /etc/bash_completion.d/ +echo "OK - bash completion available after next login" +echo "type \"bitcoin-cli getblockch\", press [Tab] → bitcoin-cli getblockchaininfo" cd rm -r /home/admin/tmpScriptDL diff --git a/home.admin/95switchMainTest.sh b/home.admin/95switchMainTest.sh new file mode 100755 index 0000000..37d3d30 --- /dev/null +++ b/home.admin/95switchMainTest.sh @@ -0,0 +1,125 @@ +#!/usr/bin/env bash +# based on pull request from vnnkl + +# load network +network=`cat .network` + +echo "" +echo "*** Switch between Testnet/Mainnet ***" + +# allow only on bitcoin network +if [ "${network}" = "bitcoin" ]; then + echo "Bitcoin network can be switched between testnet/mainnet ..." +else + echo "FAIL - Only Bitcoin Network can be switched between man/tast at the moment." + exit 1 +fi + +NETWORK_CONFIG="/home/bitcoin/.${network}/${network}.conf" +NETWORK_TEMPLATE="/home/admin/assets/${network}.conf" +LND_CONFIG="/home/bitcoin/.lnd/lnd.conf" +LND_TEMPLATE="/home/admin/assets/lnd.${network}.conf" +echo "NETWORK_CONFIG(${NETWORK_CONFIG})" +echo "LND_CONFIG(${LND_CONFIG})" +echo "NETWORK_TEMPLATE(${NETWORK_TEMPLATE})" +echo "LND_TEMPLATE(${LND_TEMPLATE})" + +# function to detect main/testnet +function isMainnet(){ + grep "^#testnet=1$" -q $NETWORK_CONFIG && return 1 + return 0 +} + +function switchToMainnet { + echo "switching to mainnet" + sed -i "s/^testnet=1/#testnet=1/g" $NETWORK_CONFIG + sed -i "s/^testnet=1/#testnet=1/g" $NETWORK_TEMPLATE + sed -i "s/^#mainnet=1/mainnet=1/g" $NETWORK_CONFIG + sed -i "s/^#mainnet=1/mainnet=1/g" $NETWORK_TEMPLATE + sed -i "s/^${network}.testnet=1/#${network}.testnet=1/g" $LND_CONFIG + sed -i "s/^#${network}.mainnet=1/${network}.mainnet=1/g" $LND_CONFIG + sed -i "s/^${network}.testnet=1/#${network}.testnet=1/g" $LND_TEMPLATE + sed -i "s/^#${network}.mainnet=1/${network}.mainnet=1/g" $LND_TEMPLATE + echo "OK switched to mainnet" +} + +function switchToTestnet { + echo "switching to testnet" + sed -i "s/^#testnet=1/testnet=1/g" $NETWORK_CONFIG + sed -i "s/^#testnet=1/testnet=1/g" $NETWORK_TEMPLATE + sed -i "s/^mainnet=1/#mainnet=1/g" $NETWORK_CONFIG + sed -i "s/^mainnet=1/#mainnet=1/g" $NETWORK_TEMPLATE + sed -i "s/^#${network}.testnet=1/${network}.testnet=1/g" $LND_CONFIG + sed -i "s/^${network}.mainnet=1/#${network}.mainnet=1/g" $LND_CONFIG + sed -i "s/^#${network}.testnet=1/${network}.testnet=1/g" $LND_TEMPLATE + sed -i "s/^${network}.mainnet=1/#${network}.mainnet=1/g" $LND_TEMPLATE + echo "OK switched to testnet" +} + +# LND Service +lndInstalled=$(systemctl status lnd.service | grep loaded -c) +if [ ${lndInstalled} -gt 0 ]; then + + echo "check for open channels" + openChannels=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} listchannels 2>/dev/null | grep chan_id -c) + if [ ${openChannels} -gt 0 ]; then + echo "" + echo "!!!!!!!!!!!!!!!!!!!" + echo "FAIL - You have still open channels and could loose funds !! - close those first with 'lncli closeallchannels' or main menu option." + echo "!!!!!!!!!!!!!!!!!!!" + exit 1 + else + echo "no open channels found" + fi + + echo "stopping lnd client" + systemctl stop lnd + sleep 4 + +else + echo "LND not running" +fi + +# NETWORK Service +networkInstalled=$(systemctl status ${network}d.service | grep loaded -c) +if [ ${networkInstalled} -gt 0 ]; then + echo "stopping bitcoind client" + systemctl stop bitcoind + sleep 4 +else + echo "Network ${network} not running" +fi + +# TURN THE SWITCH +isMainnet +if [ $? -eq 1 ]; then + echo "switching from mainnet to testnet" + switchToTestnet +else + echo "switching from testnet to mainnet" + switchToMainnet +fi + +echo "copying over config to admin user" +cp $NETWORK_CONFIG /home/admin/.${network}/ +chown admin:admin /home/admin/.${network}/${network}.conf +cp $LND_CONFIG /home/admin/.lnd/ +chown admin:admin /home/admin/.lnd/lnd.conf + +# restarting network +if [ ${networkInstalled} -gt 0 ]; then + + # start network + systemctl start bitcoind + echo "started ${network}d back up, giving it a 120 SECONDS to prepare" + sleep 120 + + # set setup info again + echo "60" > /home/admin/.setup + + # run again the complete LND init procedure + ./70initLND.sh + +else + echo "No starting of network, because it was not running before" +fi \ No newline at end of file diff --git a/home.admin/96addTorService.sh b/home.admin/96addTorService.sh new file mode 100644 index 0000000..72f097e --- /dev/null +++ b/home.admin/96addTorService.sh @@ -0,0 +1,219 @@ +#!/bin/bash + +# Background: +# https://medium.com/@lopp/how-to-run-bitcoin-as-a-tor-hidden-service-on-ubuntu-cff52d543756 +# https://bitcoin.stackexchange.com/questions/70069/how-can-i-setup-bitcoin-to-be-anonymous-with-tor +# https://github.com/lightningnetwork/lnd/blob/master/docs/configuring_tor.md + +# load network +network=`cat .network` +chain="$(${network}-cli getblockchaininfo | jq -r '.chain')" + +# location of TOR config +torrc="/etc/tor/torrc" + +# check if TOR was already installed and is funtional +clear +echo "" +echo "*** Check if TOR service is functional ***" +torRunning=$(curl --connect-timeout 10 --socks5-hostname 127.0.0.1:9050 https://check.torproject.org | grep "Congratulations. This browser is configured to use Tor." -c) +if [ ${torRunning} -gt 0 ]; then + clear + echo "You are all good - TOR is already running." + echo "" + exit 0 +else + echo "TOR not running ... proceed with switching to TOR." + echo "" +fi + +# ask user if to proceed +dialog --title " WARNING " --yesno "At the moment you just can switch TOR on - YOU CANNOT SWITCH BACK. Do you want to proceed?" 8 57 +response=$? +case $response in + 1) exit 1; +esac + +echo "*** Adding Tor Sources to sources.list ***" +echo "deb http://deb.torproject.org/torproject.org stretch main" | sudo tee -a /etc/apt/sources.list +echo "deb-src http://deb.torproject.org/torproject.org stretch main" | sudo tee -a /etc/apt/sources.list +echo "OK" +echo "" + +echo "*** Installing dirmngr ***" +sudo apt install dirmngr +echo "" + +## lopp: gpg --keyserver keys.gnupg.net --recv 886DDD89 +echo "*** Fetching GPG key ***" +gpg --keyserver keys.gnupg.net --recv A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 +gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add - +echo "" + +echo "*** Updating System ***" +sudo apt-get update +echo "" + +echo "*** Install Tor ***" +sudo apt install tor tor-arm -y + +echo "" +echo "*** Tor Config ***" +sudo rm -r -f /mnt/hdd/tor 2>/dev/null +sudo mkdir /mnt/hdd/tor +sudo mkdir /mnt/hdd/tor/sys +sudo mkdir /mnt/hdd/tor/web80 +sudo mkdir /mnt/hdd/tor/lnd9735 +sudo mkdir /mnt/hdd/tor/lndrpc9735 +sudo chmod -R 700 /mnt/hdd/tor +sudo chown -R bitcoin:bitcoin /mnt/hdd/tor +cat > ./torrc <