#!/bin/ash

# usage: borg [common options] break-lock [options] [REPOSITORY]

# Check archives for consistency

# check arguments:
#   --progress    Display progress for each file as it is checked
#   --repair      Attempt to repair any inconsistencies found (experimental and
#                 only for interactive use)
#   --only CHECK  Run a particular consistency check (repository, archives,
#                 data, or extract) instead of configured checks; can specify
#                 flag multiple times
#   -h, --help    Show this help message and exit

usage()
{
  echo
  echo "Usage: $PROG_NAME [-r: repo]"
  echo
  echo " -r      =   Repository to break log."
  echo
  exit 0
}

borgmatic_break() {
  echo "$PROG_NAME: Starting breaking lock for repository ..."
  borg break-lock "$REPO" --progress
  exit 0
}

set_variable()
{
  local varname=$1
  shift
  if [ -z "${!varname}" ]; then
    eval "$varname=\"$@\""
  else
    echo "Error: $varname already set"
    usage
  fi
}

####################################################################
# Main script starts here

# set_variable PROG_NAME "$(basename "$0")"

# if [[ $1 == "" ]]; then
#     usage;
#     exit;
# else
#     while getopts 'r:?h' c
#     do
#     case $c in
#         r) set_variable REPO "$OPTARG" ;;
#         h|?) usage ;; esac
#     done
# fi

REPO='/mnt/borg-repository'

borgmatic_break
