#!/usr/bin/env sh

retry() {
  retries=$1
  shift

  count=0
  until "$@"; do
    exit=$?
    count=$((count + 1))
    if [ $count -lt $retries ]; then
      echo "Retry $count/$retries exited $exit, retrying..."
    else
      echo "Retry $count/$retries exited $exit, no more retries left."
      return $exit
    fi
  done
  return 0
}

m2r README.md --overwrite
retry 10 sphinx-build -b html docs/source build/webserver/docs
rm README.rst
