Skip to content

Commit

Permalink
Merge pull request #242 from nolim1t/cleanup-and-documentation
Browse files Browse the repository at this point in the history
Options works so merged to master
  • Loading branch information
nolim1t authored Oct 8, 2019
2 parents b8e4011 + 4dd339e commit cd741a9
Show file tree
Hide file tree
Showing 35 changed files with 214 additions and 2,193 deletions.
153 changes: 49 additions & 104 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,101 +1,65 @@
Pi-Factory
===========================================

### _Create your own bitcoin lightning box!_
### _Easily build your own Alpine Linux box on Raspberry PI or Raspberry Zero!_

This repository lets you build a _bitcoin lightning_ box for [Raspberry Pi](https://www.raspberrypi.org) 3 Model B & 3B+ based on [Alpine](https://alpinelinux.org) Linux.
This repository lets you build you build an _[Alpine](https://alpinelinux.org) Linux_ box for [Raspberry Pi](https://www.raspberrypi.org) Model B/B+/4/Zero

**Work in progress.** While stable enough for development, this software is subject to change, some of which may be breaking changes.
**Warning!** *Do not put money at stake that you are not willing to lose!*

[![Build Status](https://travis-ci.com/lncm/pi-factory.svg?branch=v0.5)](https://travis-ci.com/lncm/pi-factory)
[![Documentation Status](https://readthedocs.org/projects/noma/badge/?version=latest)](https://pi-factory.readthedocs.io/en/latest/?badge=latest)


### Features

* `Tor` onion-routing for enhanced privacy and improved connectivity
* Lightning Labs' `LND` bundled with our *autoconnect* and *autounlock* tools
* Bitcoin Core `bitcoind` bundled with our implementation of Nicholas Dorier's *fastsync* to drastically reduce initial sync time
* `Alpine Linux`, a security-oriented, lightweight Linux distribution based on musl *libc* and `Busybox`
* Containerization of most components including `nginx`, `iotwifi`, `invoicer`, `bitcoind`, `lnd`
* *Stateless OS* - the microSD card image can be replaced with a newer version *without loss of user data*
* Simple `shell`, `Python` scripts and `Go` backends enable easy auditing and provide a small *attack surface*
* `Docker` & `docker-compose` make updates easier and orchestration painless
* [Future] the microSD card can be mounted in read-only mode for zero-wear operation
* [Future] Redundant storage persistence using RAID

- pi-factory is now a persistent OS Only! For Nodes, please refer to earlier versions or go to the [noma](https://github.com/lncm/noma) project
- Latest version updated to Alpine 3.10.2
- We now have 64 bit (aarch64) and 32 bit images (armhf). The Raspberry PI 3/3b works well on 64 bit
- Deterministic builds. Images now built and released automatically through github actions.

### LNCM components

* [invoicer](https://github.com/lncm/invoicer): lightweight `bitcoind` and `LND` backend in Go.
* [invoicer-ui](https://github.com/lncm/invoicer-ui): Point of Sale for Bitcoin and Lightning in React.
* [iotwifi-ui](https://github.com/lncm/iotwifi-ui): Wi-Fi connection wizard in React.
* [noma](https://github.com/lncm/noma): CLI node management utility and API in Python.
* [docker-bitcoind](https://github.com/lncm/docker-bitcoind): arm & amd64 support
* [docker-berkeleydb](https://github.com/lncm/docker-berkeleydb): arm & amd64 support
* [docker-lnd](https://github.com/lncm/docker-lnd): arm & amd64 support


Hardware Requirements
---------------------

* **Raspberry Pi**
* Recommended: model 3B+
* Optional: case, heatsink, LAN cable

We recommend using a heatsink on 3B+ models to unlock their full sustained performance. Useful, e.g. during syncing or filtering blocks.

* Optional: case, heatsink, LAN cable, HDMI cable and monitor (for troubleshooting and issue tracking), Keyboard (to use for troubleshooting and issue tracking)


* **microSD** card
* Recommended: SanDisk 16GB or more
* microSD card to USB adapter or built-in hardware

Quality goes over quantity here!

* **USB storage** devices
* Recommended: 4 USB flash drives of 16GB or more
* Alternatively for bitcoin full-archival nodes:
* 2 or 3 flash devices
* a hard drive or SSD for the blockchain

You may need to use a powered USB hub to prevent undervoltage when using some hard drives.

* **Power Supply** (5V/2.5A) with micro-USB cable
* Recommended: official Raspberry Pi power supply
* Alternatively:
* Alternatively:
* high-quality USB charger (e.g. Samsung)
* short USB to micro-USB cable. (a longer cable can work with 5.1V chargers)

**Warning!** Your Raspberry Pi will *not work* properly without a correctly rated power supply and cable.

You **risk losing bitcoin** and **data** when running your Raspberry Pi in an underpowered state.


**Warning!** Your Raspberry Pi will *not work* properly without a correctly rated power supply and cable, and may result in data loss. We are not responsible if you lose any data.


Instructions
------------

1. Download [Etcher](https://www.balena.io/etcher/)
* *Experienced users:* it is possible to use `dd` instead
2. Download latest [lncm-box.img.zip](
https://github.com/lncm/pi-factory/releases/download/v0.4.1/lncm-box-v0.4.1.img.zip)
3. Run Etcher and follow on-screen instructions to burn `lncm-box.img.zip` to microSD card
4. Place the SD card in your *Raspberry Pi*
5. Connect your *Raspberry Pi* to a **correctly rated power supply**
6. If you are using wired *LAN*:
* connect the cable to your Pi
* is your LAN cable active?
* congratulations, you are done!
7. If you are using *WiFi*:
* find a device with a *web browser* and *WiFi*, e.g. your smartphone or laptop
8. On your device, search for and connect to a *WiFi* network called **LNCM-Box**
* Password: **lncm box**
9. Open the *web browser* on your device, e.g. `Chrome` or `Safari`
* Navigate to "[http://box.local/wifi](http://box.local/wifi)"
* Choose your *WiFi* network from the list
* Type in your password & *connect*

Your **lightning box** will automatically start installing itself to *microSD* card once it has an internet connection. This usually takes less than *15 minutes* depending on the speed of your card and internet connection.

Once the box has *synced* up the **invoicing** service will be available at [http://box.local/pos](http://box.local/pos). Depending on the speed of your internet connection and your USB storage devices the process may take *30 minutes* to *an hour* or more.
1. Download [Etcher](https://www.balena.io/etcher/)
2. Download the image from the [Releases page](https://github.com/lncm/pi-factory/releases) or simply clone the ```https://github.com/lncm/pi-factory.git``` repository on github
3. Insert SD Card and open up Etcher
4. Etch one of the images onto the SD card
5. Remount the SD card and create a file called ```wpa_supplicant.conf```
6. Inside the file put the following

```
network={
ssid="Your Wifi SSID goes here"
key_mgmt=WPA-PSK
psk="YOUR Password goes here"
}
```

7. Unmount the drive and put it into a PI or PI zero and then start it up. And in about 10-20 minutes (PI-Zero will take longer), you will be able to login through avahi/mdns ```box.local``` , or if you don't have avahi/mdns on your desktop you will need to grab the IP address from plugging in your PI to a TV or from your router.


Access
------
Expand All @@ -111,44 +75,32 @@ Access
- **username**: root
- **password**: chiangmai

**Note:** `sudo` is not installed, use `su` instead
**Note:** `sudo` is not installed, use `su` instead. We also highly recommend that you change the password.



### Command-line via ssh
`ssh [email protected]`

**Note:** First boot will take some time as ssh host keys are generated.

### Connect to WiFi hotspot

The Raspberry Pi lightning box provides it's own WiFi hotspot to ease access and configuration.

- **WiFi name** (SSID): "LNCM-Box"
- **WiFi password**: "lncm box"


- **IP address**: 192.168.27.1
- **hostname**: box.local

### WiFi hotspot

The box provides it's own WiFi hotspot to ease access and configuration.
#### Advanced configuration

- **WiFi name** (SSID): "LNCM-Box"
- **WiFi password**: "lncm box"
- **IP address**: 192.168.27.1
- **hostname**: box.local
When building the image yourself you can create a ```wpa_supplicant.automatic.conf``` file with all your wifi passwords.

#### Advanced configuration
You may disable several stuff by placing an empty file inside the FAT partition. This should be done **before first boot**

If the wifi configuration manager does not work (currently there is an issue where the wifi manager is not getting downloaded), you may SSH in and invoke the following command.
Filename | Description
------------ | -------------
noswap | disables SWAP generation (not recommended unless you know what you are doing!)
noavahi | disables install for avahi-daemon / mdns discovery (not recommended unless you know what you are doing!)
nodocker | disables Docker installation
nopython | Disables python3 installation
notor | Disables tor installation

```bash
curl -w "\n" -d '{"ssid":"YOUR-SSID-NAME", "psk":"YOUR-PASSWORD"}' \
-H "Content-Type: application/json" \
-X POST http://192.168.27.1:8080/connect
```

Alternatively, when building the image you can create a ```wpa_supplicant.automatic.conf``` file with all your wifi passwords.
You may disable swap generation by touching a file in the FAT partition called "noswap". This needs to be done the first time.

Documentation
-------------
Expand All @@ -157,7 +109,7 @@ Documentation

Building
--------
To generate a fresh image from source run `make_img.sh` as __root__ on a *Debian*, *Ubuntu* or *Alpine* system.
To generate a fresh image from source run `./make_img.sh` as __root__ on a *Debian*, *Ubuntu* or *Alpine* system.

For convenience, we also support `vagrant` to automate setting up your development VM.

Expand Down Expand Up @@ -187,8 +139,7 @@ Also useful:
Support
-------

If you are having problems, please let us know.
We have a public [chat room](https://gitter.im/lcnm/box)
If you are having problems, please [create an issue](https://github.com/lncm/pi-factory/issues/new)


Contribute
Expand All @@ -198,13 +149,7 @@ Bug reports, pull-requests and suggestions are very welcome!

- [Issue Tracker](http://github.com/lncm/pi-factory/issues)
- [Source Code](https://github.com/lncm/pi-factory)

In the Wild
-----------

There are two public [installations](http://nodes.lncm.io) of this lightning box in Chiang Mai, Thailand acting as Bitcoin and Lightning points of sale in combination with a tablet.

Please do let us know about your own or those you spot!
- [Contributing Guidelines](https://github.com/lncm/pi-factory/blob/master/CONTRIBUTING.md)

License
-------
Expand Down
62 changes: 23 additions & 39 deletions docs/MANUAL.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
Welcome to Pi-Factory's documentation!
======================================

Pi-Factory builds Alpine Linux images with *armhf* architecture ready for booting on any Raspberry Pi.

Most of the user interaction is done thru our `noma` CLI tool

For example:

noma info
Pi-Factory builds Alpine Linux images with **aarch64** and **armhf** architecture ready for booting on any Raspberry Pi.

## Customization & Settings

These options apply to creating your own images for burning to microSD card.

#### LND Auto-unlock script

Before running, **make_img.sh** or **make_apkovl.sh**
Before running, **make_img.sh** or **make_apkovl.sh** you may wish to etch your wifi settings into the box so it will complete its setup smoothly. To do this, create a file called ```wpa_supplicant.automatic.conf``` and place the following in there:

If you wish to import your own seed, put the seed into seed.txt at ```home/lncm/seed.txt```

**Note** For the seed file, one word should exist on each line.
```
network={
ssid="Your Wifi SSID goes here"
key_mgmt=WPA-PSK
psk="YOUR Password goes here"
}
```

If you wish to save the password, do a ```touch home/lncm/save_password``` (This option is on by default)

#### Security

Expand All @@ -31,8 +26,6 @@ Passwords should be disabled when you create a new image.

For those who still are using password authentication it is recommended that you change both root and lncm users with the ```passwd``` utility.

Also, renaming the hotspot and changing the password is another thing that you need to do - the file is ```/etc/iotwifi/wificfg.json``` as the password is public.

#### Networking

If you have console access:
Expand All @@ -45,15 +38,8 @@ Or, run `setup-interfaces` if you have access to a running box.

In order to ship correct WiFi configuration, edit settings in `etc/wpa_supplicant/wpa_supplicant.conf`, run `make_apkovl.sh` and copy **box.apkovl.tar.gz** to SD card root directory (FAT partition).

##### IotWiFi Configuration

After connecting to _"LNCM-Box"_ WiFi on your computer you can tell the box to connect to your own home WiFi network by issuing the following command:
Alternatively you may copy wpa_supplicant.conf to the FAT partition of the box (can be done at any time). The box will boot up and copy this file into the correct place and OVERWRITE any changes.

```bash
curl -w "\n" -d '{"ssid":"YOUR-SSID-NAME", "psk":"YOUR-PASSWORD"}' \
-H "Content-Type: application/json" \
-X POST http://192.168.27.1:8080/connect
```
### Alpine specific

Alpine [wiki](https://wiki.alpinelinux.org/) holds further information related to system administration.
Expand All @@ -62,34 +48,32 @@ Alpine [wiki](https://wiki.alpinelinux.org/) holds further information related t

*Initially the system is mounted read-only!*

**Important note:** Alpine will not persist user changes upon reboot until it is installed and restarted.
**Important note:** Alpine will not persist user changes upon reboot until it is installed and restarted.

Use `lbu commit` to persist changes. Add `-v` to see what is being committed.

`lbu status` will show changes to be committed.

**Note:** By default `lbu commit` only applies to *some* directories.

After setup is fully complete, the system will be a full persistant system

#### Package management

- `apk update` Update repositories
- `apk update` Update repositories
- `apk upgrade` Upgrade packages
- `apk add` Install package
- `apk del` Uninstall package
- `apk add` Install package
- `apk del` Uninstall package

#### Init system

- `rc-update add docker boot` Start docker at boot
- `rc-update del docker boot` Remove docker from boot
- `rc-update` show startup services

Installation of LNCM specific components belongs in `etc/init.d/lncm`. The script is [OpenRC](https://wiki.gentoo.org/wiki/OpenRC) compatible and must be executable, without a file name extension.

`etc/apk/world` contains all apk packages to be installed by LNCM's install script.

- `service -l` list available services
- `service docker start` start docker now
- `service docker stop` stop docker now

The boot sequence is logged to `/var/log/rc.log` by default.

Expand All @@ -99,10 +83,11 @@ More information in OpenRC [user guide](https://github.com/OpenRC/openrc/blob/ma

There are various configuration tools included to help you customize to your needs:

- `setup-hostname`
- `setup-timezone`
- `setup-keymap`
- `setup-dns`
- `setup-hostname` (change the hostname)
- `setup-timezone` (change the timezone)
- `setup-keymap`
- `setup-dns` (change the DNS)
- `setup-alpine` (Go through ALL the setup scripts. Useful if you choose to setup networking manually)

## Advanced

Expand Down Expand Up @@ -144,9 +129,9 @@ Follow the steps outlined in `make_img.sh` to create your own image or SD card.
`lbu pkg /path/to/tar.gz` will produce a tarball of current system state.

#### *Important notes for distributing fresh apkovl:*

**Remove unique and security sensitive files**

`rm etc/machine-id`

`rm etc/docker/key.json`
Expand All @@ -156,4 +141,3 @@ Follow the steps outlined in `make_img.sh` to create your own image or SD card.
Rewrite `/etc/resolv.conf` to be network independent.

Be mindful of passwords you set.

Loading

0 comments on commit cd741a9

Please sign in to comment.