amoralej / centos / cbs-tools

Forked from centos/cbs-tools 2 years ago
Clone
Blob Blame History Raw
#!/bin/bash

REPOMD="repodata/repomd.xml"

KOJI_CACHE="/var/cache/cbs-monitorexternalrepos"
UPDATED_REPOS=""
UPDATED_BUILDROOTS=`mktemp`

# Ensure the cache directory is available                                                                                                                                                                                                
[ ! -d $KOJI_CACHE ] && mkdir -p $KOJI_CACHE 

OLDIFS="$IFS"
IFS=$'\n'
for REPO in `koji list-external-repos --quiet`
do
      sha=""
      oldsha=""
      repourl=`echo $REPO | rev| cut -d ' ' -f 1| rev | sed 's/\$arch/x86_64/g'`
      reponame=`echo $REPO | cut -d ' ' -f 1`
      if [ "x$reponame" == "x" ]
      then
          echo "Repository $REPO is malformed."
          break
      fi 
      sha=`curl --silent $repourl/$REPOMD | sha256sum`
      if [ $? -gt 0 ]
      then
          echo "Couldn't retrieve $repourl/$REPOMD. Skipping $reponame regeneration."
          continue
      fi
      if [ ! -f $KOJI_CACHE/$reponame.sha256sum ] 
      then
           echo "$sha" > $KOJI_CACHE/$reponame.sha256sum 
      else
           oldsha=`cat $KOJI_CACHE/$reponame.sha256sum`
           diff <(echo "$sha") <(echo "$oldsha") &> /dev/null
           if [ $? -gt 0 ]
           then
                UPDATED_REPOS="$UPDATED_REPOS $reponame"
                echo "$sha" > $KOJI_CACHE/$reponame.sha256sum
           fi
      fi
done
IFS="$OLDIFS"

for REPO in $UPDATED_REPOS
do
    buildroots=`koji list-external-repos --name=$REPO --quiet --used | cut -d ' ' -f 1`
    printf "$buildroots\n" >> $UPDATED_BUILDROOTS 
done

for BR in `cat $UPDATED_BUILDROOTS | sort | uniq`
do
    echo koji regen-repo --nowait $BR
done