|
|
5dd126 |
#!/bin/bash
|
|
|
c929c0 |
set -e
|
|
|
5dd126 |
rm -f /tmp/pyxis*.json
|
|
|
5dd126 |
TOTAL=`curl -s --negotiate -u: -H 'Content-Type: application/json' -H 'Accept: application/json' -X GET "https://pyxis.engineering.redhat.com/v1/repositories?page_size=1" | jq .total`
|
|
|
5dd126 |
if [ "$TOTAL" == "null" ]; then
|
|
|
5dd126 |
echo "Error comunicating with Pyxis API."
|
|
|
5dd126 |
exit 1
|
|
|
5dd126 |
fi
|
|
|
ce5e36 |
PAGES=$(($TOTAL/250))
|
|
|
5dd126 |
for P in `seq 0 $PAGES`; do
|
|
|
5dd126 |
curl -s --negotiate -u: -H 'Content-Type: application/json' -H 'Accept: application/json' -X GET "https://pyxis.engineering.redhat.com/v1/repositories?page_size=500&page=$P" > /tmp/pyxis$P.json
|
|
|
5dd126 |
done
|
|
|
5dd126 |
cat /tmp/pyxis*.json > /tmp/pyx.json
|
|
|
c929c0 |
rm -f /tmp/pyx_debug
|
|
|
5dd126 |
rm -f /tmp/rhel-shortnames.conf
|
|
|
c929c0 |
jq '.data[]|.published,.requires_terms,.repository,.registry,.release_categories[0]' < /tmp/pyx.json >/tmp/pyx
|
|
|
c929c0 |
readarray -t lines < /tmp/pyx
|
|
|
c929c0 |
IDX=0
|
|
|
c929c0 |
while [ $IDX -lt ${#lines[@]} ]; do
|
|
|
c929c0 |
PUBLISHED=${lines[$IDX]}
|
|
|
c929c0 |
REQ_TERMS=${lines[$IDX+1]}
|
|
|
c929c0 |
REPOSITORY=`echo ${lines[$IDX+2]} | tr -d '"'`
|
|
|
c929c0 |
REGISTRY=`echo ${lines[$IDX+3]} | tr -d '"'`
|
|
|
c929c0 |
RELEASE=`echo ${lines[$IDX+4]} | tr -d '"'`
|
|
|
c929c0 |
if [ "$PUBLISHED" == "true" ] &&
|
|
|
c929c0 |
[ "$RELEASE" == "Generally Available" ] &&
|
|
|
c929c0 |
[ $REPOSITORY != \"\" ] &&
|
|
|
c929c0 |
[[ $REPOSITORY != *[@:]* ]] &&
|
|
|
c929c0 |
[[ $REPOSITORY != *[* ]] &&
|
|
|
c929c0 |
[[ $REGISTRY == *.* ]] &&
|
|
|
c929c0 |
[ "$REGISTRY" != "non_registry" ]; then
|
|
|
5dd126 |
if [[ $REGISTRY == *quay.io* ]] ||
|
|
|
5dd126 |
[[ $REGISTRY == *redhat.com* ]]; then
|
|
|
c929c0 |
if [ "$REQ_TERMS" == "true" ]; then
|
|
|
5dd126 |
REGISTRY=registry.redhat.io
|
|
|
5dd126 |
fi
|
|
|
5dd126 |
fi
|
|
|
c929c0 |
echo "\"$REPOSITORY\" = \"$REGISTRY/$REPOSITORY\""
|
|
|
c929c0 |
echo $PUBLISHED,$REQ_TERMS,$REPOSITORY,$REGISTRY,$RELEASE >> /tmp/pyx_debug
|
|
|
c929c0 |
echo "\"$REPOSITORY\" = \"$REGISTRY/$REPOSITORY\"" >> /tmp/rhel-shortnames.conf
|
|
|
5dd126 |
fi
|
|
|
c929c0 |
IDX=$(($IDX+5))
|
|
|
c929c0 |
done
|
|
|
5dd126 |
|
|
|
5dd126 |
cp /tmp/rhel-shortnames.conf /tmp/r.conf
|
|
|
5dd126 |
for D in `cut -d\ -f1 /tmp/r.conf | sort | uniq -d`; do
|
|
|
5dd126 |
echo $D
|
|
|
5dd126 |
M=`grep ^$D /tmp/r.conf | grep 'redhat.com' | tail -n1`
|
|
|
5dd126 |
[ -z "$M" ] && M=`grep ^$D /tmp/r.conf | tail -n1`
|
|
|
5dd126 |
echo $M
|
|
|
5dd126 |
if [ ! -z "$M" ]; then
|
|
|
5dd126 |
echo "replacing $D with $M"
|
|
|
5dd126 |
grep -v "^$D.*" /tmp/r.conf > /tmp/r2.conf
|
|
|
5dd126 |
echo "$M" >> /tmp/r2.conf
|
|
|
5dd126 |
mv /tmp/r2.conf /tmp/r.conf
|
|
|
5dd126 |
fi
|
|
|
5dd126 |
done
|
|
|
5dd126 |
|
|
|
2b1b9b |
sed -i '/.*rhel.*-els\/.*$/d' /tmp/r.conf
|
|
|
5dd126 |
echo "[aliases]" > 001-rhel-shortnames-pyxis.conf
|
|
|
5dd126 |
sort /tmp/r.conf >> 001-rhel-shortnames-pyxis.conf
|