#!/bin/sh

# This restic program wrapper supplies the password and the repository
# location which is always needed every time this program is called.

# Copyright 2023 Bob Proulx <bob@proulx.com>
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.  This file is offered as-is,
# without any warranty.
#
# Written by Bob Proulx <bob@proulx.com>

if [ ! -f "$HOME/etc/restic/password" ]; then
    echo "Error: Missing $HOME/etc/restic/password file" 1>&2
    exit 1
fi

if [ ! -f "$HOME/etc/restic/repository" ]; then
    echo "Error: Missing $HOME/etc/restic/repository file" 1>&2
    exit 1
fi

# This method of passing these through the environment was chosen to
# avoid ever having them listed on the command line and therefore
# possibly showing up in a ps process status listing.  Just by
# themselves these are not security risks but following the need to
# know policy there is no need for anyone to know this from a ps
# listing and it is easy enough to avoid that by using the environment
# to pass this information.

RESTIC_PASSWORD_FILE=$HOME/etc/restic/password \
    RESTIC_REPOSITORY_FILE=$HOME/etc/restic/repository \
        exec restic "$@"
