1#!/bin/bash
2# Check if a Bootstrap Jam repository file matches the availability of the contents of haikuports.cross
3
4if [ $# -ne 1 ]; then
5	echo "usage: $0 <haikuports.cross>"
6	exit 1
7fi
8
9if [ ! -d "$1" ]; then
10	echo "Error: Unable to read haikuports directory '$1'!"
11	exit 1
12fi
13
14HAIKUPORTS="$1"
15REPOFILES="build/jam/repositories/HaikuPortsCross"
16
17if [[ ! -d $REPOFILES ]]; then
18	echo "Unable to locate ${REPOFILES}! Run me from the haiku source root!"
19	exit 2
20fi
21
22RESULT=0
23for f in $(find $REPOFILES -maxdepth 1 -type f -print); do
24	ARCHITECTURE=$(cat $f | tr '\n' ' ' | awk '{ print $4 } ')
25	echo "================ Scanning $ARCHITECTURE / $f"
26	REPO_EXPECT=$(cat $f | grep -v "#" | grep '-' | grep 'bootstrap' | grep -v 'bootstrap_')
27	for i in $REPO_EXPECT; do
28		PACKAGE=$(echo $i | cut -d'-' -f1)
29		if [[ $PACKAGE == *_devel* ]]; then
30			continue
31		fi
32		RECIPE_NAME=$(echo $i | sed 's/\-[0-9]$//g')
33		RECIPE=$(find $HAIKUPORTS -name ${RECIPE_NAME}.recipe)
34		if [[ "$RECIPE" == "" ]]; then
35			echo "    $ARCHITECTURE $i... ERROR (Missing recipe $RECIPE_NAME!)"
36			RESULT=1
37			continue
38		fi
39		REV=$(echo $i | cut -d'-' -f3)
40		grep "REVISION=\"$REV\"" $RECIPE > /dev/null
41		if [[ $? -eq 0 ]]; then
42			echo "    $ARCHITECTURE $i... OK"
43		else
44			FOUND_REV=$(grep "REVISION=" $RECIPE | cut -d'=' -f2)
45			echo "    $ARCHITECTURE $i... ERROR (Incorrect revision! Found $FOUND_REV!)"
46			RESULT=1
47		fi
48		#echo $i - $PACKAGE
49	done
50done
51exit $RESULT
52