#!/bin/sh
#

RED='\033[0;31m'
NC='\033[0m' # No Color
YELLOW='\033[1;33m'
WHITE='\033[1;37m'
LGREEN='\033[1;32m'
BOLD='\033[1m'
RESET_BOLD='\033[2m'


if [ "$(id -u)" != "0" ]; then
	echo -e "You must run this script with root privileges" 1>&2
	exit 1
fi

VERS=`lsb_release -c | awk -F ':' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'`


# Install packages needed by script
apt-get update -y
apt-get install dirmngr -y

# Import our key to apt-key
#apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 1D043681
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 1D043681

# Move old source
/bin/rm -f /etc/apt/sources.list.d/rb24.list


# Create a new debian repository source file
case "$VERS" in
    stretch)
        echo 'deb https://apt.rb24.com/ stretch main' > /etc/apt/sources.list.d/rb24.list
        ;;

     buster)
        echo 'deb https://apt.rb24.com/ stretch main' > /etc/apt/sources.list.d/rb24.list
        ;;

     bullseye)
        echo 'deb https://apt.rb24.com/ bullseye main' > /etc/apt/sources.list.d/rb24.list
        ;;
     bookworm)
        echo 'deb https://apt.rb24.com/ bookworm main' > /etc/apt/sources.list.d/rb24.list
        ;;


     *)
        echo "Don't know how to install for a distribution named $DIST" >&2
        exit 1
esac



# Update apt and install software
apt-get update -y
apt-get install sxfeeder -y

while true; do
        read -p "Do you wish to install AIS-catcher program? (y/n) " yn
    case $yn in
        [Yy]* )
                apt-get install aiscatcher -y;
                break;;
        [Nn]* )
                break;;
        * ) echo "Please answer yes or no.";;
    esac
done



echo -e "\033c"

echo -e ""
echo -e "${RED}!!!! ${BOLD}IMPORTANT${RESET_BOLD} !!!!${NC}"
echo -e ""
echo -e "By default, SXFeeder will listen for UDP data on port 34995"
echo -e "If you need to to change this port, edit configuration file located at /etc/sxfeeder.ini"
echo -e ""
echo -e "If you already have a sharing-key from previous a installation, you can set the same"
echo -e "key using this command:"
echo -e ""
echo -e "${LGREEN}sudo sxfeeder --setkey â€¹your sharing keyâ€º${WHITE}"
echo -e ""
echo -e ""
echo -e "Installation finished."
echo -e ""
echo -e "${NC}"


