#!/bin/sh

set -u
set -e

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

# 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 (ULC_rpm_OpenSSL_3.0)
baseurl=${URL}
username=${BAREOS_USERNAME}
password=${BAREOS_PASSWORD}
type=rpm-md
gpgcheck=1
repo_gpgcheck=1
gpgkey=file://${PREFIX_DIR}/etc/pki/rpm-gpg/RPM-GPG-KEY-bareos-experimental
autorefresh=1
enabled=1

[bareos-debuginfo]
name=Backup Archiving Recovery Open Sourced (ULC_rpm_OpenSSL_3.0) - Debuginfo
baseurl=${URL}/debug
username=${BAREOS_USERNAME}
password=${BAREOS_PASSWORD}
type=rpm-md
gpgcheck=1
repo_gpgcheck=1
gpgkey=file://${PREFIX_DIR}/etc/pki/rpm-gpg/RPM-GPG-KEY-bareos-experimental
autorefresh=1
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-----

mQINBF23EK4BEAC1FADpF6aaC93bxouVT6/BuXJajjtLkHNKfY26BYuvpwgLmVwp
M8vBuQWEPxxP6y2wXffv5bO/0Y1tS7tCW4i7duKz6W6as7/N13P/Mah8KOS0Zles
VM94fKXX8um7okqY9EwqgWVyHetW0PVpMKCsguMezv0IUmGAi/XX/GgJBeDYWvTh
S8DXtMhqWMXWv9yptJJsFQgdS0GVb8fcHG+Vl5GWmb+p8+R5x2JjLrP2OIoY8caD
boueBiUUeYnlPQqBa7flZSlBslSbk8qwnr75r/fX0/ihnFfLZol348AOCjPeWEYM
H3xQ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