pgreco / centos-git-common

Forked from centos-git-common 5 years ago
Clone

Blame get_sources.sh

Karanbir Singh afa935
#!/bin/bash
Karanbir Singh afa935
#
Karanbir Singh afa935
# Script to parse the non-text sources metadata file and download
Karanbir Singh afa935
# the required files from the lookaside cache
Karanbir Singh afa935
#
Karanbir Singh afa935
# Please note: this script is non-destructive, it wont replace
Karanbir Singh afa935
# files that already exist, regardless of their state, allowing you
Karanbir Singh afa935
# to have work-in-progress content that wont get overwritten.
Karanbir Singh afa935
#
Karanbir Singh afa935
# Might want to drop this in ~/bin/ and chmod u+x it
Karanbir Singh afa935
c19d26
surl="https://git.centos.org/sources/"
Karanbir Singh afa935
Karanbir Singh afa935
pn=$(basename `pwd`)
Karanbir Singh afa935
f=.${pn}.metadata
1842fe
1842fe
# for setting any overrides, such as surl or f
1842fe
if [ -f /etc/centos-git-common ]; then
1842fe
  . /etc/centos-git-common
1842fe
fi
1842fe
a4a7af
if [ ! -e ${f} ] ||  [ ! -d .git ] || [ ! -d SOURCES ]; then
Karanbir Singh afa935
  echo 'You need to run this from inside a sources git repo'
Karanbir Singh afa935
  exit 1
Karanbir Singh afa935
fi
Karanbir Singh afa935
br=$(cat .git/HEAD |awk -F'/' '{print $3}' )
Karanbir Singh afa935
while read a ; do
a4a7af
  fsha=$( echo ${a}  | cut -f1 -d\ )
a4a7af
  fname=$( echo ${a} | cut -f2 -d\ )
a4a7af
  if [ ${fsha} = "da39a3ee5e6b4b0d3255bfef95601890afd80709" ]; then
Karanbir Singh afa935
    # zero byte file
a4a7af
    touch ${fname}
Karanbir Singh afa935
  else
Karanbir Singh afa935
    if [ ! -e ${fname} ]; then
c19d26
      curl ${surl}/${pn}/${br}/${fsha} -o ${fname}
Karanbir Singh afa935
    else
Karanbir Singh afa935
      echo "${fname} exists. skipping"
Karanbir Singh afa935
    fi
Karanbir Singh afa935
  fi
a4a7af
done < ${f}