#!/bin/sh

set -u
set -e

PREFIX_DIR=""
# declare the Bareos repository
DOWNLOADSERVER="download.bareos.org"
URL="https://download.bareos.org/experimental/PR-2547/EL_10"

# setup credentials
# (required for download.bareos.com, subscription)
BAREOS_USERNAME=""
BAREOS_PASSWORD=""

# add the Bareos repository
cat <<EOT >"${PREFIX_DIR}/etc/yum.repos.d/bareos.repo"
[bareos]
name=Backup Archiving Recovery Open Sourced (EL_10)
baseurl=${URL}
username=${BAREOS_USERNAME}
password=${BAREOS_PASSWORD}
gpgcheck=1
repo_gpgcheck=1
gpgkey=file://${PREFIX_DIR}/etc/pki/rpm-gpg/RPM-GPG-KEY-bareos-experimental
enabled=1

[bareos-source]
name=Backup Archiving Recovery Open Sourced (EL_10) - Sources
baseurl=${URL}/src
username=${BAREOS_USERNAME}
password=${BAREOS_PASSWORD}
gpgcheck=1
repo_gpgcheck=1
gpgkey=file://${PREFIX_DIR}/etc/pki/rpm-gpg/RPM-GPG-KEY-bareos-experimental
enabled=0

[bareos-debuginfo]
name=Backup Archiving Recovery Open Sourced (EL_10) - Debuginfo
baseurl=${URL}/debug
username=${BAREOS_USERNAME}
password=${BAREOS_PASSWORD}
gpgcheck=1
repo_gpgcheck=1
gpgkey=file://${PREFIX_DIR}/etc/pki/rpm-gpg/RPM-GPG-KEY-bareos-experimental
enabled=0
EOT
chmod 0640 "${PREFIX_DIR}/etc/yum.repos.d/bareos.repo"

cat <<EOT >"${PREFIX_DIR}/etc/pki/rpm-gpg/RPM-GPG-KEY-bareos-experimental"
-----BEGIN PGP PUBLIC KEY BLOCK-----

[payload removed: 1568 characters in 25 lines]
=GxhN
-----END PGP PUBLIC KEY BLOCK-----
EOT

echo "Repository ${URL} successfully added."
