93 lines
3.5 KiB
Bash
Executable file
93 lines
3.5 KiB
Bash
Executable file
#!/bin/bash
|
|
# Install + start demo-withdraw API + auto-confirm loop inside bank container.
|
|
# Host:
|
|
# ./scripts/taler-bank/install-demo-withdraw-api.sh
|
|
set -euo pipefail
|
|
ROOT=$(cd "$(dirname "$0")" && pwd)
|
|
CTR="${BANK_CONTAINER:-taler-hacktivism-bank}"
|
|
|
|
podman cp "$ROOT/demo-withdraw-api.py" "$CTR:/usr/local/bin/demo-withdraw-api.py"
|
|
podman cp "$ROOT/auto-confirm-withdrawals.sh" "$CTR:/usr/local/bin/auto-confirm-withdrawals.sh"
|
|
podman cp "$ROOT/refresh-demo-withdraw.sh" "$CTR:/usr/local/bin/refresh-demo-withdraw.sh"
|
|
podman exec -u root "$CTR" chmod 755 \
|
|
/usr/local/bin/demo-withdraw-api.py \
|
|
/usr/local/bin/auto-confirm-withdrawals.sh \
|
|
/usr/local/bin/refresh-demo-withdraw.sh
|
|
|
|
# nginx: proxy demo-withdraw.json
|
|
NGX=/etc/nginx/sites-available/bank-landing
|
|
podman exec -u root "$CTR" bash -lc '
|
|
set -e
|
|
f=/etc/nginx/sites-available/bank-landing
|
|
if ! grep -q demo-withdraw.json "$f"; then
|
|
# insert before location /intro/
|
|
python3 - <<PY
|
|
from pathlib import Path
|
|
p=Path("/etc/nginx/sites-available/bank-landing")
|
|
t=p.read_text()
|
|
block=""" location = /intro/demo-withdraw.json {
|
|
proxy_pass http://127.0.0.1:19096/demo-withdraw.json;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host \$host;
|
|
add_header Cache-Control "no-store" always;
|
|
add_header Access-Control-Allow-Origin * always;
|
|
}
|
|
"""
|
|
if "demo-withdraw.json" not in t:
|
|
t=t.replace(" location /intro/ {", block+" location /intro/ {", 1)
|
|
p.write_text(t)
|
|
print("nginx location added")
|
|
else:
|
|
print("nginx already has demo-withdraw")
|
|
if "auto-account.json" not in t:
|
|
t=p.read_text()
|
|
block2=""" location = /intro/auto-account.json {
|
|
proxy_pass http://127.0.0.1:19096/auto-account.json;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host \$host;
|
|
add_header Cache-Control "no-store" always;
|
|
add_header Access-Control-Allow-Origin * always;
|
|
}
|
|
"""
|
|
t=t.replace(" location /intro/ {", block2+" location /intro/ {", 1)
|
|
p.write_text(t)
|
|
print("nginx auto-account location added")
|
|
else:
|
|
print("nginx already has auto-account")
|
|
PY
|
|
nginx -t && nginx -s reload || true
|
|
else
|
|
echo "nginx already configured"
|
|
fi
|
|
'
|
|
|
|
# start/restart API + single auto-confirm loop (flock inside script)
|
|
podman exec -u root "$CTR" bash -lc '
|
|
# stop demo-withdraw by pid (avoid pkill -f self-match)
|
|
ps -eo pid=,args= | awk "/demo-withdraw-api\\.py/ && !/awk/ {print \$1}" | while read p; do kill \$p 2>/dev/null || true; done
|
|
sleep 0.3
|
|
nohup python3 /usr/local/bin/demo-withdraw-api.py \
|
|
>>/var/log/demo-withdraw-api.log 2>&1 </dev/null &
|
|
echo "api pid $!"
|
|
# stop auto-confirm by pid
|
|
ps -eo pid=,args= | awk "/auto-confirm-withdrawals\\.sh --loop/ && !/awk/ {print \$1}" | while read p; do kill \$p 2>/dev/null || true; done
|
|
sleep 0.5
|
|
if [ -f /var/log/auto-confirm-withdrawals.log ]; then
|
|
sz=$(wc -c </var/log/auto-confirm-withdrawals.log)
|
|
if [ "${sz:-0}" -gt 5000000 ]; then
|
|
tail -100 /var/log/auto-confirm-withdrawals.log > /tmp/ac-keep.log
|
|
: > /var/log/auto-confirm-withdrawals.log
|
|
cat /tmp/ac-keep.log >> /var/log/auto-confirm-withdrawals.log
|
|
fi
|
|
fi
|
|
nohup env QUIET=1 WATCH_MAX=80 \
|
|
/usr/local/bin/auto-confirm-withdrawals.sh --loop 2 \
|
|
>>/var/log/auto-confirm-withdrawals.log 2>&1 </dev/null &
|
|
echo "auto-confirm pid $!"
|
|
sleep 1
|
|
ps -eo pid=,args= | awk "/auto-confirm-withdrawals\\.sh --loop/ && !/awk/"
|
|
curl -sS -m 8 http://127.0.0.1:19096/demo-withdraw.json | head -c 300; echo
|
|
'
|
|
|
|
echo "OK: demo-withdraw API + auto-confirm in $CTR"
|
|
echo "Public: https://bank.hacktivism.ch/intro/demo-withdraw.json"
|