#!/bin/bash

function not_install {
	echo ""
    echo "********************************************************************************************"
    echo "... this plugin is only for Dreambox with arch64 architecture and cannot install on this box"
    echo "********************************************************************************************"
    exit 0
}

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/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
    		not_install
		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
    	not_install
	fi
fi
if [ $(uname -m) == "aarch64" ]; then
	apt-get update
	apt-get -f -y --assume-yes install enigma2-plugin-extensions-dazndream
	sleep 3
	echo ""
	echo "************************"
	read -p "Gui neustarten? (j/n): " response </dev/tty
	if [ "$response" == "j" ]; then
	    echo "enigma2 wird neugestartet"
    	systemctl restart enigma2
	else
    	echo "damit das Plugin aktiv wird müssen Sie enigma2 neustarten"
	fi
	echo "... install finish"
	exit 0
else
	not_install
fi
