Merge branch 'document-default-timeout' of https://github.com/scotte/pcp into scotte...
[pcp.git] / scripts / bintray-upload
blobffbcd0ab1c08fc4dfefb134446280f8f0b8bcb5b
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"; vers="$2"
64 url="https://api.bintray.com/gpg/pcp/${repo}/pcp/versions/${vers}"
65 echo "Signing version ${repo}/${version} via:" && echo " ${url}"
66 curl -X POST -H "X-GPG-PASSPHRASE: ${gpgpass}" -u ${user}:${apikey} \
67 "${url};bt_package=pcp;bt_version=${vers};publish=1"
69 url="https://api.bintray.com/calc_metadata/pcp/${repo}"
70 echo "Signing repository ${repo} via:" && echo " ${url}"
71 curl -X POST -H "X-GPG-PASSPHRASE: ${gpgpass}" -u ${user}:${apikey} "${url}"
74 container_upload()
76 path="$1"; file="$2"; vers="$3"
78 docker login -u ${user} -p ${apikey} -e ${email} pcp-docker-pcp.bintray.io
79 $sudo docker tag ${path} \
80 pcp-docker-pcp.bintray.io/${path}:${vers}
81 docker push pcp-docker-pcp.bintray.io/${path}:${vers}
84 verify_asset()
86 file="$1"; prev="$2"
88 test -f "${file}" || return 1
89 # batch mode - if we said yes already, say yes again
90 test "X${prev}" = "Xyes" && return 0
91 echo -n "Found ${file}, upload? (y/N) "
92 read yesno
93 test "X${yesno}" = "Xy" -o "X${yesno}" = "XY" && return 0
94 return 1
97 # Source
98 cd ${topdir}/build/tar 2>/dev/null && \
99 verify_asset pcp-${version}.src.tar.gz && \
100 pkg_upload source pcp-${version}.src.tar.gz ${version}
102 # Mac OS X
103 cd ${topdir}/pcp-${version}/build/mac 2>/dev/null && \
104 verify_asset pcp-${buildversion}.dmg && \
105 pkg_upload macosx pcp-${buildversion}.dmg ${version}
107 # Windows
108 cd ${topdir}/pcp-${version}/build/win 2>/dev/null && \
109 verify_asset pcp-${buildversion}.msi && \
110 pkg_upload windows pcp-${buildversion}.msi ${version}
112 # Solaris
113 cd ${topdir}/pcp-${version}/build/sun 2>/dev/null && \
114 verify_asset pcp-${version} && \
115 pkg_upload solaris11 pcp-${version} ${version}
117 # Docker images
118 if cd ${topdir}/pcp-${version}/build/containers 2>/dev/null
119 then
120 previous=no
121 for image in *
123 [ -d ${image} ] || continue
124 cd ${topdir}/pcp-${version}/build/containers/${image}
125 verify_asset ${image}.tgz ${previous} && \
126 previous=yes && \
127 container_upload ${image} ${image}.tgz ${version}
128 done
131 # RPM packages
132 if cd ${topdir}/pcp-${version}/build/rpm 2>/dev/null
133 then
134 # $distro is something like "el7"
135 [ -z "${distro}" ] && quit "distro is not configured (via .bintrayrc)"
136 previous=no
137 srcrpm=`echo *.src.rpm`
138 for rpm in *.rpm
140 [ "${rpm}" = "${srcrpm}" ] && continue
141 verify_asset ${rpm} ${previous} && \
142 previous=yes && \
143 pkg_upload ${distro} ${rpm} ${version}
144 done
145 [ $previous = yes ] && sign_repository ${distro} ${version}
148 # DEB packages
149 if cd ${topdir}/build/deb 2>/dev/null
150 then
151 # $distro is something like "wheezy", $arch is like "amd64" or "i386"
152 [ -z "${distro}" ] && quit "distro is not configured (via .bintrayrc)"
153 [ -z "${arch}" ] && quit "arch is not configured (via .bintrayrc)"
154 previous=no
155 for deb in *.deb *.tar.gz
157 verify_asset ${deb} ${previous} && \
158 previous=yes && \
159 deb_upload ${distro} ${deb} ${version} ${arch}
160 done
161 [ $previous = yes ] && sign_repository ${distro} ${version}