[go: nahoru, domu]

Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
farscapian committed Mar 25, 2020
1 parent d91d7e4 commit f315bc8
Show file tree
Hide file tree
Showing 44 changed files with 897 additions and 463 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Bitcoin Cache Machine is open-source software that allows you to create a self-hosted privacy-preserving [software-defined data-center](https://en.wikipedia.org/wiki/Software-defined_data_center). BCM is built entirely with free and open-source software and is meant primarily for home and small office use in line with the spirit of decentralization.

> Note! Bitcoin Cache Machine REQUIRES a [Trezor-T](https://trezor.io/) to function! Consider buying a dedicated device for your BCM data center. The use of use [passphrases](https://wiki.trezor.io/Multi-passphrase_encryption_(hidden_wallets)) is REQUIRED.
BCM is a set of BASH scripts that allows administrators to run bitcoin node infrastructure. We all know that it is unlikely that the "average Joe" will run their own Bitcoin infrastrcture. There are REAL costs associated with attaining self-soverignty. Running a high-uptime node infrastructure takes real skill and resources! However, most people know one or more people in their life that are "tech-savvy" and are able to run these software services for them. Like everything in life, trade-off exists. In this case, BCM is a set of software that is run by a person you trust (i.e., the neighborhood Geek/Nerd whose morals you trust). Your administrator should be someone you trust not to act in immoral or untrustworthy ways. Examples include millennial sons and daughters, computer-literate friends, local neighborhood anarchists, etc..

## Project Status

Expand Down Expand Up @@ -43,14 +43,19 @@ All you need to get started is an SSH endpoint running Ubuntu 18.04. When runnin

## Getting Started

The first step to getting started with Bitcoin Cache Machine is to clone the git repo to your new SDN controller, a user-facing desktop or laptop running a Debian-based OS. The best way to do this is run a Debian Tempalte VM running behind a whonix gateway running on QubesOS. In either case, the installation procedures are the same:
The first step to getting started with Bitcoin Cache Machine get the BCM scripts (git repo) to your computer, a user-facing desktop or laptop running a Debian-based OS. Do the following to get the code.

```bash
sudo apt update && sudo apt install -y curl
curl https://raw.githubusercontent.com/BitcoinCacheMachine/BitcoinCacheMachine/dev/install.sh | sudo bash
# Verify init_bcm.sh
wget -o pull_bcm.sh https://raw.githubusercontent.com/BitcoinCacheMachine/BitcoinCacheMachine/dev/init_bcm.sh

# run the script; installs TOR and git pulls the BCM source code.
sudo bash -c ./init_bcm.sh
```

The script above runs the bcm entrypoint. Afterwards, you may need to log out and log back (or restart) in for your group membership to refresh. Running `bcm` at the terminal ensures that all necessary dependencies are made availble (LXD client, dockerd) and builds the docker images needed to run bcm commands.
The script above install the latest tor proxy, the pulls the BCM git clones the repo to your pwd. Now that you have the code (in the bcm directory), you can decide how you want to deploy BCM. You can deploy it locally on bare-metal (best performance, good for single-user use) or in Type-1 VMs, which is useful if you want to run multiple BCM instances on a single set of hardware. You can also use BCM shell scripts to deploy BCM server-side infrastructure to a remote SSH endpoint (or SSH exposed as an onion service).

If you want to deploy locally, just run `bcm deploy`. If you want to run BCM in Type-1 vms, use BCM_GIT_DIR/test/refresh_bcm.sh.

## Deploying your own BCM Infrastructure

Expand Down
25 changes: 19 additions & 6 deletions bcm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ IS_FRONTEND=1
BCM_HELP_FLAG=0
REBUILD_IMAGES=0

# make snap commands available to the script.
PATH="$PATH:/snap/bin"
export PATH="$PATH"

for i in "$@"; do
case $i in
--help)
Expand All @@ -26,17 +30,19 @@ for i in "$@"; do
esac
done

source ./env

if [[ $BCM_HELP_FLAG == 1 ]]; then
cat ./commands/help.txt
exit
fi

BCM_DEBUG=${BCM_DEBUG:-1}
BCM_DEBUG=${BCM_DEBUG:-0}
export BCM_DEBUG="$BCM_DEBUG"
export REBUILD_IMAGES="$REBUILD_IMAGES"


BCM_SSH_HOSTNAME=${BCM_SSH_HOSTNAME:-"localhost"}
BCM_SSH_HOSTNAME=${BCM_SSH_HOSTNAME:-"$(hostname)"}
if [[ ! -z $BCM_SSH_HOSTNAME ]]; then
BCM_SSH_HOSTNAME="$BCM_SSH_HOSTNAME"
fi
Expand Down Expand Up @@ -75,7 +81,9 @@ export BCM_VERSION="v$BCM_MAJOR_VERSION.$BCM_MINOR_VERSION.$BCM_PATCH_VERSION-$B

BCM_GIT_DIR="$(pwd)"
export BCM_GIT_DIR="$BCM_GIT_DIR"
export BCM_LXD_OPS="$BCM_GIT_DIR/project/shared"
export BCM_PROJECT_DIR="$BCM_GIT_DIR/project"
export BCM_LXD_OPS="$BCM_PROJECT_DIR/shared"
export BCM_COMMAND_DIR="$BCM_GIT_DIR/commands"

# todo; convert this to a temp encrypted ramdisk that exists for the duration of each bcm call.
BCM_HELP_FLAG=0
Expand Down Expand Up @@ -130,7 +138,12 @@ fi
export DEFAULT_KEY_ID="$DEFAULT_KEY_ID"
export GNUPGHOME="$OLD_GNUPGHOME"

RUNNING_CONTAINERS="$(lxc list --format csv --columns ns | grep "RUNNING")" || true
CLUSTER_ENDPOINTS="$(lxc cluster list --format csv | grep "$BCM_SSH_HOSTNAME" | awk -F"," '{print $1}')"
CLUSTER_NODE_COUNT=$(echo "$CLUSTER_ENDPOINTS" | wc -l)
export RUNNING_CONTAINERS="$RUNNING_CONTAINERS"
export CLUSTER_NODE_COUNT="$CLUSTER_NODE_COUNT"
export CLUSTER_ENDPOINTS="$CLUSTER_ENDPOINTS"

# Install docker if we're running this command on a front-end
if [[ $IS_FRONTEND = 1 ]]; then
./commands/cli_entrypoint.sh "$@"
fi
./commands/cli_entrypoint.sh "$@"
245 changes: 124 additions & 121 deletions commands/cli_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,130 +53,133 @@ if [[ "$BCM_CLI_COMMAND" == "info" ]]; then
./info.sh "$@"
exit
fi
# commands BEFORE the the build stage DO NOT REQUIRE docker images at the controller.
if [[ "$BCM_CLI_COMMAND" == "show" ]]; then
./show.sh "$@"
exit
fi

# If our local CLI target SSH hostname is on another machine, then
# we should execute it on the reomte machine.
if [[ "$BCM_SSH_HOSTNAME" != "localhost" ]]; then
bash -c './ssh/entrypoint.sh "$@" --execute --command="$@"'
# commands BEFORE the the build stage DO NOT REQUIRE docker images at the controller.
if [[ "$BCM_CLI_COMMAND" == "deploy" ]]; then
bash -c "$BCM_PROJECT_DIR/deploy.sh $@"
exit
else

# these commands will be executed by the local terminal
export BCM_FORCE_FLAG="$BCM_FORCE_FLAG"
export BCM_VOLUMES_FLAG="$BCM_VOLUMES_FLAG"
RUNNING_CONTAINERS="$(lxc list --format csv --columns ns | grep "RUNNING")" || true
CLUSTER_ENDPOINTS="$(lxc cluster list --format csv | grep "$BCM_SSH_HOSTNAME" | awk -F"," '{print $1}')"
CLUSTER_NODE_COUNT=$(echo "$CLUSTER_ENDPOINTS" | wc -l)
export RUNNING_CONTAINERS="$RUNNING_CONTAINERS"
export CLUSTER_NODE_COUNT="$CLUSTER_NODE_COUNT"
export CLUSTER_ENDPOINTS="$CLUSTER_ENDPOINTS"

if [[ "$BCM_CLI_COMMAND" == "cluster" ]]; then
./cluster/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "show" ]]; then
./show.sh
exit
fi

