This commit is contained in:
Ludwig Nussel 2023-02-23 17:05:34 +01:00
parent e0aac8ec9e
commit 721114aa3f

View File

@ -3,18 +3,21 @@ set -e
# config options # config options
declare -A keep declare -A keep
remote="origin" REMOTE="origin"
branch="main" BASE_BRANCH="main"
package_base_url= PACKAGE_BASE_URL=
package_relative_url="../../rpm" PACKAGE_RELATIVE_URL="../../rpm"
# https://api.opensuse.org/public/source/openSUSE:Factory:Rings:0-Bootstrap # https://api.opensuse.org/public/source/openSUSE:Factory:Rings:0-Bootstrap
ring0api= RING0API=
date="$(date "+%s %z")" DATE="$(date "+%s %z")"
keep["dummy-release"]=1 keep["dummy-release"]=1
# command line only # command line only
single= single=
verbose=0 verbose=0
cfg_file=
###################
# constant needed to aid quoting # constant needed to aid quoting
nl=$'\n' nl=$'\n'
@ -87,11 +90,11 @@ while true ; do
-v|--verbose) verbose=$((++verbose)); shift ;; -v|--verbose) verbose=$((++verbose)); shift ;;
-c|--config) cfg_file="$2"; shift 2 ;; -c|--config) cfg_file="$2"; shift 2 ;;
--single) single=1; shift ;; --single) single=1; shift ;;
--remote) remote="$2"; shift 2 ;; --remote) REMOTE="$2"; shift 2 ;;
--branch) branch="$2"; shift 2 ;; --branch) BASE_BRANCH="$2"; shift 2 ;;
--status) show_status; exit 0 ;; --status) show_status; exit 0 ;;
--clear) clear_queue; exit 0 ;; --clear) clear_queue; exit 0 ;;
--date) date="$2"; shift 2 ;; --date) DATE="$2"; shift 2 ;;
--) shift ; break ;; --) shift ; break ;;
*) echo "Internal error!" ; exit 1 ;; *) echo "Internal error!" ; exit 1 ;;
esac esac
@ -99,21 +102,22 @@ done
modules=("$@") modules=("$@")
if [ "${date:0:1}" = '@' ]; then PACKAGE_BASE_URL="$(git config --get remote."$REMOTE".url)"
date="$(stat -c %Y "${date:1}") +0100"
fi
package_base_url="$(git config --get remote."$remote".url)"
export GIT_AUTHOR_NAME="Auto"
export GIT_AUTHOR_EMAIL="auto@suse.de"
export GIT_AUTHOR_DATE="$date"
export GIT_COMMITTER_NAME="Auto"
export GIT_COMMITTER_EMAIL="auto@suse.de"
export GIT_COMMITTER_DATE="$date"
# shellcheck disable=SC1090 # shellcheck disable=SC1090
. "${cfg_file:-.settings}" . "${cfg_file:-.settings}"
if [ "${DATE:0:1}" = '@' ]; then
DATE="$(stat -c %Y "${DATE:1}") +0100"
fi
export GIT_AUTHOR_NAME="Auto"
export GIT_AUTHOR_EMAIL="auto@suse.de"
export GIT_AUTHOR_DATE="$DATE"
export GIT_COMMITTER_NAME="Auto"
export GIT_COMMITTER_EMAIL="auto@suse.de"
export GIT_COMMITTER_DATE="$DATE"
tmpfile=$(mktemp updatemodules.XXXXXX) tmpfile=$(mktemp updatemodules.XXXXXX)
tmpfile2=$(mktemp updatemodules.XXXXXX) tmpfile2=$(mktemp updatemodules.XXXXXX)
cleanup() cleanup()
@ -129,13 +133,13 @@ while read -r m t cid p; do
fi fi
[ "$t" = "commit" ] || continue [ "$t" = "commit" ] || continue
revs["$p"]="$cid" revs["$p"]="$cid"
done < <(git cat-file -p "$remote/$branch^{tree}") done < <(git cat-file -p "$REMOTE/$BASE_BRANCH^{tree}")
if [ -n "$ring0api" ]; then if [ -n "$RING0API" ]; then
while read -r p; do while read -r p; do
ring0["$p"]=1 ring0["$p"]=1
[ -n "${revs[$p]}" ] || new["$p"]=1 [ -n "${revs[$p]}" ] || new["$p"]=1
done < <(curl -s -f "$ring0api"|sed -ne 's/.*entry name="\([^":]*\).*\/>/\1/p'|sort -u | grep -v AGGR) done < <(curl -s -f "$RING0API"|sed -ne 's/.*entry name="\([^":]*\).*\/>/\1/p'|sort -u | grep -v AGGR)
for m in "${!revs[@]}"; do for m in "${!revs[@]}"; do
[ -n "${ring0[$m]}" -o -n "${keep[$m]}" ] || drop["$m"]=1 [ -n "${ring0[$m]}" -o -n "${keep[$m]}" ] || drop["$m"]=1
@ -151,13 +155,13 @@ fi
# check remotes for updates # check remotes for updates
declare -A commits declare -A commits
treetext=$(git cat-file -p "$remote/$branch^{tree}") treetext=$(git cat-file -p "$REMOTE/$BASE_BRANCH^{tree}")
git cat-file -p "$remote/$branch":.gitmodules > "$tmpfile" git cat-file -p "$REMOTE/$BASE_BRANCH":.gitmodules > "$tmpfile"
cat "$tmpfile" > "$tmpfile2" cat "$tmpfile" > "$tmpfile2"
for m in "${modules[@]}"; do for m in "${modules[@]}"; do
if isnew "$m"; then if isnew "$m"; then
path="$m" path="$m"
url="$package_relative_url/$m" url="$PACKAGE_RELATIVE_URL/$m"
smbranch= smbranch=
git config -f "$tmpfile" --add "submodule.$m.path" "$path" git config -f "$tmpfile" --add "submodule.$m.path" "$path"
git config -f "$tmpfile" --add "submodule.$m.url" "$url" git config -f "$tmpfile" --add "submodule.$m.url" "$url"
@ -171,16 +175,18 @@ for m in "${modules[@]}"; do
continue continue
fi fi
if [ "${url:0:3}" = '../' ]; then if [ "${url:0:3}" = '../' ]; then
url="$package_base_url/$url" url="$PACKAGE_BASE_URL/$url"
fi fi
cid= cid=
if ! todrop "$m"; then if ! todrop "$m"; then
set -x
read -r cid _d < <(git ls-remote "$url" "${smbranch:-HEAD}") read -r cid _d < <(git ls-remote "$url" "${smbranch:-HEAD}")
if [ -z "$cid" ]; then if [ -z "$cid" ]; then
echo "$path not in pool" >&2 echo "$path not in pool" >&2
continue continue
fi fi
set +x
fi fi
# create a new commit for this package # create a new commit for this package
@ -209,7 +215,7 @@ for m in "${modules[@]}"; do
msg="Update $m" msg="Update $m"
isnew "$m" && msg="Add $m" isnew "$m" && msg="Add $m"
todrop "$m" && msg="Remove $m" todrop "$m" && msg="Remove $m"
newcid="$(git commit-tree -p "$remote/$branch" -m "$msg" "$newtree")" newcid="$(git commit-tree -p "$REMOTE/$BASE_BRANCH" -m "$msg" "$newtree")"
commits["$m"]="$newcid" commits["$m"]="$newcid"
cat "$tmpfile2" > "$tmpfile" cat "$tmpfile2" > "$tmpfile"
fi fi
@ -218,10 +224,11 @@ done
if [ "$single" = 1 ]; then if [ "$single" = 1 ]; then
newtree="$(echo "$treetext" | git mktree)" newtree="$(echo "$treetext" | git mktree)"
newcid="$(git commit-tree -p "$remote/$branch" -m "Update all" "$newtree")" newcid="$(git commit-tree -p "$REMOTE/$BASE_BRANCH" -m "Update all" "$newtree")"
commits["all"]="$newcid" commits["all"]="$newcid"
fi fi
# push queue
declare -A pq declare -A pq
makedict pq git for-each-ref 'refs/pq/*' --format '%(refname)' makedict pq git for-each-ref 'refs/pq/*' --format '%(refname)'