summaryrefslogtreecommitdiff
path: root/cron-jobs/check_archlinux/parse_pkgbuilds.sh
blob: 7dcfbbb0b371422aab2e98f6632f27f13071cfeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash

# Usage : parse_pkgbuilds.sh arch <pkgbuilds_dir1,dir2,...>
# Example : parse_pkgbuilds.sh i686 /var/abs/core /var/abs/extra

exit() { return; }

parse() {
	unset pkgname pkgver pkgrel
	unset depends makedepends conflicts provides
	ret=0
	dir=$1
	pkgbuild=$dir/PKGBUILD
	source $pkgbuild &>/dev/null || ret=$?

	# ensure $pkgname and $pkgver variables were found
	if [ $ret -ne 0 -o -z "$pkgname" -o -z "$pkgver" ]; then
		echo -e "%INVALID%\n$pkgbuild\n"
		return 1
	fi 

	echo -e "%NAME%\n$pkgname\n"
	echo -e "%VERSION%\n$pkgver-$pkgrel\n"
	echo -e "%PATH%\n$dir\n"

	if [ -n "$arch" ]; then
		echo "%ARCH%"
		for i in ${arch[@]}; do echo $i; done
		echo ""
	fi
	if [ -n "$depends" ]; then
		echo "%DEPENDS%"
		for i in ${depends[@]}; do
			echo $i
		done
		echo ""
	fi
	if [ -n "$makedepends" ]; then
		echo "%MAKEDEPENDS%"
		for i in ${makedepends[@]}; do
			echo $i
		done
		echo ""
	fi
	if [ -n "$conflicts" ]; then
		echo "%CONFLICTS%"
		for i in ${conflicts[@]}; do echo $i; done
		echo ""
	fi
	if [ -n "$provides" ]; then
		echo "%PROVIDES%"
		for i in ${provides[@]}; do echo $i; done
		echo ""
	fi
	return 0
}

find_pkgbuilds() {
    #Skip over some dirs
    local d="$(basename $1)"
    if [ "$d" = "CVS" -o "$d" = ".svn" ]; then
        return
    fi

	if [ -f $1/PKGBUILD ]; then
		parse $1
		return
	fi
	empty=1
	for dir in $1/*; do
		if [ -d $dir ]; then
			find_pkgbuilds $dir
			unset empty
		fi
	done
	if [ -n "$empty" ]; then
		echo -e "%MISSING%\n$1\n"
	fi
}

if [ -z "$1" -o -z "$2" ]; then
	exit 1
fi

CARCH=$1
shift
for dir in "$@"; do
	find_pkgbuilds $dir
done

exit 0