From: alex Date: Fri, 24 Jun 2022 19:56:08 +0000 (-0700) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=fc214d028a5f8b6d61c2d508591db81581fcf7b2;p=cold ... --- diff --git a/cold-setup b/cold-setup index ea16733..559b83f 100755 --- a/cold-setup +++ b/cold-setup @@ -14,6 +14,12 @@ USB_PATH_PRE_DECRYPT= BITCOIN_CLI="bitcoin-cli -datadir=$DATA_DIRECTORY -chain=regtest" bitcoin_core_start() { + RUNNING=`ps -A | ( grep bitcoind > /dev/null && echo "1" ) || echo "0"` + if [[ "$RUNNING" -gt 0 ]]; then + log_error "ERROR: bitcoin core already running\nexitting..." + exit 1 + fi + log_info "starting bitcoin core..." mkdir -p "$DATA_DIRECTORY" bitcoind -daemonwait -datadir="$DATA_DIRECTORY" -chain=regtest &> /dev/null @@ -21,6 +27,12 @@ bitcoin_core_start() { } bitcoin_core_stop() { + RUNNING=`ps -A | ( grep bitcoind > /dev/null && echo "1" ) || echo "0"` + if [[ "$RUNNING" -eq 0 ]]; then + log_error "ERROR: bitcoin core not running\nexitting..." + exit 1 + fi + log_info "stopping bitcoin core..." local CMD="$BITCOIN_CLI stop" eval "$CMD" &> /dev/null @@ -29,16 +41,18 @@ bitcoin_core_stop() { } depends() { + PATH="$PATH:/sbin" + detect base64 detect bitcoind detect bitcoin-cli -# detect cryptsetup + detect cryptsetup detect eject detect jq -# detect mkfs.ext4 + detect mkfs.ext4 detect nmcli detect shred -# detect wipefs + detect wipefs } detect() { @@ -102,8 +116,7 @@ multisig_create() { } network_off() { - echo "turn networking off" - exit 1 + nmcli networking off } parse_arguments() { @@ -397,6 +410,8 @@ main() { bitcoin_core_start + network_off + wallets multisig_create diff --git a/test/bitcoin_core_start.tests.sh b/test/bitcoin_core_start.tests.sh new file mode 100755 index 0000000..dc8a133 --- /dev/null +++ b/test/bitcoin_core_start.tests.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +set -euo pipefail + +source setup.sh + +mkdir "$TEST_DIR" +cd "$TEST_DIR" + +(bitcoin_core_start > result) +EXPECTED=$'starting bitcoin core...\nbitcoin core started' +RESULT=$( result 2>&1) +assert "1" "$?" +set -e +EXPECTED=$'ERROR: bitcoin core already running\nexitting...' +RESULT=$( result) +EXPECTED=$'stopping bitcoin core...\nbitcoin core stopped' +RESULT=$( result 2>&1) +assert "1" "$?" +set -e +EXPECTED=$'ERROR: bitcoin core not running\nexitting...' +RESULT=$( result) + +clean_env + +test_succeeded diff --git a/test/detect.tests.sh b/test/detect.tests.sh new file mode 100755 index 0000000..0d21ebb --- /dev/null +++ b/test/detect.tests.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -euo pipefail + +source setup.sh + +setup_env + +(detect "ls" > result) +(detect "cp" > result) +(detect "mkdir" > result) + +set +e +(detect "masodifsoidfnaiosdnfokdir" > result 2>&1) +assert "1" "$?" +set -e +EXPECTED="masodifsoidfnaiosdnfokdir: command not found" +RESULT=$( function_replace_test/foo + +(ls function_replace_test > result) +EXPECTED="foo" +RESULT=$( result) +EXPECTED="replaced ls function" +RESULT=$(