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.
 
 
 
 
 

305 lines
8.8 KiB

  1. #!/bin/bash
  2. JENKINS_DEBIAN_GLUE_VERSION=$(dpkg --list jenkins-debian-glue 2>/dev/null | awk '/^ii/ {print $3}')
  3. JENKINS_DEBIAN_GLUE_VERSION=${JENKINS_DEBIAN_GLUE_VERSION:-unidentified}
  4. # backwards compatibility, see PR#94
  5. if [ -z "${REPOSITORY:-}" ] ; then
  6. repository_is_missing_in_env=true
  7. else
  8. repository_is_missing_in_env=false
  9. fi
  10. if [ -r /etc/jenkins/debian_glue ] ; then
  11. . /etc/jenkins/debian_glue
  12. fi
  13. # backwards compatibility, see PR#94
  14. if [ -n "${REPOSITORY:-}" ] && $repository_is_missing_in_env ; then
  15. echo "*** WARNING: 'REPOSITORY' set in /etc/jenkins/debian_glue but should be DEFAULT_REPOSITORY ***"
  16. echo "*** WARNING: Setting DEFAULT_REPOSITORY to $REPOSITORY for backwards compatibility ***"
  17. echo "*** WARNING: Please replace REPOSITORY=... in /etc/jenkins/debian_glue with DEFAULT_REPOSITORY=... ***"
  18. DEFAULT_REPOSITORY="${REPOSITORY}"
  19. fi
  20. if [ -z "${DEFAULT_REPOSITORY:-}" ] ; then
  21. echo "*** Repository variable DEFAULT_REPOSITORY is unset, using default [$DEFAULT_REPOSITORY] ***"
  22. DEFAULT_REPOSITORY='/srv/repository'
  23. fi
  24. # REPOSITORY can overwrite DEFAULT_REPOSITORY, so define only if unset
  25. if [ -z "${REPOSITORY:-}" ] ; then
  26. REPOSITORY="${DEFAULT_REPOSITORY}"
  27. echo "*** Repository variable REPOSITORY is unset, using default [$REPOSITORY] ***"
  28. fi
  29. # support usage of a reprepro wrapper
  30. REPREPRO_CMD="${REPREPRO_CMD:-reprepro}"
  31. if [ -z "${REPREPRO_OPTS:-}" ] ; then
  32. REPREPRO_OPTS='--waitforlock 1000 -v'
  33. fi
  34. LOGFILE=$(mktemp)
  35. bailout() {
  36. [ -n "${1:-}" ] && EXITCODE="$1" || EXITCODE=1
  37. rm -f "$LOGFILE"
  38. exit $EXITCODE
  39. }
  40. usage() {
  41. echo "$0
  42. Listing options for packages:
  43. --list-package <package> List repositories which provide specified package (source + binary)
  44. --list-binary-package <package> List repositories which provide specified package (binary only)
  45. --list-source-package <package> List repositories which provide specified package (source only)
  46. Listing options for repositories (known as Codenames in reprepro!):
  47. --list-repos <repos> List all packages (binary + source) registered in specified repository
  48. --list-binary-repos <repos> List all binary packages registered in specified repository
  49. --list-source-repos <repos> List all source packages registered in specified repository
  50. Configuration options:
  51. --repository </some/directory/> Use specified directory as base path
  52. Validation options:
  53. --validate-source-bin-versions Make sure source packages match with binary package versions.
  54. --validate-incoming Make sure there are no leftover files in incoming repositories.
  55. --validate-skip-package <packages> List of source packages to skip.
  56. --version-remove-epoch Remove epoch from package version
  57. Misc options:
  58. --help Display this help screen.
  59. --version Display program version.
  60. "
  61. }
  62. validate-incoming() {
  63. rc=0
  64. if ! [ -r "${REPOSITORY}/conf/incoming" ] ; then
  65. echo "No incoming repository in ${REPOSITORY} found. Nothing to be done."
  66. return 0
  67. fi
  68. for directory in $(awk '/IncomingDir: / {print $2}' "${REPOSITORY}/conf/incoming") ; do
  69. incoming="${REPOSITORY}/${directory}"
  70. if ! [ -d "$incoming" ] ; then
  71. echo "Directory $incoming of registered incoming repository does not exist, skipping."
  72. continue
  73. fi
  74. echo "Checking for leftover files in incoming directory ${incoming}:"
  75. if find "${incoming}" -type f | grep '.' ; then
  76. echo "Leftover files found. Needs investigation."
  77. rc=1
  78. else
  79. echo "Nothing found. Good."
  80. fi
  81. done
  82. return $rc
  83. }
  84. _remove_epoch() {
  85. if [[ "$1" =~ ^[[:digit:]]+:(.*) ]] ; then
  86. echo "${BASH_REMATCH[1]}"
  87. else
  88. echo "$1"
  89. fi
  90. }
  91. _skip_package() {
  92. local p
  93. for p in $1; do
  94. [[ $p = $2 ]] && return 0
  95. done
  96. return 1
  97. }
  98. validate-source-bin-versions() {
  99. rc=0
  100. for repository in $(awk '/^Codename: / {print $2}' "${REPOSITORY}"/conf/distributions 2>"${LOGFILE}") ; do
  101. for sourcepackage in $(${REPREPRO_CMD} $REPREPRO_OPTS -A source -b "${REPOSITORY}" --list-format='${package}\n' list $repository 2>"${LOGFILE}") ; do
  102. if $_opt_validate_skip_package && _skip_package "${SKIP_PACKAGE}" "$sourcepackage" ; then
  103. echo "skipping: $sourcepackage"
  104. continue
  105. fi
  106. sourceversion=$(${REPREPRO_CMD} $REPREPRO_OPTS -A source -b "${REPOSITORY}" --list-format='${version}\n' list $repository $sourcepackage 2>"${LOGFILE}")
  107. for binarypackage in $(${REPREPRO_CMD} $REPREPRO_OPTS -b "${REPOSITORY}" --list-format='${package}\n' -T deb listfilter "$repository" "\$Source (==$sourcepackage)" 2>"${LOGFILE}") ; do
  108. if $_opt_validate_skip_package && _skip_package "${SKIP_PACKAGE}" "$binarypackage" ; then
  109. echo "skipping: $binarypackage"
  110. continue
  111. fi
  112. archversion=$(${REPREPRO_CMD} $REPREPRO_OPTS -A amd64 -b "${REPOSITORY}" --list-format='${version}\n' list $repository $binarypackage 2>"${LOGFILE}")
  113. if $_opt_version_remove_epoch ; then
  114. sourceversion=$(_remove_epoch $sourceversion)
  115. archversion=$(_remove_epoch $archversion)
  116. fi
  117. if [ -z "$archversion" ] && [ -n "$sourceversion" ] ; then
  118. echo "Warning: package $binarypackage in repository $repository has sourceversion $sourceversion but lacks archversion"
  119. rc=1
  120. continue
  121. fi
  122. if [ -z "$sourceversion" ] && [ -n "$archversion" ] ; then
  123. echo "Warning: package $binarypackage in repository $repository has archversion $archversion but lacks sourceversion"
  124. rc=1
  125. continue
  126. fi
  127. if ! [[ "$sourceversion" == "$archversion" ]] ; then
  128. echo "Mismatch in repo $repository with ${binarypackage}: arch version [${archversion}] vs. sourceversion [$sourceversion]"
  129. rc=1
  130. continue
  131. fi
  132. done
  133. done
  134. done
  135. return $rc
  136. }
  137. trap bailout SIGHUP SIGINT SIGQUIT SIGABRT SIGKILL SIGALRM SIGTERM
  138. # command line handling
  139. CMDLINE_OPTS=list-package:,list-binary-package:,list-binary-repos:,list-repos:,list-source-package:,list-source-repos:,repository:,,help,validate-incoming,validate-source-bin-versions,version,version-remove-epoch,validate-skip-package:
  140. _opt_temp=$(getopt --name repository_checker -o +vhV --long $CMDLINE_OPTS -- "$@")
  141. if [ $? -ne 0 ]; then
  142. echo "Try '$0 --help' for more information." >& 2
  143. exit 1
  144. fi
  145. eval set -- "$_opt_temp"
  146. # defaults
  147. _opt_list_binary_package=false
  148. _opt_list_binary_repos=false
  149. _opt_list_packages=false
  150. _opt_list_repos=false
  151. _opt_list_source_package=false
  152. _opt_list_source_repos=false
  153. _opt_validate_source_bin_versions=false
  154. _opt_validate_incoming=false
  155. _opt_version_remove_epoch=false
  156. _opt_validate_skip_package=false
  157. while :; do
  158. case "$1" in
  159. --list-package)
  160. shift; _opt_list_packages=true ; PACKAGE="$1"
  161. ;;
  162. --list-binary-package)
  163. shift; _opt_list_binary_package=true; PACKAGE="$1"
  164. ;;
  165. --list-binary-repos)
  166. shift; _opt_list_binary_repos=true; REPOS="$1"
  167. ;;
  168. --list-repos)
  169. shift; _opt_list_repos=true; REPOS="$1"
  170. ;;
  171. --list-source-package)
  172. shift; _opt_list_source_package=true; PACKAGE="$1"
  173. ;;
  174. --list-source-repos)
  175. shift; _opt_list_source_repos=true; REPOS="$1"
  176. ;;
  177. --repository)
  178. shift; REPOSITORY="$1"
  179. ;;
  180. --help)
  181. usage ; exit 0;
  182. ;;
  183. --validate-incoming)
  184. _opt_validate_incoming=true
  185. ;;
  186. --validate-source-bin-versions)
  187. _opt_validate_source_bin_versions=true
  188. ;;
  189. --version)
  190. echo "$0 version $JENKINS_DEBIAN_GLUE_VERSION"; exit 0;
  191. ;;
  192. --version-remove-epoch)
  193. _opt_version_remove_epoch=true
  194. ;;
  195. --validate-skip-package)
  196. shift; _opt_validate_skip_package=true ; SKIP_PACKAGE="$1"
  197. ;;
  198. --)
  199. shift; break
  200. ;;
  201. *)
  202. echo "Internal getopt error! $1" >&2
  203. exit 1
  204. ;;
  205. esac
  206. shift
  207. done
  208. # sanity checks
  209. if ! [ -r "${REPOSITORY}"/conf/distributions ] ; then
  210. echo "Error: reprepro configuration ${REPOSITORY}/conf/distributions can not be read." >&2
  211. bailout 1
  212. fi
  213. # main execution
  214. if $_opt_list_packages ; then
  215. ${REPREPRO_CMD} ${REPREPRO_OPTS} -b "${REPOSITORY}" ls "${PACKAGE}"
  216. bailout 0
  217. fi
  218. if $_opt_list_source_package ; then
  219. ${REPREPRO_CMD} ${REPREPRO_OPTS} -b "${REPOSITORY}" -A source ls "${PACKAGE}"
  220. bailout 0
  221. fi
  222. if $_opt_list_binary_package ; then
  223. ${REPREPRO_CMD} ${REPREPRO_OPTS} -b "${REPOSITORY}" -T deb ls "${PACKAGE}"
  224. bailout 0
  225. fi
  226. if $_opt_list_repos ; then
  227. ${REPREPRO_CMD} ${REPREPRO_OPTS} -b "${REPOSITORY}" list "${REPOS}"
  228. bailout 0
  229. fi
  230. if $_opt_list_source_repos ; then
  231. ${REPREPRO_CMD} ${REPREPRO_OPTS} -b "${REPOSITORY}" -A source list "${REPOS}"
  232. bailout 0
  233. fi
  234. if $_opt_list_binary_repos ; then
  235. ${REPREPRO_CMD} ${REPREPRO_OPTS} -b "${REPOSITORY}" -T deb list "${REPOS}"
  236. bailout 0
  237. fi
  238. if $_opt_validate_source_bin_versions ; then
  239. validate-source-bin-versions
  240. bailout $?
  241. fi
  242. if $_opt_validate_incoming ; then
  243. validate-incoming
  244. bailout $?
  245. fi
  246. usage >&2
  247. bailout 1
  248. # vim:foldmethod=marker ts=2 ft=sh ai expandtab sw=2