-
Notifications
You must be signed in to change notification settings - Fork 22
/
obs-check-package-origin
executable file
·166 lines (147 loc) · 4.35 KB
/
obs-check-package-origin
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
#!/bin/bash -e
# Motivation: https://progress.opensuse.org/issues/154723
# 1. fetch requirements from package spec file,
# 2. look for package names for such requirements
# 3. search all relevant instances where the package is maintained
# 4. fetch version info from spec file and from Tumbleweed repo
osc="${osc:-"osc --apiurl https://api.opensuse.org"}"
BLUE="\e[94m"
RED="\e[91m"
GRAY="\e[90m"
ENDCOLOR="\e[0m"
debug() {
test -n "$DEBUG" && echo -e "${GRAY}$1${ENDCOLOR}" >&2
}
info() {
echo -e "${BLUE}$1${ENDCOLOR}" >&2
}
error() {
echo -e "${RED}$1${ENDCOLOR}" >&2
}
init_check() {
for cmd in which yq rpmspec osc zypper; do
which "$cmd" &> /dev/null || {
error "$cmd command is missing"
exit 100
}
done
}
parse_zypper() {
yq -pxml '.stream.search-result.solvable-list | (.solvable.+@name?,.solvable[].+@name)' \
| grep -v null \
| sort -u \
| tr '\n' ' '
}
get_package_version() {
local spec
spec="$(basename "$1").spec"
local tmpfile
tmpfile="$(mktemp)"
debug "Getting version from spec file for '$1'"
$osc cat "$1" "$spec" > "$tmpfile"
rpmspec -q --qf '%{version}\n' "$tmpfile" 2> /dev/null | head -n1
rm "$tmpfile"
}
get_tw_version() {
local package
package="$(basename "$1")"
test -n "$ZYPPER" -o -n "$ZYPPER_VERSION" || return
debug "Getting Tumbleweed version for '$package'"
zypper -n --no-refresh info "$package" | grep ^Version | cut -f2 -d: | tr -d ' '
}
get_package_name() {
local req
req="$(basename "$1" | cut -f1 -d' ')"
debug "Looking for package name for requirement '$req'"
$osc se --package "$req" | grep -oP "'[^']+'" | head -n1 | tr -d "'"
}
list_requirements() {
local package
local tmpfile
debug "Getting build requirements from '$1.spec'"
tmpfile="$(mktemp)"
$osc cat devel:openQA "$1" _service:obs_scm:"$1.spec" > "$tmpfile"
sed -i -e '/node_modules.spec.inc/d' "$tmpfile"
{
rpmspec -q -D "sysusers_requires BuildRequires: sysuser-tools" --buildrequires "$tmpfile"
rpmspec -q -D "sysusers_requires BuildRequires: sysuser-tools" --requires "$tmpfile"
} \
| sort -u \
| while read -r; do
package="$(get_package_name "$REPLY")"
test -n "$package" || {
error "Unable to get package name for '$REPLY'"
continue
}
echo "$package"
done
rm "$tmpfile"
}
get_codestream() {
debug "Getting codestream for package '$1'"
$osc sm "$1" 2> /dev/null | cut -f1 -d' ' || true
}
find_source_package() {
test -n "$1" || return
debug "Finding source package for '$1'"
local src
src="$(zypper -n --no-refresh info "$1" \
| grep 'Source package' \
| cut -f2 -d: \
| tr -d ' ')"
test -n "$src" || return
src="$(zypper -n --no-refresh --xmlout se -t srcpackage "$src" | parse_zypper)"
test -n "$src" || {
error "No source package found for $1, is repo-source enabled?"
return
}
echo "$src"
}
get_source_packages() {
for prov in $1; do
for src in $(find_source_package "$prov"); do
echo "$src"
done
done
}
search_provides() {
test -n "$ZYPPER" -o -n "$ZYPPER_WHATPROVIDES" || return
debug "Searching what provides '$1'"
local -a provides
readarray -t provides < <(zypper -n --no-refresh --xmlout se --provides "$1" | parse_zypper)
test "${#provides[@]}" -eq 0 && {
error "Unknown provider for $1"
return
}
info "$1 is provided by ${provides[*]}"
for src in $(get_source_packages "${provides[@]}" | sort -u); do
get_codestream "$src"
done
}
list_codestreams() {
local stream
for req in $(list_requirements "$1" | sort -u); do
stream="$(get_codestream "$req")"
test -n "$stream" || {
search_provides "$req"
continue
}
echo "$stream"
done
}
list_versions() {
for stream in $(list_codestreams "$1" | sort -u); do
version="$(get_package_version "$stream" || true)"
tw="$(get_tw_version "$stream" || true)"
echo -e "$stream\t${version:--}\t${tw:--}"
done | sort | column -t -N Origin,Version,TW-Version
}
init_check
[ $# -eq 0 ] && {
info "Usage: $0 package-name ..."
exit 99
}
while (($#)); do
list_versions "$1"
shift
done