Split obspkglist in separate script

This commit is contained in:
Ludwig Nussel 2023-03-06 16:20:50 +01:00
parent 8d9042228c
commit ead7d482ac
3 changed files with 95 additions and 15 deletions

View File

@ -27,8 +27,8 @@ REMOTE="origin"
BASE_BRANCH="main"
# optional: fixed date or a filename prefixed with @ to get a stable date for testing
DATE="@token"
# optional: an OBS project with a list of packages
OBSPKGLIST="https://api.opensuse.org/public/source/openSUSE:Factory:Rings:0-Bootstrap"
# optional: OBS projects with a list of packages
OBS_PROJECTS="openSUSE:Factory:Rings:0-Bootstrap"
```
Scripts:
@ -36,13 +36,16 @@ Scripts:
All scripts use getopt, --help may not always be up to date though
:-)
- obspkglist: given obs projects, prints all packages in those projects that
are also in gitea
- updatemodules: checks all submodules for updates. For packages
that need to be updated creates `refs/pq/$packagename`. The
updated refence there updates the submodule commit reference for
updates. It also adds or removes entries from/to `.gitmodules` if
needed. There's also a `--single` option which produces a single
reference for all updates. The `--status` option show the current
state.
state. Use --packages-from to read a package list produced by `obspkglist`.
With the list the script can also add or drop packages.
- pusher: compares the references created by the `updatemodules`
script with the specified remote. Pushed pending refs to an
`update_$packagename` ref. Gitea doesn't seem to support refs in

73
obspkglist Executable file
View File

@ -0,0 +1,73 @@
#!/bin/bash
set -e
# https://api.opensuse.org/public/source/openSUSE:Factory:Rings:0-Bootstrap
APIURL="https://api.opensuse.org"
GITEA_PACKAGES="https://gitea.opensuse.org/api/v1/repos/rpm"
OBS_PROJECTS=()
# command line only
packages_from=
single=
verbose=0
cfg_file=
###################
declare -A packages
helpandquit()
{
cat <<-EOF
Usage: $0 [OPTIONS] [<projects> ...]
OPTIONS:
--apiurl=URL OBS api url
--single create single commit for all changes
-h help screen
EOF
exit 0
}
log_info()
{
[ "$verbose" -gt 0 ] || return 0
echo "$@"
}
getopttmp=$(getopt -o hc:v --long help,config:,verbose,apiurl: -n "${0##*/}" -- "$@")
eval set -- "$getopttmp"
while true ; do
case "$1" in
-h|--help) helpandquit; shift ;;
-v|--verbose) verbose=$((++verbose)); shift ;;
-c|--config) cfg_file="$2"; shift 2 ;;
--apiurl) APIURL="$2"; shift 2 ;;
--) shift ; break ;;
*) echo "Internal error!" ; exit 1 ;;
esac
done
[ $# ] && OBS_PROJECTS=("$@")
# shellcheck disable=SC1090
. "${cfg_file:-.settings}" 2>/dev/null || :
for prj in "${OBS_PROJECTS[@]}"; do
while read -r p l; do
if [ -n "$l" ]; then
echo "Warning: link $p -> $l ignored" >&2
continue
fi
packages["$p"]=1
done < <(curl -s -f "$APIURL/public/source/$prj"|sed -ne 's/.*entry name="\([^"]*\)"\( \+originpackage="\([^"]*\)"\)\?.*\/>/\1 \3/p'|sort -u)
done
for p in "${!packages[@]}"; do
# XXX: unfortuantely plain git would ask for auth
if ! curl -s -f "$GITEA_PACKAGES/$p" >/dev/null; then
log_info "Warning: $p not found in $GITEA_PACKAGES" >&2
continue
fi
echo "$p"
done

View File

@ -7,12 +7,11 @@ REMOTE="origin"
BASE_BRANCH="main"
PACKAGE_BASE_URL=
PACKAGE_RELATIVE_URL="../../rpm"
# https://api.opensuse.org/public/source/openSUSE:Factory:Rings:0-Bootstrap
OBSPKGLIST=
DATE="$(date "+%s %z")"
keep["dummy-release"]=1
PACKAGES_KEEP=
# command line only
packages_from=
single=
verbose=0
cfg_file=
@ -22,7 +21,7 @@ cfg_file=
# constant needed to aid quoting
nl=$'\n'
declare -A obs
declare -A packages
declare -A new
declare -A drop
declare -A revs
@ -33,6 +32,7 @@ helpandquit()
cat <<-EOF
Usage: $0 [OPTIONS] [<module> ...]
OPTIONS:
--packages-from=FILE read list of packges to sync from FILE
--single create single commit for all changes
-h help screen
EOF
@ -81,7 +81,7 @@ makedict()
done
}
getopttmp=$(getopt -o hc:v --long help,single,branch:,config:,date:,remote:,status,verbose,clear -n "${0##*/}" -- "$@")
getopttmp=$(getopt -o hc:v --long help,single,branch:,config:,date:,remote:,status,verbose,clear,packages-from: -n "${0##*/}" -- "$@")
eval set -- "$getopttmp"
while true ; do
@ -90,6 +90,7 @@ while true ; do
-v|--verbose) verbose=$((++verbose)); shift ;;
-c|--config) cfg_file="$2"; shift 2 ;;
--single) single=1; shift ;;
--packages-from) packages_from="$2"; shift 2 ;;
--remote) REMOTE="$2"; shift 2 ;;
--branch) BASE_BRANCH="$2"; shift 2 ;;
--status) show_status; exit 0 ;;
@ -107,6 +108,10 @@ PACKAGE_BASE_URL="$(git config --get remote."$REMOTE".url)"
# shellcheck disable=SC1090
. "${cfg_file:-.settings}"
for p in $PACKAGES_KEEP; do
keep["$p"]=1
done
if [ "${DATE:0:1}" = '@' ]; then
DATE="$(stat -c %Y "${DATE:1}") +0100"
fi
@ -135,14 +140,13 @@ while read -r m t cid p; do
revs["$p"]="$cid"
done < <(git cat-file -p "$REMOTE/$BASE_BRANCH^{tree}")
if [ -n "$OBSPKGLIST" ]; then
if [ -n "$packages_from" ]; then
while read -r p; do
obs["$p"]=1
packages["$p"]=1
[ -n "${revs[$p]}" ] || new["$p"]=1
done < <(curl -s -f "$OBSPKGLIST"|sed -ne 's/.*entry name="\([^":]*\).*\/>/\1/p'|sort -u | grep -v AGGR)
done < "$packages_from"
for m in "${!revs[@]}"; do
[ -n "${obs[$m]}" -o -n "${keep[$m]}" ] || drop["$m"]=1
[ -n "${packages[$m]}" -o -n "${keep[$m]}" ] || drop["$m"]=1
done
fi
@ -184,9 +188,9 @@ for m in "${modules[@]}"; do
cid=
if ! todrop "$m"; then
read -r cid _d < <(git ls-remote "$url" "${smbranch:-HEAD}")
read -r cid _d < <(GIT_ASKPASS=/bin/true git ls-remote "$url" "${smbranch:-HEAD}" 2>/dev/null) || true
if [ -z "$cid" ]; then
echo "$path not in pool" >&2
echo "Warning: $path not in pool, ignored" >&2
continue
fi
fi