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

bootstrap-mysql 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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. # deliberately break to-be-deleted packages
  260. printf ' AND NOT `repl_bpir`.`is_to_be_deleted`'
  261. mysql_join_binary_packages_in_repositories_install_target_providers 'repl_bpir'
  262. mysql_join_binary_packages_in_repositories_repositories 'repl_bpir' 'repl_r'
  263. mysql_join_install_target_providers_dependencies_with_versions
  264. printf ' AND NOT EXISTS ('
  265. # dependencies of replaced packages don't matter
  266. printf 'SELECT 1'
  267. printf ' FROM `replaced_bpir_copy`'
  268. printf ' JOIN `binary_packages_in_repositories` AS `repl_bpir_copy`'
  269. printf ' ON `repl_bpir_copy`.`id`=`replaced_bpir_copy`.`id`'
  270. mysql_join_binary_packages_in_repositories_repositories 'repl_bpir_copy' 'repl_r_copy'
  271. printf ' WHERE `repl_bpir_copy`.`package`=`dependencies`.`dependent`'
  272. printf ' AND `repl_r_copy`.`architecture`=`repl_r`.`architecture`'
  273. printf ')'
  274. mysql_join_dependencies_dependency_types
  275. # consider only runtime dependencies
  276. printf ' AND `dependency_types`.`relevant_for_binary_packages`'
  277. mysql_join_dependencies_binary_packages '' 'req_bp'
  278. # we need to check whether req_bp's dependency is (un)critical
  279. mysql_join_binary_packages_binary_packages_in_repositories 'req_bp' 'req_bpir'
  280. mysql_join_binary_packages_in_repositories_repositories 'req_bpir' 'req_r'
  281. printf ' AND `repl_r`.`architecture`=`req_r`.`architecture`'
  282. # dependent package is "less stable" than dependency
  283. printf ' JOIN `repository_stability_relations` AS `repl_rr`'
  284. printf ' ON `repl_rr`.`more_stable`=`repl_r`.`stability`'
  285. printf ' AND `repl_rr`.`less_stable`=`req_r`.`stability`'
  286. # a) ^
  287. printf ' WHERE NOT EXISTS ('
  288. # no moved package ...
  289. printf 'SELECT 1'
  290. printf ' FROM `moveable_bpir_copy`'
  291. printf ' JOIN `binary_packages_in_repositories` AS `subst_bpir`'
  292. printf ' ON `subst_bpir`.`id`=`moveable_bpir_copy`.`id`'
  293. mysql_join_binary_packages_in_repositories_install_target_providers 'subst_bpir' 'subst_itp'
  294. mysql_join_binary_packages_in_repositories_repositories 'subst_bpir' 'subst_r'
  295. # ... provides the same
  296. printf ' WHERE `subst_itp`.`install_target`=`install_target_providers`.`install_target`'
  297. printf ' AND `subst_r`.`architecture`=`repl_r`.`architecture`'
  298. # b) 1) ^
  299. printf ') AND NOT EXISTS ('
  300. # no current package ...
  301. printf 'SELECT 1'
  302. printf ' FROM `binary_packages_in_repositories` AS `subst_bpir`'
  303. mysql_join_binary_packages_in_repositories_install_target_providers 'subst_bpir' 'subst_itp'
  304. # ... in a repository ...
  305. mysql_join_binary_packages_in_repositories_repositories 'subst_bpir' 'subst_r'
  306. # ... more stable ...
  307. printf ' JOIN `repository_stability_relations` AS `subst_rr`'
  308. printf ' ON `subst_rr`.`more_stable`=`subst_r`.`stability`'
  309. # ... than x's repository ...
  310. printf ' WHERE `subst_rr`.`less_stable`=`repl_r`.`stability`'
  311. printf ' AND `subst_r`.`architecture`=`repl_r`.`architecture`'
  312. # (architecture check is not necessary, as repositories of different
  313. # architectures are not less or more stable than each other)
  314. printf ' AND NOT EXISTS ('
  315. # ... and which is not replaced ...
  316. printf 'SELECT 1'
  317. printf ' FROM `replaced_bpir_copy2`'
  318. printf ' WHERE `replaced_bpir_copy2`.`id`=`subst_bpir`.`id`'
  319. printf ')'
  320. # ... and provides the same
  321. printf ' AND `subst_itp`.`install_target`=`install_target_providers`.`install_target`'
  322. # b) 2) ^
  323. printf ');\n'
  324. printf 'SET row_count_saved = row_count_saved + ROW_COUNT();\n'
  325. # refresh copies of our temporary tables *yuck*
  326. for table in 'replaced' 'moveable'; do
  327. for copy in '' '2'; do
  328. if [ "${table}" = 'moveable' ] && \
  329. [ "${copy}" = '2' ]; then
  330. continue
  331. fi
  332. printf 'DELETE FROM `%s_bpir_copy%s`;\n' "${table}" "${copy}"
  333. printf 'INSERT IGNORE INTO `%s_bpir_copy%s`' "${table}" "${copy}"
  334. printf ' SELECT `%s_bpir`.*' "${table}"
  335. printf ' FROM `%s_bpir`;\n' "${table}"
  336. done
  337. done
  338. # remove all packages of a blob, where some part cannot be moved
  339. printf 'DELETE `replaced_bpir`,`moveable_bpir`'
  340. printf ' FROM `replaced_bpir`'
  341. printf ' RIGHT JOIN `moveable_bpir`'
  342. printf ' ON `replaced_bpir`.`replaced_by`=`moveable_bpir`.`id`'
  343. printf ' JOIN `binary_packages_in_repositories`'
  344. printf ' ON `binary_packages_in_repositories`.`id`=`moveable_bpir`.`id`'
  345. mysql_join_binary_packages_in_repositories_binary_packages
  346. mysql_join_binary_packages_build_assignments
  347. printf ' JOIN `package_blobs`'
  348. printf ' ON `build_assignments`.`package_source`=`package_blobs`.`ps_a`'
  349. printf ' JOIN `build_assignments` AS `bl_ba`'
  350. printf ' ON `bl_ba`.`package_source`=`package_blobs`.`ps_b`'
  351. printf ' AND `bl_ba`.`architecture`=`build_assignments`.`architecture`'
  352. mysql_join_build_assignments_binary_packages 'bl_ba' 'bl_bp'
  353. mysql_join_binary_packages_binary_packages_in_repositories 'bl_bp' 'bl_bpir'
  354. printf ' WHERE NOT EXISTS ('
  355. printf 'SELECT 1'
  356. printf ' FROM `moveable_bpir_copy`'
  357. printf ' WHERE `moveable_bpir_copy`.`id`=`bl_bpir`.`id`'
  358. printf ');\n'
  359. printf 'SET row_count_saved = row_count_saved + ROW_COUNT();\n'
  360. printf 'UNTIL row_count_saved=0\n'
  361. printf 'END REPEAT;\n'
  362. # we now need to remove the replaced_bpir which are not actually to be
  363. # replaced, but simply hidden
  364. # refresh copies of our temporary tables *yuck*
  365. for table in 'replaced' 'moveable'; do
  366. for copy in '' '2'; do
  367. if [ "${table}" = 'moveable' ] && \
  368. [ "${copy}" = '2' ]; then
  369. continue
  370. fi
  371. printf 'DELETE FROM `%s_bpir_copy%s`;\n' "${table}" "${copy}"
  372. printf 'INSERT IGNORE INTO `%s_bpir_copy%s`' "${table}" "${copy}"
  373. printf ' SELECT `%s_bpir`.*' "${table}"
  374. printf ' FROM `%s_bpir`;\n' "${table}"
  375. done
  376. done
  377. printf 'DELETE `replaced_bpir`'
  378. printf ' FROM `replaced_bpir`'
  379. printf ' JOIN `moveable_bpir`'
  380. printf ' ON `replaced_bpir`.`replaced_by`=`moveable_bpir`.`id`'
  381. printf ' JOIN `binary_packages_in_repositories` AS `r_bpir`'
  382. printf ' ON `replaced_bpir`.`id`=`r_bpir`.`id`'
  383. mysql_join_binary_packages_in_repositories_repositories 'r_bpir' 'r_r'
  384. printf ' JOIN `repositories` AS `m_to_r`'
  385. printf ' ON `m_to_r`.`id`=`moveable_bpir`.`to_repository`'
  386. printf ' WHERE `m_to_r`.`stability`!=`r_r`.`stability`;\n'
  387. for table in 'moveable' 'replaced'; do
  388. for copy in '' '2'; do
  389. if [ "${table}" = 'moveable' ] && \
  390. [ "${copy}" = '2' ]; then
  391. continue
  392. fi
  393. printf 'DROP TEMPORARY TABLE `%s_bpir_copy%s`;\n' \
  394. "${table}" "${copy}"
  395. done
  396. done
  397. printf 'END\n'
  398. printf '//\n'
  399. printf 'DROP PROCEDURE IF EXISTS `find_the_culprit`//\n'
  400. printf 'CREATE PROCEDURE `find_the_culprit`(IN `bpir` BIGINT)\n'
  401. printf 'find_the_culprit:BEGIN\n'
  402. printf 'DECLARE row_count_saved INT DEFAULT 0;\n'
  403. printf 'UPDATE `knots`'
  404. printf ' SET `knots`.`reason_length`=NULL,'
  405. printf ' `knots`.`relevant`=NULL,'
  406. printf ' `knots`.`active`=1;\n'
  407. printf 'DELETE FROM `edges_copy`;\n'
  408. printf 'INSERT INTO `edges_copy` (`cause`,`impact`,`invert`)'
  409. printf ' SELECT `edges`.`cause`,'
  410. printf '`edges`.`impact`,'
  411. printf '`edges`.`invert`'
  412. printf ' FROM `edges`;\n'
  413. printf 'REPEAT\n'
  414. printf 'UPDATE `knots_copy`'
  415. printf ' JOIN `knots`'
  416. printf ' ON `knots_copy`.`id`=`knots`.`id`'
  417. printf ' SET `knots_copy`.`reason_length`=`knots`.`reason_length`,'
  418. printf ' `knots_copy`.`active`=`knots`.`active`;\n'
  419. printf 'SET row_count_saved=0;\n'
  420. printf '%s\n' \
  421. '0 0 1' \
  422. '0 1 0' \
  423. '1 1 1' \
  424. '1 0 0' | \
  425. while read -r and left value; do
  426. printf 'UPDATE `knots`'
  427. if [ "${left}" = '1' ]; then
  428. printf ' LEFT'
  429. fi
  430. printf ' JOIN ('
  431. printf 'SELECT `edges`.`impact`,'
  432. if [ "${and}" = '1' ]; then
  433. printf ' MIN('
  434. else
  435. printf ' MAX('
  436. fi
  437. printf 'IF('
  438. printf '`knots_copy`.`reason_length` IS NULL,'
  439. if [ "${value}" = '1' ]; then
  440. printf '0,'
  441. else
  442. printf '1,'
  443. fi
  444. printf '`edges`.`invert` XOR `knots_copy`.`active`'
  445. printf ')'
  446. printf ') AS `active`,'
  447. if [ "${left}" = '0' ]; then
  448. printf ' MIN('
  449. else
  450. printf ' MAX('
  451. fi
  452. printf '`knots_copy`.`reason_length`'
  453. printf ') AS `reason_length`'
  454. printf ' FROM `edges`'
  455. printf ' JOIN `knots_copy`'
  456. printf ' ON `knots_copy`.`id`=`edges`.`cause`'
  457. printf ' GROUP BY `edges`.`impact`'
  458. printf ') AS `edges_combined`'
  459. printf ' ON `edges_combined`.`impact`=`knots`.`id`'
  460. printf ' SET `knots`.`active`=%s,' \
  461. "${value}"
  462. printf ' `knots`.`reason_length`='
  463. if [ "${left}" = '1' ]; then
  464. printf 'IFNULL('
  465. fi
  466. printf '`edges_combined`.`reason_length`+1'
  467. if [ "${left}" = '1' ]; then
  468. printf ',0)'
  469. fi
  470. printf ' WHERE'
  471. if [ "${and}" = '0' ]; then
  472. printf ' NOT'
  473. fi
  474. printf ' `knots`.`and`'
  475. printf ' AND '
  476. if [ "${left}" = '1' ]; then
  477. printf 'IFNULL('
  478. fi
  479. printf '`edges_combined`.`active`'
  480. if [ "${left}" = '1' ]; then
  481. printf ',%s)' \
  482. "${value}"
  483. fi
  484. printf '=%s;\n' \
  485. "${value}"
  486. printf 'SET row_count_saved = row_count_saved + ROW_COUNT();\n'
  487. done
  488. printf 'UNTIL (row_count_saved=0) OR EXISTS ('
  489. printf 'SELECT 1'
  490. printf ' FROM `knots`'
  491. printf ' WHERE `knots`.`reason_length` IS NOT NULL'
  492. printf ' AND `knots`.`content_id`=`bpir`'
  493. printf ' AND `knots`.`content_type`="bpir"'
  494. printf ')\n'
  495. printf 'END REPEAT;\n'
  496. printf 'UPDATE `knots_copy`'
  497. printf ' JOIN `knots`'
  498. printf ' ON `knots_copy`.`id`=`knots`.`id`'
  499. printf ' SET `knots_copy`.`reason_length`=`knots`.`reason_length`,'
  500. printf ' `knots_copy`.`active`=`knots`.`active`;\n'
  501. printf 'IF NOT EXISTS ('
  502. printf 'SELECT 1'
  503. printf ' FROM `knots`'
  504. printf ' WHERE `knots`.`reason_length` IS NOT NULL'
  505. printf ' AND `knots`.`content_id`=`bpir`'
  506. printf ' AND `knots`.`content_type`="bpir"'
  507. printf ') THEN\n'
  508. printf 'SELECT CONCAT('
  509. printf '"I cannot decide whether ",'
  510. printf '`binary_packages`.`pkgname`,'
  511. printf ' " can be moved or not."'
  512. printf ') FROM `binary_packages`'
  513. mysql_join_binary_packages_binary_packages_in_repositories
  514. printf ' WHERE `binary_packages_in_repositories`.`id`=`bpir`;\n'
  515. printf 'LEAVE find_the_culprit;\n'
  516. printf 'END IF;\n'
  517. printf 'IF ('
  518. printf 'SELECT `knots`.`active`'
  519. printf ' FROM `knots`'
  520. printf ' WHERE `knots`.`reason_length` IS NOT NULL'
  521. printf ' AND `knots`.`content_id`=`bpir`'
  522. printf ' AND `knots`.`content_type`="bpir"'
  523. printf ') THEN\n'
  524. printf 'SELECT CONCAT('
  525. printf '`binary_packages`.`pkgname`,'
  526. printf ' " can be moved."'
  527. printf ') FROM `binary_packages`'
  528. mysql_join_binary_packages_binary_packages_in_repositories
  529. printf ' WHERE `binary_packages_in_repositories`.`id`=`bpir`;\n'
  530. printf 'LEAVE find_the_culprit;\n'
  531. printf 'END IF;\n'
  532. printf 'SELECT CONCAT('
  533. printf '`binary_packages`.`pkgname`,'
  534. printf ' " cannot be moved:"'
  535. printf ') FROM `binary_packages`'
  536. mysql_join_binary_packages_binary_packages_in_repositories
  537. printf ' WHERE `binary_packages_in_repositories`.`id`=`bpir`;\n'
  538. # now we mark all relevant knots
  539. printf 'UPDATE `knots`'
  540. printf ' SET `knots`.`relevant`=('
  541. printf '`knots`.`reason_length` IS NOT NULL'
  542. printf ' AND `knots`.`content_id`=`bpir`'
  543. printf ' AND `knots`.`content_type`="bpir"'
  544. printf ');\n'
  545. printf 'REPEAT\n'
  546. printf 'SET row_count_saved=0;\n'
  547. printf 'UPDATE `knots_copy`'
  548. printf ' JOIN `knots`'
  549. printf ' ON `knots_copy`.`id`=`knots`.`id`'
  550. printf ' SET `knots_copy`.`relevant`=`knots`.`relevant`;\n'
  551. printf 'UPDATE `knots`'
  552. printf ' JOIN `edges`'
  553. printf ' ON `knots`.`id`=`edges`.`cause`'
  554. printf ' JOIN `knots_copy`'
  555. printf ' ON `knots_copy`.`id`=`edges`.`impact`'
  556. printf ' SET `knots`.`relevant`=1'
  557. printf ' WHERE `knots_copy`.`relevant`'
  558. printf ' AND NOT `knots`.`relevant`'
  559. printf ' AND NOT ('
  560. printf '`edges`.`invert`'
  561. printf ' XOR `knots`.`active`'
  562. printf ' XOR `knots_copy`.`active`'
  563. printf ') AND ('
  564. printf '`knots_copy`.`and`=`knots_copy`.`active`'
  565. printf ' OR `knots_copy`.`reason_length`=`knots`.`reason_length`+1'
  566. printf ');\n'
  567. printf 'SET row_count_saved = row_count_saved + ROW_COUNT();\n'
  568. printf 'UNTIL row_count_saved=0\n'
  569. printf 'END REPEAT;\n'
  570. for copy in '' '_copy'; do
  571. printf 'CREATE TEMPORARY TABLE `knot_names%s` (' \
  572. "${copy}"
  573. printf '`id` BIGINT NOT NULL,'
  574. printf ' `name` VARCHAR (128),'
  575. printf ' `and` BIT,'
  576. printf ' `active` BIT,'
  577. printf ' `relevant` BIT,'
  578. printf ' `reason_length` MEDIUMINT,'
  579. printf ' UNIQUE KEY (`id`)'
  580. printf ');\n'
  581. done
  582. printf 'INSERT INTO `knot_names` (`id`,`name`,`reason_length`,`and`,`relevant`,`active`)'
  583. printf ' SELECT `knots`.`id`,'
  584. printf ' `install_targets`.`name`,'
  585. printf ' `knots`.`reason_length`,'
  586. printf ' `knots`.`and`,'
  587. printf ' `knots`.`relevant`,'
  588. printf ' `knots`.`active`'
  589. printf ' FROM `knots`'
  590. printf ' JOIN `install_targets`'
  591. printf ' ON `knots`.`content_id`=`install_targets`.`id`'
  592. printf ' AND `knots`.`content_type`="it";\n'
  593. printf 'INSERT INTO `knot_names` (`id`,`name`,`reason_length`,`and`,`relevant`,`active`)'
  594. printf ' SELECT `knots`.`id`,'
  595. printf ' CONCAT('
  596. printf '`r_a`.`name`,"/",'
  597. printf '`repositories`.`name`,"/",'
  598. mysql_package_name_query
  599. printf ') AS `name`,'
  600. printf ' `knots`.`reason_length`,'
  601. printf ' `knots`.`and`,'
  602. printf ' `knots`.`relevant`,'
  603. printf ' `knots`.`active`'
  604. printf ' FROM `knots`'
  605. printf ' JOIN `binary_packages_in_repositories`'
  606. printf ' ON `knots`.`content_id`=`binary_packages_in_repositories`.`id`'
  607. printf ' AND `knots`.`content_type`="bpir"'
  608. mysql_join_binary_packages_in_repositories_binary_packages
  609. mysql_join_binary_packages_in_repositories_repositories
  610. mysql_join_repositories_architectures '' 'r_a'
  611. mysql_join_binary_packages_architectures
  612. printf ';\n'
  613. printf 'INSERT INTO `knot_names_copy`'
  614. printf ' SELECT * FROM `knot_names`;\n'
  615. printf 'SELECT CONCAT('
  616. printf 'IF(`impact`.`and`,"(and) ","(or) "),'
  617. printf '`impact`.`name`,'
  618. printf '" ",IF(`impact`.`active`,"1","0"),'
  619. printf 'IF(`edges`.`invert`," -NOT-> "," --> "),'
  620. printf '`cause`.`name`,'
  621. printf '" ",IF(`cause`.`active`,"1","0")'
  622. printf ') FROM `edges`'
  623. printf ' JOIN `knot_names` AS `cause`'
  624. printf ' ON `cause`.`id`=`edges`.`cause`'
  625. printf ' JOIN `knot_names_copy` AS `impact`'
  626. printf ' ON `impact`.`id`=`edges`.`impact`'
  627. printf ' WHERE `cause`.`relevant`'
  628. printf ' AND `impact`.`relevant`;\n'
  629. printf 'DROP TEMPORARY TABLE `knot_names`;\n'
  630. printf 'END\n'
  631. printf '//\n'
  632. printf 'DELIMITER ;\n'
  633. if [ "x$1" != 'x-no-privileges' ]; then
  634. printf 'GRANT %s ON %s TO '"'"'buildmaster'"'"'@'"'"'localhost'"'"';\n' \
  635. 'CREATE ROUTINE' 'buildmaster.*' \
  636. 'CREATE TEMPORARY TABLES' 'buildmaster.*' \
  637. 'EXECUTE' 'buildmaster.*' \
  638. 'RELOAD' '*.*' \
  639. 'SELECT' 'buildmaster.*' \
  640. 'SELECT' 'mysql.proc' \
  641. 'SHOW VIEW' 'buildmaster.*' \
  642. 'UPDATE' 'buildmaster.*'
  643. printf 'GRANT %s ON %s TO '"'"'replikat'"'"'@'"'"'localhost'"'"';\n' \
  644. 'REPLICATION SLAVE' '*.*'
  645. printf 'GRANT %s ON %s TO '"'"'mysqldump'"'"'@'"'"'localhost'"'"';\n' \
  646. 'RELOAD' '*.*' \
  647. 'FILE' '*.*'
  648. printf 'GRANT %s ON %s TO '"'"'webserver'"'"'@'"'"'localhost'"'"';\n' \
  649. 'CREATE TEMPORARY TABLES' '`buildmaster`.*' \
  650. 'SELECT' '`buildmaster`.*' \
  651. 'REPLICATION CLIENT' '*.*'
  652. printf 'FLUSH PRIVILEGES;\n'
  653. fi
  654. } | \
  655. mysql_run_query -u root -p