#!/bin/ash

# usage: borgmatic mount [-l] [-h]

# Check archives for consistency

# check arguments:
#   -l            Last successful archive backup
#   --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 [-p] [-c/-r] [-o] "
  echo
  echo " -l      =   Last successful archive backup."
  echo "             If omitted, full archive load."
  exit 0
}

borgmatic_mount() {
  echo "$PROG_NAME: Starting mounting repository ..."
  
  borgmatic mount $LAST_ARCHIVE --mount-point /mnt/fuse 
  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 'l?h' c
    do
    case $c in
        l) set_variable LAST_ARCHIVE '--archive latest'  ;;
        h|?) usage ;; esac
    done
fi


borgmatic_mount
