#!/usr/bin/env bash # Prepara os jogos de dtsudo (Tux Planet Speedrun Any%, Tux Planet 2, Symbiosis Chess, Queen Sac, Chess Comp Stomp with Hacks, # DT Danmaku 2). Sao paginas HTML/JavaScript prontas no repositorio (C# transpilado com Bridge.NET, ou TypeScript compilado), # entao nada e compilado: o script baixa o tarball do commit (sha256 conferido), escolhe os arquivos do jogo, aplica as mudancas # de dtsudo-games/patch.py e empacota tudo num tar.gz deterministico. # # Mudancas (patch.py): CSP no index.html (nenhuma requisicao fora da pasta); o link para o GitHub do autor nao faz nada; os saves # do navegador (localStorage, mesma origem para todos os jogos) ganham o prefixo ":"; no Tux Planet Speedrun, a frase do # texto de instrucoes que xinga os "devs" fica neutra. Fora do pacote: o app Electron (main.js, package*.json, .desktop...), o # codigo-fonte C#/TypeScript (continua no tarball de fonte) e, nos jogos de xadrez, o stockfishSourceCode.zip # (vai em "sources" do bundle.yaml, ao lado do binario). O index.html e a pagina do jogo renomeada. # # src/FredGames.Bundler/Builds/build-dtsudo-games.sh [slug ...] (sem argumento: todos) # # Saida: artifacts/build/dtsudo--/{--dist.tar.gz,licenses.txt,LICENSE.txt}; o tar.gz tem que # sair igual em dois builds seguidos. set -euo pipefail here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(git -C "$here" rev-parse --show-toplevel 2>/dev/null || pwd)" cache="$root/artifacts/build/cache" mkdir -p "$cache" # slug | repositorio | commit | sha256 do tarball | pagina principal | layout (root = jogo na raiz, built = na pasta built/) GAMES=" tux-planet-speedrun|Tux-Planet-Speedrun-Any-Percent-Electron-Version|a624976065a61a4fa566c93938c992c275ff470e|384f8a0d537607dddb031ae06e4cde6637f7b08e1413014dbb5069515b328cac|TuxPlanetSpeedrunAnyPercent.html|root tux-planet-2|Tux-Planet-2|fae1c4e05f473f470a2a853cd2c4cf0b83517e9a|d6bdf89ffd293263f1f62d02fac0eb890b5a4d94185808cb6c090f5e56a61e38|TuxPlanet2.html|built symbiosis-chess|SymbiosisChess|8a64b63ee054eea2d4cf28f1f954e937f8e78d41|71ac408c2f184e55b1062adfcbea43ff44c22c8a417d2e7ce5db9c23847e0251|SymbiosisChess.html|built queen-sac|QueenSac|a7b3a32176689c1a9de07055b02853592e3534f5|1d93058bae4c815a2e5ec1cac0e2758bfeb25fa22198721f5f219e0d659d5987|QueenSac.html|built chess-comp-stomp-with-hacks|Chess-Comp-Stomp-with-Hacks-Electron-Version|e29740a003bfd816ca61e6144da200a426ddcef9|4c90f50982af8f2a2e914481640ba225c7ba4fd001e096303812db830ad5e906|ChessCompStompWithHacks.html|root dt-danmaku-2|DT-Danmaku-2-Web-Browser-Version|d2ef46c4f20dbddecdf34c7d331352addc9ccd26|869ce75b5114ba5244453a3cc6ae49ed0fe28f8a2b94382ab0ecdbaaf31a959e|DT Danmaku 2.html|root " build_one() { local slug="$1" repo="$2" commit="$3" sha="$4" page="$5" layout="$6" local short="${commit:0:7}" tgz="dtsudo-$2-${commit:0:7}.tar.gz" local out="$root/artifacts/build/dtsudo-$slug-$short" if [ ! -f "$cache/$tgz" ]; then curl -fsSL --retry 4 "https://github.com/dtsudo/$repo/archive/$commit.tar.gz" -o "$cache/$tgz.partial" && mv "$cache/$tgz.partial" "$cache/$tgz" fi echo "$sha $cache/$tgz" | shasum -a 256 -c - rm -rf "$out"; mkdir -p "$out/tree" "$out/dist" tar -xzf "$cache/$tgz" -C "$out/tree" --strip-components 1 local t="$out/tree" d="$out/dist" if [ "$layout" = built ]; then cp -R "$t/built/." "$d/" cp "$t/LICENSE.txt" "$t/README.md" "$d/" rm -f "$d/Stockfish/stockfishSourceCode.zip" [ -d "$d/ChessJs" ] && cp "$t/src/ChessJs/LICENSE.txt" "$d/ChessJs/LICENSE.txt" else cp -R "$t/Data" "$d/Data" for f in "$t"/*.js; do cp "$f" "$d/"; done cp "$t/$page" "$d/" cp "$t/README.md" "$d/" for l in "$t/LICENSE.txt" "$t/MIT license.txt"; do [ -f "$l" ] && cp "$l" "$d/"; done rm -f "$d/main.js" fi if [ "$page" != index.html ]; then mv "$d/$page" "$d/index.html"; fi python3 -I "$here/dtsudo-games/patch.py" "$slug" "$d" python3 -I "$here/dtsudo-games/licenses.py" "$slug" "$d" "$here/dtsudo-games" "$out/licenses.txt" "$out/LICENSE.txt" find "$d" -exec touch -t 202611050000 {} + ( cd "$out" && find dist -type f | LC_ALL=C sort > files.txt \ && COPYFILE_DISABLE=1 tar --format=ustar --uid 0 --gid 0 --uname root --gname root -n -cf - -T files.txt \ | gzip -n -9 > "$slug-$short-dist.tar.gz" && rm files.txt ) rm -rf "$out/tree" du -sh "$d" | sed "s|$root/||" shasum -a 256 "$out/$slug-$short-dist.tar.gz" "$out/licenses.txt" "$out/LICENSE.txt" | sed "s|$root/||" } want=" $* " while IFS='|' read -r slug repo commit sha page layout; do [ -z "$slug" ] && continue if [ "$#" -eq 0 ] || [[ "$want" == *" $slug "* ]]; then echo "=== $slug" build_one "$slug" "$repo" "$commit" "$sha" "$page" "$layout" fi done <<< "$GAMES"