-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetpkglist
More file actions
executable file
·338 lines (280 loc) · 7.64 KB
/
getpkglist
File metadata and controls
executable file
·338 lines (280 loc) · 7.64 KB
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#!/bin/bash
#
# getengpkg
#
# Use unset in case these have been set elsewhere.
unset BLD && declare BLD="[1m"
unset UND && declare UND="[4m"
unset OFF && declare OFF="[0m"
# Contlol-C exit code
# see http://www.tldp.org/LDP/abs/html/exitcodes.html
unset CTLC_EXIT && declare -i CTLC_EXIT=130
# Other exit codes
declare -i EXIT_OK=0
declare -i EXIT_INVARG=1
declare -i EXIT_INVFIL=2
declare -i EXIT_INVDIR=3
declare -a exitmsgary=(
""
"Invalid number of arguments."
" is an invalid filename."
" is an invalid directory name."
)
# script-specific globals
#
declare manager=""
declare -i optcount=0
declare b_team_on=true
declare b_pkg_on=true
declare b_grep4pkgs=false
declare gpkgdir=
declare pkgs2grep=
declare usagestr=$(
cat <<EOF
$(basename $0) [OPTIONS] pkgdir manager
Example
$(basename $0) ~/mypkgdir peterm
Description:
Create files containing lists of all the packages and their owners
in the directory passed as the first argument for RHEL7 and RHEL8.
Parse the lists for owners who report to the manager passed as the
second argument. Each entry in the list will have two fields, the
name of the package forllowed by the email address of the package
maintainer, separated by a colon, e.g.
package: maintainer@redhat.com
There will be two such lists generated, one for RHEL7 (rh7pkgs) and
one for RHEL8 (rh8pkgs). The lists will be created in the directory
passed as the first argument.
Next, a list of team members reporting to the manager will be created
in the pkgdir. This list will then be traversed to find the packages
belonging to the team members in the list and another file will be
created in the pkgdir, teampkgs, that will contain colon separated
fields as follows.
package : maintainer : rhel : [rhel]
The optional rhel as a fourth field will appear if the package is
found in both RHEL7 and RHEL8
NOTES: The following must be installed to run this script.
bugzilla - install with yum/dnf
python-bugzilla - install with yum/dnf
teamlist - can be found at:
http://git.engineering.redhat.com/git/users/prarit/tools/.git
You must be logged into bugzilla from the command line to use
this sscript.
$ bugzilla login
Arguments:
pkgdir - the directory in which the above files will be created.
manager - the manager for whom this report is generated
Output files are created in the pkgdir argument as follows.
rh7pkgs : list of all packages and their maintainers in RHEL7
rh8pkgs : list of all packages and their maintainers in RHEL8
team : list of engineers reporting to the manager passed as the
argument.
teampkgs : list of packages maintained by team members, each line
containing the following colon separated fields.
package : maintainer : rhel [: rhel]
The optioinal [rhel] field at the end of the line appears
when the package is found in both RHEL7 and RHEL8.
greptpkgs: With g option, grep the provided package list, instead.
In that case, teampkgs will not be generated by a pass
using the g option.
Options:
-h: This help test
-t: do not generate team list. Useful if this has already been done
-p: do not generate comprehensive package lists. Useful if this has
already been done.
-g pkglist: create greptpkgs from the pkglist instead of teampkgs
from the team list.
\0
EOF
)
exitme() {
local exitval=$1
local strarg=""
local exitmsg
if ([ $exitval -ne $EXIT_OK ] && [ $exitval -ne $CTLC_EXIT ]); then
[ $# -eq 2 ] && strarg=$2
[ ${#exitmsgary[@]} -gt $exitval ] \
&& exitmsg="${exitmsgary[$exitval]}"
echo -e "$BLD$strarg$exitmsg$OFF"
[ $exitval -ne 0 ] && echo -e \
"Type$BLD $(basename $0) -h$OFF for help."
fi
exit $exitval
}
# run if user hits control-c
#
control_c()
{
echo -en "
Ctrl-c detected
Cleaning up and exiting.
"
exitme $CTLC_EXIT
}
usage() {
echo -en "$usagestr"
exitme 0
}
# get_options
#
get_options() {
local args
while getopts :hpg:t OPTION; do
case "$OPTION" in
h ) usage
;;
p ) b_pkg_on=false
let optcount++
;;
t ) b_team_on=false
let optcount++
;;
g ) pkgs2grep=$OPTARG
optcount=$((optcount + 2))
b_team_on=false
b_grep4pkgs=true
;;
* ) echo "unrecognized option -$OPTION"
echo -e "$usagestr"
exit 127
esac
done
shift $optcount
$b_team_on && args=2 || args=1
[ $# -eq $args ] || exitme $EXIT_INVARG
gpkgdir="$1"
[ $args -eq 2 ] && manager="$2"
}
# waitonproc
#
# Prints a dot to the screen every second until the passed PID
# completes. An optional second argument sets the time interval
# to something other than one second. Decimal fractions allowed.
#
# $1 - PID of process we are waiting for.
# $2 - optional time argument
#
waitonproc () {
__pid__=$1;
__time__=1
[ $# -eq 2 ] && __time__=$2
while kill -0 $__pid__ > /dev/null 2>&1; do
echo -n '.';
sleep $__time__;
done
}
# clean_team
# Strips the "examining" lines generated by teamlist out of the
# team file.
#
clean_team() {
$b_team_on || return
declare team="$1"
declare tmpteam=$gpkgdir/tmpteam
> $tmpteam
while read line; do
[[ "$line" == *"examining"* ]] && continue
echo "$line" >> $tmpteam
done < $team
rm -f $team
mv $tmpteam $team
}
# get_pkgs
# Extract all the packages listed by bugzilla under the "Red Hat Enterprise"
# rubric for the given distro number, e.g 7 for RHEL7
#
get_pkgs() {
$b_pkg_on || return
declare distro=$1
declare fil=$gpkgdir/rh"$distro"pkgs
declare mypid
echo "Getting RHEL$distro Packages"
bugzilla info -o="Red Hat Enterprise Linux $distro" | sort -u > $fil &
mypid=$!
waitonproc $mypid .1
echo
}
append_teampkgs() {
local p7="$1"
local p8="$2"
local ofil=$3
if ([[ "$p7" ]] && [[ "$p8" ]]); then
echo "BOTH"
while read line; do
echo "$p8" | grep -q "$line"
[ $? -eq 0 ] && echo "$line : 7 : 8" >> $ofil \
|| echo "$line : 7" >> $ofil
done <<< "$p7"
while read line; do
echo "$p7" | grep -q "$line"
[ $? -eq 0 ] || echo "$line : 8" >> $ofil
done <<< "$p8"
elif ([[ "$p7" ]] && [[ -z "$p8" ]]); then
echo "RHEL7 only"
while read line; do
echo "$line : 7" >> $ofil
done <<< "$p7"
elif ([[ "$p8" ]] && [[ -z "$p7" ]]); then
echo "RHEL8 only"
while read line; do
echo "$line : 8" >> $ofil
done <<< "$p8"
fi
}
# map_pkgs2engs
# Map the packages in the RHEL7 and RHEL8 package files to the engineers
# in the team file reporting to the manager passed as an argument to
# this script.
#
map_pkgs2engs() {
echo -e "\nmap_pkgs2engs\n----------------"
# gpkgdir is global
local rh7="$gpkgdir/rh7pkgs"
local rh8="$gpkgdir/rh8pkgs"
local team="$gpkgdir/team"
local teampkgs="$gpkgdir/teampkgs"
local l7
local l8
> $teampkgs
while read eng; do
echo $eng
l7="$(grep -w $eng $rh7)"
l8="$(grep -w $eng $rh8)"
# echo "$l7"
# echo "$l8"
([[ "$l7" ]] || [[ "$l8" ]]) \
&& append_teampkgs "$l7" "$l8" $teampkgs
done < $team
}
grep4pkgs() {
echo -e "\ngrep4pkgs\n--------------"
# gpkgdir is global
local rh7="$gpkgdir/rh7pkgs"
local rh8="$gpkgdir/rh8pkgs"
local pkgs2grep=$gpkgdir/$pkgs2grep
local greptpkgs=$gpkgdir/greptpkgs
local l7
local l8
> $greptpkgs
while read gpkg; do
echo $gpkg
l7="$(grep -w $gpkg $rh7)"
l8="$(grep -w $gpkg $rh8)"
([[ "$l7" ]] || [[ "$l8" ]]) \
&& append_teampkgs "$l7" "$l8" $greptpkgs
done < $pkgs2grep
}
main() {
get_options $@
[ -d $gpkgdir ] || mkdir -p $gpkgdir
if $b_team_on; then
> $gpkgdir/team
teamlist $manager | tee -a $gpkgdir/team
clean_team $gpkgdir/team
fi
get_pkgs 7
get_pkgs 8
$b_grep4pkgs && grep4pkgs || map_pkgs2engs
}
main $@
exit 0