add a simple upload my debian package to my artifactory script
authorSven Höxter <sven.hoexter@rewe-digital.com>
Wed, 14 Mar 2018 18:17:17 +0000 (19:17 +0100)
committerSven Höxter <sven.hoexter@rewe-digital.com>
Wed, 14 Mar 2018 18:17:17 +0000 (19:17 +0100)
Very simple script, checks nearly nothing and uploads to a flat repository
layout.

artifactory/aput.sh [new file with mode: 0755]

diff --git a/artifactory/aput.sh b/artifactory/aput.sh
new file mode 100755 (executable)
index 0000000..5ac296d
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+APIKEY=""
+DISTROS="jessie stretch"
+COMPONENT="main"
+BASE_URL="https://artifactory.foobar/artifactory"
+REPO="foobar"
+REPO_URL="${BASE_URL}/${REPO}"
+
+function help {
+  cat <<EOF
+  ${0} mypackage.deb
+
+  This script will upload your Debian package to artifactory and rebuild
+  the index.
+EOF
+
+  exit 1
+}
+
+function build_dist_list {
+  local debdist
+  for x in ${DISTROS}; do
+    debdist="${debdist}deb.distribution=${x};"
+  done
+  echo ${debdist}
+}
+
+if [ -z "${1}" ]; then
+  echo "ERROR: no deb package provided"
+  help
+fi
+
+PKG="${1}"
+ARCH="$(dpkg -I ${PKG} | grep Architecture | cut -d' ' -f 3)"
+SHA="$(sha256sum ${PKG} | cut -d' ' -f 1)"
+DIST="$(build_dist_list)"
+
+echo "PKGNAME: ${PKG}"
+echo "SHA: ${SHA}"
+echo "DIST: ${DIST}"
+echo "ARCHITECTURE: ${ARCH}"
+
+# upload with curl
+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}"
+ret="$?"
+
+if [ "$ret" != "0" ]; then
+  echo "ERROR: Uploading your package ${pkg} to ${REPO_URL} failed - aborting"
+  exit 1
+fi
+printf "\n"
+
+# rebuild the index
+curl -s -X POST "${BASE_URL}/api/deb/reindex/${REPO}" -H"X-JFrog-Art-Api:${APIKEY}"
+ret="$?"
+
+if [ "$ret" != "0" ]; then
+  echo "ERROR: Rebuild package index for ${REPO} failed - aborting"
+  exit 1
+fi
+printf "\n"