1
1
mirror of https://gitlab.archlinux.org/archlinux/infrastructure.git synced 2025-01-18 08:06:16 +01:00
infrastructure/misc/borg.sh
2020-10-24 18:45:34 +02:00

33 lines
725 B
Bash
Executable File

#!/bin/bash
set -eu
shopt -s extglob
OFFSITE_HOST=ch-s012.rsync.net
decrypted_gpg=$(mktemp)
trap "rm \"${decrypted_gpg}\"" EXIT
[[ "$*" =~ $OFFSITE_HOST ]] && is_offsite=true || is_offsite=false
# Find matching key
matching_key=""
for gpgkey in borg-keys/!(*-offsite.gpg); do
key=$(basename "$gpgkey" .gpg)
if [[ "$*" =~ $key ]]; then
matching_key="$key"
if $is_offsite; then
matching_key=$matching_key-offsite
fi
fi
done
if [[ -z "$matching_key" ]]; then
echo "No matching keyfile found for this host"
exit 1
fi
gpg --batch --yes --decrypt -aq --output "$decrypted_gpg" borg-keys/"$matching_key.gpg"
BORG_KEY_FILE="$decrypted_gpg" borg "$@"
rm "$decrypted_gpg"