nix-bitcoin/examples/deploy-nixops.sh

51 lines
1.3 KiB
Bash
Raw Normal View History

2020-02-26 08:11:22 -08:00
#!/usr/bin/env bash
set -euo pipefail
# This script demonstrates how to setup a VirtualBox nix-bitcoin node with nixops.
# Running this script leaves no traces on your host system.
# This demo is a template for your own experiments.
# Run with option `--interactive` or `-i` to start a shell for interacting with
# the node.
2020-02-26 08:11:22 -08:00
if [[ ! -v IN_NIX_SHELL ]]; then
echo "Running script in nix shell env..."
cd "${BASH_SOURCE[0]%/*}"
2020-10-18 04:41:55 -07:00
exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*"
2020-02-26 08:11:22 -08:00
fi
# Cleanup on exit
cleanup() {
set +e
if nixops list | grep -q bitcoin-node; then
nixops destroy --confirm -d bitcoin-node
fi
rm -rf $tmpDir
}
trap "cleanup" EXIT
tmpDir=/tmp/nix-bitcoin-nixops
mkdir -p $tmpDir
# Don't write nixops and VirtualBox data to the $USER's home
export HOME=$tmpDir
# Disable interactive queries and don't write to the $USER's known_hosts file
export NIXOPS_SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
nixops create nixops/node.nix nixops/node-vbox.nix -d bitcoin-node
nixops deploy -d bitcoin-node
# Connect to node
nixops ssh bitcoin-node systemctl status bitcoind
c() { nixops ssh bitcoin-node "$@"; }
2020-10-18 04:41:55 -07:00
case ${1:-} in
-i|--interactive)
. start-bash-session.sh
;;
esac
2020-04-15 09:54:02 -07:00
2020-02-26 08:11:22 -08:00
# Cleanup happens at exit (see above)