modified version of jenkins debian glue (https://github.com/mika/jenkins-debian-glue) for devuan
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.
 
 
 
 
 

121 lines
3.4 KiB

  1. #!/bin/bash
  2. set -x
  3. set -e
  4. bailout() {
  5. [ -n "${1:-}" ] && EXIT="${1}" || EXIT=0
  6. [ -n "${2:-}" ] && echo "$2" >&2
  7. exit $EXIT
  8. }
  9. if [ -r /etc/jenkins/debian_glue ] ; then
  10. . /etc/jenkins/debian_glue
  11. fi
  12. if [ "${BUILD_ONLY:-}" = "true" ] ; then
  13. echo "BUILD_ONLY is set to true, ignoring request to generate local repository."
  14. exit 0
  15. fi
  16. ARCHITECTURES="${ARCHITECTURES:-amd64 i386 source}"
  17. COMPONENTS="${COMPONENTS:-main}"
  18. UDEB_COMPONENTS="${UDEB_COMPONENTS:-main}"
  19. while [ "$#" -gt 1 ]; do
  20. case "$1" in
  21. --architectures)
  22. ARCHITECTURES="$2"
  23. shift 2
  24. ;;
  25. --components)
  26. COMPONENTS="$2"
  27. shift 2
  28. ;;
  29. --udeb-components)
  30. UDEB_COMPONENTS="$2"
  31. shift 2
  32. ;;
  33. esac
  34. done
  35. if [ "$#" -lt 1 ] ; then
  36. echo "Usage: $0" \
  37. "[ --architectures <architectures> ]" \
  38. "[ --components <components> ]" \
  39. "[ --udeb-components <udeb components> ]" \
  40. "<codename>" >&2
  41. exit 1
  42. fi
  43. # repository/codename that should be added
  44. REPOS="$1"
  45. JENKINS_DEBIAN_GLUE_VERSION=$(dpkg --list jenkins-debian-glue 2>/dev/null | awk '/^ii/ {print $3}')
  46. if [ -n "${JENKINS_DEBIAN_GLUE_VERSION:-}" ] ; then
  47. echo "*** Running jenkins-debian-glue version $JENKINS_DEBIAN_GLUE_VERSION ***"
  48. fi
  49. if [ -z "${REPOSITORY:-}" ] ; then
  50. REPOSITORY='/srv/repository'
  51. echo "*** Repository variable REPOSITORY is unset, using default [$REPOSITORY] ***"
  52. fi
  53. if ! ${SUDO_CMD:-} mkdir -p "${REPOSITORY}"/conf ; then
  54. echo "Error creating ${REPOSITORY}/conf (forgot to create /srv/repository and chown jenkins?)" >&2
  55. exit 1
  56. fi
  57. if ! ${SUDO_CMD:-} chown $(id -un) "${REPOSITORY}"/conf ; then
  58. echo "*** Warning: failed to adjust permissions of ${REPOSITORY}/conf ***"
  59. echo "*** This might be caused by a remote FS like sshfs, so not failing the build. ***"
  60. echo "*** Please fix the underlying problem if you depend on according permissions. ***"
  61. fi
  62. touch "${REPOSITORY}"/conf/distributions
  63. if [ -r /etc/jenkins/debian_glue ] ; then
  64. echo "*** Sourcing /etc/jenkins/debian_glue ***"
  65. . /etc/jenkins/debian_glue
  66. fi
  67. # support setting key id
  68. if [ -z "${KEY_ID:-}" ] ; then
  69. echo "*** WARNING: No KEY_ID found, can not sign repository. ***"
  70. echo "*** Generate a key executing 'gpg --gen-key' as user root"
  71. echo "*** and then adjust /etc/jenkins/debian_glue."
  72. fi
  73. # lock access to file to avoid duplicate entries when two generate-reprepro-codename
  74. # runs happen at the very same time
  75. (
  76. flock --timeout 5 9 || bailout 1 "Error: could not lock file ${REPOSITORY}/conf/distributions, giving up."
  77. if grep -q "^\(Codename\|Suite\): ${REPOS}$" "${REPOSITORY}"/conf/distributions ; then
  78. echo "Codename/repository $REPOS exists already, ignoring request to add again."
  79. exit 0
  80. fi
  81. cat >> "${REPOSITORY}"/conf/distributions << EOF
  82. Codename: ${REPOS}
  83. Architectures: ${ARCHITECTURES}
  84. Components: ${COMPONENTS}
  85. EOF
  86. if [ -n "${UDEB_COMPONENTS:-}" ]; then
  87. printf "UDebComponents: ${UDEB_COMPONENTS}\n" >> "${REPOSITORY}"/conf/distributions
  88. fi
  89. printf "Tracking: minimal\n" >> "${REPOSITORY}"/conf/distributions
  90. if [ -n "${KEY_ID:-}" ] ; then
  91. echo "*** Signing repository with Key ID $KEY_ID ***"
  92. printf "SignWith: ${KEY_ID}\n" >> "${REPOSITORY}"/conf/distributions
  93. fi
  94. echo "Added $REPOS as new codename/repos to the reprepro configuration."
  95. ) 9>/var/lock/jdg-generate-reprepro-codename."$(id -un)" || bailout 1 "Error while generating reprepro codename/repos."
  96. # vim:foldmethod=marker ts=2 ft=sh ai expandtab sw=2