#!/bin/bash

set -e
. "$(dirname "$0")"/vars.sh

if [ "$BORG_RW_KEY_ADDED" != "1" ] ; then
    echo "Re-executing under a new ssh agent"
    exec env BORG_RW_KEY_ADDED=1 ssh-agent "$0"
fi

echo "=== Please enter SSH key passphrase.  Check Bitwarden for:"
echo "===   borg $HOSTNAME / read-write SSH key"
ssh-add "$(realpath "$(dirname "$0")")/ssh/id_ecdsa"

$BORG --rw prune \
        --verbose \
        --progress \
        --stats \
        --keep-within=7d \
        --keep-daily=14 \
        --keep-weekly=8 \
        --keep-monthly=-1

$BORG --rw compact \
        --verbose \
        --progress