if [[ "$BCM_CLI_COMMAND" == "stack" ]]; then
# let's make sure our docker swarm master is available for querying.
if ! lxc list --format csv --columns n,s | grep -q "$BCM_MANAGER_HOST_NAME"; then
bcm tier create bitcoin
fi

# if the manager is stopped, start it.
if lxc list --format csv --columns n,s | grep -q "$BCM_MANAGER_HOST_NAME,STOPPED"; then
lxc start "$BCM_MANAGER_HOST_NAME"
bash -c "$BCM_LXD_OPS/wait_for_dockerd.sh --container-name=$BCM_MANAGER_HOST_NAME"
fi

./stack/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "tier" ]]; then
./tier/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "restore" ]]; then
./backuprestore/entrypoint.sh "$@" --restore
exit
fi

if [[ "$BCM_CLI_COMMAND" == "backup" ]]; then
./backuprestore/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "bitcoin-cli" || "$BCM_CLI_COMMAND" == "lightning-cli" || "$BCM_CLI_COMMAND" == "lncli" ]]; then
./stack_cli/entrypoint.sh "$@"
exit
fi

./controller/build_docker_image.sh --image-title="trezor" --base-image="$BASE_DOCKER_IMAGE"
./controller/build_docker_image.sh --image-title="gpgagent" --base-image="bcm-trezor:$BCM_VERSION"
./controller/build_docker_image.sh --image-title="ots" --base-image="bcm-trezor:$BCM_VERSION"

