summaryrefslogtreecommitdiffstats
path: root/src/fedoradev-pkgowners
blob: ada57534053dc088a034a0c52d95f04ee0d74059 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/bin/bash
#
# fedoradev-pkgowners - Output list of packages owners by packages name
# Copyright (c) 2007 Thorsten Leemhuis <fedora@leemhuis.info>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

## globally used
file_fadcsvdata=
file_pkgdbfiledata=
list_of_packages=
print_comaintainers=
print_email=
print_realname=
tmpfile_owners=

##  globally used with defaults
myprog_name=fedoradev-pkgowners
myprog_version=0.0.1
# look for Fedora (and not epel) by default:
filter_for="Fedora"

# initialization
this_init()
{
	# we need to get the package names from somewhere
	# if there is a better way to check that input is comeing from a 
	#  pipe please let me know
	if [[ ! "${list_of_packages}" ]] && [[ ! -p /proc/$$/fd/0 ]]; then
		echo "Provide list of package names on command line or via pipe" >&2
		exit 2
	fi

	# we need fasfile for some optional output options
	if ( [[ "${print_email}" ]] || [[ "${print_realname}" ]] ) && [[ ! "${file_fadcsvdata}" ]] ; then
		echo "Please provide the name of the file with the FAS dumb via --fasfile <file>" >&2
		echo " Download it using your FAS username and password from:" >&2
		echo " https://admin.fedora.redhat.com/accounts/dump-group.cgi?group=cvsextras&format=csv"  >&2
		exit 2
	fi

	# check fasfile -- needs to be local, thus check first
	if [[ "${file_fadcsvdata}" ]]; then
		if [[ ! -s "${file_fadcsvdata}" ]]; then
			echo "Empty or nonexistent fas-datafile ${file_fadcsvdata}" >&2
			exit 2
		fi

		# check if that file contains data as we expect it
		if ! grep --max-count=1 -E '^.*,.*@.*,(user|sponsor|administrator),[0-9]*$' "${file_fadcsvdata}" &>/dev/null; then
			echo "File ${file_fadcsvdata} does not look like a fas file in cvs format" >&2
			exit 2
		fi
	fi

	# pkgdb bugzilla data for owners
	if [[ "${file_pkgdbfiledata}" ]]; then
		if [[ ! -s "${file_pkgdbfiledata}" ]]; then
			echo "Empty or nonexistent pkgdb-datafile ${file_pkgdbfiledata}" >&2
			exit 2
		fi
	else
		# download it to tmpfile
	
		# remove tmpfile_owners on CTRL+C
		trap "this_finish" 2

		# download owners
		tmpfile_owners=$(mktemp -t ${myprog_name}.XXXXXXXXX)
		wget --quiet --output-document="${tmpfile_owners}" "https://admin.fedoraproject.org/pkgdb/acls/bugzilla?tg_format=plain"
	
		# did download of owners succeed?
		local returncode=$?
		if (( ${returncode} > 0 )) || [[ ! -s "${tmpfile_owners}" ]] ; then
			echo "Could not download informations about owners from"$'\n'"https://admin.fedoraproject.org/pkgdb/acls/bugzilla?tg_format=plain ; aborting!" >&2
			this_finish
			exit 2
		fi

		# 
		file_pkgdbfiledata="${tmpfile_owners}"
	fi

	# check if that file contains data as we expect it
	if ! grep --max-count=1 -E '^Fedora*\|.*\|.*\|.*\|\|' "${file_pkgdbfiledata}" &>/dev/null; then
		echo "File ${file_pkgdbfiledata} does not look like a pgkdb bugzilla dump" >&2
		this_finish
		exit 2
	fi
}

