#!/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 plasma packages"
	exit 1
fi


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

cd ..

skip=(
'breeze-plymouth we do not have plymouth'
'plymouth-kcm we do not have plymouth'
'plasma-tests no CI here'
'user-manager crazy said we dont use it'
'plasma-phone-components No phone'
'plasma-mobile No phone'
'plasma-dialer No phone'
'spacebar No phone'
)

run_plasma() {

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

	upstream=$(for i in plasma
	do
		lynx -dump https://download.kde.org/stable/$i/$_F_kdever_plasma|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_plasma