if [[ "$BCM_CLI_COMMAND" == "init" ]]; then
./init.sh "$@"
exit
fi

# set our GNUPGHOME to the user cert directory
# if there is no certificate, go ahead and create it.
if [[ ! -d "$GNUPGHOME/trezor" ]]; then
echo "ERROR: 'The '$GNUPGHOME/trezor' directory does not exist. Please run 'bcm init'."
exit
fi

if [[ "$BCM_CLI_COMMAND" == "controller" ]]; then
./controller/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "pass" ]]; then
./pass/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "git" ]]; then
./git/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "file" ]]; then
./file/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "web" ]]; then
./web/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "logs" ]]; then
./stack_cli/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "get-ip" ]]; then
./get/entrypoint.sh "$@"
exit
fi
fi


# # If our local CLI target SSH hostname is on another machine, then
# # we should execute it on the reomte machine.
# if [[ "$BCM_SSH_HOSTNAME" != "localhost" ]]; then
# bash -c './ssh/entrypoint.sh "$@" --execute --command="$@"'
# exit
# else

# these commands will be executed by the local terminal
export BCM_FORCE_FLAG="$BCM_FORCE_FLAG"
export BCM_VOLUMES_FLAG="$BCM_VOLUMES_FLAG"
# RUNNING_CONTAINERS="$(lxc list --format csv --columns ns | grep "RUNNING")" || true
# CLUSTER_ENDPOINTS="$(lxc cluster list --format csv | grep "$BCM_SSH_HOSTNAME" | awk -F"," '{print $1}')"
# CLUSTER_NODE_COUNT=$(echo "$CLUSTER_ENDPOINTS" | wc -l)
# export RUNNING_CONTAINERS="$RUNNING_CONTAINERS"
# export CLUSTER_NODE_COUNT="$CLUSTER_NODE_COUNT"
# export CLUSTER_ENDPOINTS="$CLUSTER_ENDPOINTS"

if [[ "$BCM_CLI_COMMAND" == "cluster" ]]; then
./cluster/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "stack" ]]; then

# run is for running docker containers AT the SDN controller (not in LXC)
if [[ "$BCM_CLI_COMMAND" == "run" ]]; then
./run/entrypoint.sh "$@"
exit
# if the manager is stopped, start it.
if lxc list --format csv --columns n,s | grep -q "$BCM_MANAGER_HOST_NAME,STOPPED"; then
lxc start "$BCM_MANAGER_HOST_NAME"
bash -c "$BCM_LXD_OPS/wait_for_dockerd.sh --container-name=$BCM_MANAGER_HOST_NAME"
fi

