#!/bin/sh
set -ex
# e.g. deploy-libc-test regression/scanf-bytes-consumed

T=/mnt/videos/website/justine.lol/libc-test/bin
L=/home/jart/vendor/libc-test/src
V=2
mkdir -p $T/$V

for f; do
  if [ ! -f $L/$f.exe ]; then
    echo "not found: $L/$f" >&2
    exit 1
  fi

  mkdir -p $T/$V/${f%/*}
  mkdir -p ~/blink/third_party/libc-test/bin/$V/${f%/*}
  cp $L/$f.exe $T/$V/$f.elf
  rm -f $T/$V/$f.elf.gz
  gzip $T/$V/$f.elf
  sha256sum -b $T/$V/$f.elf.gz >$T/$V/$f.elf.gz.sha256
  mkdir -p ~/blink/third_party/libc-test/bin/$V
  cp $T/$V/$f.elf.gz.sha256 ~/blink/third_party/libc-test/bin/$V/$f.elf.gz.sha256

  sed -i -e 's!/mnt/videos/website/justine.lol/libc-test/bin!third_party/libc-test/bin!' \
      ~/blink/third_party/libc-test/bin/$V/$f.elf.gz.sha256

  ssh debian gsutil -m -h Cache-Control:public,max-age=31536000 cp -r -a public-read \
      /mnt/videos/website/justine.lol/libc-test/bin/$V/$f.elf.gz \
      gs://justine/libc-test/bin/$V/$f.elf.gz
done

syncweb
