Merge branch 'master' of ssh://git.sven.stormbind.net/var/lib/git/sven/scripts
[sven/scripts.git] / artifactory / aput.sh
1 #!/bin/bash
2
3 APIKEY=""
4 DISTROS="jessie stretch"
5 COMPONENT="main"
6 BASE_URL="https://artifactory.foobar/artifactory"
7 REPO="foobar"
8 REPO_URL="${BASE_URL}/${REPO}"
9
10 function help {
11   cat <<EOF
12   ${0} mypackage.deb
13
14   This script will upload your Debian package to artifactory and rebuild
15   the index.
16 EOF
17
18   exit 1
19 }
20
21 function build_dist_list {
22   local debdist
23   for x in ${DISTROS}; do
24     debdist="${debdist}deb.distribution=${x};"
25   done
26   echo ${debdist}
27 }
28
29 if [ -z "${1}" ]; then
30   echo "ERROR: no deb package provided"
31   help
32 fi
33
34 PKG="${1}"
35 ARCH="$(dpkg -I ${PKG} | grep Architecture | cut -d' ' -f 3)"
36 SHA="$(sha256sum ${PKG} | cut -d' ' -f 1)"
37 DIST="$(build_dist_list)"
38
39 echo "PKGNAME: ${PKG}"
40 echo "SHA: ${SHA}"
41 echo "DIST: ${DIST}"
42 echo "ARCHITECTURE: ${ARCH}"
43
44 # upload with curl
45 curl -s "${REPO_URL}/${PKG};${DIST}deb.component=${COMPONENT};deb.architecture=${ARCH}" -T ${PKG} -H"X-Checksum-Sha256:${SHA}" -H"X-JFrog-Art-Api:${APIKEY}"
46 ret="$?"
47
48 if [ "$ret" != "0" ]; then
49   echo "ERROR: Uploading your package ${pkg} to ${REPO_URL} failed - aborting"
50   exit 1
51 fi
52 printf "\n"
53
54 # rebuild the index
55 curl -s -X POST "${BASE_URL}/api/deb/reindex/${REPO}" -H"X-JFrog-Art-Api:${APIKEY}"
56 ret="$?"
57
58 if [ "$ret" != "0" ]; then
59   echo "ERROR: Rebuild package index for ${REPO} failed - aborting"
60   exit 1
61 fi
62 printf "\n"