moth

Monarch Of The Hill game server
git clone https://git.woozle.org/neale/moth.git

moth / contrib
Neale Pickett  ·  2023-11-21

download-everything.sh

 1#! /bin/sh
 2
 3url=${1%/}
 4teamid=$2
 5
 6case "$url:$teamid" in
 7    *:|-h*|--h*)
 8        cat <<EOD; exit 1
 9Usage: $0 MOTHURL TEAMID
10
11Downloads all content currently open,
12and writes it out to a zip file.
13
14MOTHURL   URL to the instance
15TEAMID    Team ID you used to log in
16EOD
17        ;;
18esac
19
20tmpdir=$(mktemp -d moth-dl.XXXXXX)
21bye () {
22    echo "bye now"
23    rm -rf $tmpdir
24}
25trap bye EXIT
26
27fetch () {
28    curl -s -d id=$teamid "$@"
29}
30
31echo "=== Fetching puzzles and attachments"
32fetch $url/state > $tmpdir/state.json
33cat $tmpdir/state.json \
34| jq -r '.Puzzles | to_entries[] | .key as $k | .value[] | select (. > 0) | "\($k)  \(.)"' \
35| while read cat points; do
36    echo "   + $cat $points"
37    dir=$tmpdir/$cat/$points
38    mkdir -p $dir
39    fetch $url/content/$cat/$points/puzzle.json > $dir/puzzle.json
40    cat $dir/puzzle.json | jq .Body > $dir/puzzle.html
41    cat $dir/puzzle.json | jq -r '.Attachments[]?' | while read attachment; do
42        echo "     - $attachment"
43        fetch $url/content/$cat/$points/$attachment > $dir/$attachment
44    done
45done
46
47zipfile=$(echo $url | grep -o '[a-z]*\.[a-z.]*').zip
48echo "=== Writing $zipfile"
49(cd $tmpdir && zip -r - .) > $zipfile
50
51echo "=== Wrote $zipfile"