Skip to content

Commit

Permalink
fix: reduce the number of shell scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmoon committed Jul 17, 2023
1 parent 8ba7565 commit bc8e856
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 124 deletions.
2 changes: 0 additions & 2 deletions mprocs-nix-gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions mprocs-nix-guardian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 0 additions & 9 deletions scripts/aliases.sh

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/completion.sh

This file was deleted.

30 changes: 0 additions & 30 deletions scripts/mprocs-nix-gateway.sh

This file was deleted.

29 changes: 0 additions & 29 deletions scripts/mprocs-nix-guardian.sh

This file was deleted.

34 changes: 18 additions & 16 deletions scripts/mprocs-nix.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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/urandom | head -c 4 || true)"
else
FM_TEST_DIR="${2-"$(mktemp --tmpdir -d XXXXX)"}"
if [[ -z "${IN_NIX_SHELL:-}" ]]; then
echo "Run "nix develop" first"
exit 1
fi
export FM_TEST_DIR

DEVIMINT_COMMAND=$1
MPROCS_PATH=$2

export FM_TEST_DIR="$TMP/fm-$(LC_ALL=C tr -dc A-Za-z0-9 </dev/urandom | head -c 4 || true)"
export FM_FED_SIZE=4
export FM_PID_FILE="$FM_TEST_DIR/.pid"
export FM_LOGS_DIR="$FM_TEST_DIR/logs"

echo "Setting up env variables in $FM_TEST_DIR"
devimint dev-fed 2>/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 {
Expand All @@ -34,3 +33,6 @@ function kill_fedimint_processes {
}

trap kill_fedimint_processes EXIT

echo "PATH: $MPROCS_PATH"
mprocs -c $MPROCS_PATH
38 changes: 36 additions & 2 deletions scripts/mprocs-user-shell.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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 ""
Expand Down
28 changes: 0 additions & 28 deletions scripts/user-shell.sh

This file was deleted.

0 comments on commit bc8e856

Please sign in to comment.