| #!/bin/bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| surl="https://git.centos.org/sources/" |
| |
| |
| if [ -f /etc/centos-git-common ]; then |
| . /etc/centos-git-common |
| fi |
| |
| |
| BRANCH='' |
| QUIET='' |
| CHECK=0 |
| while (($# > 0)) |
| do |
| case $1 in |
| --branch) |
| |
| BRANCH=$2 |
| shift 2 |
| ;; |
| --surl) |
| |
| surl=$2 |
| shift 2 |
| ;; |
| --check) |
| |
| CHECK=1 |
| shift |
| ;; |
| -q) |
| |
| QUIET='--silent' |
| shift |
| ;; |
| esac |
| done |
| |
| |
| found=0 |
| shopt -s nullglob |
| for meta in .*.metadata |
| do |
| pn=${meta%.metadata} |
| pn=${pn#.} |
| if [ -e "SPECS/$pn.spec" ] |
| then |
| found=1 |
| break |
| fi |
| done |
| if (( $found != 1 )) |
| then |
| echo 'Missing metadata or spec. Please run from inside a sources git repo' |
| exit 1 |
| fi |
| |
| if [ ! -d .git ] || [ ! -d SPECS ]; then |
| echo 'You need to run this from inside a sources git repo' |
| exit 1 |
| fi |
| mkdir -p SOURCES |
| |
| |
| if [ -n "$BRANCH" ] |
| then |
| branches=("$BRANCH") |
| else |
| |
| branches=() |
| while IFS='' read -r line |
| do |
| |
| branch="${line:2}" |
| if [[ "$branch" =~ "detached from" ]] |
| then |
| |
| continue |
| fi |
| if [ ".${line:0:1}" = ".*" ] |
| then |
| |
| branches=("$branch" "${branches[@]}") |
| else |
| branches=("${branches[@]}" "$branch") |
| fi |
| done <<< "$(git branch --contains HEAD)" |
| fi |
| while read -r fsha fname ; do |
| if [ ".${fsha}" = ".da39a3ee5e6b4b0d3255bfef95601890afd80709" ]; then |
| |
| touch ${fname} |
| else |
| if [ ! -e "${fname}" ]; then |
| for br in "${branches[@]}" |
| do |
| curl ${QUIET} -f "${surl}/${pn}/${br}/${fsha}" -o "${fname}" && break |
| done |
| else |
| echo "${fname} exists. skipping" |
| fi |
| if [ ${CHECK} -eq 1 ]; then |
| downsum=$(sha1sum ${fname} | awk '{print $1}') |
| if [ ${fsha} != ${downsum} ]; then |
| rm -f ${fname} |
| echo "failed to download ${fname}" >&2 |
| fi |
| fi |
| fi |
| done < "${meta}" |