jcpunk / 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
Karanbir Singh afa935
Karanbir Singh afa935
pn=$(basename `pwd`)
Karanbir Singh afa935
f=.${pn}.metadata
Karanbir Singh afa935
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
Karanbir Singh afa935
  fsha=$( echo $a  | cut -f1 -d\ )
Karanbir Singh afa935
  fname=$( echo $a | cut -f2 -d\ )
Karanbir Singh afa935
  if [ $fsha = "da39a3ee5e6b4b0d3255bfef95601890afd80709" ]; then
Karanbir Singh afa935
    # zero byte file
Karanbir Singh afa935
    touch $fname
Karanbir Singh afa935
  else
Karanbir Singh afa935
    if [ ! -e ${fname} ]; then
Karanbir Singh afa935
      curl https://git.centos.org/sources/${pn}/${br}/${fsha} -o ${fname}
Karanbir Singh afa935
    else
Karanbir Singh afa935
      echo "${fname} exists. skipping"
Karanbir Singh afa935
    fi
Karanbir Singh afa935
  fi
Karanbir Singh afa935
done < $f