#!/bin/bash

in_array()
{
	local i needle
	needle=$1
	shift 1
	# array() undefined
	[ -z "$1" ] && return 1
	for i in $*
	do
		echo $i |grep -q "^$needle" && return 0
	done
	return 1
}

if [ "$1" == "--help" ]; then
	echo "Missing kde frameworks packages"
	exit 1
fi


if [ ! -d ../.git -o ! -d ../source ]; then
	echo "hey, where are you?"
	exit 1
fi

cd ..

skip=()

run_kf5() {

	local upstream i j
	source source/include/kf5-version.sh

	upstream=$(for i in frameworks
	do
		lynx -dump https://download.kde.org/stable/$i/$_F_kdever_frameworks|grep xz$|sed 's|.*/\(.*\)-[0-9].*|\1|'
	done |sort -u |tr '[A-Z]' '[a-z]')

	for j in $upstream
	do
		if ! stat source/*/$j &>/dev/null && ! stat source/*/${j}5 &>/dev/null && ! in_array $j ${skip[@]}; then
			echo $j
		fi
	done
}

run_kf5
