forked from hgomez/obuildfactory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
push_rpm_to_bintray.sh
executable file
·76 lines (59 loc) · 2.33 KB
/
push_rpm_to_bintray.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh
#
# push_rpm_to_bintray.sh - henri.gomez@gmail.com
#
# This script push a rpm package to Bintray repo
#
function usage() {
echo "$0 username api_key repo_name rpm_file site_url"
exit 0
}
if [ $# -lt 5 ]; then
usage
fi
BINTRAY_USER=$1
BINTRAY_APIKEY=$2
BINTRAY_REPO=$3
RPM_FILE=$4
BASE_DESC=$5
CURL_CMD="curl --write-out %{http_code} --silent --output /dev/null -u$BINTRAY_USER:$BINTRAY_APIKEY"
BINTRAY_ACCOUNT=$BINTRAY_USER
RPM_NAME=`rpm --queryformat "%{NAME}" -qp $RPM_FILE`
RPM_VERSION=`rpm --queryformat "%{VERSION}" -qp $RPM_FILE`
RPM_RELEASE=`rpm --queryformat "%{RELEASE}" -qp $RPM_FILE`
RPM_ARCH=`rpm --queryformat "%{ARCH}" -qp $RPM_FILE`
RPM_LICENSE=`rpm --queryformat "%{LICENSE}" -qp $RPM_FILE`
RPM_DESCRIPTION=`rpm --queryformat "%{DESCRIPTION}" -qp $RPM_FILE`
REPO_FILE_PATH=`basename $RPM_FILE`
DESC_URL=$BASE_DESC
if [ -z "$RPM_NAME" ] || [ -z "$RPM_VERSION" ] || [ -z "$RPM_RELEASE" ] || [ -z "$RPM_ARCH" ]; then
echo "no RPM metadata information in $RPM_FILE, skipping."
exit -1
fi
echo "RPM_NAME=$RPM_NAME, RPM_VERSION=$RPM_VERSION, RPM_RELEASE=$RPM_RELEASE, RPM_ARCH=$RPM_ARCH"
echo "BINTRAY_USER=$BINTRAY_USER, BINTRAY_REPO=$BINTRAY_REPO, RPM_FILE=$RPM_FILE, BASE_DESC=$BASE_DESC"
echo "Deleting package from Bintray.."
HTTP_CODE=`$CURL_CMD -H "Content-Type: application/json" -X DELETE https://api.bintray.com/packages/$BINTRAY_ACCOUNT/$BINTRAY_REPO/$RPM_NAME`
if [ "$HTTP_CODE" != "200" ]; then
echo "can't delete package -> $HTTP_CODE"
else
echo "Package deleted"
fi
echo "Creating package on Bintray.."
HTTP_CODE=`$CURL_CMD -H "Content-Type: application/json" -X POST https://api.bintray.com/packages/$BINTRAY_ACCOUNT/$BINTRAY_REPO/ --data "{ \"name\": \"$RPM_NAME\", \"desc\": \"${RPM_DESCRIPTION}\", \"desc_url\": \"$DESC_URL\", \"labels\": \"\", \"licenses\": [ \"$RPM_LICENSE\" ]
}"`
if [ "$HTTP_CODE" != "201" ]; then
echo "can't create package -> $HTTP_CODE"
exit -1
else
echo "Package created"
fi
echo "Uploading package to Bintray.."
HTTP_CODE=`$CURL_CMD -T $RPM_FILE -u$BINTRAY_USER:$BINTRAY_APIKEY -H "X-Bintray-Package:$RPM_NAME" -H "X-Bintray-Version:$RPM_VERSION-$RPM_RELEASE" "https://api.bintray.com/content/$BINTRAY_ACCOUNT/$BINTRAY_REPO/$REPO_FILE_PATH;publish=1"`
if [ "$HTTP_CODE" != "201" ]; then
echo "failed to upload package -> $HTTP_CODE"
exit -1
else
echo "Package uploaded"
fi
exit 0