use writing to stderr as alternative to read timeouts
[gemrepl.git] / examples / zyg.sh
blob078fe2df569e40b26245cf4159e6651d902c54bb
1 #!/bin/sh
2 # Run z-machine interpreter, allowing the user to save their game in a
3 # directory specific to their client cert.
5 var=/var/gemini/zyg/
7 [ -n "$TLS_CLIENT_HASH" ] || exit 1
9 echo "Choose your poison:"
10 ls -1 "$var/games/"
12 while read input; do
13 sanitised="$(tr -dc [:alnum:]_ <<< "$input")"
14 gamefile="$var/games/$sanitised"
15 if [ -n "$sanitised" ] && [ -e "$gamefile" ]; then
16 break;
18 echo "Please enter one of the listed games"
19 done
21 echo "Starting $sanitised. Savefiles will be preserved."
22 echo
24 savesdir="$var/$TLS_CLIENT_HASH/$sanitised"
26 mkdir -p "$savesdir" || exit 1
27 cd "$savesdir" || exit 1
29 # Impose some limits to reduce potential for abuse
30 ulimit -t 1200
31 ulimit -f 5000
32 ulimit -v 20000
34 # using the z-machine interpreter infuse, which has a nice stdio interface:
35 # https://gitlab.com/monkeymind/infuse
36 stdbuf -i0 -o0 infuse "$gamefile"
38 # Previous attempt: using dfrotz, but it has some problems.
39 #dfrotz -m -Z0 -R. "$gamefile"