lookup_package()
{
	local package_info="$(grep "${filter_for}|${1}|" "${file_pkgdbfiledata}")"
	if [[ ! "${package_info}" ]]; then
		# grep did not find anything or something else went wrong, eg.
		# https://fedorahosted.org/packagedb/ticket/138
		echo "Warning: could not find info for ${1}" >&2
		return 1
	fi

	# owner?
	local owner="$(echo ${package_info} | cut -d '|' -f 4)"
	if [[ ! "${owner}" || "${owner}" == orphan ]]; then
		# No owner, assume orphan
		owner="(orphan)"
	fi

	# co-maintainers?
	if [[ "${print_comaintainers}" ]]; then
		local comaintainers="$(echo ${package_info} | cut -d '|' -f 6 | sed 's| |,|g') "
		if [[ "${comaintainers}" = " " ]]; then
			comaintainers="(none)"
		fi
	fi

	# more data?
	if [[ "${print_email}" ]] || [[ "${print_realname}" ]]; then
		local fasline="$(grep -E "^${owner},.*@.*,(user|sponsor|administrator),[0-9]*$" "${file_fadcsvdata}")"
		if [[ "${fasline}" ]]; then
			[[ "${print_email}" ]] && local email_owner="$(echo ${fasline} | cut -d ',' -f 2) "
			[[ "${print_realname}" ]] && local realname_owner="$(echo ${fasline} | cut -d ',' -f 3) "
		else
			echo "Could not find FAS-data for ${owner}" >&2
			[[ "${print_email}" ]] && local email_owner="(unknown) "
			[[ "${print_realname}" ]] && local realname_owner="(unknown) "
		fi

		# feature for later: print more info for co-maintainers as well?
	fi
	
	# print
	echo "${owner} ${1} ${email_owner}${realname_owner}${comaintainers}"
}

this_finish()
{
	[[ -e "${tmpfile_owners}" ]] && rm "${tmpfile_owners}"
}

myprog_help()
{
	echo "Usage: ${myprog_name}  [options] [list of pkgnames]"
	echo "       echo pkgname | ${myprog_name} [options]"
	echo $'\n'"Outputs list of Fedora packages owners for packages from [list] or stdin"
	echo $'\n'"Available options:"
	echo " --comaintainers    -- print comaintainers as well"
	echo " --email            -- print email (needs --fasfile<file>)"
	echo " --epel             -- look epel owner(s) up"
	echo " --fasfile <file>   -- get email or real name from fas-file ; download uri:"
	echo "   https://admin.fedora.redhat.com/accounts/dump-group.cgi?group=cvsextras&format=csv"
	echo " --pkgdbfile <file> -- get pkgowners from local file instead of downloading it from:"
	echo "   https://admin.fedoraproject.org/pkgdb/acls/bugzilla?tg_format=plain"
	echo " --realname         -- print realname (needs --fasfile <file>)"
	echo
	echo " --help             -- this text"
	echo " --version          -- output version"
	echo
	echo " Hint: use '${myprog_name} | sort | column -t' for properly formated output."
}

# parse cmdline options
while [ "${1}" ] ; do
	case "${1}" in
		--comaintainers)
			print_comaintainers="true"
			shift
			;;
		--email)
			print_email="true"
			shift
			;;
		--epel)
			filter_for="Fedora EPEL"
			shift
			;;
		--fasfile)
			shift
			file_fadcsvdata="${1}"
			shift
			;;
		--realname)
			print_realname="true"
			shift
			;;
		--pkgdbfile)
			shift
			file_pkgdbfiledata="${1}"
			shift
			;;
		--help)
			myprog_help
			exit 0
			;;
		--version)
			echo "${myprog_name} ${myprog_version}"
			exit 0
			;;
		--*)
			echo "Error: Unknown option '${1}'." >&2
			myprog_help >&2
			exit 2
			;;
		*)
			list_of_packages="${list_of_packages} ${1}"
			shift
			;;
	esac
done

# initialization and startup checks
this_init

# go
if [[ "${list_of_packages}" ]]; then
	for package in ${list_of_packages} ; do
		lookup_package ${package}
	done
elif [[ -p /proc/$$/fd/0 ]]; then
	# read list of packages from stdin (seperated by newline or space)
	while read list_of_packages ; do
		for package in ${list_of_packages} ; do
			lookup_package ${package}
		done
	done
fi

# cleanup
this_finish