Merge branch 'master' of git://git.pcp.io/kenj/pcp into kenj-merge
[pcp.git] / scripts / bintray-upload
blob78d1f9f0d27eadd8993751a5b6cea8a93bd695a8
1 #!/bin/sh
2 #
3 # Automate package uploading to bintray.com.
5 # Run in the top-level of a tree, ensuring .bintrayrc is available with
6 # valid user setting (username, email, apikey, distro, gpgphrase).
8 sudo=`which sudo` # can be cleared via .bintrayrc
9 topdir=`pwd`
11 quit()
13 echo $*
14 exit 1
17 [ -e "${topdir}/VERSION.pcp" ] || quit "Not a PCP git tree, missing VERSION.pcp"
18 [ -e "${topdir}/.bintrayrc" ] || quit "Tree is unconfigured, missing .bintrayrc"
20 . ${topdir}/.bintrayrc
21 . ${topdir}/VERSION.pcp
23 version=${PACKAGE_MAJOR}.${PACKAGE_MINOR}.${PACKAGE_REVISION}
24 buildversion=${version}-${PACKAGE_BUILD}
26 [ -z "${user}" ] && quit "user is not configured (via .bintrayrc)"
27 [ -z "${email}" ] && quit "email is not configured (via .bintrayrc)"
28 [ -z "${apikey}" ] && quit "apikey is not configured (via .bintrayrc)"
29 [ -z "${gpgpass}" ] && quit "passphrase is not configured (via .bintrayrc)"
31 pkg_upload()
33 distro="$1"; file="$2"; vers="$3"
35 url="https://api.bintray.com/content/pcp/${distro}/${file}"
36 echo "Uploading ${file} to:" && echo " ${url}"
37 curl \
38 -T ${file} -u ${user}:${apikey} \
39 -H "X-GPG-PASSPHRASE: ${gpgpass}" \
40 "${url};bt_package=pcp;bt_version=${vers};publish=1"
41 echo
44 deb_upload()
46 distro="$1"; file="$2"; vers="$3"; arch="$4"
48 deb="deb_distribution=${distro};deb_component=main;deb_architecture=${arch}"
49 url="https://api.bintray.com/content/pcp/${distro}/${file}"
50 echo "Uploading ${file} to:" && echo " ${url}"
51 curl \
52 -T ${file} -u ${user}:${apikey} \
53 -H "X-GPG-PASSPHRASE: ${gpgpass}" \
54 -H "X-Bintray-Debian-Distribution: ${distro}" \
55 -H "X-Bintray-Debian-Component: main" \
56 "${url};${deb};bt_package=pcp;bt_version=${vers};publish=1"
57 echo
60 sign_repository()
62 repo="$1"
63 url="https://api.bintray.com/calc_metadata/pcp/${repo}"
64 echo "Signing repository ${repo} via:" && echo " ${url}"
65 curl -X POST -H "X-GPG-PASSPHRASE: ${gpgpass}" -u ${user}:${apikey} "${url}"
68 container_upload()
70 path="$1"; file="$2"; vers="$3"
72 docker login -u ${user} -p ${apikey} -e ${email} pcp-docker-pcp.bintray.io
73 $sudo docker tag ${path} \
74 pcp-docker-pcp.bintray.io/${path}:${vers}
75 docker push pcp-docker-pcp.bintray.io/${path}:${vers}
78 verify_asset()
80 file="$1"
81 prev="$2"
83 test -f "${file}" || return 1
84 # batch mode - if we said yes already, say yes again
85 test "X${prev}" = "Xyes" && return 0
86 echo -n "Found ${file}, upload? (y/N) "
87 read yesno
88 test "X${yesno}" = "Xy" -o "X${yesno}" = "XY" && return 0
89 return 1
92 # Source
93 cd ${topdir}/build/tar 2>/dev/null && \
94 verify_asset pcp-${version}.src.tar.gz && \
95 pkg_upload source pcp-${version}.src.tar.gz ${version}
97 # Mac OS X
98 cd ${topdir}/pcp-${version}/build/mac 2>/dev/null && \
99 verify_asset pcp-${buildversion}.dmg && \
100 pkg_upload macosx pcp-${buildversion}.dmg ${version}
102 # Windows
103 cd ${topdir}/pcp-${version}/build/win 2>/dev/null && \
104 verify_asset pcp-${buildversion}.msi && \
105 pkg_upload windows pcp-${buildversion}.msi ${version}
107 # Solaris
108 cd ${topdir}/pcp-${version}/build/sun 2>/dev/null && \
109 verify_asset pcp-${version} && \
110 pkg_upload solaris11 pcp-${version} ${version}
112 # Docker images
113 if cd ${topdir}/pcp-${version}/build/containers 2>/dev/null
114 then
115 previous=no
116 for image in *
118 [ -d ${image} ] || continue
119 cd ${topdir}/pcp-${version}/build/containers/${image}
120 verify_asset ${image}.tgz ${previous} && \
121 previous=yes && \
122 container_upload ${image} ${image}.tgz ${version}
123 done
126 # RPM packages
127 if cd ${topdir}/pcp-${version}/build/rpm 2>/dev/null
128 then
129 # $distro is something like "el7"
130 [ -z "${distro}" ] && quit "distro is not configured (via .bintrayrc)"
131 previous=no
132 srcrpm=`echo *.src.rpm`
133 for rpm in *.rpm
135 [ "${rpm}" = "${srcrpm}" ] && continue
136 verify_asset ${rpm} ${previous} && \
137 previous=yes && \
138 pkg_upload ${distro} ${rpm} ${version}
139 done
140 [ $previous = yes ] && sign_repository ${distro}
143 # DEB packages
144 if cd ${topdir}/build/deb 2>/dev/null
145 then
146 # $distro is something like "wheezy", $arch is like "amd64" or "i386"
147 [ -z "${distro}" ] && quit "distro is not configured (via .bintrayrc)"
148 [ -z "${arch}" ] && quit "arch is not configured (via .bintrayrc)"
149 previous=no
150 for deb in *.deb *.tar.gz
152 verify_asset ${deb} ${previous} && \
153 previous=yes && \
154 deb_upload ${distro} ${deb} ${version} ${arch}
155 done
156 [ $previous = yes ] && sign_repository ${distro}