#!/bin/bash
#
# @(#) Copyright 1994-2022 Pincoder Diagnostics Inc.
#

TMP=/tmp/tmp.add_repo.$$
rm -f $TMP.*

EXIT() {
	trap "" 0 1 2 15
	rm -f $TMP.*
	exit $1
}
trap EXIT 0 1 2 15

echo
echo "[32mConfiguring apt to use our repository (deb-reversion)[0m"
echo "deb http://deb.reversion.ca/ deb-reversion/" > /etc/apt/sources.list.d/reversion.list

echo "[32mFetching GPGKEY[0m"
GPGURL="http://deb.reversion.ca/GPGKEY"
wget -O $TMP.gpgkey "$GPGURL"
if [ $? -ne 0 ]; then
	echo "[31m** Failed to get GPGKEY from '$GPGURL'[0m"
	echo
	EXIT 1
fi

echo "[32mInstalling GPGKEY[0m"
apt-key add "$TMP.gpgkey"
if [ $? -ne 0 ]; then
	echo "[31m** Failed to install GPGKEY from '$GPGURL'[0m"
	echo
	EXIT 1
fi

echo "[32mLoading Reversion repository[0m"
apt update -o Dir::Etc::sourcelist="sources.list.d/reversion.list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
if [ $? -ne 0 ]; then
	echo "[31m** Failed to load Reversion repository[0m"
	echo
	EXIT 1
fi

echo
echo "[32mConfiguration complete. You may now run:[0m"
echo
echo" [35mapt install reversion-client[0m[0m"
echo

exit 0
