#!/bin/bash

child=$1

function parents() {
	local packages="$@"
	local results=''
	for package in $packages
	do
		results="$results $(apt rdepends $package 2>/dev/null | awk '/Dépend:/ {print $2}')"
	done
	echo $results
}

function installed_parents() {
	local packages="$@"
	local results="$(dpkg -l $packages 2>/dev/null | awk '/^ii/ {print $2}')"
	echo $results
}

seed="$child"

while [[ ! "$seed" =~ 'eole-' ]]
do
	seed=$(installed_parents $(parents $seed))
done

echo -e ${seed// /\\n} | grep eole-

#dpkg -l $(apt rdepends libldap-2.5-0 2>/dev/null | awk '/Dépend:/ {print $2}') 2>/dev/null| awk '/^ii/ {print $2}')
