Blob Blame History Raw
#!/bin/bash
#
# Script to parse the non-text sources metadata file and download
# the required files from the lookaside cache
#
# Please note: this script is non-destructive, it wont replace
# files that already exist, regardless of their state, allowing you
# to have work-in-progress content that wont get overwritten.
#
# Might want to drop this in ~/bin/ and chmod u+x it

surl="https://git.centos.org/sources/"

pn=$(basename `pwd`)
f=.${pn}.metadata

# for setting any overrides, such as surl or f
if [ -f /etc/centos-git-common ]; then
  . /etc/centos-git-common
fi

if [ ! -e ${f} ] ||  [ ! -d .git ] || [ ! -d SPECS ]; then
  echo 'You need to run this from inside a sources git repo'
  exit 1
fi
mkdir -p SOURCES
br=$(cat .git/HEAD |awk -F'/' '{print $3}' )
while read a ; do
  fsha=$( echo ${a}  | cut -f1 -d\ )
  fname=$( echo ${a} | cut -f2 -d\ )
  if [ ${fsha} = "da39a3ee5e6b4b0d3255bfef95601890afd80709" ]; then
    # zero byte file
    touch ${fname}
  else
    if [ ! -e ${fname} ]; then
      curl ${surl}/${pn}/${br}/${fsha} -o ${fname}
    else
      echo "${fname} exists. skipping"
    fi
  fi
done < ${f}