2024-03-07 16:02:59 +00:00
|
|
|
#!/bin/sh
|
2024-03-07 01:04:55 +00:00
|
|
|
|
2024-03-11 20:30:35 +00:00
|
|
|
set -e
|
2024-08-01 00:44:08 +00:00
|
|
|
set -a # automatically export all variables
|
2024-08-13 20:48:22 +00:00
|
|
|
. ./.env.development
|
2024-08-01 00:44:08 +00:00
|
|
|
if [ -f .env.local ]; then
|
2024-08-13 20:48:22 +00:00
|
|
|
. ./.env.local
|
2024-08-01 00:44:08 +00:00
|
|
|
fi
|
2024-03-11 20:30:35 +00:00
|
|
|
|
2024-03-08 19:11:15 +00:00
|
|
|
docker__compose() {
|
2024-07-11 22:28:13 +00:00
|
|
|
if [ ! -x "$(command -v docker)" ]; then
|
2024-03-11 20:27:18 +00:00
|
|
|
echo "docker compose is not installed"
|
|
|
|
echo "installation instructions are here: https://docs.docker.com/desktop/"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2024-04-20 21:50:43 +00:00
|
|
|
ENV_LOCAL=
|
|
|
|
if [ -f .env.local ]; then
|
|
|
|
ENV_LOCAL='--env-file .env.local'
|
|
|
|
fi
|
|
|
|
|
2024-08-01 00:44:08 +00:00
|
|
|
CURRENT_UID=$(id -u) CURRENT_GID=$(id -g) command docker compose --env-file .env.development $ENV_LOCAL "$@"
|
2024-03-08 19:11:15 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 21:29:10 +00:00
|
|
|
docker__exec() {
|
2024-03-11 20:27:18 +00:00
|
|
|
if [ ! -x "$(command -v docker)" ]; then
|
|
|
|
echo "docker is not installed"
|
|
|
|
echo "installation instructions are here: https://docs.docker.com/desktop/"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2024-04-14 22:40:24 +00:00
|
|
|
DOCKER_CLI_HINTS=false command docker exec -i "$@"
|
2024-03-10 21:29:10 +00:00
|
|
|
}
|
|
|
|
|
2024-03-07 01:04:55 +00:00
|
|
|
sndev__start() {
|
2024-03-11 20:27:18 +00:00
|
|
|
shift
|
2024-03-07 01:04:55 +00:00
|
|
|
|
2024-03-18 14:27:26 +00:00
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
docker__compose up --build
|
|
|
|
exit 0
|
2024-03-11 20:27:18 +00:00
|
|
|
fi
|
|
|
|
|
2024-03-18 14:27:26 +00:00
|
|
|
docker__compose up "$@"
|
2024-03-11 20:27:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sndev__help_start() {
|
|
|
|
help="
|
|
|
|
start the sndev env
|
|
|
|
|
|
|
|
USAGE
|
2024-04-02 20:00:45 +00:00
|
|
|
$ sndev start [OPTIONS] [SERVICE...]
|
2024-03-11 20:27:18 +00:00
|
|
|
|
2024-03-18 14:27:26 +00:00
|
|
|
OPTIONS"
|
2024-03-11 20:27:18 +00:00
|
|
|
|
|
|
|
echo "$help"
|
2024-03-13 16:21:51 +00:00
|
|
|
docker__compose up --help | awk '/Options:/{y=1;next}y'
|
2024-03-07 01:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sndev__stop() {
|
2024-03-11 20:27:18 +00:00
|
|
|
shift
|
|
|
|
docker__compose down "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
sndev__help_stop() {
|
|
|
|
help="
|
|
|
|
stop the sndev env
|
|
|
|
|
|
|
|
USAGE
|
2024-04-02 20:00:45 +00:00
|
|
|
$ sndev stop [OPTIONS] [SERVICE...]
|
2024-03-11 20:27:18 +00:00
|
|
|
|
2024-03-18 14:27:26 +00:00
|
|
|
OPTIONS"
|
2024-03-11 20:27:18 +00:00
|
|
|
|
|
|
|
echo "$help"
|
2024-03-13 16:21:51 +00:00
|
|
|
docker__compose down --help | awk '/Options:/{y=1;next}y'
|
2024-03-07 01:04:55 +00:00
|
|
|
}
|
|
|
|
|
2024-05-04 23:06:15 +00:00
|
|
|
sndev__open() {
|
|
|
|
shift
|
|
|
|
service=$(docker__compose ps $1 --format '{{.Label "CONNECT"}}')
|
|
|
|
if [ -z "$service" ]; then
|
|
|
|
echo "no url found for $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
service="http://$service"
|
|
|
|
|
|
|
|
echo "opening $1 ... $service"
|
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
|
|
|
open $service
|
|
|
|
elif [ "$(uname)" = "Linux" ]; then
|
|
|
|
xdg-open $service
|
|
|
|
elif [ "$(uname)" = "Windows_NT" ]; then
|
|
|
|
start $service
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
sndev__help_open() {
|
|
|
|
help="
|
|
|
|
open a container's url if it has one
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
$ sndev open SERVICE
|
|
|
|
|
|
|
|
OPTIONS
|
|
|
|
no options currently exist
|
|
|
|
"
|
|
|
|
|
|
|
|
echo "$help"
|
|
|
|
}
|
|
|
|
|
2024-03-10 22:30:11 +00:00
|
|
|
sndev__restart() {
|
2024-03-11 20:27:18 +00:00
|
|
|
shift
|
|
|
|
docker__compose restart "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
sndev__help_restart() {
|
|
|
|
help="
|
|
|
|
restart the sndev env
|
|
|
|
|
|
|
|
USAGE
|
2024-04-02 20:00:45 +00:00
|
|
|
$ sndev restart [OPTIONS] [SERVICE...]
|
2024-03-11 20:27:18 +00:00
|
|
|
|
|
|
|
OPTIONS"
|
|
|
|
|
|
|
|
echo "$help"
|
2024-03-13 16:21:51 +00:00
|
|
|
docker__compose restart --help | awk '/Options:/{y=1;next}y'
|
2024-03-10 22:30:11 +00:00
|
|
|
}
|
|
|
|
|
2024-04-02 20:00:45 +00:00
|
|
|
sndev__logs() {
|
|
|
|
shift
|
2024-06-04 18:07:03 +00:00
|
|
|
if [ $# -eq 1 ]; then
|
|
|
|
docker__compose logs -t --tail=1000 -f "$@"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2024-04-02 20:00:45 +00:00
|
|
|
docker__compose logs "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
sndev__help_logs() {
|
|
|
|
help="
|
|
|
|
get logs from sndev env
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
$ sndev logs [OPTIONS] [SERVICE...]
|
|
|
|
|
|
|
|
OPTIONS"
|
|
|
|
|
|
|
|
echo "$help"
|
|
|
|
docker__compose logs --help | awk '/Options:/{y=1;next}y'
|
|
|
|
}
|
|
|
|
|
2024-03-10 22:10:38 +00:00
|
|
|
sndev__status() {
|
|
|
|
shift
|
2024-03-11 20:27:18 +00:00
|
|
|
if [ $# -eq 0 ]; then
|
2024-03-13 16:21:51 +00:00
|
|
|
docker__compose ps -a --format 'table {{.Service}}\t{{.State}}\t{{.Status}}\t{{.Label "CONNECT"}}'
|
2024-03-11 20:27:18 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
docker__compose ps "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
sndev__help_status() {
|
|
|
|
help="
|
|
|
|
show container status of sndev env
|
|
|
|
|
|
|
|
USAGE
|
2024-04-02 20:00:45 +00:00
|
|
|
$ sndev status [OPTIONS] [SERVICE...]
|
2024-03-11 20:27:18 +00:00
|
|
|
|
|
|
|
OPTIONS"
|
|
|
|
|
|
|
|
echo "$help"
|
2024-03-13 16:21:51 +00:00
|
|
|
docker__compose ps --help | awk '/Options:/{y=1;next}y'
|
2024-03-10 22:10:38 +00:00
|
|
|
}
|
|
|
|
|
2024-03-07 01:04:55 +00:00
|
|
|
sndev__delete() {
|
2024-03-13 19:29:21 +00:00
|
|
|
printf "this deletes containers, volumes, and orphans - are you sure? [y/N] "
|
2024-03-12 23:05:10 +00:00
|
|
|
read -r answer
|
|
|
|
if [ "$answer" = "y" ]; then
|
|
|
|
docker__compose down --volumes --remove-orphans
|
|
|
|
else
|
|
|
|
echo "delete cancelled"
|
|
|
|
fi
|
2024-03-07 01:04:55 +00:00
|
|
|
}
|
|
|
|
|
2024-03-11 20:27:18 +00:00
|
|
|
sndev__help_delete() {
|
|
|
|
help="
|
|
|
|
remove orphans and volumes from sndev env
|
|
|
|
equivalent to sndev stop --volumes --remove-orphans
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
$ sndev delete
|
|
|
|
"
|
|
|
|
|
|
|
|
echo "$help"
|
|
|
|
}
|
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
sndev__set_balance() {
|
2024-06-03 14:37:58 +00:00
|
|
|
shift
|
2024-11-09 21:52:04 +00:00
|
|
|
|
2024-06-03 14:37:58 +00:00
|
|
|
if [ -z "$1" ]; then
|
2024-11-09 21:52:04 +00:00
|
|
|
echo "NYM argument required"
|
|
|
|
sndev__help_set_balance
|
2024-06-03 14:37:58 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2024-11-09 21:52:04 +00:00
|
|
|
|
2024-06-03 14:37:58 +00:00
|
|
|
if [ -z "$2" ]; then
|
2024-11-09 21:52:04 +00:00
|
|
|
echo "MSATS argument required"
|
|
|
|
sndev__help_set_balance
|
2024-06-03 14:37:58 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
2024-11-09 21:52:04 +00:00
|
|
|
|
|
|
|
if ! echo "$2" | grep -qE "^[0-9]+$"; then
|
|
|
|
echo "MSATS argument is not a positive integer"
|
|
|
|
sndev__help_set_balance
|
2024-06-03 14:37:58 +00:00
|
|
|
exit 3
|
|
|
|
fi
|
2024-11-09 21:52:04 +00:00
|
|
|
|
2024-06-03 14:37:58 +00:00
|
|
|
docker__exec db psql -U sn -d stackernews -q <<EOF
|
|
|
|
UPDATE users set msats = $2 where name = '$1';
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
sndev__help_set_balance() {
|
2024-06-03 14:37:58 +00:00
|
|
|
help="
|
2024-11-09 21:52:04 +00:00
|
|
|
set the balance of a nym
|
2024-06-03 14:37:58 +00:00
|
|
|
|
|
|
|
USAGE
|
2024-11-09 21:52:04 +00:00
|
|
|
$ sndev set_balance NYM MSATS
|
2024-06-03 14:37:58 +00:00
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
NYM - the name of the user you want to set the balance of
|
|
|
|
MSATS - the amount of millisatoshis to set the account to. Must be >= 0
|
2024-06-03 14:37:58 +00:00
|
|
|
"
|
|
|
|
|
|
|
|
echo "$help"
|
|
|
|
}
|
|
|
|
|
2024-03-10 21:42:16 +00:00
|
|
|
sndev__fund() {
|
|
|
|
shift
|
2024-11-09 21:52:04 +00:00
|
|
|
if [ "$1" = "--cln" ]; then
|
|
|
|
shift
|
|
|
|
sndev__cli -t cln pay "$@"
|
|
|
|
else
|
|
|
|
sndev__cli -t lnd payinvoice "$@"
|
|
|
|
fi
|
2024-03-10 21:42:16 +00:00
|
|
|
}
|
|
|
|
|
2024-03-11 20:27:18 +00:00
|
|
|
sndev__help_fund() {
|
|
|
|
help="
|
|
|
|
pay a bolt11 for funding
|
|
|
|
|
|
|
|
USAGE
|
2024-11-09 21:52:04 +00:00
|
|
|
$ sndev fund BOLT11 [OPTIONS]
|
|
|
|
$ sndev fund --cln BOLT11
|
2024-03-11 20:27:18 +00:00
|
|
|
|
|
|
|
OPTIONS"
|
|
|
|
|
|
|
|
echo "$help"
|
2024-11-09 21:52:04 +00:00
|
|
|
sndev__cli lnd payinvoice -h | awk '/OPTIONS:/{y=1;next}y' | awk '!/^[\t ]+--pay_req value/'
|
2024-04-14 22:34:21 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 21:42:16 +00:00
|
|
|
sndev__withdraw() {
|
2024-03-10 21:29:10 +00:00
|
|
|
shift
|
2024-11-09 21:52:04 +00:00
|
|
|
if [ "$1" = "--cln" ]; then
|
|
|
|
shift
|
|
|
|
label=$(date +%s)
|
|
|
|
sndev__cli -t cln invoice "$1" "$label" sndev | jq -j '.bolt11'; echo
|
|
|
|
else
|
|
|
|
sndev__cli lnd addinvoice --amt "$@" | jq -j '.payment_request'; echo
|
|
|
|
fi
|
2024-03-10 22:30:11 +00:00
|
|
|
}
|
|
|
|
|
2024-03-11 20:27:18 +00:00
|
|
|
sndev__help_withdraw() {
|
|
|
|
help="
|
|
|
|
create a bolt11 for withdrawal
|
|
|
|
|
|
|
|
USAGE
|
2024-11-09 21:52:04 +00:00
|
|
|
$ sndev withdraw SATS [OPTIONS]
|
|
|
|
$ sndev withdraw --cln SATS
|
2024-03-11 20:27:18 +00:00
|
|
|
|
|
|
|
OPTIONS"
|
|
|
|
|
|
|
|
echo "$help"
|
2024-11-09 21:52:04 +00:00
|
|
|
sndev__cli lnd addinvoice -h | awk '/OPTIONS:/{y=1;next}y' | awk '!/^[\t ]+(--amt|--amt_msat) value/'
|
2024-03-11 20:27:18 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 23:22:54 +00:00
|
|
|
sndev__psql() {
|
2024-03-11 20:27:18 +00:00
|
|
|
shift
|
|
|
|
docker__exec -t db psql "$@" -U sn -d stackernews
|
|
|
|
}
|
|
|
|
|
|
|
|
sndev__help_psql() {
|
|
|
|
help="
|
|
|
|
open psql on db
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
$ sndev psql [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS"
|
|
|
|
|
|
|
|
echo "$help"
|
|
|
|
docker__exec db psql --help | awk '/General options:/{y=1;next}y' | sed -n '/Connection options:/q;p' |
|
|
|
|
awk '!/^([\t ]+-l, --list)|([\t ]+-d, --dbname)|([\t ]+-\?, --help)|([\t ]--help=)/'
|
2024-03-10 23:22:54 +00:00
|
|
|
}
|
|
|
|
|
2024-03-11 13:54:38 +00:00
|
|
|
sndev__prisma() {
|
2024-03-11 20:27:18 +00:00
|
|
|
shift
|
|
|
|
docker__exec -t -u apprunner app npx prisma "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
sndev__help_prisma() {
|
|
|
|
help="
|
|
|
|
run prisma commands
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
$ sndev prisma [COMMAND]
|
|
|
|
|
|
|
|
COMMANDS"
|
|
|
|
|
|
|
|
echo "$help"
|
|
|
|
sndev__prisma --help | awk '/Commands/{y=1;next}y' | awk '!/^([\t ]+init)|([\t ]+studio)/' | sed -n '/Flags/q;p'
|
2024-03-11 13:54:38 +00:00
|
|
|
}
|
|
|
|
|
2024-03-15 19:29:42 +00:00
|
|
|
sndev__lint() {
|
|
|
|
shift
|
|
|
|
docker__exec -t -u apprunner app npm run lint
|
|
|
|
}
|
|
|
|
|
|
|
|
sndev__help_lint() {
|
|
|
|
help="
|
|
|
|
run linters
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
$ sndev lint
|
|
|
|
"
|
|
|
|
|
|
|
|
echo "$help"
|
|
|
|
}
|
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
sndev__test() {
|
2024-03-10 22:30:11 +00:00
|
|
|
shift
|
2024-03-11 20:27:18 +00:00
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
args=""
|
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
args="-- $@"
|
|
|
|
fi
|
2024-03-10 22:30:11 +00:00
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
docker__exec -t -u apprunner app npm run test $args
|
2024-03-11 20:27:18 +00:00
|
|
|
}
|
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
sndev__help_test() {
|
|
|
|
help="
|
|
|
|
run tests
|
2024-03-10 21:29:10 +00:00
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
USAGE
|
|
|
|
$ sndev test [OPTIONS]
|
2024-03-11 20:27:18 +00:00
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
OPTIONS"
|
2024-04-14 22:34:21 +00:00
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
echo "$help"
|
|
|
|
docker__exec -u apprunner app npm run test -- --help | awk '/Options:/{y=1;next}y'
|
2024-04-14 22:34:21 +00:00
|
|
|
}
|
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
sndev__compose() {
|
2024-05-03 00:46:27 +00:00
|
|
|
shift
|
2024-11-09 21:52:04 +00:00
|
|
|
docker__compose "$@"
|
2024-05-03 00:46:27 +00:00
|
|
|
}
|
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
sndev__help_compose() {
|
|
|
|
docker__compose --help
|
2024-05-03 00:46:27 +00:00
|
|
|
}
|
|
|
|
|
2024-04-04 17:22:27 +00:00
|
|
|
__sndev__pr_track() {
|
|
|
|
json=$(curl -fsSH "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/stackernews/stacker.news/pulls/$1")
|
2024-03-13 19:29:21 +00:00
|
|
|
case $(git config --get remote.origin.url) in
|
2024-04-04 17:22:27 +00:00
|
|
|
"http"*) url=$(echo "$json" | grep -e '"clone_url"' | head -n1 | sed -e 's/^.*"clone_url":[[:space:]]*"//; s/",[[:space:]]*$//') ;;
|
|
|
|
*) url=$(echo "$json" | grep -e '"ssh_url"' | head -n1 | sed -e 's/^.*"ssh_url":[[:space:]]*"//; s/",[[:space:]]*$//') ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
push=$(git remote -v | grep -e "$url .*push" | head -n1) || true
|
|
|
|
if [ -n "$push" ]; then
|
2024-04-05 13:40:12 +00:00
|
|
|
remote=$(echo "$push" | cut -f 1)
|
2024-04-04 17:22:27 +00:00
|
|
|
else
|
|
|
|
remote=$(echo "$json" | grep -e '"login"' | head -n1 | sed -e 's/^.*"login":[[:space:]]*"//; s/",[[:space:]]*$//')
|
|
|
|
git remote remove "$remote" 1>/dev/null 2>&1 || true
|
|
|
|
git remote add "$remote" "$url"
|
|
|
|
fi
|
|
|
|
|
|
|
|
ref=$(echo "$json" | grep -e '"ref"' | head -n1 | sed -e 's/^.*"ref":[[:space:]]*"//; s/",[[:space:]]*$//')
|
|
|
|
git fetch "$remote" "$ref"
|
2024-05-28 14:29:27 +00:00
|
|
|
git checkout -t -b "pr/$1" "$remote/$ref"
|
|
|
|
git config --local "remote.$remote.push" pr/$1:$ref
|
2024-04-04 17:22:27 +00:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
__sndev__pr_detach() {
|
2024-04-04 23:31:07 +00:00
|
|
|
refspec="+refs/pull/$1/head:refs/remotes/pr/$1"
|
2024-04-04 17:22:27 +00:00
|
|
|
case $(git config --get remote.origin.url) in
|
|
|
|
"http"*) git fetch https://github.com/stackernews/stacker.news.git "$refspec" ;;
|
2024-03-13 19:29:21 +00:00
|
|
|
*) git fetch git@github.com:stackernews/stacker.news.git "$refspec" ;;
|
|
|
|
esac
|
|
|
|
git checkout "pr/$1"
|
2024-04-04 17:22:27 +00:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
sndev__pr() {
|
|
|
|
shift
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
-t|--track)
|
|
|
|
call "__sndev__pr_track" "$2" ;;
|
|
|
|
*)
|
|
|
|
call "__sndev__pr_detach" "$1" ;;
|
|
|
|
esac
|
2024-03-13 19:29:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sndev__help_pr() {
|
|
|
|
help="
|
|
|
|
fetch and checkout a pr
|
|
|
|
|
|
|
|
USAGE
|
2024-11-09 21:52:04 +00:00
|
|
|
$ sndev pr [OPTIONS] PR_NUMBER
|
2024-04-04 17:22:27 +00:00
|
|
|
|
|
|
|
OPTIONS
|
|
|
|
-t, --track track the pr in a new branch, creating a remote if necessary
|
|
|
|
defaults to checking out the pr in a detached state
|
2024-03-13 19:29:21 +00:00
|
|
|
"
|
|
|
|
|
|
|
|
echo "$help"
|
|
|
|
}
|
|
|
|
|
2024-03-13 23:52:58 +00:00
|
|
|
sndev__login() {
|
|
|
|
shift
|
2024-03-24 01:09:45 +00:00
|
|
|
if [ -z "$1" ]; then
|
2024-11-09 21:52:04 +00:00
|
|
|
echo "NYM argument required"
|
2024-03-24 01:09:45 +00:00
|
|
|
sndev__help_login
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-03-13 23:52:58 +00:00
|
|
|
# hardcode token for which is the hex digest of the sha256 of
|
|
|
|
# "SNDEV-TOKEN3_0W_PhDRZVanbeJsZZGIEljexkKoGbL6qGIqSwTjjI"
|
|
|
|
# next-auth concats the token with the secret from env and then sha256's it
|
|
|
|
token="d5fce54babffcb070c39f78d947761fd9ec37647fafcecb9734a3085a78e5c5e"
|
2024-05-04 23:06:15 +00:00
|
|
|
salt="202c90943c313b829e65e3f29164fb5dd7ea3370d7262c4159691c2f6493bb8b"
|
2024-03-13 23:52:58 +00:00
|
|
|
# upsert user with nym and nym@sndev.team
|
2024-05-04 23:06:15 +00:00
|
|
|
email="$1@sndev.team"
|
2024-03-13 23:52:58 +00:00
|
|
|
docker__exec db psql -U sn -d stackernews -q <<EOF
|
|
|
|
INSERT INTO users (name) VALUES ('$1') ON CONFLICT DO NOTHING;
|
2024-05-04 23:06:15 +00:00
|
|
|
UPDATE users SET email = '$email', "emailHash" = encode(digest(LOWER('$email')||'$salt', 'sha256'), 'hex') WHERE name = '$1';
|
2024-03-13 23:52:58 +00:00
|
|
|
INSERT INTO verification_requests (identifier, token, expires)
|
2024-05-04 23:06:15 +00:00
|
|
|
VALUES ('$email', '$token', NOW() + INTERVAL '1 day')
|
2024-03-13 23:52:58 +00:00
|
|
|
ON CONFLICT (token) DO UPDATE
|
2024-05-04 23:06:15 +00:00
|
|
|
SET identifier = '$email', expires = NOW() + INTERVAL '1 day';
|
2024-03-13 23:52:58 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "open url in browser"
|
|
|
|
echo "http://localhost:3000/api/auth/callback/email?token=SNDEV-TOKEN&email=$1%40sndev.team"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
sndev__help_login() {
|
|
|
|
help="
|
|
|
|
login as a nym
|
|
|
|
|
|
|
|
USAGE
|
2024-11-09 21:52:04 +00:00
|
|
|
$ sndev login NYM
|
2024-03-13 23:52:58 +00:00
|
|
|
"
|
|
|
|
|
|
|
|
echo "$help"
|
|
|
|
}
|
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
sndev__onion() {
|
|
|
|
shift
|
|
|
|
tordir=$(docker__compose ps $1 --format '{{.Label "TORDIR"}}')
|
|
|
|
if [ -z "$tordir" ]; then
|
|
|
|
echo "no TORDIR label found for $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
onion=$(docker__exec $1 cat $tordir/hidden_service/hostname | tr -d '[:space:]')
|
|
|
|
echo "$onion"
|
|
|
|
}
|
|
|
|
|
|
|
|
sndev__help_onion() {
|
2024-11-07 15:03:54 +00:00
|
|
|
help="
|
2024-11-09 21:52:04 +00:00
|
|
|
get the onion address of a service
|
2024-11-07 15:03:54 +00:00
|
|
|
|
|
|
|
USAGE
|
2024-11-09 21:52:04 +00:00
|
|
|
$ sndev onion SERVICE
|
2024-11-07 15:03:54 +00:00
|
|
|
"
|
|
|
|
|
|
|
|
echo "$help"
|
|
|
|
}
|
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
sndev__cert() {
|
2024-11-07 15:03:54 +00:00
|
|
|
shift
|
2024-11-09 21:52:04 +00:00
|
|
|
certdir=$(docker__compose ps $1 --format '{{.Label "CERTDIR"}}')
|
|
|
|
if [ -z "$certdir" ]; then
|
|
|
|
echo "no CERTDIR label found for $1"
|
2024-11-07 15:03:54 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2024-11-09 21:52:04 +00:00
|
|
|
docker__exec $1 cat $certdir/tls.cert | base64
|
2024-11-07 15:03:54 +00:00
|
|
|
}
|
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
sndev__help_cert() {
|
2024-11-07 15:03:54 +00:00
|
|
|
help="
|
2024-11-09 21:52:04 +00:00
|
|
|
get the tls cert of a service
|
2024-11-07 15:03:54 +00:00
|
|
|
|
|
|
|
USAGE
|
2024-11-09 21:52:04 +00:00
|
|
|
$ sndev cert SERVICE
|
2024-11-07 15:03:54 +00:00
|
|
|
"
|
2024-11-09 21:52:04 +00:00
|
|
|
|
|
|
|
echo "$help"
|
2024-11-07 15:03:54 +00:00
|
|
|
}
|
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
sndev__cli() {
|
|
|
|
t=$1
|
|
|
|
|
|
|
|
if [ "$t" = "-t" ]; then
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
t=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "cli" ]; then
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2024-11-07 15:03:54 +00:00
|
|
|
if [ -z "$1" ]; then
|
2024-11-09 21:52:04 +00:00
|
|
|
echo "SERVICE required"
|
|
|
|
sndev__help_cli
|
2024-11-07 15:03:54 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2024-11-09 21:52:04 +00:00
|
|
|
|
|
|
|
service=$1
|
|
|
|
cli=$(docker__compose ps $service --format '{{.Label "CLI"}}')
|
|
|
|
cli_user=$(docker__compose ps $service --format '{{.Label "CLI_USER"}}')
|
|
|
|
cli_args=$(docker__compose ps $service --format '{{.Label "CLI_ARGS"}}')
|
|
|
|
|
|
|
|
if [ -z "$cli" ]; then
|
|
|
|
echo "no CLI label found for $service"
|
|
|
|
exit 1
|
2024-11-07 15:03:54 +00:00
|
|
|
fi
|
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
shift
|
|
|
|
|
|
|
|
if [ -n "$cli_user" ]; then
|
|
|
|
cli_user="-u $cli_user"
|
|
|
|
fi
|
2024-11-07 15:03:54 +00:00
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
docker__exec $t $cli_user $service $cli $cli_args "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
sndev__help_cli() {
|
2024-11-07 15:03:54 +00:00
|
|
|
help="
|
2024-11-09 21:52:04 +00:00
|
|
|
run a cli command on a service
|
2024-11-07 15:03:54 +00:00
|
|
|
|
|
|
|
USAGE
|
2024-11-09 21:52:04 +00:00
|
|
|
$ sndev cli SERVICE [COMMAND [ARGS]]
|
2024-11-07 15:03:54 +00:00
|
|
|
"
|
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
echo "$help"
|
2024-11-07 15:03:54 +00:00
|
|
|
}
|
|
|
|
|
2024-03-07 01:04:55 +00:00
|
|
|
sndev__help() {
|
2024-03-11 20:27:18 +00:00
|
|
|
if [ $# -eq 2 ]; then
|
|
|
|
call "sndev__$1_$2" "$@"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
help="
|
2024-03-10 21:59:15 +00:00
|
|
|
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
|
2024-03-07 01:04:55 +00:00
|
|
|
|
|
|
|
USAGE
|
|
|
|
$ sndev [COMMAND]
|
2024-03-11 20:27:18 +00:00
|
|
|
$ sndev help [COMMAND]
|
2024-03-07 01:04:55 +00:00
|
|
|
|
|
|
|
COMMANDS
|
2024-11-07 15:03:54 +00:00
|
|
|
help show help
|
2024-03-10 22:30:11 +00:00
|
|
|
|
|
|
|
env:
|
2024-11-07 15:03:54 +00:00
|
|
|
start start env
|
|
|
|
stop stop env
|
|
|
|
restart restart env
|
|
|
|
status status of env
|
|
|
|
logs logs from env
|
|
|
|
delete delete env
|
2024-03-10 22:30:11 +00:00
|
|
|
|
2024-03-13 23:52:58 +00:00
|
|
|
sn:
|
2024-11-07 15:03:54 +00:00
|
|
|
login login as a nym
|
2024-11-09 21:52:04 +00:00
|
|
|
set_balance set the balance of a nym
|
2024-03-13 23:52:58 +00:00
|
|
|
|
2024-11-09 21:52:04 +00:00
|
|
|
lightning:
|
2024-11-07 15:03:54 +00:00
|
|
|
fund pay a bolt11 for funding
|
|
|
|
withdraw create a bolt11 for withdrawal
|
2024-03-10 22:30:11 +00:00
|
|
|
|
2024-03-10 23:22:54 +00:00
|
|
|
db:
|
2024-11-07 15:03:54 +00:00
|
|
|
psql open psql on db
|
|
|
|
prisma run prisma commands
|
2024-03-10 23:22:54 +00:00
|
|
|
|
2024-03-15 19:29:42 +00:00
|
|
|
dev:
|
2024-11-07 15:03:54 +00:00
|
|
|
pr fetch and checkout a pr
|
|
|
|
lint run linters
|
2024-11-09 21:52:04 +00:00
|
|
|
test run tests
|
2024-03-13 19:29:21 +00:00
|
|
|
|
2024-03-11 13:54:38 +00:00
|
|
|
other:
|
2024-11-09 21:52:04 +00:00
|
|
|
cli service cli passthrough
|
|
|
|
open open service GUI in browser
|
|
|
|
onion service onion address
|
|
|
|
cert service tls cert
|
2024-11-07 15:03:54 +00:00
|
|
|
compose docker compose passthrough
|
2024-03-07 01:04:55 +00:00
|
|
|
"
|
2024-03-11 20:27:18 +00:00
|
|
|
echo "$help"
|
2024-03-07 01:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
call() {
|
|
|
|
func=$1
|
|
|
|
if type "$func" 1>/dev/null 2>&1; then
|
2024-03-11 20:27:18 +00:00
|
|
|
# if it's sndev COMMAND help, then call help for that command
|
|
|
|
case $3 in
|
|
|
|
-h|--help|help)
|
|
|
|
call "sndev__help_$2"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift # remove func from args
|
2024-03-07 01:04:55 +00:00
|
|
|
"$func" "$@" # invoke our named function w/ all remaining arguments
|
|
|
|
else
|
2024-03-11 20:27:18 +00:00
|
|
|
# if it's sndev -h COMMAND, then call help for that command
|
|
|
|
case $2 in
|
|
|
|
-h|--help)
|
|
|
|
call "sndev__help_$3"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
2024-03-07 01:04:55 +00:00
|
|
|
sndev__help
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
call "sndev__$1" "$@"
|