Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft script for fetching origins of required packages
Reference: https://progress.opensuse.org/issues/154723
- Loading branch information
Showing
1 changed file
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/bin/bash -e | ||
|
||
# https://en.opensuse.org/openSUSE:Maintenance_update_process | ||
|
||
|
||
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() { | ||
which yq &>/dev/null || { error "yq command is missing"; exit 100; } | ||
} | ||
|
||
parse_zypper() { | ||
yq -pxml '.stream.search-result.solvable-list | (.solvable.+@name?,.solvable[].+@name)' \ | ||
| grep -v null \ | ||
| tr '\n' ' ' | ||
} | ||
|
||
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 | ||
debug "Getting build requirements from '$1.spec'" | ||
$osc cat devel:openQA "$1" _service:obs_scm:"$1.spec" \ | ||
| rpmspec -q --buildrequires /dev/stdin \ | ||
| 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 | ||
} | ||
|
||
get_codestream() { | ||
debug "Getting codestream for package '$1'" | ||
$osc sm "$1" 2>/dev/null || 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" || 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 | ||
} | ||
|
||
init_check | ||
list_codestreams "$1" | sort -u |