#!/bin/sh
# Debian/Ubuntu · same as bank landing deb pane (install + run)
set -eu

# install (deb.taler.net · trixie): keyring, apt source, packages
if ! command -v taler-wallet-cli >/dev/null 2>&1; then
  sudo mkdir -p /etc/apt/keyrings && \
  sudo wget -q -O /etc/apt/keyrings/taler-systems.gpg https://taler.net/taler-systems.gpg && \
  echo 'deb [signed-by=/etc/apt/keyrings/taler-systems.gpg] https://deb.taler.net/apt/debian trixie main' | sudo tee /etc/apt/sources.list.d/taler.list && \
  sudo apt-get update && sudo apt-get install -y taler-wallet-cli wget
fi
command -v wget >/dev/null 2>&1 || sudo apt-get install -y wget

# private wallet DB under /tmp (not the default home DB)
tw() {
  taler-wallet-cli \
    --wallet-db="${TMPDIR:-/tmp}/taler-wallet-goa.sqlite3" \
    --no-throttle "$@"
}

# mint from bank, register exchange, withdraw GOA:10
wget -q -O demo-withdraw.json https://bank.hacktivism.ch/intro/demo-withdraw.json && \
tw exchanges add https://exchange.hacktivism.ch/ && \
tw exchanges accept-tos https://exchange.hacktivism.ch/ && \
tw withdraw accept-uri --exchange https://exchange.hacktivism.ch/ \
  "$(grep -o 'taler://[^"]*' demo-withdraw.json)" && \
tw run-until-done && \

# pay orbit-sticker (GOA:2); balance ends at GOA:8
tw handle-uri --yes \
  taler://pay-template/taler.hacktivism.ch/instances/goa-shop/orbit-sticker && \
tw run-until-done && tw balance
