#!/usr/bin/env bash
#
# retry-until-success - repeatedly execute command until it succeeds (exits 0)

# ensure command is provided
if [ "$#" -eq "0" ]; then
  printf '%s\n' "No command provided. Usage: ${0##*/} <command>"
  exit 1
fi

# execute command until it succeeds
while ! "$@"; do
  echo "Command failed, retrying..."
  # pause between attempts
  # avoids using too much cpu if command quickly fails each time
  sleep 1
done

echo "Command succeeded."
