From bc8e856b25744596daac1b0f62e0ac93760e8799 Mon Sep 17 00:00:00 2001 From: Justin Moon Date: Mon, 17 Jul 2023 18:48:54 -0500 Subject: [PATCH] fix: reduce the number of shell scripts --- mprocs-nix-gateway.yml | 2 -- mprocs-nix-guardian.yml | 2 -- package.json | 4 ++-- scripts/aliases.sh | 9 -------- scripts/completion.sh | 4 ---- scripts/mprocs-nix-gateway.sh | 30 --------------------------- scripts/mprocs-nix-guardian.sh | 29 -------------------------- scripts/mprocs-nix.sh | 34 ++++++++++++++++-------------- scripts/mprocs-user-shell.sh | 38 ++++++++++++++++++++++++++++++++-- scripts/user-shell.sh | 28 ------------------------- 10 files changed, 56 insertions(+), 124 deletions(-) delete mode 100644 scripts/aliases.sh delete mode 100644 scripts/completion.sh delete mode 100755 scripts/mprocs-nix-gateway.sh delete mode 100755 scripts/mprocs-nix-guardian.sh mode change 100644 => 100755 scripts/mprocs-nix.sh mode change 100755 => 100644 scripts/mprocs-user-shell.sh delete mode 100644 scripts/user-shell.sh diff --git a/mprocs-nix-gateway.yml b/mprocs-nix-gateway.yml index 973acdef2..22bd6c780 100644 --- a/mprocs-nix-gateway.yml +++ b/mprocs-nix-gateway.yml @@ -22,8 +22,6 @@ procs: shell: tail -n +0 -F $FM_LOGS_DIR/bitcoind.log devimint: shell: tail -n +0 -F $FM_LOGS_DIR/devimint.log - faucet: - shell: tail -n +0 -F $FM_LOGS_DIR/faucet.log gateway-ui: cwd: apps/gateway-ui/ shell: yarn dev diff --git a/mprocs-nix-guardian.yml b/mprocs-nix-guardian.yml index 31493da04..a2007d576 100644 --- a/mprocs-nix-guardian.yml +++ b/mprocs-nix-guardian.yml @@ -22,8 +22,6 @@ procs: shell: tail -n +0 -F $FM_LOGS_DIR/bitcoind.log devimint: shell: tail -n +0 -F $FM_LOGS_DIR/devimint.log - faucet: - shell: tail -n +0 -F $FM_LOGS_DIR/faucet.log guardian-ui-1: cwd: apps/guardian-ui/ shell: yarn dev diff --git a/package.json b/package.json index c5c4f618b..f62f6ca67 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ "lint": "turbo run lint", "test": "turbo run test", "prepare": "husky install", - "nix-guardian": "./scripts/mprocs-nix-guardian.sh", - "nix-gateway": "./scripts/mprocs-nix-gateway.sh", + "nix-guardian": "./scripts/mprocs-nix.sh dev-fed mprocs-nix-gateway.yml", + "nix-gateway": "./scripts/mprocs-nix.sh run-ui mprocs-nix-gateway.yml", "mprocs": "mprocs -c ./mprocs.yml" }, "devDependencies": { diff --git a/scripts/aliases.sh b/scripts/aliases.sh deleted file mode 100644 index 31457be53..000000000 --- a/scripts/aliases.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -alias lightning-cli="\$FM_LIGHTNING_CLI" -alias lncli="\$FM_LNCLI" -alias bitcoin-cli="\$FM_BTC_CLIENT" -alias fedimint-cli="\$FM_MINT_CLIENT" -alias gateway-cln="\$FM_GWCLI_CLN" -alias gateway-lnd="\$FM_GWCLI_LND" -# alias restart="./scripts/restart-tmux.sh" diff --git a/scripts/completion.sh b/scripts/completion.sh deleted file mode 100644 index e6d9de52b..000000000 --- a/scripts/completion.sh +++ /dev/null @@ -1,4 +0,0 @@ -# shellcheck shell=bash - -eval "$(fedimint-cli completion bash)" || true -eval "$(gateway-cli completion bash)" || true diff --git a/scripts/mprocs-nix-gateway.sh b/scripts/mprocs-nix-gateway.sh deleted file mode 100755 index 6980d2426..000000000 --- a/scripts/mprocs-nix-gateway.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -export FM_TEST_DIR="${2-$TMP}/fm-$(LC_ALL=C tr -dc A-Za-z0-9 /dev/null & - -mkdir $FM_TEST_DIR -mkdir $FM_LOGS_DIR -touch $FM_PID_FILE -echo $! >> $FM_PID_FILE -eval "$(devimint env)" - -# Function for killing processes stored in FM_PID_FILE in reverse-order they were created in -function kill_fedimint_processes { - echo "Killing fedimint processes" - PIDS=$(cat $FM_PID_FILE | sed '1!G;h;$!d') # sed reverses order - if [ -n "$PIDS" ] - then - kill $PIDS 2>/dev/null - fi - rm -f $FM_PID_FILE -} - -trap kill_fedimint_processes EXIT - -mprocs -c mprocs-nix-gateway.yml - diff --git a/scripts/mprocs-nix-guardian.sh b/scripts/mprocs-nix-guardian.sh deleted file mode 100755 index 6855536dc..000000000 --- a/scripts/mprocs-nix-guardian.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -export FM_TEST_DIR="${2-$TMP}/fm-$(LC_ALL=C tr -dc A-Za-z0-9 /dev/null & - -mkdir $FM_TEST_DIR -mkdir $FM_LOGS_DIR -touch $FM_PID_FILE -echo $! >> $FM_PID_FILE -eval "$(devimint env)" - -# Function for killing processes stored in FM_PID_FILE in reverse-order they were created in -function kill_fedimint_processes { - echo "Killing fedimint processes" - PIDS=$(cat $FM_PID_FILE | sed '1!G;h;$!d') # sed reverses order - if [ -n "$PIDS" ] - then - kill $PIDS 2>/dev/null - fi - rm -f $FM_PID_FILE -} - -trap kill_fedimint_processes EXIT - -mprocs -c mprocs-nix-guardian.yml \ No newline at end of file diff --git a/scripts/mprocs-nix.sh b/scripts/mprocs-nix.sh old mode 100644 new mode 100755 index 51c33345e..026324d0b --- a/scripts/mprocs-nix.sh +++ b/scripts/mprocs-nix.sh @@ -1,26 +1,25 @@ #!/usr/bin/env bash -echo "Run with 'source ./mprocs-nix.sh [guardian|gateway]" - -# If $TMP contains '/nix-shell.' it is already unique to the -# nix shell instance, and appending more characters to it is -# pointless. It only gets us closer to the 108 character limit -# for named unix sockets (https://stackoverflow.com/a/34833072), -# so let's not do it. - -if [[ "${TMP:-}" == *"/nix-shell."* ]]; then - FM_TEST_DIR="${2-$TMP}/fm-$(LC_ALL=C tr -dc A-Za-z0-9 /dev/null & -mkdir -p "$FM_TEST_DIR" -touch "$FM_PID_FILE" +mkdir $FM_TEST_DIR +mkdir $FM_LOGS_DIR +touch $FM_PID_FILE +echo $! >> $FM_PID_FILE +eval "$(devimint $DEVIMINT_COMMAND)" # Function for killing processes stored in FM_PID_FILE in reverse-order they were created in function kill_fedimint_processes { @@ -34,3 +33,6 @@ function kill_fedimint_processes { } trap kill_fedimint_processes EXIT + +echo "PATH: $MPROCS_PATH" +mprocs -c $MPROCS_PATH diff --git a/scripts/mprocs-user-shell.sh b/scripts/mprocs-user-shell.sh old mode 100755 new mode 100644 index 0db687b2f..f53d46d64 --- a/scripts/mprocs-user-shell.sh +++ b/scripts/mprocs-user-shell.sh @@ -1,7 +1,41 @@ -#!/usr/bin/env bash +# shellcheck shell=bash -source ./scripts/user-shell.sh +eval "$(devimint env)" +source ./scripts/completion.sh +source ./scripts/aliases.sh +echo Waiting for fedimint start + +STATUS="$(devimint wait)" +if [ "$STATUS" = "ERROR" ] +then + echo "fedimint didn't start correctly" + echo "See other panes for errors" + exit 1 +fi + +alias lightning-cli="\$FM_LIGHTNING_CLI" +alias lncli="\$FM_LNCLI" +alias bitcoin-cli="\$FM_BTC_CLIENT" +alias fedimint-cli="\$FM_MINT_CLIENT" +alias gateway-cln="\$FM_GWCLI_CLN" +alias gateway-lnd="\$FM_GWCLI_LND" + +eval "$(fedimint-cli completion bash)" || true +eval "$(gateway-cli completion bash)" || true + +echo Done! +echo +echo "This shell provides the following aliases:" +echo "" +echo " fedimint-cli - cli client to interact with the federation" +echo " lightning-cli - cli client for Core Lightning" +echo " lncli - cli client for LND" +echo " bitcoin-cli - cli client for bitcoind" +echo " gateway-cln - cli client for the CLN gateway" +echo " gateway-lnd - cli client for the LND gateway" +echo +echo "Use '--help' on each command for more information" echo "" echo "Important mprocs key sequences:" echo "" diff --git a/scripts/user-shell.sh b/scripts/user-shell.sh deleted file mode 100644 index a50535e0d..000000000 --- a/scripts/user-shell.sh +++ /dev/null @@ -1,28 +0,0 @@ -# shellcheck shell=bash - -eval "$(devimint env)" -source ./scripts/completion.sh -source ./scripts/aliases.sh - -echo Waiting for fedimint start - -STATUS="$(devimint wait)" -if [ "$STATUS" = "ERROR" ] -then - echo "fedimint didn't start correctly" - echo "See other panes for errors" - exit 1 -fi - -echo Done! -echo -echo "This shell provides the following aliases:" -echo "" -echo " fedimint-cli - cli client to interact with the federation" -echo " lightning-cli - cli client for Core Lightning" -echo " lncli - cli client for LND" -echo " bitcoin-cli - cli client for bitcoind" -echo " gateway-cln - cli client for the CLN gateway" -echo " gateway-lnd - cli client for the LND gateway" -echo -echo "Use '--help' on each command for more information"