#!/bin/sh
# created by Lizard - Installer for DreamOS

# remove old lists
if [ -f /etc/apt/sources.list.d/disneydream.list ]; then
	rm /etc/apt/sources.list.d/disneydream.list
fi
if [ -f /etc/apt/sources.list.d/amazonprimedream.list ]; then
	rm /etc/apt/sources.list.d/amazonprimedream.list
fi
if [ -f /etc/apt/sources.list.d/boxpiratesreader.list ]; then
	rm /etc/apt/sources.list.d/boxpiratesreader.list
fi
if [ -f /etc/apt/sources.list.d/dazndream.list ]; then
	rm /etc/apt/sources.list.d/dazndream.list
fi
if [ -f /etc/apt/sources.list.d/justwatch.list ]; then
	rm /etc/apt/sources.list.d/justwatch.list
fi
if [ -f /etc/apt/sources.list.d/netflixdream.list ]; then
	rm /etc/apt/sources.list.d/netflixdream.list
fi
if [ -f /etc/apt/sources.list.d/boxpiratespanel.list ]; then
    rm -f /etc/apt/sources.list.d/boxpiratespanel.list
fi

if [ -f /etc/apt/sources.list.d/boxpiratescammanager.list ]; then
    rm -f /etc/apt/sources.list.d/boxpiratescammanager.list
fi
if [ $(dpkg-query -W -f='${Status}' enigma2-plugin-extensions-boxpirates-panel 2>/dev/null | grep -c "ok installed") == 1 ]; then
    apt-get -y remove --purge enigma2-plugin-extensions-boxpirates-panel
    if [ -d /usr/lib/enigma2/python/Plugins/Extensions/BoxPirates_Panel ]; then
        rm -rf /usr/lib/enigma2/python/Plugins/Extensions/BoxPirates_Panel
    fi
fi
# echo deb [trusted=yes] http://plugins.boxpirates.to/apt/ ./ > /etc/apt/sources.list.d/plugins-boxpirates.list

if [ -f /etc/apt/sources.list.d/plugins-boxpirates.list ]; then
	if [ $(grep "boxpirates.dynvpn.de" /etc/apt/sources.list.d/plugins-boxpirates.list|wc -l) -gt 0 ]; then
		if [ $(uname -m) == "aarch64" ]; then
    		echo deb [trusted=yes] http://plugins.boxpirates.to/apt64/ ./ > /etc/apt/sources.list.d/plugins-boxpirates.list
		else
    		echo deb [trusted=yes] http://plugins.boxpirates.to/apt/ ./ > /etc/apt/sources.list.d/plugins-boxpirates.list
		fi
	fi
else
	if [ $(uname -m) == "aarch64" ]; then
    	echo deb [trusted=yes] http://plugins.boxpirates.to/apt64/ ./ > /etc/apt/sources.list.d/plugins-boxpirates.list
	else
    	echo deb [trusted=yes] http://plugins.boxpirates.to/apt/ ./ > /etc/apt/sources.list.d/plugins-boxpirates.list
	fi
fi

apt-get update
apt-get install -y enigma2-plugin-extensions-boxpirates-cammanager
sleep 3
echo "... please restart gui"
