summaryrefslogtreecommitdiffstats
path: root/redhat/build/get_source_files.sh
blob: 3f42de99d2977b553b5bb0757317214c240cbf4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash

PKGNAME="${1##*/}"
TDE_VERSION="${2:-${TDE_VERSION:-14.1.2}}"
DIST="$3"

[ -z "${PKGNAME}" ] && echo "You must specify a package name !" && exit 1
SPECFILE=$(get_specfile.sh ${PKGNAME} ${TDE_VERSION})
SPECDIR="${SPECFILE%/*}"
RPMPKGNAME="$(get_rpm_package_name.sh ${PKGNAME})"
[ ! -r "${SPECFILE}" ] && exit 2

while read var val; do
  case "${var}" in
    Version:*) VERSION="${val}";;
    Source*:|Source:|Patch[0-9]*:)
      if [ "${val:0:7}" = "http://" ] || [ "${val:0:8}" = "https://" ]; then
        FILE="${SPECDIR}/${val##*/}"
      else
        FILE="${SPECDIR}/${val}"
      fi
      if [ "${DIST}" = "any" ] && [ "${var//%\{?dist\}/}" = "${var}" ]; then
        FILES="${FILE//%\{?dist\}/.}"*
      else
        FILES="${FILE}"
      fi

      for FILE in $FILES; do
        for name in ${RPMPKGNAME} ${PKGNAME} trinity-${PKGNAME}; do
          file=$(rpm --define "tde_pkg ${PKGNAME}" \
                     --define "tde_version ${TDE_VERSION}" \
                     --define "name ${name}" \
                     --define "version ${VERSION}" \
                     --define "dist ${DIST:-$(rpmdist.sh --dist)}" \
                     -E "${FILE}")
          [ -r "${file}" ] && break
        done
        [ -r "${file}" ] && echo "${file}"
      done
    ;;
  esac
done < "${SPECFILE}"