arrfab / centos / cbs-tools

Forked from centos/cbs-tools 5 years ago
Clone

Blame scripts/external_repos_updates.sh

Thomas Oulevey 1c7045
#!/bin/bash
Thomas Oulevey 1c7045
Thomas Oulevey 1c7045
REPOMD="repodata/repomd.xml"
Thomas Oulevey 1c7045
Thomas Oulevey 1c7045
KOJI_CACHE="/var/cache/cbs-monitorexternalrepos"
Thomas Oulevey 1c7045
UPDATED_REPOS=""
Thomas Oulevey 1c7045
UPDATED_BUILDROOTS=`mktemp`
Thomas Oulevey 1c7045
Thomas Oulevey 1c7045
# Ensure the cache directory is available                                                                                                                                                                                                
Thomas Oulevey 1c7045
[ ! -d $KOJI_CACHE ] && mkdir -p $KOJI_CACHE 
Thomas Oulevey 1c7045
Thomas Oulevey 1c7045
OLDIFS="$IFS"
Thomas Oulevey 1c7045
IFS=$'\n'
Thomas Oulevey 1c7045
for REPO in `koji list-external-repos --quiet`
Thomas Oulevey 1c7045
do
Thomas Oulevey 1c7045
      sha=""
Thomas Oulevey 1c7045
      oldsha=""
Thomas Oulevey 1c7045
      repourl=`echo $REPO | rev| cut -d ' ' -f 1| rev | sed 's/\$arch/x86_64/g'`
Thomas Oulevey 1c7045
      reponame=`echo $REPO | cut -d ' ' -f 1`
Thomas Oulevey 1c7045
      if [ "x$reponame" == "x" ]
Thomas Oulevey 1c7045
      then
Thomas Oulevey 1c7045
          echo "Repository $REPO is malformed."
Thomas Oulevey 1c7045
          break
Thomas Oulevey 1c7045
      fi 
Thomas Oulevey 1c7045
      sha=`curl --silent $repourl/$REPOMD | sha256sum`
Thomas Oulevey 1c7045
      if [ $? -gt 0 ]
Thomas Oulevey 1c7045
      then
Thomas Oulevey 1c7045
          echo "Couldn't retrieve $repourl/$REPOMD. Skipping $reponame regeneration."
Thomas Oulevey 1c7045
          continue
Thomas Oulevey 1c7045
      fi
Thomas Oulevey 1c7045
      if [ ! -f $KOJI_CACHE/$reponame.sha256sum ] 
Thomas Oulevey 1c7045
      then
Thomas Oulevey 1c7045
           echo "$sha" > $KOJI_CACHE/$reponame.sha256sum 
Thomas Oulevey 1c7045
      else
Thomas Oulevey 1c7045
           oldsha=`cat $KOJI_CACHE/$reponame.sha256sum`
Thomas Oulevey 1c7045
           diff <(echo "$sha") <(echo "$oldsha") &> /dev/null
Thomas Oulevey 1c7045
           if [ $? -gt 0 ]
Thomas Oulevey 1c7045
           then
Thomas Oulevey 1c7045
                UPDATED_REPOS="$UPDATED_REPOS $reponame"
Thomas Oulevey 1c7045
                echo "$sha" > $KOJI_CACHE/$reponame.sha256sum
Thomas Oulevey 1c7045
           fi
Thomas Oulevey 1c7045
      fi
Thomas Oulevey 1c7045
done
Thomas Oulevey 1c7045
IFS="$OLDIFS"
Thomas Oulevey 1c7045
Thomas Oulevey 1c7045
for REPO in $UPDATED_REPOS
Thomas Oulevey 1c7045
do
Thomas Oulevey 1c7045
    buildroots=`koji list-external-repos --name=$REPO --quiet --used | cut -d ' ' -f 1`
Thomas Oulevey 1c7045
    printf "$buildroots\n" >> $UPDATED_BUILDROOTS 
Thomas Oulevey 1c7045
done
Thomas Oulevey 1c7045
Thomas Oulevey 1c7045
for BR in `cat $UPDATED_BUILDROOTS | sort | uniq`
Thomas Oulevey 1c7045
do
Thomas Oulevey 1c7045
    echo koji regen-repo --nowait $BR
Thomas Oulevey 1c7045
done
Thomas Oulevey 1c7045