0562b70fa02ef6abb79f7436b44ee474056fdd03
[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         else
22                 DISTRO="centos/5.5"
23         fi
24 fi
25 topdir=`rpm --eval "%{_topdir}"`
26 BUILD_DIR=${BUILD_DIR:=${topdir}}
27 pkg_names=`rpm -q --specfile ${specfile} --queryformat "%{NAME}-%{VERSION}-%{RELEASE}\n"`
28 pkg_short=`rpm -q --specfile ${specfile} --queryformat "%{NAME};" | cut -d ";" -f1`
29
30 UPLOAD_DIR=${UPLOAD_DIR:=${pkg_short}}
31 UPLOAD_URI=${UPLOAD_HOST}:${UPLOAD_PATH}/${UPLOAD_DIR}
32 echo "Uploading to ${UPLOAD_URI}..."
33 inc_src=true
34 if test ! -d ${BUILD_DIR}/SRPMS; then 
35         echo "No SRPMS dir under ${BUILD_DIR}"
36         inc_src=false
37 fi
38 inc_bin=true
39 if test ! -d ${BUILD_DIR}/RPMS; then 
40         echo "No RPMS dir under ${BUILD_DIR}"
41         inc_bin=false
42 fi
43
44 for pkg in ${pkg_names}; do
45         if $inc_src; then
46                 if test ! -f ${BUILD_DIR}/SRPMS/${pkg}.src.rpm; then
47                         echo "FAILED: No SRPM for ${pkg}"
48                         exit 1
49                 fi
50                 scp ${BUILD_DIR}/SRPMS/${pkg}.src.rpm ${UPLOAD_URI}/redhat/${DISTRO}/SRPMS/
51         fi
52         if $inc_bin; then
53                 copy=false
54                 for dir in ${BUILD_DIR}/RPMS/*; do
55                         arch=`basename ${dir}`
56                         if test -f ${dir}/${pkg}.${arch}.rpm; then
57                                 copy=true
58                                 scp ${dir}/${pkg}.${arch}.rpm ${UPLOAD_URI}/redhat/${DISTRO}/RPMS/${arch}/
59                         fi
60                 done
61                 if ! $copy; then
62                         echo "FAILED: No RPM copied for: ${pkg}"
63                         exit 1
64                 fi
65         fi
66 done