9450fbe750cae55b0e288ee3b10bb7fe419919de
[git-tools-moved-to-github.git] / id-rpm-build / upload-rpms.sh
1 #!/bin/sh
2 PWD=`pwd`
3 UPLOAD_PATH=${UPLOAD_PATH:=/home/ftp/pub}
4 UPLOAD_HOST=${UPLOAD_HOST:=ftp.indexdata.dk}
5 specfile=$1
6 if test ! -f "${specfile}"; then
7         echo "Missing .spec file argument."
8         exit 1
9 fi
10 if test ! -x /bin/rpm; then
11         echo "$0: /bin/rpm missing. Install rpm"
12         exit 1
13 fi
14 if test ! -f /etc/redhat-release; then
15         echo "/etc/redhat-release missing"
16         exit 1
17 fi
18 if test -z "$DISTRO"; then
19         if grep 'release 6' /etc/redhat-release >/dev/null; then
20                 DISTRO="centos/6"
21         elif grep 'release 7' /etc/redhat-release > /dev/null; then
22                 DISTRO="centos/7"
23         else
24                 DISTRO="centos/5.5"
25         fi
26 fi
27 topdir=`rpm --eval "%{_topdir}"`
28 BUILD_DIR=${BUILD_DIR:=${topdir}}
29 pkg_names=`rpm -q --specfile ${specfile} --queryformat "%{NAME}-%{VERSION}-%{RELEASE}\n"`
30 pkg_short=`rpm -q --specfile ${specfile} --queryformat "%{NAME};" | cut -d ";" -f1`
31
32 UPLOAD_DIR=${UPLOAD_DIR:=${pkg_short}}
33 UPLOAD_URI=${UPLOAD_HOST}:${UPLOAD_PATH}/${UPLOAD_DIR}
34 echo "Uploading to ${UPLOAD_URI}..."
35 inc_src=true
36 if test ! -d ${BUILD_DIR}/SRPMS; then 
37         echo "No SRPMS dir under ${BUILD_DIR}"
38         inc_src=false
39 fi
40 inc_bin=true
41 if test ! -d ${BUILD_DIR}/RPMS; then 
42         echo "No RPMS dir under ${BUILD_DIR}"
43         inc_bin=false
44 fi
45
46 for pkg in ${pkg_names}; do
47         copy=false
48         if $inc_src; then
49                 if test -f ${BUILD_DIR}/SRPMS/${pkg}.src.rpm; then
50                         scp ${BUILD_DIR}/SRPMS/${pkg}.src.rpm ${UPLOAD_URI}/redhat/${DISTRO}/SRPMS/
51                         copy=true
52                 fi
53         fi
54         if $inc_bin; then
55                 for dir in ${BUILD_DIR}/RPMS/*; do
56                         arch=`basename ${dir}`
57                         if test -f ${dir}/${pkg}.${arch}.rpm; then
58                                 copy=true
59                                 scp ${dir}/${pkg}.${arch}.rpm ${UPLOAD_URI}/redhat/${DISTRO}/RPMS/${arch}/
60                         fi
61                 done
62                 if ! $copy; then
63                         echo "FAILED: No RPM copied for: ${pkg}"
64                         exit 1
65                 fi
66         fi
67 done