2022-02-17 20:49:39 +01:00
|
|
|
#!/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 )
|
|
|
|
|
2022-07-19 12:04:13 +02:00
|
|
|
if [ -z "${HTTP_USER}" ] || [ -z "${HTTP_PASS}" ] ; then
|
2022-02-17 20:49:39 +01:00
|
|
|
AUTH=""
|
|
|
|
else
|
|
|
|
HOST=$(echo "$API_URL" | sed -E 's/^https?\:\/\/(.*)\/.*/\1/g' )
|
2022-07-19 12:04:13 +02:00
|
|
|
echo "machine ${HOST} login ${HTTP_USER} password ${HTTP_PASS}" > "$NETRC"
|
2022-02-17 20:49:39 +01:00
|
|
|
AUTH="--netrc-file ${NETRC}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# maybe do this better, it can lead to unwanted word splitting
|
2022-07-19 12:04:13 +02:00
|
|
|
cp -r $( echo "${FILES}" | sed 's/\([^\\]\)\,/\1 /g' ) "${TMPDIR}/"
|
2022-02-17 20:49:39 +01:00
|
|
|
|
2022-07-19 12:04:13 +02:00
|
|
|
cd "${TMPDIR}" || exit
|
|
|
|
for file in *.deb ; do
|
2022-02-17 20:49:39 +01:00
|
|
|
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}"
|
|
|
|
|
2022-07-19 12:04:13 +02:00
|
|
|
if [ -n "${PASSPHRASE}" ] ; then
|
2022-02-17 20:49:39 +01:00
|
|
|
echo "Signing and publishing ${REPO}"
|
2022-07-19 12:04:13 +02:00
|
|
|
curl ${AUTH} -X PUT -H 'Content-Type: application/json' --data "{\"Signing\": {\"Passphrase\": \"${PASSPHRASE}\", \"Batch\":true}, \"ForceOverwrite\": true}" "${API_URL}/publish/:./${DISTRIBUTION}"
|
2022-02-17 20:49:39 +01:00
|
|
|
fi
|
|
|
|
|