#!/bin/bash

function list() {
	echo -e "DEPRECATED

This is the old Parrot Mirror Selector tool.

This software aimed at helping the selection of an APT mirror server
in older versions of Parrot.

Nowadays the Parrot images come with a pre-installed mirror redirector
that detects the location of the user (via geoip) and redirects its
requests to the nearest server available.

If you need to change your mirror repository, visit https://docs.parrotsec.org/doku.php/mirrors-list
and manually choose the best mirror for you.

Otherwise leave /etc/apt/sources.list empty
and put the following content in /etc/apt/sources.list.d/parrot.list

	deb http://deb.parrotsec.org/parrot stable main contrib non-free

"
}


branch="parrot"
case $2 in
	stable)
		branch="parrot"
	;;
	testing)
		branch="testing"
	;;
	parrot)
		branch="parrot"
	;;
	parrot-testing)
		branch="testing"
	;;
esac

areas="main contrib non-free"
case $3 in
	nonfree)
		areas="main contrib non-free"
	;;
	free)
		areas="main"
	;;
esac

case $1 in
	list)
		list
	;;
	default)
		base="http://deb.parrotsec.org/parrot/"
	;;
	0)
		base="http://archive.parrotsec.org/parrot/"
	;;
	*)
		list
	;;
esac

if [ "$base" != "" ]; then
	if [ "$branch" != "" ]; then
		if [ "$areas" != "" ]; then
			echo "# parrot repository" > /etc/apt/sources.list.d/parrot.list
			echo "# this file was automatically generated by parrot-mirror-selector" >> /etc/apt/sources.list.d/parrot.list
			echo "deb $base $branch $areas" >> /etc/apt/sources.list.d/parrot.list
			echo "#deb-src $base $branch $areas" >> /etc/apt/sources.list.d/parrot.list
		fi
	fi
fi
