Take the spec file as a parameter
[git-tools-moved-to-github.git] / id-rpm-build / upload-rpms.sh
1 BUILD_DIR=${BUILD_DIR:=/usr/src/redhat/}
2 PWD=`pwd`
3 UPLOAD_PATH=${UPLOAD_PATH:=/home/ftp/pub}
4 UPLOAD_HOST=${UPLOAD_HOST:=flurry}
5 DISTRO=${DISTRO:="centos/5.5"}
6 specfile=$1
7 if test ! -f ${specfile}; then
8         echo "Missing .spec file argument."
9         exit 1
10 fi
11 if test ! -x /bin/rpm; then
12         echo "$0: /bin/rpm missing. Install rpm"
13         exit 1
14 fi
15 pkg_names=`rpm -q --specfile ${specfile}`
16 pkg_short=`rpm -q --specfile ${specfile} --queryformat "%{NAME};" | cut -d ";" -f1`
17
18 UPLOAD_DIR=${UPLOAD_DIR:=${pkg_short}}
19 UPLOAD_URI=${UPLOAD_HOST}:${UPLOAD_PATH}/${UPLOAD_DIR}
20 echo "Uploading to ${UPLOAD_URI}..."
21 inc_src=true
22 if test ! -d ${BUILD_DIR}/SRPMS; then 
23         echo "No SRPMS dir under ${BUILD_DIR}"
24         inc_src=false
25 fi
26 inc_bin=true
27 if test ! -d ${BUILD_DIR}/RPMS; then 
28         echo "No RPMS dir under ${BUILD_DIR}"
29         inc_bin=false
30 fi
31
32 for pkg in ${pkg_names}; do
33         if $inc_src; then
34                 if test ! -f ${BUILD_DIR}/SRPMS/${pkg}.src.rpm; then
35                         echo "No SRPM for ${pkg}"
36                 else
37                         scp ${BUILD_DIR}/SRPMS/${pkg}.src.rpm ${UPLOAD_URI}/redhat/${DISTRO}/SRPMS/
38                 fi      
39         fi  
40         if $inc_bin; then
41                 for dir in ${BUILD_DIR}/RPMS/*; do
42                         arch=`basename ${dir}`
43                         if test -f ${dir}/${pkg}.${arch}.rpm; then
44                                 scp ${dir}/${pkg}.${arch}.rpm ${UPLOAD_URI}/redhat/${DISTRO}/RPMS/${arch}/
45                         else
46                                 echo "No ${pkg} in arch ${arch}"
47                         fi
48                 done
49         fi
50 done