# run is for running docker containers AT the SDN controller (not in LXC)
if [[ "$BCM_CLI_COMMAND" == "run" ]]; then
./run/entrypoint.sh "$@"
exit
fi
./stack/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "tier" ]]; then
./tier/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "restore" ]]; then
./backuprestore/entrypoint.sh "$@" --restore
exit
fi

if [[ "$BCM_CLI_COMMAND" == "backup" ]]; then
./backuprestore/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "bitcoin-cli" || "$BCM_CLI_COMMAND" == "lightning-cli" || "$BCM_CLI_COMMAND" == "lncli" ]]; then
./stack_cli/entrypoint.sh "$@"
exit
fi

./controller/build_docker_image.sh --image-title="trezor" --base-image="$BASE_DOCKER_IMAGE"
./controller/build_docker_image.sh --image-title="gpgagent" --base-image="bcm-trezor:$BCM_VERSION"
./controller/build_docker_image.sh --image-title="ots" --base-image="bcm-trezor:$BCM_VERSION"

if [[ "$BCM_CLI_COMMAND" == "init" ]]; then
./init.sh "$@"
exit
fi

# set our GNUPGHOME to the user cert directory
# if there is no certificate, go ahead and create it.
if [[ ! -d "$GNUPGHOME/trezor" ]]; then
echo "ERROR: 'The '$GNUPGHOME/trezor' directory does not exist. Please run 'bcm init'."
exit
fi

if [[ "$BCM_CLI_COMMAND" == "controller" ]]; then
./controller/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "pass" ]]; then
./pass/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "git" ]]; then
./git/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "file" ]]; then
./file/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "web" ]]; then
./web/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "logs" ]]; then
./stack_cli/entrypoint.sh "$@"
exit
fi

if [[ "$BCM_CLI_COMMAND" == "get-ip" ]]; then
./get/entrypoint.sh "$@"
exit
fi

# run is for running docker containers AT the SDN controller (not in LXC)
if [[ "$BCM_CLI_COMMAND" == "run" ]]; then
./run/entrypoint.sh "$@"
exit
fi

# run is for running docker containers AT the SDN controller (not in LXC)
if [[ "$BCM_CLI_COMMAND" == "run" ]]; then
./run/entrypoint.sh "$@"
exit
fi
# fi
4 changes: 1 addition & 3 deletions commands/cluster/clear_lxd.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/bin/bash

set -Eeuox pipefail
set -Eeuo pipefail
cd "$(dirname "$0")"

echo "ALL_FLAG: $ALL_FLAG"

## Delete anything that's tied to a project
for project in $(lxc query "/1.0/projects?recursion=1" | jq .[].name -r); do
echo "==> Deleting all containers for project: ${project}"
Expand Down
6 changes: 3 additions & 3 deletions commands/cluster/cluster_create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
set -Eeuo pipefail
cd "$(dirname "$0")"

BCM_SSH_HOSTNAME=localhost
#BCM_SSH_HOSTNAME=localhost

for i in "$@"; do
case $i in
--hostname=*)
BCM_SSH_HOSTNAME="${i#*=}"
shift # past argument=value
;;

*)
# unknown option
;;
Expand All @@ -29,7 +29,7 @@ IP_OF_MACVLAN_INTERFACE="$(ip addr show "$MACVLAN_INTERFACE" | grep "inet " | cu
BCM_LXD_SECRET="$(apg -n 1 -m 30 -M CN)"
export BCM_LXD_SECRET="$BCM_LXD_SECRET"
export MACVLAN_INTERFACE="$MACVLAN_INTERFACE"
LXD_SERVER_NAME="$BCM_SSH_HOSTNAME"
LXD_SERVER_NAME="$(hostname)"
# these two lines are so that ssh hosts can have the correct naming convention for LXD node info.
if [[ ! "$LXD_SERVER_NAME" == *"-01"* ]]; then
LXD_SERVER_NAME="$LXD_SERVER_NAME-01"
Expand Down
Loading

0 comments on commit f315bc8

Please sign in to comment.