Files
docker-aptly-pusher/run.sh
2025-06-15 12:20:46 +02:00

61 lines
1.6 KiB
Bash
Executable File

#!/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
# TODO: 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}'"
# shellcheck disable=SC2086
curl ${AUTH} -X POST -F "file=@${file}" "${API_URL}/files/${UPLOADDIRNAME}"
done
echo "Adding files to ${REPO}"
# shellcheck disable=SC2086
curl ${AUTH} -X POST "${API_URL}/repos/${REPO}/file/${UPLOADDIRNAME}"
if [[ -n "${PASSPHRASE}" ]] ; then
echo "Signing and publishing ${REPO}"
# shellcheck disable=SC2086
curl ${AUTH} -X PUT -H 'Content-Type: application/json' --data "{\"Signing\": {\"Passphrase\": \"${PASSPHRASE}\", \"Batch\":true}, \"ForceOverwrite\": true}" "${API_URL}/publish/:./${DISTRIBUTION}"
fi