2022-02-23 16:08:26 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
2022-02-25 11:54:00 +00:00
|
|
|
export HOME="/home/builder"
|
|
|
|
|
2022-02-23 16:08:26 +00:00
|
|
|
prog_NAME=$(basename "${0}")
|
|
|
|
|
|
|
|
warn()
|
|
|
|
{
|
|
|
|
echo "${prog_NAME}: WARN: $*"
|
|
|
|
}
|
|
|
|
|
|
|
|
err()
|
|
|
|
{
|
|
|
|
echo "${prog_NAME}: ERROR: $*" 1>&2
|
|
|
|
}
|
|
|
|
|
|
|
|
die()
|
|
|
|
{
|
|
|
|
echo "${prog_NAME}: ERROR: $*" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
cat <<EOM 1>&2
|
|
|
|
usage: ${prog_NAME} [ OPTIONS ] FILE
|
|
|
|
Updates an aptly package repository
|
|
|
|
Options:
|
|
|
|
--build-time=STRING
|
|
|
|
Build timestamp (used for the version of the package).
|
|
|
|
--sha256=STRING
|
2022-05-19 13:12:41 +00:00
|
|
|
Hex encoded SHA256 digest of the main binary.
|
2022-02-23 16:08:26 +00:00
|
|
|
--job=STRING
|
|
|
|
Job name that was built.
|
|
|
|
--platform=STRING
|
|
|
|
Platform name on which the build was performed.
|
|
|
|
EOM
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
BUILD_TIME=
|
|
|
|
SHA=
|
|
|
|
JOB=
|
|
|
|
PLATFORM=
|
|
|
|
|
|
|
|
while [ $# -gt 1 ]; do
|
|
|
|
OPT="$1"
|
|
|
|
|
|
|
|
case "${OPT}" in
|
|
|
|
--build-time=*)
|
|
|
|
BUILD_TIME="${OPT##*=}"
|
|
|
|
;;
|
|
|
|
--sha256=*)
|
|
|
|
SHA="${OPT##*=}"
|
|
|
|
;;
|
|
|
|
--job=*)
|
|
|
|
JOB="${OPT##*=}"
|
|
|
|
;;
|
|
|
|
--platform=*)
|
|
|
|
PLATFORM="${OPT##*=}"
|
|
|
|
;;
|
|
|
|
--*)
|
|
|
|
warn "Ignoring unknown option: '${OPT}'"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
err "Unknown option: '${OPT}'"
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
[ -z "${BUILD_TIME}" ] && die "The --build-time option must be specified"
|
|
|
|
[ -z "${SHA}" ] && die "The --sha256 option must be specified"
|
|
|
|
[ -z "${JOB}" ] && die "The --job option must be specified"
|
|
|
|
[ -z "${PLATFORM}" ] && die "The --platform option must be specified"
|
|
|
|
|
|
|
|
FILENAME="${1}"
|
|
|
|
|
|
|
|
if [ $(basename "${FILENAME}" .deb) = $(basename "${FILENAME}") ]; then
|
|
|
|
echo "Not a Debian package"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if aptly repo show -with-packages "${PLATFORM}" | grep "${SHA}" > /dev/null; then
|
|
|
|
echo "Package with same SHA256 already in repository"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
TMP=$(mktemp -d -t debrep)
|
|
|
|
|
|
|
|
cleanup () {
|
|
|
|
rm -rf "${TMP}"
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
2022-03-07 17:37:17 +00:00
|
|
|
PKG_ROOT="${TMP}/pkg"
|
|
|
|
|
|
|
|
mkdir "${PKG_ROOT}"
|
|
|
|
|
|
|
|
dpkg-deb -R "${FILENAME}" "${PKG_ROOT}"
|
2022-02-23 16:08:26 +00:00
|
|
|
|
|
|
|
VERSION=$(dpkg-deb -f "${FILENAME}" Version)
|
|
|
|
NEW_VERSION="${VERSION}"-"${BUILD_TIME}"-"${SHA}"
|
|
|
|
|
2022-03-07 17:37:17 +00:00
|
|
|
sed -i "" -e "s/Version:.*/Version: ${NEW_VERSION}/g" "${PKG_ROOT}/DEBIAN/control"
|
2022-02-23 16:08:26 +00:00
|
|
|
|
2022-03-07 17:37:17 +00:00
|
|
|
dpkg-deb --build "${PKG_ROOT}" "${TMP}"
|
2022-02-23 16:08:26 +00:00
|
|
|
|
|
|
|
if ! aptly repo show "${PLATFORM}" > /dev/null 2>&1; then
|
|
|
|
aptly repo create --distribution="${PLATFORM}" "${PLATFORM}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
aptly repo add "${PLATFORM}" "${TMP}"
|
|
|
|
|
|
|
|
: "${REPO_KEYID:="D5E2DC92617877EDF7D4FD4345EA05FB7E26053D"}"
|
|
|
|
|
2022-02-25 13:34:24 +00:00
|
|
|
if ! aptly publish show "${PLATFORM}" > /dev/null 2>&1; then
|
2022-02-25 13:20:13 +00:00
|
|
|
aptly publish repo -gpg-key="${REPO_KEYID}" "${PLATFORM}"
|
2022-02-23 16:08:26 +00:00
|
|
|
else
|
|
|
|
aptly publish update -gpg-key="${REPO_KEYID}" "${PLATFORM}"
|
|
|
|
fi
|