-#!/bin/sh
-PWD=`pwd`
-UPLOAD_PATH=${UPLOAD_PATH:=/home/ftp/pub}
-UPLOAD_HOST=${UPLOAD_HOST:=ftp.indexdata.dk}
-specfile=$1
-if test ! -f "${specfile}"; then
- echo "Missing .spec file argument."
- exit 1
-fi
-if test ! -x /bin/rpm; then
- echo "$0: /bin/rpm missing. Install rpm"
- exit 1
-fi
-if test ! -f /etc/redhat-release; then
- echo "/etc/redhat-release missing"
- exit 1
-fi
-if test -z "$DISTRO"; then
- if grep 'release 6' /etc/redhat-release >/dev/null; then
- DISTRO="centos/6"
- elif grep 'release 7' /etc/redhat-release > /dev/null; then
- DISTRO="centos/7"
- else
- DISTRO="centos/5.5"
- fi
-fi
-topdir=`rpm --eval "%{_topdir}"`
-BUILD_DIR=${BUILD_DIR:=${topdir}}
-pkg_names=`rpm -q --specfile ${specfile} --queryformat "%{NAME}-%{VERSION}-%{RELEASE}\n"`
-pkg_short=`rpm -q --specfile ${specfile} --queryformat "%{NAME};" | cut -d ";" -f1`
-
-UPLOAD_DIR=${UPLOAD_DIR:=${pkg_short}}
-UPLOAD_URI=${UPLOAD_HOST}:${UPLOAD_PATH}/${UPLOAD_DIR}
-echo "Uploading to ${UPLOAD_URI}..."
-inc_src=true
-if test ! -d ${BUILD_DIR}/SRPMS; then
- echo "No SRPMS dir under ${BUILD_DIR}"
- inc_src=false
-fi
-inc_bin=true
-if test ! -d ${BUILD_DIR}/RPMS; then
- echo "No RPMS dir under ${BUILD_DIR}"
- inc_bin=false
-fi
-
-for pkg in ${pkg_names}; do
- copy=false
- if $inc_src; then
- if test -f ${BUILD_DIR}/SRPMS/${pkg}.src.rpm; then
- scp ${BUILD_DIR}/SRPMS/${pkg}.src.rpm ${UPLOAD_URI}/redhat/${DISTRO}/SRPMS/
- copy=true
- fi
- fi
- if $inc_bin; then
- for dir in ${BUILD_DIR}/RPMS/*; do
- arch=`basename ${dir}`
- if test -f ${dir}/${pkg}.${arch}.rpm; then
- copy=true
- scp ${dir}/${pkg}.${arch}.rpm ${UPLOAD_URI}/redhat/${DISTRO}/RPMS/${arch}/
- fi
- done
- if ! $copy; then
- echo "FAILED: No RPM copied for: ${pkg}"
- exit 1
- fi
- fi
-done