#!/bin/sh

HOSTNAME=${HOSTNAME:-$(hostname)}

if ! [ -d /mnt/backups/restic/$HOSTNAME ]; then
  echo "creating restic repo for $HOSTNAME..."
  if ! [ -f /etc/ixvd/secrets/restic/$HOSTNAME.secret ]; then
    echo "no secret for $HOSTNAME found."
    exit 1
  fi
  restic \
    -r /mnt/backups/restic/$HOSTNAME \
    -p /etc/ixvd/secrets/restic/$HOSTNAME.secret \
    init
fi