You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jenkins-debian-glue/scripts/generate-reprepro-codename

150 lines
3.9 KiB

#!/bin/bash
if [ -z ${JENKINS_DEBIAN_GLUE_QUIET:-} ]; then
set -x
fi
set -e
bailout() {
[ -n "${1:-}" ] && EXIT="${1}" || EXIT=0
[ -n "${2:-}" ] && echo "$2" >&2
exit $EXIT
}
if [ -r /etc/jenkins/debian_glue ] ; then
echo "*** Sourcing /etc/jenkins/debian_glue ***"
. /etc/jenkins/debian_glue
fi
if [ "${BUILD_ONLY:-}" = "true" ] ; then
echo "BUILD_ONLY is set to true, ignoring request to generate local repository."
exit 0
fi
ARCHITECTURES="${ARCHITECTURES:-amd64 i386 source}"
COMPONENTS="${COMPONENTS:-main}"
UDEB_COMPONENTS="${UDEB_COMPONENTS:-main}"
usage() {
echo "Usage: $0" \
"[ --architectures <architectures> ]" \
"[ --components <components> ]" \
"[ --udeb-components <udeb components> ]" \
"[ --origin <origin> ]" \
"[ --suite <suite> ]" \
"<codename>"
}
while [ "$#" -gt 1 ]; do
case "$1" in
--architectures)
ARCHITECTURES="$2"
shift 2
;;
--components)
COMPONENTS="$2"
shift 2
;;
--udeb-components)
UDEB_COMPONENTS="$2"
shift 2
;;
--origin)
ORIGIN="$2"
shift 2
;;
--suite)
SUITE="$2"
shift 2
;;
--)
shift; break
;;
*)
echo "Usage error." >&2
usage >&2
exit 1
;;
esac
done
if [ "$#" -lt 1 ] ; then
usage >&2
exit 1
fi
# repository/codename that should be added
REPOS="$1"
JENKINS_DEBIAN_GLUE_VERSION=$(dpkg --list jenkins-debian-glue 2>/dev/null | awk '/^ii/ {print $3}')
if [ -n "${JENKINS_DEBIAN_GLUE_VERSION:-}" ] ; then
echo "*** Running jenkins-debian-glue version $JENKINS_DEBIAN_GLUE_VERSION ***"
fi
if [ -z "${REPOSITORY:-}" ] ; then
REPOSITORY='/srv/repository'
echo "*** Repository variable REPOSITORY is unset, using default [$REPOSITORY] ***"
fi
if ! ${SUDO_CMD:-} mkdir -p "${REPOSITORY}"/conf ; then
echo "Error creating ${REPOSITORY}/conf (forgot to create /srv/repository and chown jenkins?)" >&2
exit 1
fi
if ! ${SUDO_CMD:-} chown $(id -un) "${REPOSITORY}"/conf ; then
echo "*** Warning: failed to adjust permissions of ${REPOSITORY}/conf ***"
echo "*** This might be caused by a remote FS like sshfs, so not failing the build. ***"
echo "*** Please fix the underlying problem if you depend on according permissions. ***"
fi
touch "${REPOSITORY}"/conf/distributions
# support setting key id
if [ -z "${KEY_ID:-}" ] ; then
echo "*** WARNING: No KEY_ID found, can not sign repository. ***"
echo "*** Generate a key executing 'gpg --gen-key' as user root"
echo "*** and then adjust /etc/jenkins/debian_glue."
fi
# lock access to file to avoid duplicate entries when two generate-reprepro-codename
# runs happen at the very same time
(
flock --timeout 5 9 || bailout 1 "Error: could not lock file ${REPOSITORY}/conf/distributions, giving up."
if grep -q "^\(Codename\|Suite\): ${REPOS}$" "${REPOSITORY}"/conf/distributions ; then
echo "Codename/repository $REPOS exists already, ignoring request to add again."
exit 0
fi
cat >> "${REPOSITORY}"/conf/distributions << EOF
Codename: ${REPOS}
Architectures: ${ARCHITECTURES}
Components: ${COMPONENTS}
EOF
if [ -n "${SUITE:-}" ]; then
printf "Suite: ${SUITE}\n" >> "${REPOSITORY}"/conf/distributions
fi
if [ -n "${ORIGIN:-}" ]; then
printf "Origin: ${ORIGIN}\n" >> "${REPOSITORY}"/conf/distributions
fi
if [ -n "${UDEB_COMPONENTS:-}" ]; then
printf "UDebComponents: ${UDEB_COMPONENTS}\n" >> "${REPOSITORY}"/conf/distributions
fi
printf "Tracking: minimal\n" >> "${REPOSITORY}"/conf/distributions
if [ -n "${KEY_ID:-}" ] ; then
echo "*** Signing repository with Key ID $KEY_ID ***"
printf "SignWith: ${KEY_ID}\n" >> "${REPOSITORY}"/conf/distributions
fi
echo "Added $REPOS as new codename/repos to the reprepro configuration."
) 9>/var/lock/jdg-generate-reprepro-codename."$(id -un)" || bailout 1 "Error while generating reprepro codename/repos."
# vim:foldmethod=marker ts=2 ft=sh ai expandtab sw=2