#!/bin/bash # parameters FILES=${PLUGIN_FILES:-"*"} API_URL=${PLUGIN_API_URL} REPO=${PLUGIN_REPO} DISTRIBUTION=${PLUGIN_DISTRIBUTION} PASSPHRASE=${PLUGIN_PASSPHRASE} HTTP_USER=${PLUGIN_HTTP_USER} HTTP_PASS=${PLUGIN_HTTP_PASS} if [ -z "$API_URL" ] ; then echo "API_URL is required" exit 1 fi if [ -z "$REPO" ] ; then echo "REPO is required" exit 1 fi if [ -z "$DISTRIBUTION" ] ; then echo "DISTRIBUTION is required" exit 1 fi TMPDIR=$( mktemp -d ) UPLOADDIRNAME=$( head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 ) NETRC=$( mktemp ) if [ -z "${HTTP_USER}" ] || [ -z "${HTTP_PASS}" ] ; then AUTH="" else HOST=$(echo "$API_URL" | sed -E 's/^https?\:\/\/(.*)\/.*/\1/g' ) echo "machine ${HOST} login ${HTTP_USER} password ${HTTP_PASS}" > "$NETRC" AUTH="--netrc-file ${NETRC}" fi # maybe do this better, it can lead to unwanted word splitting cp -r $( echo "${FILES}" | sed 's/\([^\\]\)\,/\1 /g' ) "${TMPDIR}/" cd "${TMPDIR}" || exit for file in *.deb ; do echo "uploading '$file' to remote directory '${UPLOADDIRNAME}'" curl ${AUTH} -X POST -F "file=@${file}" "${API_URL}/files/${UPLOADDIRNAME}" done echo "Adding files to ${REPO}" curl ${AUTH} -X POST "${API_URL}/repos/${REPO}/file/${UPLOADDIRNAME}" if [ -n "${PASSPHRASE}" ] ; then echo "Signing and publishing ${REPO}" curl ${AUTH} -X PUT -H 'Content-Type: application/json' --data "{\"Signing\": {\"Passphrase\": \"${PASSPHRASE}\", \"Batch\":true}, \"ForceOverwrite\": true}" "${API_URL}/publish/:./${DISTRIBUTION}" fi