#!/bin/sh
# $Id: tl-update-lmtx-bin 74435 2025-03-04 17:01:16Z karl $
# Public domain. Originally written 2023, Karl Berry.
# Download new luametatex binaries from the garden.

real0=`realpath $0`
mydir=`cd \`dirname "$real0"\` && pwd`  # Master/tlpkg/bin
Master=`cd $mydir/../.. && pwd`
test -z "$Master" && exit 1

# for universal-darwin, check ~koch and/or ask Dick.
# netbsd and cygwin builders commit themselves.

# for the rest, get from the CG farm:
cg=https://build.contextgarden.net/dl/luametatex/work
# (Other choice is main; indeterminate which to use. Check versions.)

for cgplat in  \
  aarch64-linux \
  amd64-freebsd \
  i386-freebsd \
  i386-linux \
  x86_64-darwinlegacy \
  x86_64-linux \
  x86_64-linuxmusl \
  x86_64-w64-mingw32 \
; do
  if test $cgplat = x86_64-w64-mingw32; then
    tlplat=windows
    exeext=.exe
  else
    tlplat=$cgplat
    exeext=
  fi
  cd $Master/bin/$tlplat || exit 1
  binfile=luametatex$exeext
  url=$cg/$cgplat/$binfile
  if wget -nv $url -O lmtx.new; then
    mv lmtx.new $binfile || exit 1
    echo $tlplat/$binfile
    if test $tlplat = windows; then
      cp -p $binfile context.exe || exit 1
      cp -p $binfile mtxrun.exe || exit 1
    fi
  else
    echo "$0: goodbye, wget failed: $url" >&2
    exit 1
  fi
done

cd $Master/bin && svn status
