#!/bin/sh
systemctl stop lidarr
systemctl disable lidarr
rm -rf /etc/systemd/system/lidarr.service
rm -rf /opt/Lidarr
rm -rf /etc/apache2/sites-enabled/lidarr.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/.radarr.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/.lidarr.lock
apt-get -y autoremove && apt-get -y autoclean
service apache2 reload
echo "Lidarr uninstalled!"
