#!/bin/sh docker__compose() { CURRENT_UID=$(id -u) CURRENT_GID=$(id -g) command docker compose --env-file .env.sndev "$@" } docker__exec() { command docker exec "$@" } docker__sn_lnd() { docker__exec -u lnd sn_lnd lncli "$@" } docker__stacker_lnd() { docker__exec -u lnd stacker_lnd lncli "$@" } sndev__start() { if [ ! -x "$(command -v docker-compose)" ]; then echo "docker compose is not installed" echo "installation instructions are here: https://docs.docker.com/desktop/" exit 0 fi if ! [ -f .env.sndev ]; then echo ".env.sndev does not exist." echo "creating from .env.sample" cp .env.sample .env.sndev fi echo "Starting application" docker__compose up --build } sndev__stop() { echo "Stopping application" docker__compose down } sndev__restart() { docker__compose restart } sndev__status() { shift docker__compose ps --format 'table {{.Service}}\t{{.State}}\t{{.Status}}\t{{.Ports}}' } sndev__delete() { echo "Deleting application" docker__compose down --volumes --remove-orphans } sndev__fund() { shift docker__stacker_lnd payinvoice --force "$@" } sndev__withdraw() { shift docker__stacker_lnd addinvoice --amt "$@" | jq -r '.payment_request' } sndev__compose() { shift docker__compose "$@" } sndev__sn_lncli() { shift docker__sn_lnd "$@" } sndev__stacker_lncli() { shift docker__stacker_lnd "$@" } sndev__help() { if [ $# -eq 3 ]; then call "sndev__$1__$2__$3" "$@" elif [ $# -eq 2 ]; then call "sndev__$1__$2" "$@" else help=" 888 888 888 .d8888b 88888b. .d88888 .d88b. 888 888 88K 888 '88b d88' 888 d8P Y8b 888 888 'Y8888b. 888 888 888 888 88888888 Y88 88P X88 888 888 Y88b 888 Y8b. Y8bd8P 88888P' 888 888 'Y88888 'Y8888 Y88P manages a docker based stacker news development environment USAGE $ sndev [COMMAND] COMMANDS help show help env: start start env stop stop env restart restart env status status of env delete delete env lnd: fund pay a bolt11 for funding withdraw make a bolt11 for withdrawal raw: compose call docker compose directly sn_lncli call lncli on sn_lnd directly stacker_lncli call lncli on stacker_lnd directly " echo "$help" fi } call() { func=$1 if type "$func" 1>/dev/null 2>&1; then shift "$func" "$@" # invoke our named function w/ all remaining arguments else sndev__help exit 1 fi } call "sndev__$1" "$@"