#!/bin/bash

. /usr/lib/frugalware/fwmakepkg

if [ "$1" == "--help" ]; then
	echo "Packages using SCM builds."
	exit 1
fi

cd ../..

SCM_TMP_FILE="$(mktemp)"

## cleaner output with git grep -lw
for scm_p in $(find source -name FrugalBuild | xargs git grep -lw  _F_scm_url)
do
	## exclude USE_DEVEL=n , these have _F_scm but don't use it
	if grep -q "USE_DEVEL\(.*\)n" $scm_p; then
		## nothing
		continue
	## exclude FBs with oberriden up2date
	elif grep -q "up2date" $scm_p; then
		## nothing
                continue
	else
		## source/group/package/FrugalBuild -> group/package
		scm_clean=$(echo $scm_p | sed 's/source\/\(.*\)\/FrugalBuild/\1/')
		echo "-> $scm_clean" >>$SCM_TMP_FILE
	fi
done


cat $SCM_TMP_FILE | sort -u
echo ""
echo "Total SCM packages found: `cat $SCM_TMP_FILE | sort -u | wc -l`"
echo ""

rm -rf $SCM_TMP_FILE