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

bootstrap-mysql 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. #!/bin/sh
  2. # shellcheck disable=SC2119,SC2120
  3. # shellcheck source=../lib/load-configuration
  4. . "${0%/*}/../lib/load-configuration"
  5. exec 9> "${build_list_lock_file}"
  6. if ! verbose_flock -n 9; then
  7. >&2 echo 'Cannot get build-list lock.'
  8. exit 1
  9. fi
  10. exec 8> "${sanity_check_lock_file}"
  11. if ! verbose_flock -s -n 9; then
  12. >&2 echo 'Cannot get sanity-check lock.'
  13. exit 1
  14. fi
  15. exec 7> "${package_database_lock_file}"
  16. if ! verbose_flock -s -n 7; then
  17. >&2 echo 'Cannot get package-database lock.'
  18. exit 1
  19. fi
  20. #shellcheck disable=SC2016
  21. {
  22. # calculate_maximal_moveable_set
  23. # stores results in `moveable_bpir` and `replaced_bpir`
  24. # Give a maximal list of packages to be moved, while implementing the
  25. # condition from db-update:
  26. # Every package which is replaced[1], must have its provided install_targets:
  27. # a) provided by another moved or not-replaced package or
  28. # b) not required by any not-replaced package.
  29. # Every package being moved needs to have all dependencies
  30. # installable in the target repository.
  31. printf 'DELIMITER //\n'
  32. printf 'DROP PROCEDURE IF EXISTS `calculate_maximal_moveable_set`//\n'
  33. printf 'CREATE PROCEDURE `calculate_maximal_moveable_set`('
  34. printf 'IN `arch_id` MEDIUMINT,'
  35. printf 'IN `from_stability` MEDIUMINT'
  36. printf ')\n'
  37. printf 'BEGIN\n'
  38. # variable to store count of changed rows
  39. printf 'DECLARE row_count_saved INT DEFAULT 0;\n'
  40. for copy in '' '_copy' '_copy2'; do
  41. printf 'DROP TEMPORARY TABLE IF EXISTS `%s_bpir%s`;\n' \
  42. 'moveable' "${copy}" \
  43. 'replaced' "${copy}"
  44. printf 'CREATE TEMPORARY TABLE `replaced_bpir%s` (`id` BIGINT, `replaced_by` BIGINT, UNIQUE KEY (`id`));\n' \
  45. "${copy}"
  46. if [ "${copy}" = '_copy2' ]; then
  47. continue
  48. fi
  49. printf 'CREATE TEMPORARY TABLE `moveable_bpir%s` (`id` BIGINT, `to_repository` MEDIUMINT, UNIQUE KEY (`id`));\n' \
  50. "${copy}"
  51. done
  52. # TODO: `package_blobs` needs too much space!
  53. printf 'DROP TEMPORARY TABLE IF EXISTS `package_blobs`;\n'
  54. printf 'CREATE TEMPORARY TABLE `package_blobs` (`ps_a` BIGINT, `ps_b` BIGINT, UNIQUE KEY `content` (`ps_a`,`ps_b`));\n'
  55. # all packages being vaguely relevant enter `package_blobs`, because
  56. # they might block any other package from moving
  57. printf 'INSERT IGNORE INTO `package_blobs` (`ps_a`,`ps_b`)'
  58. printf ' SELECT `a_ps`.`id`,`b_ps`.`id`'
  59. printf ' FROM `package_sources` AS `a_ps`'
  60. printf ' JOIN `package_sources` AS `b_ps`'
  61. printf ' ON UNIX_TIMESTAMP(`a_ps`.`commit_time`) - UNIX_TIMESTAMP(`b_ps`.`commit_time`) BETWEEN -10 AND 10'
  62. printf ' AND `a_ps`.`commit_time`!="0000-00-00 00:00:00"'
  63. printf ' AND `b_ps`.`commit_time`!="0000-00-00 00:00:00"'
  64. mysql_join_package_sources_build_assignments 'a_ps' 'a_ba'
  65. mysql_join_package_sources_build_assignments 'b_ps' 'b_ba'
  66. mysql_join_build_assignments_binary_packages 'a_ba' 'a_bp'
  67. mysql_join_build_assignments_binary_packages 'b_ba' 'b_bp'
  68. mysql_join_binary_packages_binary_packages_in_repositories 'a_bp' 'a_bpir'
  69. mysql_join_binary_packages_in_repositories_repositories 'a_bpir' 'a_r'
  70. mysql_join_binary_packages_binary_packages_in_repositories 'b_bp' 'b_bpir'
  71. mysql_join_binary_packages_in_repositories_repositories 'b_bpir' 'b_r'
  72. printf ' WHERE `a_r`.`stability` = `from_stability`'
  73. printf ' AND `a_r`.`architecture` = `arch_id`'
  74. printf ' AND `b_r`.`stability` = `from_stability`'
  75. printf ' AND `b_r`.`architecture` = `arch_id`;\n'
  76. # these packages are considered for moving:
  77. printf 'INSERT IGNORE INTO `moveable_bpir` (`id`,`to_repository`)'
  78. printf ' SELECT `binary_packages_in_repositories`.`id`,`repository_moves`.`to_repository`'
  79. printf ' FROM `binary_packages_in_repositories`'
  80. mysql_join_binary_packages_in_repositories_binary_packages
  81. mysql_join_binary_packages_in_repositories_repositories
  82. mysql_join_repositories_repository_stabilities
  83. mysql_join_binary_packages_build_assignments
  84. mysql_join_build_assignments_package_sources
  85. mysql_join_package_sources_upstream_repositories
  86. mysql_join_upstream_repositories_repository_moves
  87. printf ' AND `repository_moves`.`from_repository`=`binary_packages_in_repositories`.`repository`'
  88. # correct stability: "testing"/"staging" - as chosen
  89. printf ' WHERE `repository_stabilities`.`id`=`from_stability`'
  90. printf ' AND `repositories`.`architecture`=`arch_id`'
  91. printf ' AND ('
  92. # this should not be replaced by ${repository_stability_ids__staging},
  93. # because it may change
  94. printf '`repository_stabilities`.`name`="staging"'
  95. # "testing" packages must be tested
  96. printf ' OR `binary_packages`.`is_tested`'
  97. printf ')'
  98. # no open issues
  99. printf ' AND NOT `binary_packages`.`has_issues`'
  100. printf ';\n'
  101. # add all considered packages, so we move split packages together, too
  102. printf 'INSERT IGNORE INTO `package_blobs` (`ps_a`,`ps_b`)'
  103. printf ' SELECT `package_sources`.`id`,`package_sources`.`id`'
  104. printf ' FROM `package_sources`'
  105. mysql_join_package_sources_build_assignments
  106. mysql_join_build_assignments_binary_packages
  107. mysql_join_binary_packages_binary_packages_in_repositories
  108. mysql_join_binary_packages_in_repositories_repositories
  109. printf ' WHERE `repositories`.`stability`=`from_stability`'
  110. printf ' AND `repositories`.`architecture`=`arch_id`;\n'
  111. # these packages are considered for being replaced:
  112. # for each moved package
  113. printf 'INSERT IGNORE INTO `replaced_bpir` (`id`,`replaced_by`)'
  114. printf ' SELECT `r_bpir`.`id`,`m_bpir`.`id`'
  115. printf ' FROM `moveable_bpir`'
  116. printf ' JOIN `binary_packages_in_repositories` AS `m_bpir`'
  117. printf ' ON `m_bpir`.`id`=`moveable_bpir`.`id`'
  118. mysql_join_binary_packages_in_repositories_binary_packages 'm_bpir' 'm_bp'
  119. # in all repositories more stable than its target repository
  120. printf ' JOIN `repositories` AS `m_to_r`'
  121. printf ' ON `moveable_bpir`.`to_repository`=`m_to_r`.`id`'
  122. printf ' JOIN `repository_stability_relations` AS `rsr`'
  123. printf ' ON `rsr`.`less_stable`=`m_to_r`.`stability`'
  124. printf ' JOIN `repositories` AS `r_r`'
  125. printf ' ON `rsr`.`more_stable`=`r_r`.`stability`'
  126. printf ' AND `r_r`.`architecture`=`m_to_r`.`architecture`'
  127. mysql_join_repositories_binary_packages_in_repositories 'r_r' 'r_bpir'
  128. mysql_join_binary_packages_in_repositories_binary_packages 'r_bpir' 'r_bp'
  129. # all packages with identical names
  130. printf ' AND `r_bp`.`pkgname`=`m_bp`.`pkgname`;\n'
  131. # create copies of our temporary tables *yuck*
  132. for table in 'replaced' 'moveable'; do
  133. for copy in '' '2'; do
  134. if [ "${table}" = 'moveable' ] && \
  135. [ "${copy}" = '2' ]; then
  136. continue
  137. fi
  138. printf 'DELETE FROM `%s_bpir_copy%s`;\n' "${table}" "${copy}"
  139. printf 'INSERT IGNORE INTO `%s_bpir_copy%s`' "${table}" "${copy}"
  140. printf ' SELECT `%s_bpir`.*' "${table}"
  141. printf ' FROM `%s_bpir`;\n' "${table}"
  142. done
  143. done
  144. # only the least stable of equally named to-be-replaced packages is
  145. # kept
  146. printf 'DELETE `replaced_bpir`'
  147. printf ' FROM `replaced_bpir`'
  148. printf ' JOIN `binary_packages_in_repositories` AS `not_r_bpir`'
  149. printf ' ON `not_r_bpir`.`id`=`replaced_bpir`.`id`'
  150. mysql_join_binary_packages_in_repositories_binary_packages 'not_r_bpir' 'not_r_bp'
  151. mysql_join_binary_packages_in_repositories_repositories 'not_r_bpir' 'not_r_r'
  152. printf ' JOIN `binary_packages` AS `r_bp`'
  153. printf ' ON `r_bp`.`pkgname`=`not_r_bp`.`pkgname`'
  154. printf ' AND `r_bp`.`id`!=`not_r_bp`.`id`'
  155. mysql_join_binary_packages_binary_packages_in_repositories 'r_bp' 'r_bpir'
  156. printf ' JOIN `replaced_bpir_copy`'
  157. printf ' ON `r_bpir`.`id`=`replaced_bpir_copy`.`id`'
  158. mysql_join_binary_packages_in_repositories_repositories 'r_bpir' 'r_r'
  159. printf ' AND `not_r_r`.`architecture`=`r_r`.`architecture`'
  160. printf ' JOIN `repository_stability_relations` AS `rsr`'
  161. printf ' ON `rsr`.`less_stable`=`r_r`.`stability`'
  162. printf ' AND `rsr`.`more_stable`=`not_r_r`.`stability`;\n'
  163. # now we delete all unreplaceable and unmoveable packages from the respective
  164. # list until no further changes are required, e.g. until all packages are
  165. # moveable or replaceable respectively
  166. printf 'REPEAT\n'
  167. printf 'SET row_count_saved = 0;\n'
  168. # create copies of our temporary tables *yuck*
  169. for table in 'replaced' 'moveable'; do
  170. for copy in '' '2'; do
  171. if [ "${table}" = 'moveable' ] && \
  172. [ "${copy}" = '2' ]; then
  173. continue
  174. fi
  175. printf 'DELETE FROM `%s_bpir_copy%s`;\n' "${table}" "${copy}"
  176. printf 'INSERT IGNORE INTO `%s_bpir_copy%s`' "${table}" "${copy}"
  177. printf ' SELECT `%s_bpir`.*' "${table}"
  178. printf ' FROM `%s_bpir`;\n' "${table}"
  179. done
  180. done
  181. # a package is not moveable if its dependencies are not provided ...
  182. printf 'DELETE `replaced_bpir`,`moveable_bpir`'
  183. printf ' FROM `replaced_bpir`'
  184. printf ' RIGHT JOIN `moveable_bpir`'
  185. printf ' ON `moveable_bpir`.`id`=`replaced_bpir`.`replaced_by`'
  186. printf ' JOIN `binary_packages_in_repositories`'
  187. printf ' ON `binary_packages_in_repositories`.`id`=`moveable_bpir`.`id`'
  188. printf ' JOIN `repositories` AS `target_repositories`'
  189. printf ' ON `moveable_bpir`.`to_repository`=`target_repositories`.`id`'
  190. mysql_join_binary_packages_in_repositories_binary_packages
  191. mysql_join_binary_packages_dependencies
  192. mysql_join_dependencies_dependency_types
  193. printf ' AND `dependency_types`.`relevant_for_binary_packages`'
  194. # ... by a not-deleted, "more stable" package already in place or ...
  195. printf ' WHERE NOT EXISTS ('
  196. printf 'SELECT 1'
  197. printf ' FROM `install_target_providers`'
  198. mysql_join_install_target_providers_binary_packages '' 'prov_bp'
  199. mysql_join_binary_packages_binary_packages_in_repositories 'prov_bp' 'prov_bpir'
  200. mysql_join_binary_packages_in_repositories_repositories 'prov_bpir' 'prov_r'
  201. printf ' JOIN `repository_stability_relations`'
  202. printf ' ON `prov_r`.`stability`=`repository_stability_relations`.`more_stable`'
  203. printf ' WHERE `install_target_providers`.`install_target`=`dependencies`.`depending_on`'
  204. printf ' AND `target_repositories`.`stability`=`repository_stability_relations`.`less_stable`'
  205. printf ' AND `target_repositories`.`architecture`=`prov_r`.`architecture`'
  206. # This assumes, the moved package which replaces the install-target-provider
  207. # will not be deleted from the moveable list. Note, that there is no greedy
  208. # way to find out wether that is the case or not - so we just assume,
  209. # it stays on the list.
  210. printf ' AND NOT EXISTS ('
  211. printf 'SELECT 1'
  212. printf ' FROM `replaced_bpir_copy`'
  213. printf ' WHERE `replaced_bpir_copy`.`id`=`prov_bpir`.`id`'
  214. printf ')'
  215. # ... by a moved package
  216. printf ') AND NOT EXISTS ('
  217. printf 'SELECT 1'
  218. printf ' FROM `install_target_providers`'
  219. mysql_join_install_target_providers_binary_packages_in_repositories '' 'itp_bpir'
  220. printf ' JOIN `moveable_bpir_copy`'
  221. printf ' ON `moveable_bpir_copy`.`id`=`itp_bpir`.`id`'
  222. printf ' WHERE `install_target_providers`.`install_target`=`dependencies`.`depending_on`'
  223. printf ');\n'
  224. printf 'SET row_count_saved = row_count_saved + ROW_COUNT();\n'
  225. # refresh copies of our temporary tables *yuck*
  226. for table in 'replaced' 'moveable'; do
  227. for copy in '' '2'; do
  228. if [ "${table}" = 'moveable' ] && \
  229. [ "${copy}" = '2' ]; then
  230. continue
  231. fi
  232. printf 'DELETE FROM `%s_bpir_copy%s`;\n' "${table}" "${copy}"
  233. printf 'INSERT IGNORE INTO `%s_bpir_copy%s`' "${table}" "${copy}"
  234. printf ' SELECT `%s_bpir`.*' "${table}"
  235. printf ' FROM `%s_bpir`;\n' "${table}"
  236. done
  237. done
  238. # TODO: we might want to deliberately break packages that fail(ed) to build
  239. # for quite some time
  240. # packages which should not be replaced: ones providing something that is:
  241. # a) still needed by a not-replaced package x "less stable" than the target repository and
  242. # b) not provided by:
  243. # 1) a moved package or
  244. # 2) any current, not-replaced package in a repository more stable than x's repository
  245. #
  246. # Note, that this is not 100% clean from an academic point of view:
  247. # It might require _downgrading_ of a package to keep fulfilling a dependency
  248. # and it might require to do so _without_ any chance for the user to notice,
  249. # because there may be more "dependencies" in the database than in the package files.
  250. #
  251. # However, in practice both should not happen.
  252. #
  253. printf 'DELETE `replaced_bpir`,`moveable_bpir`'
  254. printf ' FROM `replaced_bpir`'
  255. printf ' JOIN `moveable_bpir`'
  256. printf ' ON `replaced_bpir`.`replaced_by`=`moveable_bpir`.`id`'
  257. printf ' JOIN `binary_packages_in_repositories` AS `repl_bpir`'
  258. printf ' ON `repl_bpir`.`id`=`replaced_bpir`.`id`'
  259. mysql_join_binary_packages_in_repositories_install_target_providers 'repl_bpir'
  260. mysql_join_binary_packages_in_repositories_repositories 'repl_bpir' 'repl_r'
  261. mysql_join_install_target_providers_dependencies_with_versions
  262. printf ' AND NOT EXISTS ('
  263. # dependencies of replaced packages don't matter
  264. printf 'SELECT 1'
  265. printf ' FROM `replaced_bpir_copy`'
  266. printf ' JOIN `binary_packages_in_repositories` AS `repl_bpir_copy`'
  267. printf ' ON `repl_bpir_copy`.`id`=`replaced_bpir_copy`.`id`'
  268. mysql_join_binary_packages_in_repositories_repositories 'repl_bpir_copy' 'repl_r_copy'
  269. printf ' WHERE `repl_bpir_copy`.`package`=`dependencies`.`dependent`'
  270. printf ' AND `repl_r_copy`.`architecture`=`repl_r`.`architecture`'
  271. printf ')'
  272. mysql_join_dependencies_dependency_types
  273. # consider only runtime dependencies
  274. printf ' AND `dependency_types`.`relevant_for_binary_packages`'
  275. mysql_join_dependencies_binary_packages '' 'req_bp'
  276. # we need to check whether req_bp's dependency is (un)critical
  277. mysql_join_binary_packages_binary_packages_in_repositories 'req_bp' 'req_bpir'
  278. mysql_join_binary_packages_in_repositories_repositories 'req_bpir' 'req_r'
  279. printf ' AND `repl_r`.`architecture`=`req_r`.`architecture`'
  280. # dependent package is "less stable" than dependency
  281. printf ' JOIN `repository_stability_relations` AS `repl_rr`'
  282. printf ' ON `repl_rr`.`more_stable`=`repl_r`.`stability`'
  283. printf ' AND `repl_rr`.`less_stable`=`req_r`.`stability`'
  284. # a) ^
  285. printf ' WHERE NOT EXISTS ('
  286. # no moved package ...
  287. printf 'SELECT 1'
  288. printf ' FROM `moveable_bpir_copy`'
  289. printf ' JOIN `binary_packages_in_repositories` AS `subst_bpir`'
  290. printf ' ON `subst_bpir`.`id`=`moveable_bpir_copy`.`id`'
  291. mysql_join_binary_packages_in_repositories_install_target_providers 'subst_bpir' 'subst_itp'
  292. mysql_join_binary_packages_in_repositories_repositories 'subst_bpir' 'subst_r'
  293. # ... provides the same
  294. printf ' WHERE `subst_itp`.`install_target`=`install_target_providers`.`install_target`'
  295. printf ' AND `subst_r`.`architecture`=`repl_r`.`architecture`'
  296. # b) 1) ^
  297. printf ') AND NOT EXISTS ('
  298. # no current package ...
  299. printf 'SELECT 1'
  300. printf ' FROM `binary_packages_in_repositories` AS `subst_bpir`'
  301. mysql_join_binary_packages_in_repositories_install_target_providers 'subst_bpir' 'subst_itp'
  302. # ... in a repository ...
  303. mysql_join_binary_packages_in_repositories_repositories 'subst_bpir' 'subst_r'
  304. # ... more stable ...
  305. printf ' JOIN `repository_stability_relations` AS `subst_rr`'
  306. printf ' ON `subst_rr`.`more_stable`=`subst_r`.`stability`'
  307. # ... than x's repository ...
  308. printf ' WHERE `subst_rr`.`less_stable`=`repl_r`.`stability`'
  309. printf ' AND `subst_r`.`architecture`=`repl_r`.`architecture`'
  310. # (architecture check is not necessary, as repositories of different
  311. # architectures are not less or more stable than each other)
  312. printf ' AND NOT EXISTS ('
  313. # ... and which is not replaced ...
  314. printf 'SELECT 1'
  315. printf ' FROM `replaced_bpir_copy2`'
  316. printf ' WHERE `replaced_bpir_copy2`.`id`=`subst_bpir`.`id`'
  317. printf ')'
  318. # ... and provides the same
  319. printf ' AND `subst_itp`.`install_target`=`install_target_providers`.`install_target`'
  320. # b) 2) ^
  321. printf ');\n'
  322. printf 'SET row_count_saved = row_count_saved + ROW_COUNT();\n'
  323. # refresh copies of our temporary tables *yuck*
  324. for table in 'replaced' 'moveable'; do
  325. for copy in '' '2'; do
  326. if [ "${table}" = 'moveable' ] && \
  327. [ "${copy}" = '2' ]; then
  328. continue
  329. fi
  330. printf 'DELETE FROM `%s_bpir_copy%s`;\n' "${table}" "${copy}"
  331. printf 'INSERT IGNORE INTO `%s_bpir_copy%s`' "${table}" "${copy}"
  332. printf ' SELECT `%s_bpir`.*' "${table}"
  333. printf ' FROM `%s_bpir`;\n' "${table}"
  334. done
  335. done
  336. # remove all packages of a blob, where some part cannot be moved
  337. printf 'DELETE `replaced_bpir`,`moveable_bpir`'
  338. printf ' FROM `replaced_bpir`'
  339. printf ' RIGHT JOIN `moveable_bpir`'
  340. printf ' ON `replaced_bpir`.`replaced_by`=`moveable_bpir`.`id`'
  341. printf ' JOIN `binary_packages_in_repositories`'
  342. printf ' ON `binary_packages_in_repositories`.`id`=`moveable_bpir`.`id`'
  343. mysql_join_binary_packages_in_repositories_binary_packages
  344. mysql_join_binary_packages_build_assignments
  345. printf ' JOIN `package_blobs`'
  346. printf ' ON `build_assignments`.`package_source`=`package_blobs`.`ps_a`'
  347. printf ' JOIN `build_assignments` AS `bl_ba`'
  348. printf ' ON `bl_ba`.`package_source`=`package_blobs`.`ps_b`'
  349. printf ' AND `bl_ba`.`architecture`=`build_assignments`.`architecture`'
  350. mysql_join_build_assignments_binary_packages 'bl_ba' 'bl_bp'
  351. mysql_join_binary_packages_binary_packages_in_repositories 'bl_bp' 'bl_bpir'
  352. printf ' WHERE NOT EXISTS ('
  353. printf 'SELECT 1'
  354. printf ' FROM `moveable_bpir_copy`'
  355. printf ' WHERE `moveable_bpir_copy`.`id`=`bl_bpir`.`id`'
  356. printf ');\n'
  357. printf 'SET row_count_saved = row_count_saved + ROW_COUNT();\n'
  358. printf 'UNTIL row_count_saved=0\n'
  359. printf 'END REPEAT;\n'
  360. # we now need to remove the replaced_bpir which are not actually to be
  361. # replaced, but simply hidden
  362. # refresh copies of our temporary tables *yuck*
  363. for table in 'replaced' 'moveable'; do
  364. for copy in '' '2'; do
  365. if [ "${table}" = 'moveable' ] && \
  366. [ "${copy}" = '2' ]; then
  367. continue
  368. fi
  369. printf 'DELETE FROM `%s_bpir_copy%s`;\n' "${table}" "${copy}"
  370. printf 'INSERT IGNORE INTO `%s_bpir_copy%s`' "${table}" "${copy}"
  371. printf ' SELECT `%s_bpir`.*' "${table}"
  372. printf ' FROM `%s_bpir`;\n' "${table}"
  373. done
  374. done
  375. printf 'DELETE `replaced_bpir`'
  376. printf ' FROM `replaced_bpir`'
  377. printf ' JOIN `moveable_bpir`'
  378. printf ' ON `replaced_bpir`.`replaced_by`=`moveable_bpir`.`id`'
  379. printf ' JOIN `binary_packages_in_repositories` AS `r_bpir`'
  380. printf ' ON `replaced_bpir`.`id`=`r_bpir`.`id`'
  381. mysql_join_binary_packages_in_repositories_repositories 'r_bpir' 'r_r'
  382. printf ' JOIN `repositories` AS `m_to_r`'
  383. printf ' ON `m_to_r`.`id`=`moveable_bpir`.`to_repository`'
  384. printf ' WHERE `m_to_r`.`stability`!=`r_r`.`stability`;\n'
  385. for table in 'moveable' 'replaced'; do
  386. for copy in '' '2'; do
  387. if [ "${table}" = 'moveable' ] && \
  388. [ "${copy}" = '2' ]; then
  389. continue
  390. fi
  391. printf 'DROP TEMPORARY TABLE `%s_bpir_copy%s`;\n' \
  392. "${table}" "${copy}"
  393. done
  394. done
  395. printf 'END\n'
  396. printf '//\n'
  397. printf 'DROP PROCEDURE IF EXISTS `find_the_culprit`//\n'
  398. printf 'CREATE PROCEDURE `find_the_culprit`(IN `bpir` BIGINT)\n'
  399. printf 'find_the_culprit:BEGIN\n'
  400. printf 'DECLARE row_count_saved INT DEFAULT 0;\n'
  401. printf 'UPDATE `knots`'
  402. printf ' SET `knots`.`reason_length`=NULL,'
  403. printf ' `knots`.`relevant`=NULL,'
  404. printf ' `knots`.`active`=1;\n'
  405. printf 'DELETE FROM `edges_copy`;\n'
  406. printf 'INSERT INTO `edges_copy` (`cause`,`impact`,`invert`)'
  407. printf ' SELECT `edges`.`cause`,'
  408. printf '`edges`.`impact`,'
  409. printf '`edges`.`invert`'
  410. printf ' FROM `edges`;\n'
  411. printf 'REPEAT\n'
  412. printf 'UPDATE `knots_copy`'
  413. printf ' JOIN `knots`'
  414. printf ' ON `knots_copy`.`id`=`knots`.`id`'
  415. printf ' SET `knots_copy`.`reason_length`=`knots`.`reason_length`,'
  416. printf ' `knots_copy`.`active`=`knots`.`active`;\n'
  417. printf 'SET row_count_saved=0;\n'
  418. printf '%s\n' \
  419. '0 0 1' \
  420. '0 1 0' \
  421. '1 1 1' \
  422. '1 0 0' | \
  423. while read -r and left value; do
  424. printf 'UPDATE `knots`'
  425. if [ "${left}" = '1' ]; then
  426. printf ' LEFT'
  427. fi
  428. printf ' JOIN ('
  429. printf 'SELECT `edges`.`impact`,'
  430. if [ "${and}" = '1' ]; then
  431. printf ' MIN('
  432. else
  433. printf ' MAX('
  434. fi
  435. printf 'IF('
  436. printf '`knots_copy`.`reason_length` IS NULL,'
  437. if [ "${value}" = '1' ]; then
  438. printf '0,'
  439. else
  440. printf '1,'
  441. fi
  442. printf '`edges`.`invert` XOR `knots_copy`.`active`'
  443. printf ')'
  444. printf ') AS `active`,'
  445. if [ "${left}" = '0' ]; then
  446. printf ' MIN('
  447. else
  448. printf ' MAX('
  449. fi
  450. printf '`knots_copy`.`reason_length`'
  451. printf ') AS `reason_length`'
  452. printf ' FROM `edges`'
  453. printf ' JOIN `knots_copy`'
  454. printf ' ON `knots_copy`.`id`=`edges`.`cause`'
  455. printf ' GROUP BY `edges`.`impact`'
  456. printf ') AS `edges_combined`'
  457. printf ' ON `edges_combined`.`impact`=`knots`.`id`'
  458. printf ' SET `knots`.`active`=%s,' \
  459. "${value}"
  460. printf ' `knots`.`reason_length`='
  461. if [ "${left}" = '1' ]; then
  462. printf 'IFNULL('
  463. fi
  464. printf '`edges_combined`.`reason_length`+1'
  465. if [ "${left}" = '1' ]; then
  466. printf ',0)'
  467. fi
  468. printf ' WHERE'
  469. if [ "${and}" = '0' ]; then
  470. printf ' NOT'
  471. fi
  472. printf ' `knots`.`and`'
  473. printf ' AND '
  474. if [ "${left}" = '1' ]; then
  475. printf 'IFNULL('
  476. fi
  477. printf '`edges_combined`.`active`'
  478. if [ "${left}" = '1' ]; then
  479. printf ',%s)' \
  480. "${value}"
  481. fi
  482. printf '=%s;\n' \
  483. "${value}"
  484. printf 'SET row_count_saved = row_count_saved + ROW_COUNT();\n'
  485. done
  486. printf 'UNTIL (row_count_saved=0) OR EXISTS ('
  487. printf 'SELECT 1'
  488. printf ' FROM `knots`'
  489. printf ' WHERE `knots`.`reason_length` IS NOT NULL'
  490. printf ' AND `knots`.`content_id`=`bpir`'
  491. printf ' AND `knots`.`content_type`="bpir"'
  492. printf ')\n'
  493. printf 'END REPEAT;\n'
  494. printf 'UPDATE `knots_copy`'
  495. printf ' JOIN `knots`'
  496. printf ' ON `knots_copy`.`id`=`knots`.`id`'
  497. printf ' SET `knots_copy`.`reason_length`=`knots`.`reason_length`,'
  498. printf ' `knots_copy`.`active`=`knots`.`active`;\n'
  499. printf 'IF NOT EXISTS ('
  500. printf 'SELECT 1'
  501. printf ' FROM `knots`'
  502. printf ' WHERE `knots`.`reason_length` IS NOT NULL'
  503. printf ' AND `knots`.`content_id`=`bpir`'
  504. printf ' AND `knots`.`content_type`="bpir"'
  505. printf ') THEN\n'
  506. printf 'SELECT CONCAT('
  507. printf '"I cannot decide whether ",'
  508. printf '`binary_packages`.`pkgname`,'
  509. printf ' " can be moved or not."'
  510. printf ') FROM `binary_packages`'
  511. mysql_join_binary_packages_binary_packages_in_repositories
  512. printf ' WHERE `binary_packages_in_repositories`.`id`=`bpir`;\n'
  513. printf 'LEAVE find_the_culprit;\n'
  514. printf 'END IF;\n'
  515. printf 'IF ('
  516. printf 'SELECT `knots`.`active`'
  517. printf ' FROM `knots`'
  518. printf ' WHERE `knots`.`reason_length` IS NOT NULL'
  519. printf ' AND `knots`.`content_id`=`bpir`'
  520. printf ' AND `knots`.`content_type`="bpir"'
  521. printf ') THEN\n'
  522. printf 'SELECT CONCAT('
  523. printf '`binary_packages`.`pkgname`,'
  524. printf ' " can be moved."'
  525. printf ') FROM `binary_packages`'
  526. mysql_join_binary_packages_binary_packages_in_repositories
  527. printf ' WHERE `binary_packages_in_repositories`.`id`=`bpir`;\n'
  528. printf 'LEAVE find_the_culprit;\n'
  529. printf 'END IF;\n'
  530. printf 'SELECT CONCAT('
  531. printf '`binary_packages`.`pkgname`,'
  532. printf ' " cannot be moved:"'
  533. printf ') FROM `binary_packages`'
  534. mysql_join_binary_packages_binary_packages_in_repositories
  535. printf ' WHERE `binary_packages_in_repositories`.`id`=`bpir`;\n'
  536. # now we mark all relevant knots
  537. printf 'UPDATE `knots`'
  538. printf ' SET `knots`.`relevant`=('
  539. printf '`knots`.`reason_length` IS NOT NULL'
  540. printf ' AND `knots`.`content_id`=`bpir`'
  541. printf ' AND `knots`.`content_type`="bpir"'
  542. printf ');\n'
  543. printf 'REPEAT\n'
  544. printf 'SET row_count_saved=0;\n'
  545. printf 'UPDATE `knots_copy`'
  546. printf ' JOIN `knots`'
  547. printf ' ON `knots_copy`.`id`=`knots`.`id`'
  548. printf ' SET `knots_copy`.`relevant`=`knots`.`relevant`;\n'
  549. printf 'UPDATE `knots`'
  550. printf ' JOIN `edges`'
  551. printf ' ON `knots`.`id`=`edges`.`cause`'
  552. printf ' JOIN `knots_copy`'
  553. printf ' ON `knots_copy`.`id`=`edges`.`impact`'
  554. printf ' SET `knots`.`relevant`=1'
  555. printf ' WHERE `knots_copy`.`relevant`'
  556. printf ' AND NOT `knots`.`relevant`'
  557. printf ' AND NOT ('
  558. printf '`edges`.`invert`'
  559. printf ' XOR `knots`.`active`'
  560. printf ' XOR `knots_copy`.`active`'
  561. printf ') AND ('
  562. printf '`knots_copy`.`and`=`knots_copy`.`active`'
  563. printf ' OR `knots_copy`.`reason_length`=`knots`.`reason_length`+1'
  564. printf ');\n'
  565. printf 'SET row_count_saved = row_count_saved + ROW_COUNT();\n'
  566. printf 'UNTIL row_count_saved=0\n'
  567. printf 'END REPEAT;\n'
  568. for copy in '' '_copy'; do
  569. printf 'CREATE TEMPORARY TABLE `knot_names%s` (' \
  570. "${copy}"
  571. printf '`id` BIGINT NOT NULL,'
  572. printf ' `name` VARCHAR (128),'
  573. printf ' `and` BIT,'
  574. printf ' `active` BIT,'
  575. printf ' `relevant` BIT,'
  576. printf ' `reason_length` MEDIUMINT,'
  577. printf ' UNIQUE KEY (`id`)'
  578. printf ');\n'
  579. done
  580. printf 'INSERT INTO `knot_names` (`id`,`name`,`reason_length`,`and`,`relevant`,`active`)'
  581. printf ' SELECT `knots`.`id`,'
  582. printf ' `install_targets`.`name`,'
  583. printf ' `knots`.`reason_length`,'
  584. printf ' `knots`.`and`,'
  585. printf ' `knots`.`relevant`,'
  586. printf ' `knots`.`active`'
  587. printf ' FROM `knots`'
  588. printf ' JOIN `install_targets`'
  589. printf ' ON `knots`.`content_id`=`install_targets`.`id`'
  590. printf ' AND `knots`.`content_type`="it";\n'
  591. printf 'INSERT INTO `knot_names` (`id`,`name`,`reason_length`,`and`,`relevant`,`active`)'
  592. printf ' SELECT `knots`.`id`,'
  593. printf ' CONCAT('
  594. printf '`r_a`.`name`,"/",'
  595. printf '`repositories`.`name`,"/",'
  596. mysql_package_name_query
  597. printf ') AS `name`,'
  598. printf ' `knots`.`reason_length`,'
  599. printf ' `knots`.`and`,'
  600. printf ' `knots`.`relevant`,'
  601. printf ' `knots`.`active`'
  602. printf ' FROM `knots`'
  603. printf ' JOIN `binary_packages_in_repositories`'
  604. printf ' ON `knots`.`content_id`=`binary_packages_in_repositories`.`id`'
  605. printf ' AND `knots`.`content_type`="bpir"'
  606. mysql_join_binary_packages_in_repositories_binary_packages
  607. mysql_join_binary_packages_in_repositories_repositories
  608. mysql_join_repositories_architectures '' 'r_a'
  609. mysql_join_binary_packages_architectures
  610. printf ';\n'
  611. printf 'INSERT INTO `knot_names_copy`'
  612. printf ' SELECT * FROM `knot_names`;\n'
  613. printf 'SELECT CONCAT('
  614. printf 'IF(`impact`.`and`,"(and) ","(or) "),'
  615. printf '`impact`.`name`,'
  616. printf '" ",IF(`impact`.`active`,"1","0"),'
  617. printf 'IF(`edges`.`invert`," -NOT-> "," --> "),'
  618. printf '`cause`.`name`,'
  619. printf '" ",IF(`cause`.`active`,"1","0")'
  620. printf ') FROM `edges`'
  621. printf ' JOIN `knot_names` AS `cause`'
  622. printf ' ON `cause`.`id`=`edges`.`cause`'
  623. printf ' JOIN `knot_names_copy` AS `impact`'
  624. printf ' ON `impact`.`id`=`edges`.`impact`'
  625. printf ' WHERE `cause`.`relevant`'
  626. printf ' AND `impact`.`relevant`;\n'
  627. printf 'DROP TEMPORARY TABLE `knot_names`;\n'
  628. printf 'END\n'
  629. printf '//\n'
  630. printf 'DELIMITER ;\n'
  631. if [ "x$1" != 'x-no-privileges' ]; then
  632. printf 'GRANT %s ON %s TO '"'"'buildmaster'"'"'@'"'"'localhost'"'"';\n' \
  633. 'CREATE ROUTINE' 'buildmaster.*' \
  634. 'CREATE TEMPORARY TABLES' 'buildmaster.*' \
  635. 'EXECUTE' 'buildmaster.*' \
  636. 'RELOAD' '*.*' \
  637. 'SELECT' 'buildmaster.*' \
  638. 'SELECT' 'mysql.proc' \
  639. 'SHOW VIEW' 'buildmaster.*' \
  640. 'UPDATE' 'buildmaster.*'
  641. printf 'GRANT %s ON %s TO '"'"'replikat'"'"'@'"'"'localhost'"'"';\n' \
  642. 'REPLICATION SLAVE' '*.*'
  643. printf 'GRANT %s ON %s TO '"'"'mysqldump'"'"'@'"'"'localhost'"'"';\n' \
  644. 'RELOAD' '*.*' \
  645. 'FILE' '*.*'
  646. printf 'GRANT %s ON %s TO '"'"'webserver'"'"'@'"'"'localhost'"'"';\n' \
  647. 'CREATE TEMPORARY TABLES' '`buildmaster`.*' \
  648. 'SELECT' '`buildmaster`.*' \
  649. 'REPLICATION CLIENT' '*.*'
  650. printf 'FLUSH PRIVILEGES;\n'
  651. fi
  652. } | \
  653. mysql_run_query -u root -p