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

create-build-support-package 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. #!/bin/sh
  2. # shellcheck source=../lib/load-configuration
  3. . "${0%/*}/../lib/load-configuration"
  4. # shellcheck disable=SC2016
  5. usage() {
  6. >&2 echo 'usage:'
  7. >&2 echo ' create-build-support-package [options] --from $pkgname-$epoch:$pkgver-$pkgrel.$sub_pkgrel [--] $file1 $file2 $file3 ...'
  8. >&2 echo ' create $pkgname-shim containing'
  9. >&2 echo ' $file1, $file2, ... from the original package'
  10. >&2 echo ' create-build-support-package [options] --shim $pkgfile'
  11. >&2 echo ' insert $pkgfile into $repo_arch/build-support/$pkgname-shim'
  12. >&2 echo ''
  13. >&2 echo 'possible options:'
  14. >&2 echo ' -a|--arch $repo_arch: (required)'
  15. >&2 echo ' Operate on repository of given architecture.'
  16. >&2 echo ' -h|--help:'
  17. >&2 echo ' Show this help and exit.'
  18. >&2 echo ' --only-versioned-so-provides:'
  19. >&2 echo ' Remove all but versioned *.so provide entries. (only with --from)'
  20. >&2 echo ' -w|--wait:'
  21. >&2 echo ' Wait for lock if necessary.'
  22. [ -z "$1" ] && exit 1 || exit "$1"
  23. }
  24. eval set -- "$(
  25. getopt -o a:hw \
  26. --long arch: \
  27. --long from: \
  28. --long help \
  29. --long only-versioned-so-provides \
  30. --long shim: \
  31. --long wait \
  32. -n "$(basename "$0")" -- "$@" || \
  33. echo usage
  34. )"
  35. only_versioned_so_provides=false
  36. repo_arch=''
  37. shim_package=''
  38. source_package=''
  39. wait_for_lock='-n'
  40. while true; do
  41. case "$1" in
  42. -a|--arch)
  43. if [ -n "${repo_arch}" ]; then
  44. >&2 prinf -- '-a|--arch given more than once.\n'
  45. usage
  46. fi
  47. shift
  48. repo_arch="$1"
  49. ;;
  50. --from)
  51. if [ -n "${source_package}" ]; then
  52. >&2 prinf -- '--from given more than once.\n'
  53. usage
  54. fi
  55. shift
  56. source_package="$1"
  57. ;;
  58. -h|--help)
  59. usage 0
  60. ;;
  61. --only-versioned-so-provides)
  62. only_versioned_so_provides=true
  63. ;;
  64. --shim)
  65. if [ -n "${shim_package}" ]; then
  66. >&2 prinf -- '--shim given more than once.\n'
  67. usage
  68. fi
  69. shift
  70. shim_package="$1"
  71. ;;
  72. -w|--wait)
  73. wait_for_lock=''
  74. ;;
  75. --)
  76. shift
  77. break
  78. ;;
  79. *)
  80. >&2 printf 'Whoops, forgot to implement option "%s" internally.\n' \
  81. "$1"
  82. exit 42
  83. ;;
  84. esac
  85. shift
  86. done
  87. if [ -n "${source_package}" ] \
  88. && [ -n "${shim_package}" ]; then
  89. >&2 echo 'Conflicting parameters: --from and --shim'
  90. usage
  91. fi
  92. if ${only_versioned_so_provides} \
  93. && [ -n "${shim_package}" ]; then
  94. >&2 echo 'Conflicting parameters: --shim and --only-versioned-so-provides'
  95. usage
  96. fi
  97. exec 9> "${sanity_check_lock_file}"
  98. verbose_flock -s ${wait_for_lock} 9
  99. tmp_dir=$(mktemp -d 'tmp.create-build-support.XXXXXXXXXX')
  100. # shellcheck disable=SC2064
  101. trap "rm -rf --one-file-system '${tmp_dir:?}'" EXIT
  102. if [ -n "${source_package}" ]; then
  103. # create shim_package from source_package
  104. if [ $# -eq 0 ]; then
  105. usage 1
  106. fi
  107. pkg=$(
  108. # shellcheck disable=SC2016
  109. {
  110. printf 'SELECT DISTINCT '
  111. mysql_package_name_query
  112. printf ' FROM `binary_packages`'
  113. mysql_join_binary_packages_binary_packages_in_repositories
  114. mysql_join_binary_packages_in_repositories_repositories
  115. mysql_join_repositories_architectures '' 'r_a'
  116. mysql_join_binary_packages_architectures
  117. printf ' WHERE `repositories`.`is_on_master_mirror`'
  118. printf ' AND `r_a`.`name`=from_base64("%s")' \
  119. "$(
  120. printf '%s' "${repo_arch}" \
  121. | base64 -w0
  122. )"
  123. printf ' AND '
  124. mysql_package_name_query '' 'XX' \
  125. | sed '
  126. s/,"-",`XX.*\.pkg\.tar\.xz"//
  127. '
  128. printf '=from_base64("%s")' \
  129. "$(
  130. printf '%s' "${source_package}" \
  131. | base64 -w0
  132. )"
  133. } \
  134. | mysql_run_query \
  135. | tr '\t' ' '
  136. )
  137. if [ -z "${pkg}" ]; then
  138. >&2 printf 'Could not find %s/%s in the database.\n' \
  139. "${repo_arch}" "${source_package}"
  140. exit 1
  141. fi
  142. if printf '%s\n' "${pkg}" \
  143. | wc -l \
  144. | grep -vqxF '1'; then
  145. >&2 printf 'Package %s/%s was found multiple times:\n' \
  146. "${repo_arch}" "${source_package}"
  147. >&2 printf '%s\n' "${pkg}"
  148. exit 1
  149. fi
  150. new_pkg="${pkg%-*-*-*}"
  151. new_pkg="${new_pkg}-shim${pkg#${new_pkg}}"
  152. failsafe_rsync \
  153. "${master_mirror_rsync_directory}/pool/${pkg}" \
  154. "${tmp_dir}/"
  155. mkdir "${tmp_dir}/content"
  156. bsdtar -C "${tmp_dir}/content" -xf "${tmp_dir}/${pkg}" \
  157. '.BUILDINFO' \
  158. '.PKGINFO' \
  159. "$@"
  160. # TODO: mangle customizable meta-infos here (new provides, keep some
  161. # depends)
  162. sed -i '
  163. /^pkgname = / s/ \S\+$/\0-shim\nprovides =\0/
  164. /^depend = /d
  165. ' "${tmp_dir}/content/.PKGINFO"
  166. if ${only_versioned_so_provides}; then
  167. sed -i '
  168. /^provides = / {
  169. / = \S\+\.so=/ ! d
  170. }
  171. /^replaces = / d
  172. /^conflict = / d
  173. ' "${tmp_dir}/content/.PKGINFO"
  174. fi
  175. # from /usr/bin/makepkg
  176. list_package_files() {
  177. (
  178. cd "${tmp_dir}/content"
  179. find . -path './.*' \! -name '.'; find . \! -path './.*' \! -name '.' \
  180. | LC_ALL=C sort
  181. ) \
  182. | sed -e 's|^\./||' \
  183. | tr '\n' '\0'
  184. }
  185. list_package_files \
  186. | LANG=C bsdtar -C "${tmp_dir}/content" -cnf - --format=mtree \
  187. --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' \
  188. --null --files-from - --exclude .MTREE \
  189. | gzip -c -f -n \
  190. > "${tmp_dir}/content/.MTREE"
  191. list_package_files \
  192. | LANG=C bsdtar -C "${tmp_dir}/content" -cnf - --null --files-from - \
  193. | xz -c -z - \
  194. > "${tmp_dir}/${new_pkg}"
  195. rm -rf --one-file-system "${tmp_dir:?}/content"
  196. mv "${tmp_dir}/${new_pkg}" "${work_dir}/"
  197. >&2 printf 'Please sign %s with a build slave key and run\n' \
  198. "${work_dir}/${new_pkg}"
  199. # shellcheck disable=SC2016
  200. >&2 printf 'create-build-support-package --arch %s --shim %s\n' \
  201. "${repo_arch}" \
  202. "${work_dir}/${new_pkg}"
  203. elif [ -n "${shim_package}" ]; then
  204. # insert shim_package into [build-support]
  205. if [ $# -ne 0 ]; then
  206. >&2 echo 'Too many arguments'
  207. usage
  208. fi
  209. if [ ! -r "${shim_package}" ]; then
  210. >&2 printf 'Cannot open file %s\n' \
  211. "${shim_package}"
  212. exit 1
  213. fi
  214. if ! gpg --batch --status-fd 1 -q --homedir /etc/pacman.d/gnupg --verify \
  215. "${shim_package}.sig" \
  216. "${shim_package}" \
  217. 2> /dev/null \
  218. | cut -d' ' -f2 \
  219. | grep -qxF TRUST_FULLY; then
  220. >&2 printf '%s has invalid signature\n' \
  221. "${shim_package}"
  222. exit 1
  223. fi
  224. exec 8> "${package_database_lock_file}"
  225. verbose_flock ${wait_for_lock} 8
  226. original_pkg_id=$(
  227. # shellcheck disable=SC2016
  228. {
  229. printf 'SELECT DISTINCT `binary_packages`.`id`'
  230. printf ' FROM `binary_packages`'
  231. mysql_join_binary_packages_architectures
  232. printf ' WHERE '
  233. mysql_package_name_query \
  234. | sed 's/pkgname`,"/\0-shim/'
  235. printf '=from_base64("%s")' \
  236. "$(
  237. printf '%s' "${shim_package##*/}" \
  238. | base64 -w0
  239. )"
  240. } | \
  241. mysql_run_query
  242. )
  243. if [ -z "${original_pkg_id}" ]; then
  244. >&2 printf 'could not find the original package to %s.\n' \
  245. "${shim_package##*/}"
  246. exit 1
  247. fi
  248. cp "${shim_package}" "${shim_package}.sig" "${tmp_dir}/"
  249. failsafe_rsync \
  250. "${master_mirror_rsync_directory}/${repo_arch}/build-support/build-support.db."* \
  251. "${master_mirror_rsync_directory}/${repo_arch}/build-support/build-support.files."* \
  252. "${tmp_dir}/"
  253. repo-add \
  254. "${tmp_dir}/build-support.db.tar.gz" \
  255. "${tmp_dir}/${shim_package##*/}"
  256. # shellcheck disable=SC2016
  257. {
  258. printf 'INSERT INTO `binary_packages`('
  259. printf '`build_assignment`,'
  260. printf '`epoch`,'
  261. printf '`pkgver`,'
  262. printf '`pkgrel`,'
  263. printf '`sub_pkgrel`,'
  264. printf '`architecture`,'
  265. printf '`sub_pkgrel_omitted`,'
  266. printf '`pkgname`,'
  267. printf '`has_issues`,'
  268. printf '`is_tested`,'
  269. printf '`sha512sum`'
  270. printf ')'
  271. printf ' SELECT '
  272. printf '`binary_packages`.`%s`,' \
  273. 'build_assignment' \
  274. 'epoch' \
  275. 'pkgver' \
  276. 'pkgrel' \
  277. 'sub_pkgrel' \
  278. 'architecture' \
  279. 'sub_pkgrel_omitted'
  280. printf 'CONCAT(`binary_packages`.`pkgname`,"-shim"),'
  281. printf '0,0,"%s"' \
  282. "$(
  283. sha512sum "${tmp_dir}/${shim_package##*/}" \
  284. | awk '{print $1}'
  285. )"
  286. printf ' FROM `binary_packages`'
  287. printf ' WHERE `binary_packages`.`id`=%s' \
  288. "${original_pkg_id}"
  289. printf ' LIMIT 1;\n'
  290. printf 'SET @`new_package_id`=LAST_INSERT_ID();\n'
  291. printf 'INSERT INTO `binary_packages_in_repositories` (`package`,`repository`,`is_to_be_deleted`)'
  292. printf ' SELECT @`new_package_id`,`repositories`.`id`,0'
  293. printf ' FROM `repositories`'
  294. mysql_join_repositories_architectures
  295. printf ' WHERE `repositories`.`name`="build-support"'
  296. printf ' AND `architectures`.`name`=from_base64("%s");\n' \
  297. "$(
  298. printf '%s' "${repo_arch}" \
  299. | base64 -w0
  300. )"
  301. printf 'INSERT INTO `install_target_providers` (`package`,`install_target`,`version`,`install_target_is_group`)'
  302. printf ' SELECT @`new_package_id`'
  303. printf ',`install_target_providers`.`%s`' \
  304. 'install_target' \
  305. 'version' \
  306. 'install_target_is_group'
  307. printf ' FROM `install_target_providers`'
  308. printf ' WHERE `install_target_providers`.`package`=%s;\n' \
  309. "${original_pkg_id}"
  310. # TODO: maybe add (some?) depends here, too?
  311. } | \
  312. mysql_run_query
  313. failsafe_rsync \
  314. "${tmp_dir}/${shim_package##*/}" \
  315. "${tmp_dir}/${shim_package##*/}.sig" \
  316. "${master_mirror_rsync_directory}/pool/"
  317. rm \
  318. "${tmp_dir}/${shim_package##*/}" \
  319. "${tmp_dir}/${shim_package##*/}.sig"
  320. ln -s "../../pool/${shim_package##*/}" "${tmp_dir}/${shim_package##*/}"
  321. ln -s "../../pool/${shim_package##*/}.sig" "${tmp_dir}/${shim_package##*/}.sig"
  322. failsafe_rsync \
  323. "${tmp_dir}/${shim_package##*/}" \
  324. "${tmp_dir}/${shim_package##*/}.sig" \
  325. "${tmp_dir}/build-support.db."* \
  326. "${tmp_dir}/build-support.files."* \
  327. "${master_mirror_rsync_directory}/${repo_arch}/build-support/"
  328. rm\
  329. "${shim_package}" \
  330. "${shim_package}.sig"
  331. else
  332. >&2 echo 'Need either --from or --shim.'
  333. usage
  334. fi