#!/usr/bin/env bash

set -e
set -o pipefail

case "$1" in
    clean)
        backup forget --keep-last 10 --prune
        ;;
    *)
        sudo --login                                                        \
             RESTIC_PASSWORD="$(pass show wugi.info/restic/all)"            \
             RESTIC_REPOSITORY="${RESTIC_REPOSITORY:-/srv/backup/guixsd}"   \
             "$HOME/.guix-profile/bin/restic" "$@"
        # shellcheck disable=SC2016
        cat <<'EOF'

Restore "${HOME}/.mozilla" backup example:
    sudo --login RESTIC_PASSWORD="$(pass show wugi.info/restic/all)" RESTIC_REPOSITORY="${RESTIC_REPOSITORY:-/srv/backup/guixsd}" "${HOME}/.guix-profile/bin/restic" restore latest --include "${HOME}/.mozilla" --target /

List Windows snapshots:
    sudo --login RESTIC_PASSWORD="$(sudo cat /etc/guix/secrets/windows)" RESTIC_REPOSITORY="${RESTIC_REPOSITORY:-/srv/backup/win10}" "${HOME}/.guix-profile/bin/restic" snapshots

Restore Windows snapshot:
    RESTIC_PASSWORD="$(sudo cat /etc/guix/secrets/windows)" RESTIC_REPOSITORY="${RESTIC_REPOSITORY:-/srv/backup/win10}" "${HOME}/.guix-profile/bin/restic" dump latest win10.img | dd of=/dev/lvm1/win10 bs=4M
EOF
        ;;
esac
