Tools for building 32-bit archlinux packages from archlinux.org's official, 64-bit tested PKGBUILDs et al.

return-assignment 37KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. #!/bin/sh
  2. # report back on a build assignment
  3. # either on success via:
  4. # "$0 $package $revision $mod_revision $repository $arch $sub_pkgrel" and tar'ed packages and logs
  5. # (= a tar of package(s), signature(s) and log(s)) on stdin
  6. # or on failure via:
  7. # "$0 $package $revision $mod_revision $repository $arch ERROR" and tar'ed logs
  8. # or to abort:
  9. # "$0 ABORT"
  10. # exit codes:
  11. # 0: ok
  12. # 1: another instance was already running
  13. # 2: outdated package
  14. # 3: signature error
  15. # 4: package error (e.g. wrong packages sent)
  16. # 5: wrong number of arguments
  17. # TODO: sign database
  18. # TODO: it would be nice to check for broken packages (and old broken
  19. # packages?) if they are flagged out-of-date upstream
  20. # shellcheck disable=SC2119,SC2120
  21. # shellcheck source=../lib/load-configuration
  22. . "${0%/*}/../lib/load-configuration"
  23. if [ -s "${work_dir}/build-master-sanity" ]; then
  24. >&2 echo 'Build master is not sane.'
  25. exit 1
  26. fi
  27. # aborting does not need any locks
  28. if [ $# -eq 1 ] && \
  29. [ "$1" = 'ABORT' ]; then
  30. old_pkgbase=$(
  31. # shellcheck disable=SC2016
  32. {
  33. printf 'SELECT `package_sources`.`pkgbase`'
  34. printf ' FROM `build_slaves`'
  35. mysql_join_build_slaves_build_assignments
  36. mysql_join_build_assignments_package_sources
  37. # shellcheck disable=SC2154
  38. printf ' WHERE `build_slaves`.`id`=%s;\n' \
  39. "${slave_id}"
  40. printf 'UPDATE `build_slaves`'
  41. printf ' SET `build_slaves`.`currently_building`=NULL'
  42. # shellcheck disable=SC2154
  43. printf ' WHERE `build_slaves`.`id`=%s;\n' \
  44. "${slave_id}"
  45. } | \
  46. mysql_run_query 'unimportant'
  47. )
  48. if [ -z "${old_pkgbase}" ]; then
  49. >&2 printf 'Umm, nothing to abort for your.\n'
  50. else
  51. >&2 printf 'I aborted your build-assignment (%s).\n' \
  52. "${old_pkgbase}"
  53. fi
  54. exit
  55. fi
  56. if [ $# -ne 6 ]; then
  57. >&2 printf 'return-assignment: Wrong number of arguments (%s)\n' \
  58. "$#"
  59. >&2 printf 'call either:\n'
  60. >&2 printf ' return-assignment ABORT\n'
  61. >&2 printf ' return-assignment pkgbase git_revision mod_git_revision repository arch ERROR\n'
  62. >&2 printf ' return-assignment pkgbase git_revision mod_git_revision repository arch sub-pkgrel\n'
  63. exit 5
  64. fi
  65. # Create a lock file and a trap.
  66. exec 9> "${build_list_lock_file}"
  67. if ! verbose_flock -n 9; then
  68. >&2 echo 'come back (shortly) later - I cannot lock build list.'
  69. exit 1
  70. fi
  71. exec 8> "${sanity_check_lock_file}"
  72. if ! verbose_flock -s -n 8; then
  73. >&2 echo 'come back (shortly) later - sanity-check running.'
  74. exit 1
  75. fi
  76. clean_up_tmp_dir() {
  77. cd "${base_dir}"
  78. rm -rf --one-file-system "${tmp_dir}"
  79. }
  80. tmp_dir=$(mktemp -d "${work_dir}/tmp.return-assignment.XXXXXXXXXX")
  81. trap clean_up_tmp_dir EXIT
  82. if [ "$6" = 'ERROR' ]; then
  83. # the build failed on the build slave
  84. # shellcheck disable=SC2016
  85. infos=$(
  86. {
  87. printf 'SELECT DISTINCT'
  88. printf ' `build_assignments`.`id`,'
  89. printf 'IF(`build_assignments`.`is_broken`,"true","false")'
  90. printf ' FROM `build_slaves`'
  91. mysql_join_build_slaves_build_assignments
  92. mysql_join_build_assignments_package_sources
  93. mysql_join_package_sources_upstream_repositories
  94. mysql_join_build_assignments_binary_packages
  95. mysql_join_binary_packages_binary_packages_in_repositories
  96. printf ' JOIN `architecture_compatibilities`'
  97. printf ' ON `architecture_compatibilities`.`fully_compatible`'
  98. printf ' AND `architecture_compatibilities`.`built_for`=`build_assignments`.`architecture`'
  99. printf ' JOIN `architectures`'
  100. printf ' ON `architecture_compatibilities`.`runs_on`=`architectures`.`id`'
  101. printf ' WHERE `build_slaves`.`id`=from_base64("%s")' \
  102. "$(
  103. # shellcheck disable=SC2154
  104. printf '%s' "${slave_id}" | \
  105. base64 -w0
  106. )"
  107. printf ' AND `package_sources`.`%s`=from_base64("%s")' \
  108. 'pkgbase' "$(printf '%s' "$1" | base64 -w0)" \
  109. 'git_revision' "$(printf '%s' "$2" | base64 -w0)" \
  110. 'mod_git_revision' "$(printf '%s' "$3" | base64 -w0)"
  111. printf ' AND `upstream_repositories`.`name`=from_base64("%s")' \
  112. "$(printf '%s' "$4" | base64 -w0)"
  113. printf ' AND `architectures`.`name`=from_base64("%s")' \
  114. "$(printf '%s' "$5" | base64 -w0)"
  115. printf ' AND `binary_packages_in_repositories`.`repository`=%s;\n' \
  116. "${repository_ids__any_build_list}"
  117. } | \
  118. mysql_run_query | \
  119. tr '\t' ' '
  120. )
  121. if [ -z "${infos}" ]; then
  122. >&2 echo 'You do not build this package (anymore) - move on.'
  123. exit 2
  124. fi
  125. was_broken_before="${infos##* }"
  126. build_assignment_id="${infos%% *}"
  127. # save sent build logs
  128. saved_build_logs=$(
  129. tar -vx \
  130. -C "${build_log_directory}/error" \
  131. --wildcards \
  132. --no-wildcards-match-slash \
  133. --transform="s|^|$1.$2.$3.$4.$5.|" \
  134. '*.build-log.gz'
  135. )
  136. # shellcheck disable=SC2016
  137. {
  138. if [ -n "${saved_build_logs}" ]; then
  139. printf 'CREATE TEMPORARY TABLE `failures` ('
  140. printf '`%s` %s,' \
  141. 'date' 'TIMESTAMP' \
  142. 'reason' 'SMALLINT' \
  143. 'log_file' 'VARCHAR(512)' | \
  144. sed 's/,$//'
  145. printf ');\n'
  146. fail_reason_identifiers=$(
  147. {
  148. printf 'SELECT `fail_reasons`.`id`,replace(to_base64(`fail_reasons`.`identifier`),"\\n","")'
  149. printf ' FROM `fail_reasons` ORDER BY `fail_reasons`.`severity`'
  150. } | \
  151. mysql_run_query
  152. )
  153. for saved_build_log in ${saved_build_logs}; do
  154. printf '%s\n' "${fail_reason_identifiers}" | \
  155. while read -r reason_id identifier; do
  156. if zgrep -qx "\s*$(
  157. printf '%s' "${identifier}" | \
  158. base64 -d
  159. )\s*" \
  160. "${build_log_directory}/error/$1.$2.$3.$4.$5.${saved_build_log}"; then
  161. printf ' (from_base64("%s"),%s,from_base64("%s")),' \
  162. "$(
  163. printf '%s' "${saved_build_log}" | \
  164. sed 's|\.build-log\.gz$||;s|^.*\.||' | \
  165. base64 -w0
  166. )" \
  167. "${reason_id}" \
  168. "$(
  169. printf '%s' "$1.$2.$3.$4.$5.${saved_build_log}" | \
  170. base64 -w0
  171. )"
  172. break
  173. fi
  174. done
  175. done | \
  176. sed '
  177. 1 s/^/INSERT IGNORE INTO `failures` (`date`,`reason`,`log_file`) VALUES /
  178. s/,$/;\n/
  179. '
  180. printf 'INSERT IGNORE INTO `failed_builds` (`build_slave`,`build_assignment`,`date`,`reason`,`log_file`,`log_file_exists`)'
  181. printf ' SELECT '
  182. printf 'from_base64("%s"),' \
  183. "$(printf '%s' "${slave_id}" | base64 -w0)" \
  184. "$(printf '%s' "${build_assignment_id}" | base64 -w0)"
  185. printf '`failures`.`%s`,' \
  186. 'date' 'reason' 'log_file'
  187. printf '1'
  188. printf ' FROM `failures`;\n'
  189. printf 'DROP TEMPORARY TABLE `failures`;\n'
  190. printf 'COMMIT;\n'
  191. fi
  192. printf 'UPDATE `build_assignments`'
  193. printf ' SET `build_assignments`.`is_broken`=1,'
  194. printf '`build_assignments`.`priority`=0'
  195. printf ' WHERE `build_assignments`.`id`=from_base64("%s");\n' \
  196. "$(
  197. printf '%s' "${build_assignment_id}" | \
  198. base64 -w0
  199. )"
  200. printf 'COMMIT;\n'
  201. printf 'UPDATE `build_slaves`'
  202. printf ' SET `build_slaves`.`currently_building`=NULL,'
  203. printf ' `build_slaves`.`last_action`=NULL,'
  204. printf ' `build_slaves`.`logged_lines`=NULL,'
  205. printf ' `build_slaves`.`trials`=NULL'
  206. printf ' WHERE `build_slaves`.`id`=from_base64("%s");\n' \
  207. "$(
  208. printf '%s' "${slave_id}" | \
  209. base64 -w0
  210. )"
  211. } | \
  212. mysql_run_query
  213. if ! ${was_broken_before}; then
  214. mysql_load_min_and_max_versions
  215. # this will hold a list of "$build_time $haskell_package $version"
  216. # meaning that the given $haskell_package with version $version did
  217. # not work at $build_time
  218. # note, that $build_time is only considered when $architecture or
  219. # $version are unavailable
  220. find "${build_log_directory}/error" -type f \
  221. -name "$1.$2.$3.$4.$5.*.build-log.gz" \
  222. -exec zgrep -qF "$(
  223. printf '%s\n' \
  224. 'The following packages are broken because other packages they depend on are missing. These broken packages must be rebuilt before they can be used.' \
  225. 'mismatched interface file versions (wanted ' \
  226. )" {} \; \
  227. -printf '%p\n' | \
  228. sed '
  229. s/^.*\.\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\)\.build-log\.gz$/\1 \0/
  230. ' | \
  231. while read -r build_time build_log; do
  232. build_time=$(
  233. date +%s -d"${build_time}"
  234. )
  235. zcat "${build_log}" | \
  236. sed -n '
  237. /^Packages ([0-9]\+) /,/^\s*$/ p
  238. ' | \
  239. tr ' ' '\n' | \
  240. sed '
  241. 1,2 d
  242. /^\s*$/d
  243. p
  244. s/^haskell-//
  245. t
  246. d
  247. ' | \
  248. sort -u | \
  249. sed '
  250. s/-\(\([0-9]\+\):\)\?\([^-:]\+\)-\([^-.]\+\)\(\.\([^-.]\+\)\)\?$/ \2 \3 \4 \6/
  251. s/ $/ 0/
  252. s/ / 0 /g
  253. ' > \
  254. "${tmp_dir}/installed-versions"
  255. zcat "${build_log}" | \
  256. sed '
  257. s/^installed package \(.*\) is broken due to missing package .*$/\1/
  258. t
  259. s@^.*Bad interface file: /usr/lib/ghc-[0-9.]\+/site-local/\([^/]\+\)-[0-9.]\+/.*$@\1@
  260. t
  261. d
  262. ' | \
  263. tr ' ' '\n' | \
  264. tr '[:upper:]' '[:lower:]' | \
  265. sed '
  266. s/^/'"${build_time}"' /
  267. s/-[0-9.]\+$//
  268. ' | \
  269. sort -u | \
  270. sort -k2,2 > \
  271. "${tmp_dir}/broken-packages"
  272. {
  273. cut -d' ' -f1 < \
  274. "${tmp_dir}/installed-versions" | \
  275. sed 'p'
  276. cut -d' ' -f2 < \
  277. "${tmp_dir}/broken-packages"
  278. } | \
  279. sort | \
  280. uniq -u | \
  281. sed '
  282. s/$/ '"${max_version%%:*}"' '"${max_version#*:}"' 0 0/
  283. ' | \
  284. sponge -a "${tmp_dir}/installed-versions"
  285. sort -k1,1 < \
  286. "${tmp_dir}/installed-versions" | \
  287. sponge "${tmp_dir}/installed-versions"
  288. join -1 2 -2 1 \
  289. "${tmp_dir}/broken-packages" \
  290. "${tmp_dir}/installed-versions"
  291. done | \
  292. sort -k2 -k1nr,1 | \
  293. uniq -f1 | \
  294. tr ' ' '\t' > \
  295. "${tmp_dir}/broken-packages-with-version"
  296. # now we look if the broken packages have been rebuilt in the meantime
  297. haskell_rebuild_packages=$(
  298. # shellcheck disable=SC2016
  299. {
  300. printf 'CREATE TEMPORARY TABLE `broken`('
  301. printf '`time_stamp` BIGINT,'
  302. printf '`pkgname` VARCHAR(64),'
  303. printf '`epoch` MEDIUMINT,'
  304. printf '`pkgver` VARCHAR(64),'
  305. printf '`pkgrel` MEDIUMINT,'
  306. printf '`sub_pkgrel` MEDIUMINT,'
  307. printf 'KEY `time_stamp`(`time_stamp`),'
  308. printf 'KEY `pkgname`(`pkgname`),'
  309. printf 'KEY `epoch`(`epoch`),'
  310. printf 'KEY `pkgver`(`pkgver`),'
  311. printf 'KEY `pkgrel`(`pkgrel`),'
  312. printf 'KEY `sub_pkgrel`(`sub_pkgrel`),'
  313. printf 'UNIQUE KEY `pkgfile`(`pkgname`,`epoch`,`pkgver`,`pkgrel`,`sub_pkgrel`)'
  314. printf ');\n'
  315. printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `broken`(' \
  316. "${tmp_dir}/broken-packages-with-version"
  317. printf '`%s`,' \
  318. 'pkgname' \
  319. 'time_stamp' \
  320. 'epoch' \
  321. 'pkgver' \
  322. 'pkgrel' \
  323. 'sub_pkgrel' | \
  324. sed 's/,$//'
  325. printf ');\n'
  326. printf 'SELECT DISTINCT `broken`.`pkgname`'
  327. printf ' FROM `broken`'
  328. printf ' WHERE NOT EXISTS ('
  329. printf 'SELECT *'
  330. printf ' FROM `binary_packages`'
  331. mysql_join_binary_packages_binary_packages_in_repositories
  332. mysql_join_binary_packages_in_repositories_repositories
  333. printf ' AND ('
  334. printf '`repositories`.`is_on_master_mirror`'
  335. printf ' OR `repositories`.`id`=%s' \
  336. "${repository_ids__any_build_list}"
  337. printf ')'
  338. mysql_join_binary_packages_build_assignments
  339. printf ' JOIN `architecture_compatibilities`'
  340. printf ' ON `architecture_compatibilities`.`fully_compatible`'
  341. printf ' AND `architecture_compatibilities`.`built_for`=`build_assignments`.`architecture`'
  342. printf ' JOIN `architectures`'
  343. printf ' ON `architecture_compatibilities`.`runs_on`=`architectures`.`id`'
  344. printf ' AND `architectures`.`name`=from_base64("%s")' \
  345. "$(
  346. printf '%s' "$5" | \
  347. base64 -w0
  348. )"
  349. printf ' WHERE ('
  350. printf '`binary_packages`.`pkgname`=`broken`.`pkgname`'
  351. printf ' OR `binary_packages`.`pkgname`=CONCAT("haskell-",`broken`.`pkgname`)'
  352. printf ') AND ('
  353. printf '`build_assignments`.`return_date`>FROM_UNIXTIME(`broken`.`time_stamp`)'
  354. printf ' OR ('
  355. printf '`binary_packages`.`epoch`>`broken`.`epoch`'
  356. printf ' OR ('
  357. printf '`binary_packages`.`epoch`=`broken`.`epoch`'
  358. printf ' AND `binary_packages`.`pkgver`>`broken`.`pkgver`'
  359. printf ')'
  360. printf ' OR ('
  361. printf '`binary_packages`.`epoch`=`broken`.`epoch`'
  362. printf ' AND `binary_packages`.`pkgver`=`broken`.`pkgver`'
  363. printf ' AND `binary_packages`.`pkgrel`>`broken`.`pkgrel`'
  364. printf ')'
  365. printf ' OR ('
  366. printf '`binary_packages`.`epoch`=`broken`.`epoch`'
  367. printf ' AND `binary_packages`.`pkgver`=`broken`.`pkgver`'
  368. printf ' AND `binary_packages`.`pkgrel`=`broken`.`pkgrel`'
  369. printf ' AND `binary_packages`.`sub_pkgrel`>`broken`.`sub_pkgrel`'
  370. printf ')'
  371. printf ')'
  372. printf ' OR `repositories`.`id`=%s' \
  373. "${repository_ids__any_build_list}"
  374. printf ')'
  375. printf ');\n'
  376. } | \
  377. mysql_run_query | \
  378. sed '
  379. s/^/-p ^(haskell-)?/
  380. s/$/$/
  381. '
  382. )
  383. # release lock on build-list - otherwise seed-build-list won't run
  384. flock -u 9
  385. rescheduled_packages=$(
  386. if [ -n "${haskell_rebuild_packages}" ]; then
  387. # shellcheck disable=SC2086
  388. "${base_dir}/bin/seed-build-list" ${haskell_rebuild_packages} | \
  389. sed 's/ .*$//'
  390. fi
  391. )
  392. # prioritize _this_ build assignment iff we rescheduled any broken dependencies
  393. if [ -n "${rescheduled_packages}" ]; then
  394. # shellcheck disable=SC2016
  395. {
  396. printf 'UPDATE `build_assignments`'
  397. printf ' SET `build_assignments`.`priority`=('
  398. printf 'SELECT MAX(`build_assignments`.`priority`)'
  399. printf ' FROM `build_assignments`'
  400. printf ')+1'
  401. printf ' WHERE `build_assignments`.`id`=from_base64("%s");\n' \
  402. "$(
  403. printf '%s' "${build_assignment_id}" | \
  404. base64 -w0
  405. )"
  406. } | \
  407. mysql_run_query
  408. fi
  409. # shellcheck disable=SC2119
  410. {
  411. printf '%s/%s ' \
  412. "$5" \
  413. "$1"
  414. if [ "${1%s}s" = "$1" ]; then
  415. printf 'are'
  416. else
  417. printf 'is'
  418. fi
  419. # shellcheck disable=SC2154
  420. printf ' broken (says %s)' \
  421. "${slave}"
  422. if [ "$1" = 'electron' ] || [ "$1" = 'electron2' ]; then
  423. printf -- ' - as usual'
  424. fi
  425. if [ -n "${rescheduled_packages}" ]; then
  426. printf -- ' - I rescheduled:'
  427. # shellcheck disable=SC2086
  428. printf ' %s,' ${rescheduled_packages} | \
  429. sed 's/,$//'
  430. fi
  431. printf ': https://archlinux32.org/buildmaster/build-log.php?a=%s&p=%s\n' \
  432. "$5" \
  433. "$1"
  434. } | \
  435. irc_say
  436. fi
  437. exit 0
  438. fi
  439. # the build was successful on the build slave
  440. # so we also need a lock on the package database
  441. exec 7> "${package_database_lock_file}"
  442. if ! verbose_flock -n 7; then
  443. >&2 echo 'come back (shortly) later - I cannot lock package database.'
  444. exit 1
  445. fi
  446. # shellcheck disable=SC2016
  447. build_assignment_id=$(
  448. {
  449. printf 'SELECT DISTINCT `build_assignments`.`id`'
  450. printf ' FROM `build_slaves`'
  451. mysql_join_build_slaves_build_assignments
  452. mysql_join_build_assignments_package_sources
  453. mysql_join_package_sources_upstream_repositories
  454. mysql_join_build_assignments_binary_packages
  455. mysql_join_binary_packages_binary_packages_in_repositories
  456. printf ' JOIN `architecture_compatibilities`'
  457. printf ' ON `build_assignments`.`architecture`=`architecture_compatibilities`.`built_for`'
  458. printf ' AND `architecture_compatibilities`.`fully_compatible`'
  459. printf ' JOIN `architectures`'
  460. printf ' ON `architecture_compatibilities`.`runs_on`=`architectures`.`id`'
  461. printf ' WHERE `build_slaves`.`id`=from_base64("%s")' \
  462. "$(
  463. # shellcheck disable=SC2154
  464. printf '%s' "${slave_id}" | \
  465. base64 -w0
  466. )"
  467. printf ' AND `package_sources`.`%s`=from_base64("%s")' \
  468. 'pkgbase' "$(
  469. printf '%s' "$1" | \
  470. base64 -w0
  471. )" \
  472. 'git_revision' "$(
  473. printf '%s' "$2" | \
  474. base64 -w0
  475. )" \
  476. 'mod_git_revision' "$(
  477. printf '%s' "$3" | \
  478. base64 -w0
  479. )"
  480. printf ' AND `upstream_repositories`.`name`=from_base64("%s")' \
  481. "$(
  482. printf '%s' "$4" | \
  483. base64 -w0
  484. )"
  485. printf ' AND `architectures`.`name`=from_base64("%s")' \
  486. "$(
  487. printf '%s' "$5" | \
  488. base64 -w0
  489. )"
  490. printf ' AND `binary_packages_in_repositories`.`repository`=%s' \
  491. "${repository_ids__any_build_list}"
  492. printf ' AND `binary_packages`.`sub_pkgrel`=from_base64("%s");\n' \
  493. "$(
  494. printf '%s' "$6" | \
  495. base64 -w0
  496. )"
  497. } | \
  498. mysql_run_query | \
  499. tr '\t' ' '
  500. )
  501. if [ -z "${build_assignment_id}" ]; then
  502. >&2 echo 'Sorry, the sent package is outdated.'
  503. exit 2
  504. fi
  505. cd "${tmp_dir}"
  506. export TMPDIR="${tmp_dir}"
  507. # extract package(s)
  508. tar -x \
  509. --wildcards \
  510. --no-wildcards-match-slash \
  511. '*.pkg.tar.xz' \
  512. '*.pkg.tar.xz.sig' \
  513. '*.pkg.tar.xz-namcap.log.gz' \
  514. '*.pkg.tar.xz.so.needs.gz' \
  515. '*.pkg.tar.xz.so.provides.gz'
  516. # check if all packages come with:
  517. # - a package file
  518. # - a signature
  519. # - a namcap log
  520. # - a list of needed libraries
  521. # - a list of provided libraries
  522. missing_files=$(
  523. find . -maxdepth 1 \( \
  524. \( \
  525. -name '*.pkg.tar.xz' \
  526. -printf '%f package\n' \
  527. \) -o \
  528. \( \
  529. -name '*.pkg.tar.xz.sig' \
  530. -printf '%f signature\n' \
  531. \) -o \
  532. \( \
  533. -name '*.pkg.tar.xz-namcap.log.gz' \
  534. -printf '%f namcap\n' \
  535. \) -o \
  536. \( \
  537. -name '*.pkg.tar.xz.so.needs.gz' \
  538. -printf '%f needed-libraries\n' \
  539. \) -o \
  540. \( \
  541. -name '*.pkg.tar.xz.so.provides.gz' \
  542. -printf '%f provided-libraries\n' \
  543. \) \
  544. \) | \
  545. sed '
  546. s/\(\.pkg\.tar\.xz\)\(\.sig\|\(-namcap\.log\|\.so\.\(provides\|needs\)\)\.gz\) /\1 /
  547. ' | \
  548. sort -k1,1 -k2,2 | \
  549. sed '
  550. :a
  551. $!N
  552. s/^\(\(\S\+\) [^\n]\+\)\n\2 /\1 /
  553. ta
  554. P
  555. D
  556. ' | \
  557. sed -n '
  558. s/$/ /
  559. / package /!{
  560. h
  561. s/^\(\S\+\) .*$/Package "\1" is missing./
  562. p
  563. g
  564. }
  565. / signature /!{
  566. h
  567. s/^\(\S\+\) .*$/Signature of "\1" is missing./
  568. p
  569. g
  570. }
  571. / namcap /!{
  572. h
  573. s/^\(\S\+\) .*$/Namcap log of "\1" is missing./
  574. p
  575. g
  576. }
  577. / needed-libraries /!{
  578. h
  579. s/^\(\S\+\) .*$/List of libraries needed by "\1" is missing./
  580. p
  581. g
  582. }
  583. / provided-libraries /!{
  584. h
  585. s/^\(\S\+\) .*$/List of libraries provided by "\1" is missing./
  586. p
  587. g
  588. }
  589. '
  590. )
  591. if [ -n "${missing_files}" ]; then
  592. >&2 echo 'The following packages lack a signature, namcap log, package file or list of needed/provided libraries:'
  593. printf 'Your buildslave "%s" uploaded some incomplete package(s):\n' \
  594. "${slave}" | \
  595. irc_say "${operator}"
  596. printf '%s\n' "${missing_files}" | \
  597. irc_say "${operator}" 'copy' >&2
  598. exit 3
  599. fi
  600. # check if the signatures are valid
  601. signatures=$(
  602. find . -maxdepth 1 -name '*.pkg.tar.xz' \
  603. -printf 'package file %f\n' \
  604. -exec gpg --batch --status-fd 1 -q --homedir /etc/pacman.d/gnupg --verify '{}.sig' '{}' \; 2> /dev/null
  605. )
  606. if [ -z "$(
  607. printf '%s\n' "${signatures}" | \
  608. cut -d' ' -f2 | \
  609. grep -x 'file\|TRUST_FULLY' | \
  610. sort | \
  611. uniq -c | \
  612. awk '{print $1}' | \
  613. uniq -d
  614. )" ]; then
  615. >&2 echo 'Signature(s) is/are not fully trusted:'
  616. printf 'Your buildslave "%s" uploaded a package with a not fully-trusted signature:\n' \
  617. "${slave}" | \
  618. irc_say "${operator}"
  619. printf '%s\n' "${signatures}" | \
  620. irc_say "${operator}" 'copy' >&2
  621. exit 3
  622. fi
  623. # check if the package maintainer is set
  624. errors=$(
  625. find . -maxdepth 1 -name '*.pkg.tar.xz' | \
  626. while read -r pkg; do
  627. tar -OxJf "${pkg}" '.BUILDINFO' 2>/dev/null | \
  628. grep -vxF 'packager = Unknown Packager' | \
  629. grep -q '^packager = ' || \
  630. printf '%s misses a valid packager.\n' \
  631. "${pkg##*/}"
  632. done
  633. )
  634. if [ -n "${errors}" ]; then
  635. >&2 echo 'Packager error(s):'
  636. printf 'Your buildslave "%s" uploaded package(s) with invalid packager:\n' \
  637. "${slave}" | \
  638. irc_say "${operator}"
  639. printf '%s\n' "${errors}" | \
  640. irc_say "${operator}" 'copy' >&2
  641. exit 3
  642. fi
  643. # check if the sent packages are the expected ones
  644. find . -maxdepth 1 -name '*.pkg.tar.xz' -printf '%f\n' > \
  645. "${tmp_dir}/packages"
  646. # shellcheck disable=SC2016
  647. {
  648. printf 'SELECT'
  649. printf ' `binary_packages`.`id`,'
  650. mysql_package_name_query
  651. printf ' FROM `binary_packages`'
  652. mysql_join_binary_packages_architectures
  653. mysql_join_binary_packages_binary_packages_in_repositories
  654. printf ' WHERE `binary_packages`.`build_assignment`=from_base64("%s")' \
  655. "$(
  656. printf '%s' "${build_assignment_id}" | \
  657. base64 -w0
  658. )"
  659. printf ' AND `binary_packages_in_repositories`.`repository`=%s' \
  660. "${repository_ids__any_build_list}"
  661. printf ';\n'
  662. } | \
  663. mysql_run_query | \
  664. tr '\t' ' ' | \
  665. sort -k2 > \
  666. "${tmp_dir}/package-ids"
  667. package_errors=$(
  668. {
  669. sed '
  670. s|^|was_built: |
  671. ' "${tmp_dir}/packages"
  672. sed '
  673. s|^[0-9]\+ |expected: |
  674. ' "${tmp_dir}/package-ids"
  675. } | \
  676. sort -k2 | \
  677. uniq -u -f1
  678. )
  679. if [ -n "${package_errors}" ]; then
  680. >&2 echo 'The following packages should have been built but are missing or vice versa:'
  681. >&2 printf '%s\n' "${package_errors}"
  682. {
  683. printf 'Your buildslave "%s" uploaded the wrong package(s):\n' \
  684. "${slave}"
  685. printf '%s\n' "${package_errors}"
  686. } | \
  687. irc_say "${operator}"
  688. exit 4
  689. fi
  690. if [ ! -s "${tmp_dir}/package-ids" ]; then
  691. >&2 echo 'No package was expected, no package was built.'
  692. >&2 echo 'That should not happen!'
  693. exit 4
  694. fi
  695. # TODO: maybe, we should not put "any" packages into repositories of all
  696. # architectures at once, but wait until they can actually be installed
  697. # on that architecture? (They might be missing an architecture specific
  698. # dependency)
  699. # shellcheck disable=SC2016
  700. {
  701. printf 'SELECT `binary_packages`.`id`,'
  702. mysql_package_name_query
  703. printf ',`t`.`id`,`t_a`.`name`,`t`.`name`'
  704. printf ' FROM `build_assignments`'
  705. mysql_join_build_assignments_binary_packages
  706. mysql_join_binary_packages_binary_packages_in_repositories
  707. printf ' AND `binary_packages_in_repositories`.`repository`=%s' \
  708. "${repository_ids__any_build_list}"
  709. mysql_join_binary_packages_architectures
  710. mysql_join_build_assignments_package_sources
  711. mysql_join_package_sources_upstream_repositories
  712. mysql_join_upstream_repositories_repository_moves
  713. printf ' JOIN `repositories` as `t`'
  714. printf ' ON `t`.`id`=`repository_moves`.`to_repository`'
  715. mysql_join_repositories_architectures 't' 't_a'
  716. printf ' JOIN `architecture_compatibilities`'
  717. printf ' ON `architecture_compatibilities`.`built_for`=`binary_packages`.`architecture`'
  718. printf ' AND `architecture_compatibilities`.`runs_on`=`t`.`architecture`'
  719. printf ' AND `architecture_compatibilities`.`fully_compatible`'
  720. printf ' WHERE `repository_moves`.`from_repository`=%s' \
  721. "${repository_ids__any_build_list}"
  722. printf ' AND `build_assignments`.`id`=from_base64("%s");\n' \
  723. "$(
  724. printf '%s' "${build_assignment_id}" | \
  725. base64 -w0
  726. )"
  727. } | \
  728. mysql_run_query | \
  729. tr '\t' ' ' | \
  730. sort -u > \
  731. "${tmp_dir}/repository-ids"
  732. errors=$(
  733. {
  734. cut -d' ' -f2 < \
  735. "${tmp_dir}/repository-ids" | \
  736. sort -u | \
  737. sed 's/^/repository-was-found: /'
  738. cut -d' ' -f2 < \
  739. "${tmp_dir}/package-ids" | \
  740. sort -u | \
  741. sed 's/^/package-was-sent: /'
  742. } | \
  743. sort -k2 | \
  744. uniq -uf1
  745. )
  746. if [ -n "${errors}" ]; then
  747. >&2 echo 'I cannot determine, where this package (or some part of it)'
  748. >&2 echo 'should be published:'
  749. >&2 printf '%s\n' "${errors}"
  750. >&2 echo 'This is some internal error and not (necessarily) your fault.'
  751. # We give a temporary error (although resolving this needs manual
  752. # intervention), because there is nothing wrong with the sent package
  753. # whence it does not need to be built again, but can simply be sent again.
  754. exit 1
  755. fi
  756. mysql_load_min_and_max_versions
  757. while read -r package_id package_name; do
  758. # move namcap.logs
  759. mv \
  760. "${tmp_dir}/${package_name}-namcap.log.gz" \
  761. "${build_log_directory}/success/"
  762. # generate checksum
  763. sha512sum "${tmp_dir}/${package_name}" | \
  764. awk '{print "'"${package_id}"'\t" $1}' >> \
  765. "${tmp_dir}/sha512sums"
  766. # generate list of required/provided libraries
  767. for lib in 'provides' 'needs'; do
  768. zcat "${tmp_dir}/${package_name}.so.${lib}.gz" | \
  769. sed '
  770. s/\(=\|<\|<=\|>=\|>\)\([^[:space:]-]\+\)$/\t\1\t\2/
  771. t
  772. h
  773. s/$/\t>=\t'"${min_version}"'/
  774. '"$(
  775. if [ "${lib}" = 'provides' ]; then
  776. printf '%s\n' \
  777. 'p' \
  778. 'g' \
  779. 's/$/\t<=\t'"${max_version}"'/'
  780. fi
  781. )" | \
  782. sed '
  783. s/\(\s[0-9]\+\):\(\S\+\)$/\1\t\2/
  784. t coda
  785. s/\s\S\+$/\t0\0/
  786. :coda
  787. s/^/'"${package_id}"'\tlink\t/
  788. ' >> "${tmp_dir}/${lib}"
  789. done
  790. # generate list of make-,check-,rundepends according to .PKGINFO
  791. extract_dependencies_from_package \
  792. "${tmp_dir}/${package_name}" \
  793. | sed 's/^/'"${package_id}"' /' \
  794. | tr ' ' '\t' \
  795. >> "${tmp_dir}/needs"
  796. # TODO: this makes sense for provide= entries in .PKGINFO, too
  797. done < \
  798. "${tmp_dir}/package-ids"
  799. # move packages
  800. cut -d' ' -f4,5 "${tmp_dir}/repository-ids" | \
  801. sort -u | \
  802. while read -r arch repo; do
  803. mkdir -p "${arch}/${repo}"
  804. failsafe_rsync \
  805. "${master_mirror_rsync_directory}/${arch}/${repo}/${repo}.db."* \
  806. "${master_mirror_rsync_directory}/${arch}/${repo}/${repo}.files."* \
  807. "${arch}/${repo}/"
  808. grep " $(str_to_regex "${arch} ${repo}")\$" "${tmp_dir}/repository-ids" | \
  809. cut -d' ' -f2 | \
  810. xargs -r repo-add "${arch}/${repo}/${repo}.db.tar.gz"
  811. # xargs -r repo-add -v -s -k "${repo_key}" "${destination}.db.tar.gz"
  812. done
  813. # upload the packages into /pool
  814. failsafe_rsync -c --copy-dest=/.transfer \
  815. ./*".pkg.tar.xz" \
  816. ./*".pkg.tar.xz.sig" \
  817. "${master_mirror_rsync_directory}/pool/"
  818. # create symlinks
  819. find . \( -name '*.pkg.tar.xz' -o -name '*.pkg.tar.xz.sig' \) -printf '%f\n' | \
  820. while read -r file; do
  821. rm "${file}"
  822. ln -s "../../pool/${file}" "${file}"
  823. done
  824. # upload the database and the symlinks into /$arch/$repo
  825. cut -d' ' -f4,5 "${tmp_dir}/repository-ids" | \
  826. sort -u | \
  827. while read -r arch repo; do
  828. recompress_gz \
  829. "${tmp_dir}" \
  830. "${arch}/${repo}/${repo}."*".tar.gz" \
  831. "${arch}/${repo}/${repo}."*".tar.gz.old"
  832. # shellcheck disable=SC2046
  833. failsafe_rsync \
  834. "${arch}/${repo}/${repo}.db."* \
  835. "${arch}/${repo}/${repo}.files."* \
  836. $(
  837. grep " $(str_to_regex "${arch} ${repo}")\$" "${tmp_dir}/repository-ids" | \
  838. cut -d' ' -f2 | \
  839. sed '
  840. s,^,./,
  841. p
  842. s/$/.sig/
  843. '
  844. ) \
  845. "${master_mirror_rsync_directory}/${arch}/${repo}/"
  846. done
  847. # shellcheck disable=SC2016
  848. {
  849. # insert checksums into database
  850. printf 'CREATE TEMPORARY TABLE `pkg_hashes` (`pkgid` BIGINT, `sha512sum` VARCHAR(128));\n'
  851. printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `pkg_hashes`;\n' \
  852. "${tmp_dir}/sha512sums"
  853. printf 'UPDATE `binary_packages`'
  854. printf ' JOIN `pkg_hashes`'
  855. printf ' ON `pkg_hashes`.`pkgid`=`binary_packages`.`id`'
  856. printf ' SET `binary_packages`.`sha512sum`=`pkg_hashes`.`sha512sum`;\n'
  857. printf 'COMMIT;\n'
  858. # insert provided/needed libraries into database
  859. for lib_link in 'pl:provides' 'nl:needs'; do
  860. printf 'CREATE TEMPORARY TABLE `%s` (' \
  861. "${lib_link%:*}"
  862. printf '`pkgid` BIGINT,'
  863. if [ "${lib_link}" = 'nl:needs' ]; then
  864. printf '`dep_type` VARCHAR(32),'
  865. fi
  866. printf '`lib` VARCHAR(128),'
  867. printf '`relation` VARCHAR(2),'
  868. printf '`epoch` MEDIUMINT,'
  869. printf '`version` VARCHAR(32)'
  870. printf ');\n'
  871. printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `%s`;\n' \
  872. "${tmp_dir}/${lib_link#*:}" "${lib_link%:*}"
  873. printf 'INSERT IGNORE INTO `install_targets` (`name`)'
  874. printf ' SELECT DISTINCT `%s`.`lib`' \
  875. "${lib_link%:*}"
  876. printf ' FROM `%s`;\n' \
  877. "${lib_link%:*}"
  878. printf 'COMMIT;\n'
  879. # TODO: possibly remove install_target_providers with less restrictive
  880. # versions than we have now
  881. printf 'INSERT IGNORE INTO `versions` (`epoch`,`version`)'
  882. printf ' SELECT DISTINCT `%s`.`epoch`,`%s`.`version`' \
  883. "${lib_link%:*}" "${lib_link%:*}"
  884. printf ' FROM `%s`;\n' \
  885. "${lib_link%:*}"
  886. printf 'COMMIT;\n'
  887. if [ "${lib_link%:*}" = 'pl' ]; then
  888. printf 'INSERT IGNORE INTO `install_target_providers` (`package`,`install_target`,`install_target_is_group`,`version`)'
  889. else
  890. # clear out the old dependencies - we will add the ones from the built package
  891. printf 'DELETE `dependencies`'
  892. printf ' FROM `nl`'
  893. printf ' JOIN `dependencies`'
  894. printf ' ON `dependencies`.`depending_on`=`nl`.`pkgid`;\n'
  895. printf 'INSERT IGNORE INTO `dependencies` (`dependent`,`depending_on`,`dependency_type`,`version_relation`,`version`)'
  896. fi
  897. printf ' SELECT `%s`.`pkgid`,`install_targets`.`id`,' \
  898. "${lib_link%:*}"
  899. if [ "${lib_link%:*}" = 'nl' ]; then
  900. printf '`dependency_types`.`id`,'
  901. printf '`%s`.`relation`,' \
  902. "${lib_link%:*}"
  903. else
  904. printf '0,'
  905. fi
  906. printf '`versions`.`id`'
  907. printf ' FROM `install_targets`'
  908. printf ' JOIN `%s`' \
  909. "${lib_link%:*}"
  910. printf ' ON `%s`.`lib`=`install_targets`.`name`' \
  911. "${lib_link%:*}"
  912. if [ "${lib_link%:*}" = 'nl' ]; then
  913. printf ' JOIN `dependency_types`'
  914. printf ' ON `dependency_types`.`name`=`nl`.`dep_type`'
  915. fi
  916. printf ' JOIN `versions`'
  917. printf ' ON `versions`.`epoch`=`%s`.`epoch`' \
  918. "${lib_link%:*}"
  919. printf ' AND `versions`.`version`=`%s`.`version`' \
  920. "${lib_link%:*}"
  921. printf ';\n'
  922. printf 'COMMIT;\n'
  923. done
  924. # remove build_assignment's markers
  925. printf 'UPDATE `build_assignments`'
  926. printf ' SET'
  927. printf ' `build_assignments`.`is_broken`=0,'
  928. printf ' `build_assignments`.`priority`=0,'
  929. printf ' `build_assignments`.`return_date`=NOW()'
  930. printf ' WHERE `build_assignments`.`id`=from_base64("%s");\n' \
  931. "$(
  932. printf '%s' "${build_assignment_id}" | \
  933. base64 -w0
  934. )"
  935. printf 'COMMIT;\n'
  936. # insert into appropriate repositories and retrieve ids
  937. while read -r package_id _ repository_id _; do
  938. printf 'INSERT INTO `binary_packages_in_repositories` (`package`,`repository`,`is_to_be_deleted`) VALUES '
  939. printf '(%s,%s,0)' \
  940. "${package_id}" "${repository_id}"
  941. printf ' ON DUPLICATE KEY UPDATE `id`=LAST_INSERT_ID(`binary_packages_in_repositories`.`id`);\n'
  942. printf 'SELECT LAST_INSERT_ID();\n'
  943. done < \
  944. "${tmp_dir}/repository-ids"
  945. printf 'COMMIT;\n'
  946. # reschedule toolchain packages if they were not fully unblocked
  947. printf 'INSERT IGNORE INTO `binary_packages` ('
  948. printf '`build_assignment`,'
  949. printf '`epoch`,'
  950. printf '`pkgver`,'
  951. printf '`pkgrel`,'
  952. printf '`has_issues`,'
  953. printf '`is_tested`,'
  954. printf '`pkgname`,'
  955. printf '`architecture`,'
  956. printf '`sub_pkgrel`)'
  957. printf ' SELECT '
  958. printf '`binary_packages`.`%s`,' \
  959. 'build_assignment' \
  960. 'epoch' \
  961. 'pkgver' \
  962. 'pkgrel' \
  963. 'has_issues' \
  964. 'is_tested' \
  965. 'pkgname' \
  966. 'architecture'
  967. printf '`binary_packages`.`sub_pkgrel`+1'
  968. printf ' FROM `binary_packages`'
  969. printf ' JOIN `pkg_hashes`'
  970. printf ' ON `pkg_hashes`.`pkgid`=`binary_packages`.`id`'
  971. mysql_join_binary_packages_build_assignments
  972. mysql_join_build_assignments_package_sources
  973. printf ' JOIN `toolchain_order` AS `late`'
  974. printf ' ON `late`.`pkgbase`=`package_sources`.`pkgbase`'
  975. printf ' JOIN `toolchain_order` AS `early`'
  976. printf ' ON `early`.`number`<`late`.`number`'
  977. printf ' AND `early`.`pkgbase`!=`late`.`pkgbase`'
  978. printf ' JOIN `package_sources` AS `early_ps`'
  979. printf ' ON `early`.`pkgbase`=`early_ps`.`pkgbase`'
  980. mysql_join_package_sources_build_assignments 'early_ps' 'early_ba'
  981. mysql_join_build_assignments_binary_packages 'early_ba' 'early_bp'
  982. printf ' WHERE ('
  983. printf '`early_bp`.`architecture`=`binary_packages`.`architecture`'
  984. # shellcheck disable=SC2154
  985. printf ' OR `%s`.`architecture`=%s' \
  986. 'early_bp' "${architecture_ids__any}" \
  987. 'binary_packages' "${architecture_ids__any}"
  988. printf ') AND NOT EXISTS ('
  989. printf 'SELECT 1'
  990. printf ' FROM `binary_packages` AS `early_bp`'
  991. mysql_join_binary_packages_binary_packages_in_repositories 'early_bp' 'early_bpir'
  992. mysql_join_binary_packages_in_repositories_repositories 'early_bpir' 'early_r'
  993. printf ' WHERE `early_r`.`is_on_master_mirror`'
  994. printf ' AND `early_bp`.`build_assignment`=`early_ba`.`id`'
  995. printf ');\n'
  996. join_part=$(
  997. printf ' JOIN `pkg_hashes`'
  998. printf ' ON `built_bp`.`id`=`pkg_hashes`.`pkgid`'
  999. printf ' JOIN `binary_packages` AS `new_bp`'
  1000. printf ' ON'
  1001. printf ' `built_bp`.`%s`=`new_bp`.`%s` AND' \
  1002. 'build_assignment' 'build_assignment' \
  1003. 'epoch' 'epoch' \
  1004. 'pkgver' 'pkgver' \
  1005. 'pkgrel' 'pkgrel' \
  1006. 'has_issues' 'has_issues' \
  1007. 'is_tested' 'is_tested' \
  1008. 'pkgname' 'pkgname' \
  1009. 'architecture' 'architecture'
  1010. printf ' `built_bp`.`sub_pkgrel`+1=`new_bp`.`sub_pkgrel`'
  1011. )
  1012. printf 'INSERT IGNORE INTO `binary_packages_in_repositories`'
  1013. printf ' (`package`,`repository`,`is_to_be_deleted`)'
  1014. printf ' SELECT `new_bp`.`id`,%s,0' \
  1015. "${repository_ids__any_build_list}"
  1016. printf ' FROM `binary_packages` AS `built_bp`'
  1017. printf '%s;\n' "${join_part}"
  1018. printf 'INSERT IGNORE INTO `dependencies`'
  1019. printf ' (`dependent`,`depending_on`,`dependency_type`,`version`,`version_relation`)'
  1020. printf ' SELECT `new_bp`.`id`'
  1021. printf ',`dependencies`.`%s`' \
  1022. 'depending_on' \
  1023. 'dependency_type' \
  1024. 'version' \
  1025. 'version_relation'
  1026. printf ' FROM `dependencies`'
  1027. mysql_join_dependencies_binary_packages '' 'built_bp'
  1028. printf '%s;\n' "${join_part}"
  1029. # TODO: set version and install_target_providers, too
  1030. printf 'INSERT IGNORE INTO `install_target_providers`'
  1031. printf ' (`package`,`install_target`)'
  1032. printf ' SELECT `new_bp`.`id`,`install_target_providers`.`install_target`'
  1033. printf ' FROM `install_target_providers`'
  1034. mysql_join_install_target_providers_binary_packages '' 'built_bp'
  1035. printf '%s;\n' "${join_part}"
  1036. # remove from build-list
  1037. printf 'DELETE `binary_packages_in_repositories`'
  1038. printf ' FROM `binary_packages_in_repositories`'
  1039. printf ' JOIN `pkg_hashes`'
  1040. printf ' ON `pkg_hashes`.`pkgid`=`binary_packages_in_repositories`.`package`'
  1041. printf ' WHERE `binary_packages_in_repositories`.`repository`=%s;\n' \
  1042. "${repository_ids__any_build_list}"
  1043. printf 'COMMIT;\n'
  1044. # update package information
  1045. printf 'UPDATE `binary_packages`'
  1046. printf ' SET'
  1047. printf ' `binary_packages`.`has_issues`=0,'
  1048. printf ' `binary_packages`.`is_tested`=0'
  1049. printf ' WHERE `binary_packages`.`id` IN ('
  1050. cut -d' ' -f1 < \
  1051. "${tmp_dir}/package-ids" | \
  1052. base64_encode_each | \
  1053. sed '
  1054. s/^/from_base64("/
  1055. s/$/"),/
  1056. $ s/,$//
  1057. '
  1058. printf ');\n'
  1059. printf 'COMMIT;\n'
  1060. # remove from build slave's `currently_building`
  1061. printf 'UPDATE `build_slaves`'
  1062. printf ' SET `build_slaves`.`currently_building`=NULL,'
  1063. printf ' `build_slaves`.`last_action`=NULL,'
  1064. printf ' `build_slaves`.`logged_lines`=NULL,'
  1065. printf ' `build_slaves`.`trials`=NULL'
  1066. printf ' WHERE `build_slaves`.`currently_building`=from_base64("%s");\n' \
  1067. "$(
  1068. printf '%s' "${build_assignment_id}" | \
  1069. base64 -w0
  1070. )"
  1071. printf 'COMMIT;\n'
  1072. # remove broken loops
  1073. printf 'CREATE TEMPORARY TABLE `loops_to_delete` (`loop` MEDIUMINT);\n'
  1074. printf 'INSERT IGNORE INTO `loops_to_delete`'
  1075. printf ' SELECT `build_dependency_loops`.`loop`'
  1076. printf ' FROM `build_dependency_loops`'
  1077. mysql_join_build_dependency_loops_binary_packages
  1078. mysql_join_binary_packages_binary_packages_in_repositories
  1079. printf ' WHERE NOT `binary_packages_in_repositories`.`repository`=%s;\n' \
  1080. "${repository_ids__any_build_list}"
  1081. printf 'COMMIT;\n'
  1082. printf 'DELETE FROM `build_dependency_loops`'
  1083. printf ' WHERE EXISTS ('
  1084. printf 'SELECT 1'
  1085. printf ' FROM `loops_to_delete`'
  1086. printf ' WHERE `loops_to_delete`.`loop`=`build_dependency_loops`.`loop`'
  1087. printf ');\n'
  1088. printf 'DROP TEMPORARY TABLE `loops_to_delete`;\n'
  1089. } | \
  1090. mysql_run_query | \
  1091. sort -u | \
  1092. remove_old_package_versions
  1093. trigger_mirror_refreshs