#4 2 Changes to make get_sources more portable
Merged 5 years ago by arrfab. Opened 5 years ago by bstinson.
bstinson/centos-git-common minimize-get-sources  into  master

file modified
+12 -12
@@ -102,13 +102,13 @@ 

      QUIET=''

  fi

  

- which git >/dev/null 2>&1

+ command -v git >/dev/null 2>&1

  if [[ $? -ne 0 ]]; then

      echo 'You need git in PATH' >&2

      exit 1

  fi

  

- which curl >/dev/null 2>&1

+ command -v curl >/dev/null 2>&1

  if [[ $? -ne 0 ]]; then

      echo 'You need curl in PATH' >&2

      exit 1
@@ -117,7 +117,7 @@ 

  # should go into a function section at some point

  weakHashDetection () {

    strHash=${1};

-   case $((`echo ${strHash}|wc -m` - 1 )) in

+   case $((`echo "${strHash}"|wc -m` - 1 )) in

      128)

        hashBin='sha512sum'

        ;;
@@ -181,20 +181,20 @@ 

      else

        branches=("${branches[@]}" "$branch")

      fi

-   done <<< "$(git branch --contains HEAD)"

+   done <<< "$(git branch -r --contains HEAD | grep '^\s\+origin/'| sed 's#origin/##g')"

  fi

  while read -r fsha fname ; do

    if [ ".${fsha}" = ".da39a3ee5e6b4b0d3255bfef95601890afd80709" ]; then

      # zero byte file

-     touch ${fname}

+     touch "${fname}"

    else

      if [ ${CHECK} -eq 1 ]; then

-       hashType=$(weakHashDetection ${fsha})

+       hashType=$(weakHashDetection "${fsha}")

        if [ "${hashType}" == "unknown" ]; then

          echo 'Failure: Hash type unknown.' >&2

          exit 1;

        else

-         which ${hashType} >/dev/null 2>&1

+         command -v "${hashType}" >/dev/null 2>&1

          if [[ $? -ne 0 ]]; then

            echo "Failure: You need ${hashType} in PATH." >&2

            exit 1;
@@ -203,15 +203,15 @@ 

      fi

      if [ -e ${fname} -a ${CHECK} -eq 1 ]; then

  	# check hash sum and force download if wrong

-         downsum=$(${hashType} ${fname} | awk '{print $1}')

+         downsum=$(${hashType} "${fname}" | awk '{print $1}')

          if [ "${fsha}" != "${downsum}" ]; then

-             rm -f ${fname}

+             rm -f "${fname}"

          fi

      fi

      if [ ! -e "${fname}" ]; then

        for br in "${branches[@]}"

        do

-         br=$(echo ${br}| sed -e s'|remotes/origin/||')

+         br=$(echo "${br}"| sed -e s'|remotes/origin/||')

          url="${SURL}/${pn}/${br}/${fsha}"

          echo "Retrieving ${url}"

          curl -L ${QUIET} -f "${url}" -o "${fname}" && break
@@ -220,9 +220,9 @@ 

        echo "${fname} exists. skipping"

      fi

      if [ ${CHECK} -eq 1 ]; then

-         downsum=$(${hashType} ${fname} | awk '{print $1}')

+         downsum=$(${hashType} "${fname}" | awk '{print $1}')

          if [ "${fsha}" != "${downsum}" ]; then

-             rm -f ${fname}

+             rm -f "${fname}"

              echo "Failure: ${fname} hash does not match hash from the .metadata file" >&2

              exit 1;

          fi

This changes get_sources to allow you to clone directly by commit id (without setting a local branch name), and gets the proper branch name from the remote.

It also uses the 'command' builtin rather than requiring a dependency on /usr/bin/which

1 new commit added

  • use command instead of which. this is more portable and doesn\'t require another dep
5 years ago

@pgreco: can you test this with your setup?

@bstinson, tested locally without problems.
The only strange thing (though unrelated) is that when the file doesn't exist, I get this error

curl: (22) NSS: client certificate not found (nickname not specified)

@hughesjr @arrfab, any thoughts? I think this is ready to merge. We've been using this script in mbox to pull sources for building.

I'd like to rebuild centpkg-minimal from this git repo rather than my fork sometime.

Pull-Request has been merged by arrfab

5 years ago
Metadata