#!/bin/sh
systemctl stop radarr
systemctl disable radarr
rm -rf /etc/systemd/system/radarr.service
rm -rf /opt/Radarr
rm -rf /etc/apache2/sites-enabled/radarr.conf
if [[ -f /install/.jackett.lock ]]; then
if ls mono-* >/dev/null 2>&1; then
    echo "mono sources list was found"
    ls mono-*
fi
for list in /etc/apt/sources.list.d/mono-*; do
    if [[ -f $list ]]; then
        echo "removing and replacing with stable mono"
        rm -rf /etc/apt/sources.list.d/mono-*
        sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
        echo "deb http://download.mono-project.com/repo/ubuntu stable-xenial main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
        break
    fi
done
fi
if [[ -f /install/.lidarr.lock ]]; then
if ls mono-* >/dev/null 2>&1; then
    echo "mono sources list was found"
    ls mono-*
fi
for list in /etc/apt/sources.list.d/mono-*; do
    if [[ -f $list ]]; then
        echo "removing and replacing with stable mono"
        rm -rf /etc/apt/sources.list.d/mono-*
        sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
        echo "deb http://download.mono-project.com/repo/ubuntu stable-xenial main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
        break
    fi
done
fi
if [[ -f /install/.sonarr.lock ]]; then
if ls mono-* >/dev/null 2>&1; then
    echo "mono sources list was found"
    ls mono-*
fi
for list in /etc/apt/sources.list.d/mono-*; do
    if [[ -f $list ]]; then
        echo "removing and replacing with stable mono"
        rm -rf /etc/apt/sources.list.d/mono-*
        sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
        echo "deb http://download.mono-project.com/repo/ubuntu stable-xenial main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
        break
    fi
done
fi
rm -rf /install/.radarr.lock
apt-get -y autoremove && apt-get -y autoclean
service apache2 reload
echo "Radarr uninstalled!"
