summaryrefslogtreecommitdiff
blob: 2bbd60273f925d24467da1b6cb0ffc674019d96f (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash

EMAIL="wolf31o2@gentoo.org"
CVSROOT="/var/cvsroot/gentoo-x86"
COMMIT="yes"
SENDMAIL="/usr/sbin/sendmail"

usage() {
	echo "$(basename ${0}): <keyword> <input file> [bug #]"
	echo
	echo "The input file should be a listing of packages in the following format:"
	echo "category/package version"
	echo
}

if [ -z "${1}" -o -z "${2}" ]
then
	usage
	exit 0
fi

check_failed() {
	if [ "${ret}" -ne 0 ]
	then
		failed_packages="${failed_packages}
	${package}"
	fi
}

cpv=$(cat ${2} | grep -v "^#" | grep -v "^[[:space:]]*#")
packages=$(cat ${2} | grep -v "^#" | grep -v "^[[:space:]]*#" | cut -d" " -f1 | uniq )

echo "${cpv}" > /tmp/cpv.txt
echo "${packages}" > /tmp/packages.txt

# We actually make two passes.  Pass #1 is where we do our initial KEYWORDS.
# This is so repoman doesn't find broken *DEPEND if our input file is not
# already sorted properly.
for package in ${packages}
do
	for version in $(grep "${package} " /tmp/cpv.txt | cut -d" " -f2)
	do
		ebuild="$(echo ${package} | cut -d"/" -f2)-${version}"
		cd ${CVSROOT}/${package}
		echo "DEBUG: ${package}"
		cvs up
		if [ $(echo ${1} | grep '^~') ]
		then
			ekeyword ${1} ${ebuild}.ebuild
		elif [ -n "$(grep "~${1}" ${ebuild}.ebuild)" ] # | grep -v ~x86-fbsd)" ]
		then
			ekeyword ${1} ${ebuild}.ebuild
		fi
	done
done

# This second pass, we verify that the packages are still correct, and if not,
# we remove the file, then start over on just this one package.
for package in ${packages}
do
	ebuild="$(echo ${package} | cut -d"/" -f2)-${version}"
	for version in $(grep "${package} " /tmp/cpv.txt | cut -d" " -f2)
	do
		cd ${CVSROOT}/${package}
		if [ "$(cvs up | grep ^C | grep ${ebuild}.ebuild | cut -d" " -f1)" == "C" ]
		then
			rm -f .#* ${ebuild}.ebuild
			cvs up
			ekeyword ${1} ${ebuild}.ebuild
		fi
	done
	if [ "${COMMIT}" == "yes" ]
	then
		rm -f .#*
		if [ "$(cvs up | grep ^M | cut -d" " -f1)" == "M" ]
		then
			ebuild ${ebuild} digest
			repoman scan
			ret=$?
			check_failed
			if [ -n "${3}" ]
			then
				append_msg=" wrt bug #${3}."
			else
				append_msg="."
			fi

			if [ $(echo ${1} | grep '^~') ]
			then
				commit_msg="Adding ${1}${append_msg}"
			else
				commit_msg="Stable on ${1}${append_msg}"
			fi
			echangelog "${commit_msg}"
			ret=$?
			check_failed
			repoman commit -I -m "${commit_msg}"
			ret=$?
			check_failed
		fi
	fi
done

if [ -n "${failed_packages}" ]
then
	echo -e "From: ${EMAIL}\r\nTo: ${EMAIL}\r\nSubject: Failed commits\r\n\r\nThis email is to let you know that the following packages failed keywording for ${1}.\r\nYou will need to fix these packages manually.\r\n${failed_packages}\r\n" | ${SENDMAIL} -f ${EMAIL} ${EMAIL}
fi