ansible-koji/roles/kojid/files/mxos-get-sources.bash
Rénich Bon Ćirić 8ca23088f4
feat(build): fix lookaside cache fallback and organize repository structure
- Add fallback to official CentOS Stream lookaside cache in SCM get-sources script
- Update documentation to reflect CentOS-style structured repositories on cs10-repo
- Update project journal with progress and decisions

Co-developed-by: Gemini AI <renich+gemini@woralelandia.com>
Signed-off-by: Rénich Bon Ćirić <renich@woralelandia.com>
2026-06-16 21:34:34 -06:00

51 lines
No EOL
1.7 KiB
Shell

#!/usr/bin/bash
set -ex
SURL="https://cs10-koji-04.mx-os/sources"
PKGNAME=$(basename "$PWD")
if [ ! -f "sources" ]; then
echo "No sources file found."
exit 0
fi
while read -r alg filename_part eq hash; do
# Format: SHA512 (filename) = hash
# filename_part is "(filename)"
filename="${filename_part:1:-1}"
if [ -f "$filename" ]; then
echo "File $filename already exists, skipping."
continue
fi
# Construct URL based on MxOS layout: SURL/PKGNAME/FILENAME/HASH/FILENAME
# Note: PKGNAME might need to be passed or detected.
# Usually in Koji execution, PWD is the SCM root, so basename PWD should work if directory matches package name.
# However, Koji often clones into 'ed' or similar.
# Using the layout found: sources/ed/ed-1.20.tar.lz/HASH/
# Assuming the file is INSIDE that hash directory.
# Check if there's a trailing slash in SURL, remove it if so.
SURL=${SURL%/}
# Algo to lowercase
alg_lower=$(echo "$alg" | tr '[:upper:]' '[:lower:]')
# URL: SURL/rpms/PKGNAME/FILENAME/ALGO/HASH/FILENAME
url="$SURL/rpms/$PKGNAME/$filename/$alg_lower/$hash/$filename"
echo "Downloading $filename from local lookaside: $url"
if curl -L --fail --retry 3 -o "$filename" "$url"; then
echo "Successfully downloaded $filename from local lookaside."
else
upstream_url="https://sources.stream.centos.org/sources/rpms/$PKGNAME/$filename/$alg_lower/$hash/$filename"
echo "Local download failed. Trying upstream CentOS Stream lookaside: $upstream_url"
curl -L --fail --retry 5 -o "$filename" "$upstream_url"
fi
# Verify hash (optional but good)
echo "$hash $filename" | sha512sum -c -
done < sources