examples: improve robustness of deploy scripts
- The scripts now work within arbitrary nix-shells. Previously, they failed when run from nix shells other than `examples/shell.nix`. - The scripts now work from arbitrary working dirs.
This commit is contained in:
parent
4022f86b92
commit
cc7149eb78
@ -8,10 +8,12 @@ set -euo pipefail
|
|||||||
# Run with option `--interactive` or `-i` to start a shell for interacting with
|
# Run with option `--interactive` or `-i` to start a shell for interacting with
|
||||||
# the node.
|
# the node.
|
||||||
|
|
||||||
if [[ ! -v IN_NIX_SHELL ]]; then
|
if [[ ! -v NIX_BITCOIN_EXAMPLES_DIR ]]; then
|
||||||
echo "Running script in nix shell env..."
|
echo "Running script in nix shell env..."
|
||||||
cd "${BASH_SOURCE[0]%/*}"
|
cd "${BASH_SOURCE[0]%/*}"
|
||||||
exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*"
|
exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*"
|
||||||
|
else
|
||||||
|
cd "$NIX_BITCOIN_EXAMPLES_DIR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $(sysctl -n net.ipv4.ip_forward || sudo sysctl -n net.ipv4.ip_forward) != 1 ]]; then
|
if [[ $(sysctl -n net.ipv4.ip_forward || sudo sysctl -n net.ipv4.ip_forward) != 1 ]]; then
|
||||||
@ -22,7 +24,7 @@ fi
|
|||||||
|
|
||||||
if [[ $EUID != 0 ]]; then
|
if [[ $EUID != 0 ]]; then
|
||||||
# NixOS containers require root permissions
|
# NixOS containers require root permissions
|
||||||
exec sudo "PATH=$PATH" "NIX_PATH=$NIX_PATH" "IN_NIX_SHELL=$IN_NIX_SHELL" "${BASH_SOURCE[0]}" "$@"
|
exec sudo "PATH=$PATH" "NIX_PATH=$NIX_PATH" "NIX_BITCOIN_EXAMPLES_DIR=$NIX_BITCOIN_EXAMPLES_DIR" "${BASH_SOURCE[0]}" "$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
interactive=
|
interactive=
|
||||||
|
@ -12,10 +12,12 @@ set -euo pipefail
|
|||||||
# MAKE SURE TO REPLACE the SSH identity file if you use this script for
|
# MAKE SURE TO REPLACE the SSH identity file if you use this script for
|
||||||
# anything serious.
|
# anything serious.
|
||||||
|
|
||||||
if [[ ! -v IN_NIX_SHELL ]]; then
|
if [[ ! -v NIX_BITCOIN_EXAMPLES_DIR ]]; then
|
||||||
echo "Running script in nix shell env..."
|
echo "Running script in nix shell env..."
|
||||||
cd "${BASH_SOURCE[0]%/*}"
|
cd "${BASH_SOURCE[0]%/*}"
|
||||||
exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*"
|
exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*"
|
||||||
|
else
|
||||||
|
cd "$NIX_BITCOIN_EXAMPLES_DIR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
source qemu-vm/run-vm.sh
|
source qemu-vm/run-vm.sh
|
||||||
|
@ -11,10 +11,12 @@ set -euo pipefail
|
|||||||
# MAKE SURE TO REPLACE the SSH identity file if you use this script for
|
# MAKE SURE TO REPLACE the SSH identity file if you use this script for
|
||||||
# anything serious.
|
# anything serious.
|
||||||
|
|
||||||
if [[ ! -v IN_NIX_SHELL ]]; then
|
if [[ ! -v NIX_BITCOIN_EXAMPLES_DIR ]]; then
|
||||||
echo "Running script in nix shell env..."
|
echo "Running script in nix shell env..."
|
||||||
cd "${BASH_SOURCE[0]%/*}"
|
cd "${BASH_SOURCE[0]%/*}"
|
||||||
exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*"
|
exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*"
|
||||||
|
else
|
||||||
|
cd "$NIX_BITCOIN_EXAMPLES_DIR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
source qemu-vm/run-vm.sh
|
source qemu-vm/run-vm.sh
|
||||||
|
@ -26,6 +26,8 @@ stdenv.mkDerivation rec {
|
|||||||
export NIX_PATH="nixpkgs=${nixpkgs-path}:nix-bitcoin=${toString nix-bitcoin-path}:."
|
export NIX_PATH="nixpkgs=${nixpkgs-path}:nix-bitcoin=${toString nix-bitcoin-path}:."
|
||||||
export PATH="${path}''${PATH:+:}$PATH"
|
export PATH="${path}''${PATH:+:}$PATH"
|
||||||
|
|
||||||
|
export NIX_BITCOIN_EXAMPLES_DIR="${toString ./.}"
|
||||||
|
|
||||||
alias fetch-release="${toString nix-bitcoin-path}/helper/fetch-release"
|
alias fetch-release="${toString nix-bitcoin-path}/helper/fetch-release"
|
||||||
|
|
||||||
krops-deploy() {
|
krops-deploy() {
|
||||||
|
Loading…
Reference in New Issue
Block a user