#!/bin/bash
#
# Macroscop Astra SE Repository

rm -rf /etc/apt/sources.list.d/macroscop*

sudo apt-get update
sudo apt-get install gpg -y

wget -O - -q https://packages.macroscop.com/deb/install/macroscop.gpg.key | sudo apt-key add -

if [[ "$(grep DISTRIB_DESCRIPTION /etc/*release)" == *"Astra Linux 1.7"* ]]; then
    echo "deb [arch=amd64] https://packages.macroscop.com/deb/public main main" | sudo tee /etc/apt/sources.list.d/macroscop.list > /dev/null
    echo "deb [arch=amd64] https://packages.macroscop.com/deb/public astra-se-1.7 main" | sudo tee /etc/apt/sources.list.d/macroscop.list > /dev/null
    echo "deb [arch=amd64] https://packages.macroscop.com/deb/public astra-se-1.7 extensions" | sudo tee -a /etc/apt/sources.list.d/macroscop.list > /dev/null

    echo "Package: *" | sudo tee /etc/apt/preferences.d/macroscop > /dev/null
    echo "Pin: release a=astra-se-1.7" | sudo tee -a /etc/apt/preferences.d/macroscop > /dev/null
    echo "Pin-Priority: 900" | sudo tee -a /etc/apt/preferences.d/macroscop > /dev/null
else
    echo "deb [arch=amd64] https://packages.macroscop.com/deb/public main main" | sudo tee /etc/apt/sources.list.d/macroscop.list > /dev/null
    echo "deb [arch=amd64] https://packages.macroscop.com/deb/public astra-se-1.8 main" | sudo tee /etc/apt/sources.list.d/macroscop.list > /dev/null
    echo "deb [arch=amd64] https://packages.macroscop.com/deb/public astra-se-1.8 extensions" | sudo tee -a /etc/apt/sources.list.d/macroscop.list > /dev/null

    echo "Package: *" | sudo tee /etc/apt/preferences.d/macroscop > /dev/null
    echo "Pin: release a=astra-se-1.8" | sudo tee -a /etc/apt/preferences.d/macroscop > /dev/null
    echo "Pin-Priority: 900" | sudo tee -a /etc/apt/preferences.d/macroscop > /dev/null
fi

sudo apt-get update
