Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 64.85 KB | None | 0 0
  1. #!/usr/bin/bash
  2. #
  3. # makepkg - make packages compatible for use with pacman
  4. # Generated from makepkg.sh.in; do not edit by hand.
  5. #
  6. # Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org>
  7. # Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
  8. # Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
  9. # Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
  10. # Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
  11. # Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk>
  12. # Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org>
  13. #
  14. # This program is free software; you can redistribute it and/or modify
  15. # it under the terms of the GNU General Public License as published by
  16. # the Free Software Foundation; either version 2 of the License, or
  17. # (at your option) any later version.
  18. #
  19. # This program is distributed in the hope that it will be useful,
  20. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. # GNU General Public License for more details.
  23. #
  24. # You should have received a copy of the GNU General Public License
  25. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. #
  27.  
  28. # makepkg uses quite a few external programs during its execution. You
  29. # need to have at least the following installed for makepkg to function:
  30. # awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, file, find (findutils),
  31. # gettext, gpg, grep, gzip, openssl, sed, tput (ncurses), xz
  32.  
  33. # gettext initialization
  34. export TEXTDOMAIN='pacman-scripts'
  35. export TEXTDOMAINDIR='/usr/share/locale'
  36.  
  37. # file -i does not work on Mac OSX unless legacy mode is set
  38. export COMMAND_MODE='legacy'
  39. # Ensure CDPATH doesn't screw with our cd calls
  40. unset CDPATH
  41. # Ensure GREP_OPTIONS doesn't screw with our grep calls
  42. unset GREP_OPTIONS
  43.  
  44. declare -r makepkg_version='5.0.1'
  45. declare -r confdir='/etc'
  46. declare -r BUILDSCRIPT='PKGBUILD'
  47. declare -r startdir="$PWD"
  48.  
  49. LIBRARY=${LIBRARY:-'/usr/share/makepkg'}
  50.  
  51. build_options=('ccache' 'distcc' 'buildflags' 'makeflags')
  52. splitpkg_overrides=('pkgdesc' 'arch' 'url' 'license' 'groups' 'depends'
  53. 'optdepends' 'provides' 'conflicts' 'replaces' 'backup'
  54. 'options' 'install' 'changelog')
  55. readonly -a build_options splitpkg_overrides
  56.  
  57. known_hash_algos=('md5' 'sha1' 'sha224' 'sha256' 'sha384' 'sha512' 'whirlpool')
  58.  
  59. # Options
  60. ASDEPS=0
  61. BUILDFUNC=0
  62. CHECKFUNC=0
  63. CLEANBUILD=0
  64. CLEANUP=0
  65. DEP_BIN=0
  66. FORCE=0
  67. GENINTEG=0
  68. HOLDVER=0
  69. IGNOREARCH=0
  70. INFAKEROOT=0
  71. INSTALL=0
  72. LOGGING=0
  73. NEEDED=0
  74. NOARCHIVE=0
  75. NOBUILD=0
  76. NODEPS=0
  77. NOEXTRACT=0
  78. PKGFUNC=0
  79. PKGVERFUNC=0
  80. PREPAREFUNC=0
  81. REPKG=0
  82. RMDEPS=0
  83. SKIPCHECKSUMS=0
  84. SKIPPGPCHECK=0
  85. SIGNPKG=''
  86. SPLITPKG=0
  87. SOURCEONLY=0
  88. VERIFYSOURCE=0
  89.  
  90. PACMAN_OPTS=
  91.  
  92. shopt -s extglob
  93.  
  94. ### SUBROUTINES ###
  95.  
  96. # Import libmakepkg
  97. for lib in "$LIBRARY"/*.sh; do
  98. source "$lib"
  99. done
  100.  
  101. ##
  102. # Special exit call for traps, Don't print any error messages when inside,
  103. # the fakeroot call, the error message will be printed by the main call.
  104. ##
  105. trap_exit() {
  106. local signal=$1; shift
  107.  
  108. if (( ! INFAKEROOT )); then
  109. echo
  110. error "$@"
  111. fi
  112. [[ -n $srclinks ]] && rm -rf "$srclinks"
  113.  
  114. # unset the trap for this signal, and then call the default handler
  115. trap -- "$signal"
  116. kill "-$signal" "$$"
  117. }
  118.  
  119.  
  120. ##
  121. # Clean up function. Called automatically when the script exits.
  122. ##
  123. clean_up() {
  124. local EXIT_CODE=$?
  125.  
  126. if (( INFAKEROOT )); then
  127. # Don't clean up when leaving fakeroot, we're not done yet.
  128. return
  129. fi
  130.  
  131. if (( ! EXIT_CODE && CLEANUP )); then
  132. local pkg file
  133.  
  134. # If it's a clean exit and -c/--clean has been passed...
  135. msg "$(gettext "Cleaning up...")"
  136. rm -rf "$pkgdirbase" "$srcdir"
  137. if [[ -n $pkgbase ]]; then
  138. local fullver=$(get_full_version)
  139. # Can't do this unless the BUILDSCRIPT has been sourced.
  140. if (( BUILDFUNC )); then
  141. rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"*
  142. fi
  143. if (( CHECKFUNC )); then
  144. rm -f "${pkgbase}-${fullver}-${CARCH}-check.log"*
  145. fi
  146. if (( PKGFUNC )); then
  147. rm -f "${pkgbase}-${fullver}-${CARCH}-package.log"*
  148. elif (( SPLITPKG )); then
  149. for pkg in ${pkgname[@]}; do
  150. rm -f "${pkgbase}-${fullver}-${CARCH}-package_${pkg}.log"*
  151. done
  152. fi
  153.  
  154. # clean up dangling symlinks to packages
  155. for pkg in ${pkgname[@]}; do
  156. for file in ${pkg}-*-*-*{${PKGEXT},${SRCEXT}}; do
  157. if [[ -h $file && ! -e $file ]]; then
  158. rm -f "$file"
  159. fi
  160. done
  161. done
  162. fi
  163. fi
  164.  
  165. remove_deps
  166. }
  167.  
  168. enter_fakeroot() {
  169. msg "$(gettext "Entering %s environment...")" "fakeroot"
  170. fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
  171. }
  172.  
  173. # Automatically update pkgver variable if a pkgver() function is provided
  174. # Re-sources the PKGBUILD afterwards to allow for other variables that use $pkgver
  175. update_pkgver() {
  176. newpkgver=$(run_function_safe pkgver)
  177. if ! check_pkgver "$newpkgver"; then
  178. error "$(gettext "pkgver() generated an invalid version: %s")" "$newpkgver"
  179. exit 1
  180. fi
  181.  
  182. if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then
  183. if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
  184. if ! sed --follow-symlinks -i "s:^pkgver=[^ ]*:pkgver=$newpkgver:" "$BUILDFILE"; then
  185. error "$(gettext "Failed to update %s from %s to %s")" \
  186. "pkgver" "$pkgver" "$newpkgver"
  187. exit 1
  188. fi
  189. sed --follow-symlinks -i "s:^pkgrel=[^ ]*:pkgrel=1:" "$BUILDFILE"
  190. source_safe "$BUILDFILE"
  191. local fullver=$(get_full_version)
  192. msg "$(gettext "Updated version: %s")" "$pkgbase $fullver"
  193. else
  194. warning "$(gettext "%s is not writeable -- pkgver will not be updated")" \
  195. "$BUILDFILE"
  196. fi
  197. fi
  198. }
  199.  
  200. # Print 'source not found' error message and exit makepkg
  201. missing_source_file() {
  202. error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")"
  203. plain "$(gettext "Aborting...")"
  204. exit 1 # $E_MISSING_FILE
  205. }
  206.  
  207. source_has_signatures() {
  208. local file all_sources
  209.  
  210. get_all_sources_for_arch 'all_sources'
  211. for file in "${all_sources[@]}"; do
  212. if [[ ${file%%::*} = *.@(sig?(n)|asc) ]]; then
  213. return 0
  214. fi
  215. done
  216. return 1
  217. }
  218.  
  219. run_pacman() {
  220. local cmd
  221. if [[ $1 != -@(T|Qq) ]]; then
  222. cmd=("$PACMAN_PATH" $PACMAN_OPTS "$@")
  223. else
  224. cmd=("$PACMAN_PATH" "$@")
  225. fi
  226. if [[ $1 != -@(T|Qq|Q) ]]; then
  227. if type -p sudo >/dev/null; then
  228. cmd=(sudo "${cmd[@]}")
  229. else
  230. cmd=(su root -c "$(printf '%q ' "${cmd[@]}")")
  231. fi
  232. fi
  233. "${cmd[@]}"
  234. }
  235.  
  236. check_deps() {
  237. (( $# > 0 )) || return 0
  238.  
  239. local ret=0
  240. local pmout
  241. pmout=$(run_pacman -T "$@")
  242. ret=$?
  243.  
  244. if (( ret == 127 )); then #unresolved deps
  245. printf "%s\n" "$pmout"
  246. elif (( ret )); then
  247. error "$(gettext "'%s' returned a fatal error (%i): %s")" "$PACMAN" "$ret" "$pmout"
  248. return "$ret"
  249. fi
  250. }
  251.  
  252. handle_deps() {
  253. local R_DEPS_SATISFIED=0
  254. local R_DEPS_MISSING=1
  255.  
  256. (( $# == 0 )) && return $R_DEPS_SATISFIED
  257.  
  258. local deplist="$*"
  259.  
  260. if (( ! DEP_BIN )); then
  261. return $R_DEPS_MISSING
  262. fi
  263.  
  264. if (( DEP_BIN )); then
  265. # install missing deps from binary packages (using pacman -S)
  266. msg "$(gettext "Installing missing dependencies...")"
  267.  
  268. if ! run_pacman -S --asdeps $deplist; then
  269. error "$(gettext "'%s' failed to install missing dependencies.")" "$PACMAN"
  270. exit 1 # TODO: error code
  271. fi
  272. fi
  273.  
  274. # we might need the new system environment
  275. # save our shell options and turn off extglob
  276. local shellopts=$(shopt -p)
  277. shopt -u extglob
  278. source /etc/profile &>/dev/null
  279. eval "$shellopts"
  280.  
  281. return $R_DEPS_SATISFIED
  282. }
  283.  
  284. resolve_deps() {
  285. local R_DEPS_SATISFIED=0
  286. local R_DEPS_MISSING=1
  287.  
  288. # deplist cannot be declared like this: local deplist=$(foo)
  289. # Otherwise, the return value will depend on the assignment.
  290. local deplist
  291. deplist="$(set +E; check_deps $*)" || exit 1
  292. [[ -z $deplist ]] && return $R_DEPS_SATISFIED
  293.  
  294. if handle_deps $deplist; then
  295. # check deps again to make sure they were resolved
  296. deplist="$(set +E; check_deps $*)" || exit 1
  297. [[ -z $deplist ]] && return $R_DEPS_SATISFIED
  298. fi
  299.  
  300. msg "$(gettext "Missing dependencies:")"
  301. local dep
  302. for dep in $deplist; do
  303. msg2 "$dep"
  304. done
  305.  
  306. return $R_DEPS_MISSING
  307. }
  308.  
  309. remove_deps() {
  310. (( ! RMDEPS )) && return
  311.  
  312. # check for packages removed during dependency install (e.g. due to conflicts)
  313. # removing all installed packages is risky in this case
  314. if [[ -n $(grep -xvFf <(printf '%s\n' "${current_pkglist[@]}") \
  315. <(printf '%s\n' "${original_pkglist[@]}")) ]]; then
  316. warning "$(gettext "Failed to remove installed dependencies.")"
  317. return 0
  318. fi
  319.  
  320. local deplist
  321. deplist=($(grep -xvFf <(printf "%s\n" "${original_pkglist[@]}") \
  322. <(printf "%s\n" "${current_pkglist[@]}")))
  323. if [[ -z $deplist ]]; then
  324. return 0
  325. fi
  326.  
  327. msg "Removing installed dependencies..."
  328. # exit cleanly on failure to remove deps as package has been built successfully
  329. if ! run_pacman -Rn ${deplist[@]}; then
  330. warning "$(gettext "Failed to remove installed dependencies.")"
  331. return 0
  332. fi
  333. }
  334.  
  335. get_integlist() {
  336. local integ
  337. local integlist=()
  338.  
  339. for integ in "${known_hash_algos[@]}"; do
  340. local sumname="${integ}sums[@]"
  341. if [[ -n ${!sumname} ]]; then
  342. integlist+=("$integ")
  343. fi
  344. done
  345.  
  346. if (( ${#integlist[@]} > 0 )); then
  347. printf "%s\n" "${integlist[@]}"
  348. else
  349. printf "%s\n" "${INTEGRITY_CHECK[@]}"
  350. fi
  351. }
  352.  
  353. generate_one_checksum() {
  354. local integ=$1 arch=$2 sources numsrc indentsz idx
  355.  
  356. if [[ $arch ]]; then
  357. array_build sources "source_$arch"
  358. else
  359. array_build sources 'source'
  360. fi
  361.  
  362. numsrc=${#sources[*]}
  363. if (( numsrc == 0 )); then
  364. return
  365. fi
  366.  
  367. if [[ $arch ]]; then
  368. printf "%ssums_%s=(%n" "$integ" "$arch" indentsz
  369. else
  370. printf "%ssums=(%n" "$integ" indentsz
  371. fi
  372.  
  373. for (( idx = 0; idx < numsrc; ++idx )); do
  374. local netfile=${sources[idx]}
  375. local proto sum
  376. proto="$(get_protocol "$netfile")"
  377.  
  378. case $proto in
  379. bzr*|git*|hg*|svn*)
  380. sum="SKIP"
  381. ;;
  382. *)
  383. if [[ $netfile != *.@(sig?(n)|asc) ]]; then
  384. local file
  385. file="$(get_filepath "$netfile")" || missing_source_file "$netfile"
  386. sum="$(openssl dgst -${integ} "$file")"
  387. sum=${sum##* }
  388. else
  389. sum="SKIP"
  390. fi
  391. ;;
  392. esac
  393.  
  394. # indent checksum on lines after the first
  395. printf "%*s%s" $(( idx ? indentsz : 0 )) '' "'$sum'"
  396.  
  397. # print a newline on lines before the last
  398. (( idx < (numsrc - 1) )) && echo
  399. done
  400.  
  401. echo ")"
  402. }
  403.  
  404. generate_checksums() {
  405. msg "$(gettext "Generating checksums for source files...")"
  406.  
  407. if ! type -p openssl >/dev/null; then
  408. error "$(gettext "Cannot find the %s binary required for generating sourcefile checksums.")" "openssl"
  409. exit 1 # $E_MISSING_PROGRAM
  410. fi
  411.  
  412. local integlist
  413. if (( $# == 0 )); then
  414. IFS=$'\n' read -rd '' -a integlist < <(get_integlist)
  415. else
  416. integlist=("$@")
  417. fi
  418.  
  419. local integ
  420. for integ in "${integlist[@]}"; do
  421. if ! in_array "$integ" "${known_hash_algos[@]}"; then
  422. error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
  423. exit 1 # $E_CONFIG_ERROR
  424. fi
  425.  
  426. generate_one_checksum "$integ"
  427. for a in "${arch[@]}"; do
  428. generate_one_checksum "$integ" "$a"
  429. done
  430. done
  431. }
  432.  
  433. verify_integrity_one() {
  434. local source_name=$1 integ=$2 expectedsum=$3
  435.  
  436. local file="$(get_filename "$source_name")"
  437. printf ' %s ... ' "$file" >&2
  438.  
  439. if [[ $expectedsum = 'SKIP' ]]; then
  440. printf '%s\n' "$(gettext "Skipped")" >&2
  441. return
  442. fi
  443.  
  444. if ! file="$(get_filepath "$file")"; then
  445. printf '%s\n' "$(gettext "NOT FOUND")" >&2
  446. return 1
  447. fi
  448.  
  449. local realsum="$(openssl dgst -${integ} "$file")"
  450. realsum="${realsum##* }"
  451. if [[ ${expectedsum,,} = "$realsum" ]]; then
  452. printf '%s\n' "$(gettext "Passed")" >&2
  453. else
  454. printf '%s\n' "$(gettext "FAILED")" >&2
  455. return 1
  456. fi
  457.  
  458. return 0
  459. }
  460.  
  461. verify_integrity_sums() {
  462. local integ=$1 arch=$2 integrity_sums=() sources=() srcname
  463.  
  464. if [[ $arch ]]; then
  465. array_build integrity_sums "${integ}sums_$arch"
  466. srcname=source_$arch
  467. else
  468. array_build integrity_sums "${integ}sums"
  469. srcname=source
  470. fi
  471.  
  472. array_build sources "$srcname"
  473. if (( ${#integrity_sums[@]} == 0 && ${#sources[@]} == 0 )); then
  474. return 1
  475. fi
  476.  
  477. if (( ${#integrity_sums[@]} == ${#sources[@]} )); then
  478. msg "$(gettext "Validating %s files with %s...")" "$srcname" "${integ}sums"
  479. local idx errors=0
  480. for (( idx = 0; idx < ${#sources[*]}; idx++ )); do
  481. verify_integrity_one "${sources[idx]}" "$integ" "${integrity_sums[idx]}" || errors=1
  482. done
  483.  
  484. if (( errors )); then
  485. error "$(gettext "One or more files did not pass the validity check!")"
  486. exit 1 # TODO: error code
  487. fi
  488. elif (( ${#integrity_sums[@]} )); then
  489. error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ"
  490. exit 1 # TODO: error code
  491. else
  492. return 1
  493. fi
  494. }
  495.  
  496. check_checksums() {
  497. local integ a
  498. declare -A correlation
  499. (( SKIPCHECKSUMS )) && return 0
  500.  
  501. # Initialize a map which we'll use to verify that every source array has at
  502. # least some kind of checksum array associated with it.
  503. (( ${#source[*]} )) && correlation['source']=1
  504. case $1 in
  505. all)
  506. for a in "${arch[@]}"; do
  507. array_build _ source_"$a" && correlation["source_$a"]=1
  508. done
  509. ;;
  510. *)
  511. array_build _ source_"$CARCH" && correlation["source_$CARCH"]=1
  512. ;;
  513. esac
  514.  
  515. for integ in "${known_hash_algos[@]}"; do
  516. verify_integrity_sums "$integ" && unset "correlation[source]"
  517.  
  518. case $1 in
  519. all)
  520. for a in "${arch[@]}"; do
  521. verify_integrity_sums "$integ" "$a" && unset "correlation[source_$a]"
  522. done
  523. ;;
  524. *)
  525. verify_integrity_sums "$integ" "$CARCH" && unset "correlation[source_$CARCH]"
  526. ;;
  527. esac
  528. done
  529.  
  530. if (( ${#correlation[*]} )); then
  531. error "$(gettext "Integrity checks are missing for: %s")" "${!correlation[*]}"
  532. exit 1 # TODO: error code
  533. fi
  534. }
  535.  
  536. parse_gpg_statusfile() {
  537. local type arg1 arg6 arg10
  538.  
  539. while read -r _ type arg1 _ _ _ _ arg6 _ _ _ arg10 _; do
  540. case "$type" in
  541. GOODSIG)
  542. pubkey=$arg1
  543. success=1
  544. status="good"
  545. ;;
  546. EXPSIG)
  547. pubkey=$arg1
  548. success=1
  549. status="expired"
  550. ;;
  551. EXPKEYSIG)
  552. pubkey=$arg1
  553. success=1
  554. status="expiredkey"
  555. ;;
  556. REVKEYSIG)
  557. pubkey=$arg1
  558. success=0
  559. status="revokedkey"
  560. ;;
  561. BADSIG)
  562. pubkey=$arg1
  563. success=0
  564. status="bad"
  565. ;;
  566. ERRSIG)
  567. pubkey=$arg1
  568. success=0
  569. if [[ $arg6 == 9 ]]; then
  570. status="missingkey"
  571. else
  572. status="error"
  573. fi
  574. ;;
  575. VALIDSIG)
  576. if [[ $arg10 ]]; then
  577. # If the file was signed with a subkey, arg10 contains
  578. # the fingerprint of the primary key
  579. fingerprint=$arg10
  580. else
  581. fingerprint=$arg1
  582. fi
  583. ;;
  584. TRUST_UNDEFINED|TRUST_NEVER)
  585. trusted=0
  586. ;;
  587. TRUST_MARGINAL|TRUST_FULLY|TRUST_ULTIMATE)
  588. trusted=1
  589. ;;
  590. esac
  591. done < "$1"
  592. }
  593.  
  594. check_pgpsigs() {
  595. (( SKIPPGPCHECK )) && return 0
  596. ! source_has_signatures && return 0
  597.  
  598. msg "$(gettext "Verifying source file signatures with %s...")" "gpg"
  599.  
  600. local file ext decompress found pubkey success status fingerprint trusted
  601. local warning=0
  602. local errors=0
  603. local statusfile=$(mktemp)
  604. local all_sources
  605.  
  606. case $1 in
  607. all)
  608. get_all_sources 'all_sources'
  609. ;;
  610. *)
  611. get_all_sources_for_arch 'all_sources'
  612. ;;
  613. esac
  614. for file in "${all_sources[@]}"; do
  615. file="$(get_filename "$file")"
  616. if [[ $file != *.@(sig?(n)|asc) ]]; then
  617. continue
  618. fi
  619.  
  620. printf " %s ... " "${file%.*}" >&2
  621.  
  622. if ! file="$(get_filepath "$file")"; then
  623. printf '%s\n' "$(gettext "SIGNATURE NOT FOUND")" >&2
  624. errors=1
  625. continue
  626. fi
  627.  
  628. found=0
  629. for ext in "" gz bz2 xz lrz lzo Z; do
  630. if sourcefile="$(get_filepath "${file%.*}${ext:+.$ext}")"; then
  631. found=1
  632. break;
  633. fi
  634. done
  635. if (( ! found )); then
  636. printf '%s\n' "$(gettext "SOURCE FILE NOT FOUND")" >&2
  637. errors=1
  638. continue
  639. fi
  640.  
  641. case "$ext" in
  642. gz) decompress="gzip -c -d -f" ;;
  643. bz2) decompress="bzip2 -c -d -f" ;;
  644. xz) decompress="xz -c -d" ;;
  645. lrz) decompress="lrzip -q -d" ;;
  646. lzo) decompress="lzop -c -d -q" ;;
  647. Z) decompress="uncompress -c -f" ;;
  648. "") decompress="cat" ;;
  649. esac
  650.  
  651. $decompress < "$sourcefile" | gpg --quiet --batch --status-file "$statusfile" --verify "$file" - 2> /dev/null
  652. # these variables are assigned values in parse_gpg_statusfile
  653. success=0
  654. status=
  655. pubkey=
  656. fingerprint=
  657. trusted=
  658. parse_gpg_statusfile "$statusfile"
  659. if (( ! $success )); then
  660. printf '%s' "$(gettext "FAILED")" >&2
  661. case "$status" in
  662. "missingkey")
  663. printf ' (%s)' "$(gettext "unknown public key") $pubkey" >&2
  664. ;;
  665. "revokedkey")
  666. printf " ($(gettext "public key %s has been revoked"))" "$pubkey" >&2
  667. ;;
  668. "bad")
  669. printf ' (%s)' "$(gettext "bad signature from public key") $pubkey" >&2
  670. ;;
  671. "error")
  672. printf ' (%s)' "$(gettext "error during signature verification")" >&2
  673. ;;
  674. esac
  675. errors=1
  676. else
  677. if (( ${#validpgpkeys[@]} == 0 && !trusted )); then
  678. printf "%s ($(gettext "the public key %s is not trusted"))" $(gettext "FAILED") "$fingerprint" >&2
  679. errors=1
  680. elif (( ${#validpgpkeys[@]} > 0 )) && ! in_array "$fingerprint" "${validpgpkeys[@]}"; then
  681. printf "%s (%s %s)" "$(gettext "FAILED")" "$(gettext "invalid public key")" "$fingerprint"
  682. errors=1
  683. else
  684. printf '%s' "$(gettext "Passed")" >&2
  685. case "$status" in
  686. "expired")
  687. printf ' (%s)' "$(gettext "WARNING:") $(gettext "the signature has expired.")" >&2
  688. warnings=1
  689. ;;
  690. "expiredkey")
  691. printf ' (%s)' "$(gettext "WARNING:") $(gettext "the key has expired.")" >&2
  692. warnings=1
  693. ;;
  694. esac
  695. fi
  696. fi
  697. printf '\n' >&2
  698. done
  699.  
  700. rm -f "$statusfile"
  701.  
  702. if (( errors )); then
  703. error "$(gettext "One or more PGP signatures could not be verified!")"
  704. exit 1
  705. fi
  706.  
  707. if (( warnings )); then
  708. warning "$(gettext "Warnings have occurred while verifying the signatures.")"
  709. plain "$(gettext "Please make sure you really trust them.")"
  710. fi
  711. }
  712.  
  713. check_source_integrity() {
  714. if (( SKIPCHECKSUMS && SKIPPGPCHECK )); then
  715. warning "$(gettext "Skipping all source file integrity checks.")"
  716. elif (( SKIPCHECKSUMS )); then
  717. warning "$(gettext "Skipping verification of source file checksums.")"
  718. check_pgpsigs "$@"
  719. elif (( SKIPPGPCHECK )); then
  720. warning "$(gettext "Skipping verification of source file PGP signatures.")"
  721. check_checksums "$@"
  722. else
  723. check_checksums "$@"
  724. check_pgpsigs "$@"
  725. fi
  726. }
  727.  
  728. error_function() {
  729. if [[ -p $logpipe ]]; then
  730. rm "$logpipe"
  731. fi
  732. # first exit all subshells, then print the error
  733. if (( ! BASH_SUBSHELL )); then
  734. error "$(gettext "A failure occurred in %s().")" "$1"
  735. plain "$(gettext "Aborting...")"
  736. fi
  737. exit 2 # $E_BUILD_FAILED
  738. }
  739.  
  740. source_safe() {
  741. shopt -u extglob
  742. if ! source "$@"; then
  743. error "$(gettext "Failed to source %s")" "$1"
  744. exit 1
  745. fi
  746. shopt -s extglob
  747. }
  748.  
  749. merge_arch_attrs() {
  750. local attr supported_attrs=(
  751. provides conflicts depends replaces optdepends
  752. makedepends checkdepends)
  753.  
  754. for attr in "${supported_attrs[@]}"; do
  755. eval "$attr+=(\"\${${attr}_$CARCH[@]}\")"
  756. done
  757.  
  758. # ensure that calling this function is idempotent.
  759. unset -v "${supported_attrs[@]/%/_$CARCH}"
  760. }
  761.  
  762. source_buildfile() {
  763. source_safe "$@"
  764. }
  765.  
  766. run_function_safe() {
  767. local restoretrap
  768.  
  769. set -e
  770. set -E
  771.  
  772. restoretrap=$(trap -p ERR)
  773. trap 'error_function $pkgfunc' ERR
  774.  
  775. run_function "$1"
  776.  
  777. eval $restoretrap
  778.  
  779. set +E
  780. set +e
  781. }
  782.  
  783. run_function() {
  784. if [[ -z $1 ]]; then
  785. return 1
  786. fi
  787. local pkgfunc="$1"
  788.  
  789. # clear user-specified buildflags if requested
  790. if check_option "buildflags" "n"; then
  791. unset CPPFLAGS CFLAGS CXXFLAGS LDFLAGS
  792. fi
  793.  
  794. if check_option "debug" "y"; then
  795. CFLAGS+=" $DEBUG_CFLAGS"
  796. CXXFLAGS+=" $DEBUG_CXXFLAGS"
  797. fi
  798.  
  799. # clear user-specified makeflags if requested
  800. if check_option "makeflags" "n"; then
  801. unset MAKEFLAGS
  802. fi
  803.  
  804. msg "$(gettext "Starting %s()...")" "$pkgfunc"
  805. cd_safe "$srcdir"
  806.  
  807. # ensure all necessary build variables are exported
  808. export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
  809. # save our shell options so pkgfunc() can't override what we need
  810. local shellopts=$(shopt -p)
  811.  
  812. local ret=0
  813. if (( LOGGING )); then
  814. local fullver=$(get_full_version)
  815. local BUILDLOG="$LOGDEST/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
  816. if [[ -f $BUILDLOG ]]; then
  817. local i=1
  818. while true; do
  819. if [[ -f $BUILDLOG.$i ]]; then
  820. i=$(($i +1))
  821. else
  822. break
  823. fi
  824. done
  825. mv "$BUILDLOG" "$BUILDLOG.$i"
  826. fi
  827.  
  828. # ensure overridden package variables survive tee with split packages
  829. logpipe=$(mktemp -u "$LOGDEST/logpipe.XXXXXXXX")
  830. mkfifo "$logpipe"
  831. tee "$BUILDLOG" < "$logpipe" &
  832. local teepid=$!
  833.  
  834. $pkgfunc &>"$logpipe"
  835.  
  836. wait $teepid
  837. rm "$logpipe"
  838. else
  839. "$pkgfunc"
  840. fi
  841. # reset our shell options
  842. eval "$shellopts"
  843. }
  844.  
  845. run_prepare() {
  846. run_function_safe "prepare"
  847. }
  848.  
  849. run_build() {
  850. local ccache=0
  851.  
  852. # use ccache if it is requested (check buildenv and PKGBUILD opts)
  853. if check_buildoption "ccache" "y" && [[ -d /usr/lib/ccache/bin ]]; then
  854. export PATH="/usr/lib/ccache/bin:$PATH"
  855. ccache=1
  856. fi
  857.  
  858. # use distcc if it is requested (check buildenv and PKGBUILD opts)
  859. if check_buildoption "distcc" "y"; then
  860. if (( ccache )); then
  861. export CCACHE_PREFIX="${CCACHE_PREFIX:+$CCACHE_PREFIX }distcc"
  862. export CCACHE_BASEDIR="$srcdir"
  863. elif [[ -d /usr/lib/distcc/bin ]]; then
  864. export PATH="/usr/lib/distcc/bin:$PATH"
  865. fi
  866. export DISTCC_HOSTS
  867. fi
  868.  
  869. run_function_safe "build"
  870. }
  871.  
  872. run_check() {
  873. run_function_safe "check"
  874. }
  875.  
  876. run_package() {
  877. local pkgfunc
  878. if [[ -z $1 ]]; then
  879. pkgfunc="package"
  880. else
  881. pkgfunc="package_$1"
  882. fi
  883.  
  884. run_function_safe "$pkgfunc"
  885. }
  886.  
  887. find_libdepends() {
  888. local d sodepends;
  889.  
  890. sodepends=0;
  891. for d in "${depends[@]}"; do
  892. if [[ $d = *.so ]]; then
  893. sodepends=1;
  894. break;
  895. fi
  896. done
  897.  
  898. if (( sodepends == 0 )); then
  899. printf '%s\n' "${depends[@]}"
  900. return;
  901. fi
  902.  
  903. local libdeps filename soarch sofile soname soversion;
  904. declare -A libdeps;
  905.  
  906. while read -r filename; do
  907. # get architecture of the file; if soarch is empty it's not an ELF binary
  908. soarch=$(LC_ALL=C readelf -h "$filename" 2>/dev/null | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
  909. [[ -n "$soarch" ]] || continue
  910.  
  911. # process all libraries needed by the binary
  912. for sofile in $(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p')
  913. do
  914. # extract the library name: libfoo.so
  915. soname="${sofile%.so?(+(.+([0-9])))}".so
  916. # extract the major version: 1
  917. soversion="${sofile##*\.so\.}"
  918.  
  919. if [[ ${libdeps[$soname]} ]]; then
  920. if [[ ${libdeps[$soname]} != *${soversion}-${soarch}* ]]; then
  921. libdeps[$soname]+=" ${soversion}-${soarch}"
  922. fi
  923. else
  924. libdeps[$soname]="${soversion}-${soarch}"
  925. fi
  926. done
  927. done < <(find "$pkgdir" -type f -perm -u+x)
  928.  
  929. local libdepends v
  930. for d in "${depends[@]}"; do
  931. case "$d" in
  932. *.so)
  933. if [[ ${libdeps[$d]} ]]; then
  934. for v in ${libdeps[$d]}; do
  935. libdepends+=("$d=$v")
  936. done
  937. else
  938. warning "$(gettext "Library listed in %s is not required by any files: %s")" "'depends'" "$d"
  939. libdepends+=("$d")
  940. fi
  941. ;;
  942. *)
  943. libdepends+=("$d")
  944. ;;
  945. esac
  946. done
  947.  
  948. printf '%s\n' "${libdepends[@]}"
  949. }
  950.  
  951.  
  952. find_libprovides() {
  953. local p libprovides missing
  954. for p in "${provides[@]}"; do
  955. missing=0
  956. case "$p" in
  957. *.so)
  958. mapfile -t filename < <(find "$pkgdir" -type f -name $p\*)
  959. if [[ $filename ]]; then
  960. # packages may provide multiple versions of the same library
  961. for fn in "${filename[@]}"; do
  962. # check if we really have a shared object
  963. if LC_ALL=C readelf -h "$fn" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then
  964. # get the string binaries link to (e.g. libfoo.so.1.2 -> libfoo.so.1)
  965. local sofile=$(LC_ALL=C readelf -d "$fn" 2>/dev/null | sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p')
  966. if [[ -z "$sofile" ]]; then
  967. warning "$(gettext "Library listed in %s is not versioned: %s")" "'provides'" "$p"
  968. libprovides+=("$p")
  969. continue
  970. fi
  971.  
  972. # get the library architecture (32 or 64 bit)
  973. local soarch=$(LC_ALL=C readelf -h "$fn" | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
  974.  
  975. # extract the library major version
  976. local soversion="${sofile##*\.so\.}"
  977.  
  978. libprovides+=("${p}=${soversion}-${soarch}")
  979. else
  980. warning "$(gettext "Library listed in %s is not a shared object: %s")" "'provides'" "$p"
  981. libprovides+=("$p")
  982. fi
  983. done
  984. else
  985. libprovides+=("$p")
  986. missing=1
  987. fi
  988. ;;
  989. *)
  990. libprovides+=("$p")
  991. ;;
  992. esac
  993.  
  994. if (( missing )); then
  995. warning "$(gettext "Cannot find library listed in %s: %s")" "'provides'" "$p"
  996. fi
  997. done
  998.  
  999. printf '%s\n' "${libprovides[@]}"
  1000. }
  1001.  
  1002. srcinfo_open_section() {
  1003. printf '%s = %s\n' "$1" "$2"
  1004. }
  1005.  
  1006. srcinfo_close_section() {
  1007. echo
  1008. }
  1009.  
  1010. srcinfo_write_attr() {
  1011. # $1: attr name
  1012. # $2: attr values
  1013.  
  1014. local attrname=$1 attrvalues=("${@:2}")
  1015.  
  1016. # normalize whitespace, strip leading and trailing
  1017. attrvalues=("${attrvalues[@]//+([[:space:]])/ }")
  1018. attrvalues=("${attrvalues[@]#[[:space:]]}")
  1019. attrvalues=("${attrvalues[@]%[[:space:]]}")
  1020.  
  1021. printf "\t$attrname = %s\n" "${attrvalues[@]}"
  1022. }
  1023.  
  1024. pkgbuild_extract_to_srcinfo() {
  1025. # $1: pkgname
  1026. # $2: attr name
  1027. # $3: multivalued
  1028.  
  1029. local pkgname=$1 attrname=$2 isarray=$3 outvalue=
  1030.  
  1031. if get_pkgbuild_attribute "$pkgname" "$attrname" "$isarray" 'outvalue'; then
  1032. srcinfo_write_attr "$attrname" "${outvalue[@]}"
  1033. fi
  1034. }
  1035.  
  1036. srcinfo_write_section_details() {
  1037. local attr package_arch a
  1038. local multivalued_arch_attrs=(source provides conflicts depends replaces
  1039. optdepends makedepends checkdepends
  1040. {md5,sha{1,224,256,384,512}}sums)
  1041.  
  1042. for attr in "${singlevalued[@]}"; do
  1043. pkgbuild_extract_to_srcinfo "$1" "$attr" 0
  1044. done
  1045.  
  1046. for attr in "${multivalued[@]}"; do
  1047. pkgbuild_extract_to_srcinfo "$1" "$attr" 1
  1048. done
  1049.  
  1050. get_pkgbuild_attribute "$1" 'arch' 1 'package_arch'
  1051. for a in "${package_arch[@]}"; do
  1052. # 'any' is special. there's no support for, e.g. depends_any.
  1053. [[ $a = any ]] && continue
  1054.  
  1055. for attr in "${multivalued_arch_attrs[@]}"; do
  1056. pkgbuild_extract_to_srcinfo "$1" "${attr}_$a" 1
  1057. done
  1058. done
  1059. }
  1060.  
  1061. srcinfo_write_global() {
  1062. local singlevalued=(pkgdesc pkgver pkgrel epoch url install changelog)
  1063. local multivalued=(arch groups license checkdepends makedepends
  1064. depends optdepends provides conflicts replaces
  1065. noextract options backup
  1066. source validpgpkeys {md5,sha{1,224,256,384,512}}sums)
  1067.  
  1068. srcinfo_open_section 'pkgbase' "${pkgbase:-$pkgname}"
  1069. srcinfo_write_section_details ''
  1070. srcinfo_close_section
  1071. }
  1072.  
  1073. srcinfo_write_package() {
  1074. local singlevalued=(pkgdesc url install changelog)
  1075. local multivalued=(arch groups license checkdepends depends optdepends
  1076. provides conflicts replaces options backup)
  1077.  
  1078. srcinfo_open_section 'pkgname' "$1"
  1079. srcinfo_write_section_details "$1"
  1080. srcinfo_close_section
  1081. }
  1082.  
  1083. write_srcinfo_header() {
  1084. printf "# Generated by makepkg %s\n" "$makepkg_version"
  1085. printf "# %s\n" "$(LC_ALL=C date -u)"
  1086. }
  1087.  
  1088. write_srcinfo_content() {
  1089. local pkg
  1090.  
  1091. srcinfo_write_global
  1092.  
  1093. for pkg in "${pkgname[@]}"; do
  1094. srcinfo_write_package "$pkg"
  1095. done
  1096. }
  1097.  
  1098. write_srcinfo() {
  1099. write_srcinfo_header
  1100. write_srcinfo_content
  1101. }
  1102.  
  1103. write_pkginfo() {
  1104. local builddate=$(date -u "+%s")
  1105. if [[ -n $PACKAGER ]]; then
  1106. local packager="$PACKAGER"
  1107. else
  1108. local packager="Unknown Packager"
  1109. fi
  1110.  
  1111. local size="$(/usr/bin/du -sk --apparent-size)"
  1112. size="$(( ${size%%[^0-9]*} * 1024 ))"
  1113.  
  1114. merge_arch_attrs
  1115.  
  1116. msg2 "$(gettext "Generating %s file...")" ".PKGINFO"
  1117. printf "# Generated by makepkg %s\n" "$makepkg_version"
  1118. printf "# using %s\n" "$(fakeroot -v)"
  1119. printf "# %s\n" "$(LC_ALL=C date -u)"
  1120.  
  1121. printf "pkgname = %s\n" "$pkgname"
  1122. if (( SPLITPKG )) || [[ "$pkgbase" != "$pkgname" ]]; then
  1123. printf "pkgbase = %s\n" "$pkgbase"
  1124. fi
  1125.  
  1126. local fullver=$(get_full_version)
  1127. printf "pkgver = %s\n" "$fullver"
  1128. if [[ "$fullver" != "$basever" ]]; then
  1129. printf "basever = %s\n" "$basever"
  1130. fi
  1131.  
  1132. # TODO: all fields should have this treatment
  1133. local spd="${pkgdesc//+([[:space:]])/ }"
  1134. spd=("${spd[@]#[[:space:]]}")
  1135. spd=("${spd[@]%[[:space:]]}")
  1136.  
  1137. printf "pkgdesc = %s\n" "$spd"
  1138. printf "url = %s\n" "$url"
  1139. printf "builddate = %s\n" "$builddate"
  1140. printf "packager = %s\n" "$packager"
  1141. printf "size = %s\n" "$size"
  1142. printf "arch = %s\n" "$pkgarch"
  1143.  
  1144. mapfile -t provides < <(find_libprovides)
  1145. mapfile -t depends < <(find_libdepends)
  1146.  
  1147. [[ $license ]] && printf "license = %s\n" "${license[@]}"
  1148. [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}"
  1149. [[ $groups ]] && printf "group = %s\n" "${groups[@]}"
  1150. [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}"
  1151. [[ $provides ]] && printf "provides = %s\n" "${provides[@]}"
  1152. [[ $backup ]] && printf "backup = %s\n" "${backup[@]}"
  1153. [[ $depends ]] && printf "depend = %s\n" "${depends[@]}"
  1154. [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]//+([[:space:]])/ }"
  1155. [[ $makedepends ]] && printf "makedepend = %s\n" "${makedepends[@]}"
  1156. [[ $checkdepends ]] && printf "checkdepend = %s\n" "${checkdepends[@]}"
  1157. }
  1158.  
  1159. write_buildinfo() {
  1160. msg2 "$(gettext "Generating %s file...")" ".BUILDINFO"
  1161.  
  1162. printf "builddir = %s\n" "${BUILDDIR}"
  1163.  
  1164. local sum="$(openssl dgst -sha256 "${BUILDFILE}")"
  1165. sum=${sum##* }
  1166.  
  1167. printf "pkgbuild_sha256sum = %s\n" $sum
  1168.  
  1169. printf "buildenv = %s\n" "${BUILDENV[@]}"
  1170. printf "options = %s\n" "${OPTIONS[@]}"
  1171.  
  1172. local pkglist=($(run_pacman -Q | sed "s# #-#"))
  1173. printf "installed = %s\n" "${pkglist[@]}"
  1174. }
  1175.  
  1176. create_package() {
  1177. (( NOARCHIVE )) && return
  1178.  
  1179. if [[ ! -d $pkgdir ]]; then
  1180. error "$(gettext "Missing %s directory.")" "\$pkgdir/"
  1181. plain "$(gettext "Aborting...")"
  1182. exit 1 # $E_MISSING_PKGDIR
  1183. fi
  1184.  
  1185. cd_safe "$pkgdir"
  1186. msg "$(gettext "Creating package \"%s\"...")" "$pkgname"
  1187.  
  1188. pkgarch=$(get_pkg_arch)
  1189. write_pkginfo > .PKGINFO
  1190. write_buildinfo > .BUILDINFO
  1191.  
  1192. local comp_files=('.PKGINFO' '.BUILDINFO')
  1193.  
  1194. # check for changelog/install files
  1195. for i in 'changelog/.CHANGELOG' 'install/.INSTALL'; do
  1196. IFS='/' read -r orig dest < <(printf '%s\n' "$i")
  1197.  
  1198. if [[ -n ${!orig} ]]; then
  1199. msg2 "$(gettext "Adding %s file...")" "$orig"
  1200. if ! cp "$startdir/${!orig}" "$dest"; then
  1201. error "$(gettext "Failed to add %s file to package.")" "$orig"
  1202. exit 1
  1203. fi
  1204. chmod 644 "$dest"
  1205. comp_files+=("$dest")
  1206. fi
  1207. done
  1208.  
  1209. # tar it up
  1210. local fullver=$(get_full_version)
  1211. local pkg_file="$PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT}"
  1212. local ret=0
  1213.  
  1214. [[ -f $pkg_file ]] && rm -f "$pkg_file"
  1215. [[ -f $pkg_file.sig ]] && rm -f "$pkg_file.sig"
  1216.  
  1217. # when fileglobbing, we want * in an empty directory to expand to
  1218. # the null string rather than itself
  1219. shopt -s nullglob
  1220.  
  1221. msg2 "$(gettext "Generating .MTREE file...")"
  1222. LANG=C bsdtar -czf .MTREE --format=mtree \
  1223. --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' \
  1224. "${comp_files[@]}" *
  1225. comp_files+=(".MTREE")
  1226.  
  1227. msg2 "$(gettext "Compressing package...")"
  1228. # TODO: Maybe this can be set globally for robustness
  1229. shopt -s -o pipefail
  1230. # bsdtar's gzip compression always saves the time stamp, making one
  1231. # archive created using the same command line distinct from another.
  1232. # Disable bsdtar compression and use gzip -n for now.
  1233. LANG=C bsdtar -cf - "${comp_files[@]}" * |
  1234. case "$PKGEXT" in
  1235. *tar.gz) ${COMPRESSGZ[@]:-gzip -c -f -n} ;;
  1236. *tar.bz2) ${COMPRESSBZ2[@]:-bzip2 -c -f} ;;
  1237. *tar.xz) ${COMPRESSXZ[@]:-xz -c -z -} ;;
  1238. *tar.lrz) ${COMPRESSLRZ[@]:-lrzip -q} ;;
  1239. *tar.lzo) ${COMPRESSLZO[@]:-lzop -q} ;;
  1240. *tar.Z) ${COMPRESSZ[@]:-compress -c -f} ;;
  1241. *tar) cat ;;
  1242. *) warning "$(gettext "'%s' is not a valid archive extension.")" \
  1243. "$PKGEXT"; cat ;;
  1244. esac > "${pkg_file}" || ret=$?
  1245.  
  1246. shopt -u nullglob
  1247. shopt -u -o pipefail
  1248.  
  1249. if (( ret )); then
  1250. error "$(gettext "Failed to create package file.")"
  1251. exit 1 # TODO: error code
  1252. fi
  1253.  
  1254. create_signature "$pkg_file"
  1255.  
  1256. if (( ! ret )) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then
  1257. rm -f "${pkg_file/$PKGDEST/$startdir}"
  1258. ln -s "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
  1259. ret=$?
  1260. if [[ -f $pkg_file.sig ]]; then
  1261. rm -f "${pkg_file/$PKGDEST/$startdir}.sig"
  1262. ln -s "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
  1263. fi
  1264. fi
  1265.  
  1266. if (( ret )); then
  1267. warning "$(gettext "Failed to create symlink to package file.")"
  1268. fi
  1269. }
  1270.  
  1271. create_debug_package() {
  1272. # check if a debug package was requested
  1273. if ! check_option "debug" "y" || ! check_option "strip" "y"; then
  1274. return
  1275. fi
  1276.  
  1277. pkgdir="${pkgdir}-debug"
  1278.  
  1279. # check if we have any debug symbols to package
  1280. if dir_is_empty "$pkgdir/usr/lib/debug"; then
  1281. return
  1282. fi
  1283.  
  1284. depends=("$pkgname=$(get_full_version)")
  1285. pkgdesc="Detached debugging symbols for $pkgname"
  1286. pkgname=$pkgname-debug
  1287.  
  1288. unset groups optdepends provides conflicts replaces backup install changelog
  1289.  
  1290. create_package
  1291. }
  1292.  
  1293. create_signature() {
  1294. if [[ $SIGNPKG != 'y' ]]; then
  1295. return
  1296. fi
  1297. local ret=0
  1298. local filename="$1"
  1299. msg "$(gettext "Signing package...")"
  1300.  
  1301. local SIGNWITHKEY=""
  1302. if [[ -n $GPGKEY ]]; then
  1303. SIGNWITHKEY="-u ${GPGKEY}"
  1304. fi
  1305.  
  1306. gpg --detach-sign --use-agent ${SIGNWITHKEY} --no-armor "$filename" &>/dev/null || ret=$?
  1307.  
  1308.  
  1309. if (( ! ret )); then
  1310. msg2 "$(gettext "Created signature file %s.")" "$filename.sig"
  1311. else
  1312. warning "$(gettext "Failed to sign package file.")"
  1313. fi
  1314. }
  1315.  
  1316. create_srcpackage() {
  1317. local ret=0
  1318. msg "$(gettext "Creating source package...")"
  1319. local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
  1320. mkdir "${srclinks}"/${pkgbase}
  1321.  
  1322. msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
  1323. ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
  1324.  
  1325. msg2 "$(gettext "Generating %s file...")" .SRCINFO
  1326. write_srcinfo > "$srclinks/$pkgbase"/.SRCINFO
  1327.  
  1328. local file all_sources
  1329.  
  1330. get_all_sources 'all_sources'
  1331. for file in "${all_sources[@]}"; do
  1332. if [[ "$file" = "$(get_filename "$file")" ]] || (( SOURCEONLY == 2 )); then
  1333. local absfile
  1334. absfile=$(get_filepath "$file") || missing_source_file "$file"
  1335. msg2 "$(gettext "Adding %s...")" "${absfile##*/}"
  1336. ln -s "$absfile" "$srclinks/$pkgbase"
  1337. fi
  1338. done
  1339.  
  1340. local i
  1341. for i in 'changelog' 'install'; do
  1342. local file files
  1343.  
  1344. [[ ${!i} ]] && files+=("${!i}")
  1345. for name in "${pkgname[@]}"; do
  1346. if extract_function_variable "package_$name" "$i" 0 file; then
  1347. files+=("$file")
  1348. fi
  1349. done
  1350.  
  1351. for file in "${files[@]}"; do
  1352. if [[ $file && ! -f "${srclinks}/${pkgbase}/$file" ]]; then
  1353. msg2 "$(gettext "Adding %s file (%s)...")" "$i" "${file}"
  1354. ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
  1355. fi
  1356. done
  1357. done
  1358.  
  1359. local TAR_OPT
  1360. case "$SRCEXT" in
  1361. *tar.gz) TAR_OPT="-z" ;;
  1362. *tar.bz2) TAR_OPT="-j" ;;
  1363. *tar.xz) TAR_OPT="-J" ;;
  1364. *tar.lrz) TAR_OPT="--lrzip" ;;
  1365. *tar.lzo) TAR_OPT="--lzop" ;;
  1366. *tar.Z) TAR_OPT="-Z" ;;
  1367. *tar) TAR_OPT="" ;;
  1368. *) warning "$(gettext "'%s' is not a valid archive extension.")" \
  1369. "$SRCEXT" ;;
  1370. esac
  1371.  
  1372. local fullver=$(get_full_version)
  1373. local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
  1374.  
  1375. # tar it up
  1376. msg2 "$(gettext "Compressing source package...")"
  1377. cd_safe "${srclinks}"
  1378. if ! LANG=C bsdtar -cL ${TAR_OPT} -f "$pkg_file" ${pkgbase}; then
  1379. error "$(gettext "Failed to create source package file.")"
  1380. exit 1 # TODO: error code
  1381. fi
  1382.  
  1383. create_signature "$pkg_file"
  1384.  
  1385. if [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then
  1386. rm -f "${pkg_file/$SRCPKGDEST/$startdir}"
  1387. ln -s "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}"
  1388. ret=$?
  1389. if [[ -f $pkg_file.sig ]]; then
  1390. rm -f "${pkg_file/$SRCPKGDEST/$startdir}.sig"
  1391. ln -s "$pkg_file.sig" "${pkg_file/$SRCPKGDEST/$startdir}.sig"
  1392. fi
  1393. fi
  1394.  
  1395. if (( ret )); then
  1396. warning "$(gettext "Failed to create symlink to source package file.")"
  1397. fi
  1398.  
  1399. cd_safe "${startdir}"
  1400. rm -rf "${srclinks}"
  1401. }
  1402.  
  1403. # this function always returns 0 to make sure clean-up will still occur
  1404. install_package() {
  1405. (( ! INSTALL )) && return
  1406.  
  1407. if (( ! SPLITPKG )); then
  1408. msg "$(gettext "Installing package %s with %s...")" "$pkgname" "$PACMAN -U"
  1409. else
  1410. msg "$(gettext "Installing %s package group with %s...")" "$pkgbase" "$PACMAN -U"
  1411. fi
  1412.  
  1413. local fullver pkgarch pkg pkglist
  1414. (( ASDEPS )) && pkglist+=('--asdeps')
  1415. (( NEEDED )) && pkglist+=('--needed')
  1416.  
  1417. for pkg in ${pkgname[@]}; do
  1418. fullver=$(get_full_version)
  1419. pkgarch=$(get_pkg_arch $pkg)
  1420. pkglist+=("$PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT}")
  1421.  
  1422. if [[ -f "$PKGDEST/${pkg}-debug-${fullver}-${pkgarch}${PKGEXT}" ]]; then
  1423. pkglist+=("$PKGDEST/${pkg}-debug-${fullver}-${pkgarch}${PKGEXT}")
  1424. fi
  1425. done
  1426.  
  1427. if ! run_pacman -U "${pkglist[@]}"; then
  1428. warning "$(gettext "Failed to install built package(s).")"
  1429. return 0
  1430. fi
  1431. }
  1432.  
  1433. get_vcsclient() {
  1434. local proto=${1%%+*}
  1435.  
  1436. local i
  1437. for i in "${VCSCLIENTS[@]}"; do
  1438. local handler="${i%%::*}"
  1439. if [[ $proto = "$handler" ]]; then
  1440. local client="${i##*::}"
  1441. break
  1442. fi
  1443. done
  1444.  
  1445. # if we didn't find an client, return an error
  1446. if [[ -z $client ]]; then
  1447. error "$(gettext "Unknown download protocol: %s")" "$proto"
  1448. plain "$(gettext "Aborting...")"
  1449. exit 1 # $E_CONFIG_ERROR
  1450. fi
  1451.  
  1452. printf "%s\n" "$client"
  1453. }
  1454.  
  1455. check_vcs_software() {
  1456. local all_sources all_deps deps ret=0
  1457.  
  1458. if (( SOURCEONLY == 1 )); then
  1459. # we will not download VCS sources
  1460. return $ret
  1461. fi
  1462.  
  1463. if [[ -z $PACMAN_PATH ]]; then
  1464. warning "$(gettext "Cannot find the %s binary needed to check VCS source requirements.")" "$PACMAN"
  1465. return $ret
  1466. fi
  1467.  
  1468. # we currently only use global depends/makedepends arrays for --syncdeps
  1469. for attr in depends makedepends; do
  1470. get_pkgbuild_attribute "$pkg" "$attr" 1 'deps'
  1471. all_deps+=("${deps[@]}")
  1472.  
  1473. get_pkgbuild_attribute "$pkg" "${attr}_$CARCH" 1 'deps'
  1474. all_deps+=("${deps[@]}")
  1475. done
  1476.  
  1477. get_all_sources_for_arch 'all_sources'
  1478. for netfile in ${all_sources[@]}; do
  1479. local proto=$(get_protocol "$netfile")
  1480.  
  1481. case $proto in
  1482. bzr*|git*|hg*|svn*)
  1483. if ! type -p ${proto%%+*} > /dev/null; then
  1484. local client
  1485. client=$(get_vcsclient "$proto") || exit $?
  1486. # ensure specified program is installed
  1487. local uninstalled
  1488. uninstalled="$(set +E; check_deps $client)" || exit 1
  1489. # if not installed, check presence in depends or makedepends
  1490. if [[ -n "$uninstalled" ]] && (( ! NODEPS || ( VERIFYSOURCE && !DEP_BIN ) )); then
  1491. if ! in_array "$client" ${all_deps[@]}; then
  1492. error "$(gettext "Cannot find the %s package needed to handle %s sources.")" \
  1493. "$client" "${proto%%+*}"
  1494. ret=1
  1495. fi
  1496. fi
  1497. fi
  1498. ;;
  1499. *)
  1500. # non VCS source
  1501. ;;
  1502. esac
  1503. done
  1504.  
  1505. return $ret
  1506. }
  1507.  
  1508. check_software() {
  1509. # check for needed software
  1510. local ret=0
  1511.  
  1512. # check for PACMAN if we need it
  1513. if (( ! NODEPS || DEP_BIN || RMDEPS || INSTALL )); then
  1514. if [[ -z $PACMAN_PATH ]]; then
  1515. error "$(gettext "Cannot find the %s binary required for dependency operations.")" "$PACMAN"
  1516. ret=1
  1517. fi
  1518. fi
  1519.  
  1520. # check for sudo if we will need it during makepkg execution
  1521. if (( DEP_BIN || RMDEPS || INSTALL )); then
  1522. if ! type -p sudo >/dev/null; then
  1523. warning "$(gettext "Cannot find the %s binary. Will use %s to acquire root privileges.")" "sudo" "su"
  1524. fi
  1525. fi
  1526.  
  1527. # fakeroot - correct package file permissions
  1528. if check_buildenv "fakeroot" "y" && (( EUID > 0 )); then
  1529. if ! type -p fakeroot >/dev/null; then
  1530. error "$(gettext "Cannot find the %s binary.")" "fakeroot"
  1531. ret=1
  1532. fi
  1533. fi
  1534.  
  1535. # gpg - package signing
  1536. if [[ $SIGNPKG == 'y' ]] || { [[ -z $SIGNPKG ]] && check_buildenv "sign" "y"; }; then
  1537. if ! type -p gpg >/dev/null; then
  1538. error "$(gettext "Cannot find the %s binary required for signing packages.")" "gpg"
  1539. ret=1
  1540. fi
  1541. fi
  1542.  
  1543. # gpg - source verification
  1544. if (( ! SKIPPGPCHECK )) && source_has_signatures; then
  1545. if ! type -p gpg >/dev/null; then
  1546. error "$(gettext "Cannot find the %s binary required for verifying source files.")" "gpg"
  1547. ret=1
  1548. fi
  1549. fi
  1550.  
  1551. # openssl - checksum operations
  1552. if (( ! SKIPCHECKSUMS )); then
  1553. if ! type -p openssl >/dev/null; then
  1554. error "$(gettext "Cannot find the %s binary required for validating source file checksums.")" "openssl"
  1555. ret=1
  1556. fi
  1557. fi
  1558.  
  1559. # upx - binary compression
  1560. if check_option "upx" "y"; then
  1561. if ! type -p upx >/dev/null; then
  1562. error "$(gettext "Cannot find the %s binary required for compressing binaries.")" "upx"
  1563. ret=1
  1564. fi
  1565. fi
  1566.  
  1567. # optipng - PNG image optimization
  1568. if check_option "optipng" "y"; then
  1569. if ! type -p optipng >/dev/null; then
  1570. error "$(gettext "Cannot find the %s binary required for optimizing PNG images.")" "optipng"
  1571. ret=1
  1572. fi
  1573. fi
  1574.  
  1575. # distcc - compilation with distcc
  1576. if check_buildoption "distcc" "y"; then
  1577. if ! type -p distcc >/dev/null; then
  1578. error "$(gettext "Cannot find the %s binary required for distributed compilation.")" "distcc"
  1579. ret=1
  1580. fi
  1581. fi
  1582.  
  1583. # ccache - compilation with ccache
  1584. if check_buildoption "ccache" "y"; then
  1585. if ! type -p ccache >/dev/null; then
  1586. error "$(gettext "Cannot find the %s binary required for compiler cache usage.")" "ccache"
  1587. ret=1
  1588. fi
  1589. fi
  1590.  
  1591. # strip - strip symbols from binaries/libraries
  1592. if check_option "strip" "y"; then
  1593. if ! type -p strip >/dev/null; then
  1594. error "$(gettext "Cannot find the %s binary required for object file stripping.")" "strip"
  1595. ret=1
  1596. fi
  1597. fi
  1598.  
  1599. # gzip - compressig man and info pages
  1600. if check_option "zipman" "y"; then
  1601. if ! type -p gzip >/dev/null; then
  1602. error "$(gettext "Cannot find the %s binary required for compressing man and info pages.")" "gzip"
  1603. ret=1
  1604. fi
  1605. fi
  1606.  
  1607. # tools to download vcs sources
  1608. if ! check_vcs_software; then
  1609. ret=1
  1610. fi
  1611.  
  1612. return $ret
  1613. }
  1614.  
  1615. check_build_status() {
  1616. if (( ! SPLITPKG )); then
  1617. fullver=$(get_full_version)
  1618. pkgarch=$(get_pkg_arch)
  1619. if [[ -f $PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT} ]] \
  1620. && ! (( FORCE || SOURCEONLY || NOBUILD || NOARCHIVE)); then
  1621. if (( INSTALL )); then
  1622. warning "$(gettext "A package has already been built, installing existing package...")"
  1623. install_package
  1624. exit 0
  1625. else
  1626. error "$(gettext "A package has already been built. (use %s to overwrite)")" "-f"
  1627. exit 1
  1628. fi
  1629. fi
  1630. else
  1631. allpkgbuilt=1
  1632. somepkgbuilt=0
  1633. for pkg in ${pkgname[@]}; do
  1634. fullver=$(get_full_version)
  1635. pkgarch=$(get_pkg_arch $pkg)
  1636. if [[ -f $PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT} ]]; then
  1637. somepkgbuilt=1
  1638. else
  1639. allpkgbuilt=0
  1640. fi
  1641. done
  1642. if ! (( FORCE || SOURCEONLY || NOBUILD || NOARCHIVE)); then
  1643. if (( allpkgbuilt )); then
  1644. if (( INSTALL )); then
  1645. warning "$(gettext "The package group has already been built, installing existing packages...")"
  1646. install_package
  1647. exit 0
  1648. else
  1649. error "$(gettext "The package group has already been built. (use %s to overwrite)")" "-f"
  1650. exit 1
  1651. fi
  1652. fi
  1653. if (( somepkgbuilt && ! PKGVERFUNC )); then
  1654. error "$(gettext "Part of the package group has already been built. (use %s to overwrite)")" "-f"
  1655. exit 1
  1656. fi
  1657. fi
  1658. unset allpkgbuilt somepkgbuilt
  1659. fi
  1660. }
  1661.  
  1662. backup_package_variables() {
  1663. local var
  1664. for var in ${splitpkg_overrides[@]}; do
  1665. local indirect="${var}_backup"
  1666. eval "${indirect}=(\"\${$var[@]}\")"
  1667. done
  1668. }
  1669.  
  1670. restore_package_variables() {
  1671. local var
  1672. for var in ${splitpkg_overrides[@]}; do
  1673. local indirect="${var}_backup"
  1674. if [[ -n ${!indirect} ]]; then
  1675. eval "${var}=(\"\${$indirect[@]}\")"
  1676. else
  1677. unset ${var}
  1678. fi
  1679. done
  1680. }
  1681.  
  1682. run_split_packaging() {
  1683. local pkgname_backup=("${pkgname[@]}")
  1684. for pkgname in ${pkgname_backup[@]}; do
  1685. pkgdir="$pkgdirbase/$pkgname"
  1686. mkdir "$pkgdir"
  1687. backup_package_variables
  1688. run_package $pkgname
  1689. tidy_install
  1690. lint_package
  1691. create_package
  1692. create_debug_package
  1693. restore_package_variables
  1694. done
  1695. pkgname=("${pkgname_backup[@]}")
  1696. }
  1697.  
  1698. # getopt-like parser
  1699. parseopts() {
  1700. local opt= optarg= i= shortopts=$1
  1701. local -a longopts=() unused_argv=()
  1702.  
  1703. shift
  1704. while [[ $1 && $1 != '--' ]]; do
  1705. longopts+=("$1")
  1706. shift
  1707. done
  1708. shift
  1709.  
  1710. longoptmatch() {
  1711. local o longmatch=()
  1712. for o in "${longopts[@]}"; do
  1713. if [[ ${o%:} = "$1" ]]; then
  1714. longmatch=("$o")
  1715. break
  1716. fi
  1717. [[ ${o%:} = "$1"* ]] && longmatch+=("$o")
  1718. done
  1719.  
  1720. case ${#longmatch[*]} in
  1721. 1)
  1722. # success, override with opt and return arg req (0 == none, 1 == required)
  1723. opt=${longmatch%:}
  1724. if [[ $longmatch = *: ]]; then
  1725. return 1
  1726. else
  1727. return 0
  1728. fi ;;
  1729. 0)
  1730. # fail, no match found
  1731. return 255 ;;
  1732. *)
  1733. # fail, ambiguous match
  1734. printf "makepkg: $(gettext "option '%s' is ambiguous; possibilities:")" "--$1"
  1735. printf " '%s'" "${longmatch[@]%:}"
  1736. printf '\n'
  1737. return 254 ;;
  1738. esac >&2
  1739. }
  1740.  
  1741. while (( $# )); do
  1742. case $1 in
  1743. --) # explicit end of options
  1744. shift
  1745. break
  1746. ;;
  1747. -[!-]*) # short option
  1748. for (( i = 1; i < ${#1}; i++ )); do
  1749. opt=${1:i:1}
  1750.  
  1751. # option doesn't exist
  1752. if [[ $shortopts != *$opt* ]]; then
  1753. printf "makepkg: $(gettext "invalid option") -- '%s'\n" "$opt" >&2
  1754. OPTRET=(--)
  1755. return 1
  1756. fi
  1757.  
  1758. OPTRET+=("-$opt")
  1759. # option requires optarg
  1760. if [[ $shortopts = *$opt:* ]]; then
  1761. # if we're not at the end of the option chunk, the rest is the optarg
  1762. if (( i < ${#1} - 1 )); then
  1763. OPTRET+=("${1:i+1}")
  1764. break
  1765. # if we're at the end, grab the the next positional, if it exists
  1766. elif (( i == ${#1} - 1 )) && [[ $2 ]]; then
  1767. OPTRET+=("$2")
  1768. shift
  1769. break
  1770. # parse failure
  1771. else
  1772. printf "makepkg: $(gettext "option requires an argument") -- '%s'\n" "$opt" >&2
  1773. OPTRET=(--)
  1774. return 1
  1775. fi
  1776. fi
  1777. done
  1778. ;;
  1779. --?*=*|--?*) # long option
  1780. IFS='=' read -r opt optarg <<< "${1#--}"
  1781. longoptmatch "$opt"
  1782. case $? in
  1783. 0)
  1784. # parse failure
  1785. if [[ $optarg ]]; then
  1786. printf "makepkg: $(gettext "option '%s' does not allow an argument")\n" "--$opt" >&2
  1787. OPTRET=(--)
  1788. return 1
  1789. # --longopt
  1790. else
  1791. OPTRET+=("--$opt")
  1792. fi
  1793. ;;
  1794. 1)
  1795. # --longopt=optarg
  1796. if [[ $optarg ]]; then
  1797. OPTRET+=("--$opt" "$optarg")
  1798. # --longopt optarg
  1799. elif [[ $2 ]]; then
  1800. OPTRET+=("--$opt" "$2" )
  1801. shift
  1802. # parse failure
  1803. else
  1804. printf "makepkg: $(gettext "option '%s' requires an argument")\n" "--$opt" >&2
  1805. OPTRET=(--)
  1806. return 1
  1807. fi
  1808. ;;
  1809. 254)
  1810. # ambiguous option -- error was reported for us by longoptmatch()
  1811. OPTRET=(--)
  1812. return 1
  1813. ;;
  1814. 255)
  1815. # parse failure
  1816. printf "makepkg: $(gettext "invalid option") '--%s'\n" "$opt" >&2
  1817. OPTRET=(--)
  1818. return 1
  1819. ;;
  1820. esac
  1821. ;;
  1822. *) # non-option arg encountered, add it as a parameter
  1823. unused_argv+=("$1")
  1824. ;;
  1825. esac
  1826. shift
  1827. done
  1828.  
  1829. # add end-of-opt terminator and any leftover positional parameters
  1830. OPTRET+=('--' "${unused_argv[@]}" "$@")
  1831. unset longoptmatch
  1832.  
  1833. return 0
  1834. }
  1835.  
  1836.  
  1837. usage() {
  1838. printf "makepkg (pacman) %s\n" "$makepkg_version"
  1839. echo
  1840. printf -- "$(gettext "Make packages compatible for use with pacman")\n"
  1841. echo
  1842. printf -- "$(gettext "Usage: %s [options]")\n" "$0"
  1843. echo
  1844. printf -- "$(gettext "Options:")\n"
  1845. printf -- "$(gettext " -A, --ignorearch Ignore incomplete %s field in %s")\n" "arch" "$BUILDSCRIPT"
  1846. printf -- "$(gettext " -c, --clean Clean up work files after build")\n"
  1847. printf -- "$(gettext " -C, --cleanbuild Remove %s dir before building the package")\n" "\$srcdir/"
  1848. printf -- "$(gettext " -d, --nodeps Skip all dependency checks")\n"
  1849. printf -- "$(gettext " -e, --noextract Do not extract source files (use existing %s dir)")\n" "\$srcdir/"
  1850. printf -- "$(gettext " -f, --force Overwrite existing package")\n"
  1851. printf -- "$(gettext " -g, --geninteg Generate integrity checks for source files")\n"
  1852. printf -- "$(gettext " -h, --help Show this help message and exit")\n"
  1853. printf -- "$(gettext " -i, --install Install package after successful build")\n"
  1854. printf -- "$(gettext " -L, --log Log package build process")\n"
  1855. printf -- "$(gettext " -m, --nocolor Disable colorized output messages")\n"
  1856. printf -- "$(gettext " -o, --nobuild Download and extract files only")\n"
  1857. printf -- "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
  1858. printf -- "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")\n"
  1859. printf -- "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")\n"
  1860. printf -- "$(gettext " -s, --syncdeps Install missing dependencies with %s")\n" "pacman"
  1861. printf -- "$(gettext " -S, --source Generate a source-only tarball without downloaded sources")\n"
  1862. printf -- "$(gettext " -V, --version Show version information and exit")\n"
  1863. printf -- "$(gettext " --allsource Generate a source-only tarball including downloaded sources")\n"
  1864. printf -- "$(gettext " --check Run the %s function in the %s")\n" "check()" "$BUILDSCRIPT"
  1865. printf -- "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf"
  1866. printf -- "$(gettext " --holdver Do not update VCS sources")\n"
  1867. printf -- "$(gettext " --key <key> Specify a key to use for %s signing instead of the default")\n" "gpg"
  1868. printf -- "$(gettext " --noarchive Do not create package archive")\n"
  1869. printf -- "$(gettext " --nocheck Do not run the %s function in the %s")\n" "check()" "$BUILDSCRIPT"
  1870. printf -- "$(gettext " --noprepare Do not run the %s function in the %s")\n" "prepare()" "$BUILDSCRIPT"
  1871. printf -- "$(gettext " --nosign Do not create a signature for the package")\n"
  1872. printf -- "$(gettext " --packagelist Only list packages that would be produced, without PKGEXT")\n"
  1873. printf -- "$(gettext " --printsrcinfo Print the generated SRCINFO and exit")\n"
  1874. printf -- "$(gettext " --sign Sign the resulting package with %s")\n" "gpg"
  1875. printf -- "$(gettext " --skipchecksums Do not verify checksums of the source files")\n"
  1876. printf -- "$(gettext " --skipinteg Do not perform any verification checks on source files")\n"
  1877. printf -- "$(gettext " --skippgpcheck Do not verify source files with PGP signatures")\n"
  1878. printf -- "$(gettext " --verifysource Download source files (if needed) and perform integrity checks")\n"
  1879. echo
  1880. printf -- "$(gettext "These options can be passed to %s:")\n" "pacman"
  1881. echo
  1882. printf -- "$(gettext " --asdeps Install packages as non-explicitly installed")\n"
  1883. printf -- "$(gettext " --needed Do not reinstall the targets that are already up to date")\n"
  1884. printf -- "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")\n"
  1885. printf -- "$(gettext " --noprogressbar Do not show a progress bar when downloading files")\n"
  1886. echo
  1887. printf -- "$(gettext "If %s is not specified, %s will look for '%s'")\n" "-p" "makepkg" "$BUILDSCRIPT"
  1888. echo
  1889. }
  1890.  
  1891. version() {
  1892. printf "makepkg (pacman) %s\n" "$makepkg_version"
  1893. printf -- "$(gettext "\
  1894. Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org>.\n\
  1895. Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
  1896. This is free software; see the source for copying conditions.\n\
  1897. There is NO WARRANTY, to the extent permitted by law.\n")"
  1898. }
  1899.  
  1900. # PROGRAM START
  1901.  
  1902. # ensure we have a sane umask set
  1903. umask 0022
  1904.  
  1905. # determine whether we have gettext; make it a no-op if we do not
  1906. if ! type -p gettext >/dev/null; then
  1907. gettext() {
  1908. printf "%s\n" "$@"
  1909. }
  1910. fi
  1911.  
  1912. ARGLIST=("$@")
  1913.  
  1914. # Parse Command Line Options.
  1915. OPT_SHORT="AcCdefFghiLmop:rRsSV"
  1916. OPT_LONG=('allsource' 'check' 'clean' 'cleanbuild' 'config:' 'force' 'geninteg'
  1917. 'help' 'holdver' 'ignorearch' 'install' 'key:' 'log' 'noarchive' 'nobuild'
  1918. 'nocolor' 'nocheck' 'nodeps' 'noextract' 'noprepare' 'nosign' 'packagelist'
  1919. 'printsrcinfo' 'repackage' 'rmdeps' 'sign' 'skipchecksums' 'skipinteg'
  1920. 'skippgpcheck' 'source' 'syncdeps' 'verifysource' 'version')
  1921.  
  1922. # Pacman Options
  1923. OPT_LONG+=('asdeps' 'noconfirm' 'needed' 'noprogressbar')
  1924.  
  1925. if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
  1926. exit 1 # E_INVALID_OPTION;
  1927. fi
  1928. set -- "${OPTRET[@]}"
  1929. unset OPT_SHORT OPT_LONG OPTRET
  1930.  
  1931. while true; do
  1932. case "$1" in
  1933. # Pacman Options
  1934. --asdeps) ASDEPS=1;;
  1935. --needed) NEEDED=1;;
  1936. --noconfirm) PACMAN_OPTS+=" --noconfirm" ;;
  1937. --noprogressbar) PACMAN_OPTS+=" --noprogressbar" ;;
  1938.  
  1939. # Makepkg Options
  1940. --allsource) SOURCEONLY=2 ;;
  1941. -A|--ignorearch) IGNOREARCH=1 ;;
  1942. -c|--clean) CLEANUP=1 ;;
  1943. -C|--cleanbuild) CLEANBUILD=1 ;;
  1944. --check) RUN_CHECK='y' ;;
  1945. --config) shift; MAKEPKG_CONF=$1 ;;
  1946. -d|--nodeps) NODEPS=1 ;;
  1947. -e|--noextract) NOEXTRACT=1 ;;
  1948. -f|--force) FORCE=1 ;;
  1949. -F) INFAKEROOT=1 ;;
  1950. # generating integrity checks does not depend on architecture
  1951. -g|--geninteg) GENINTEG=1 IGNOREARCH=1;;
  1952. --holdver) HOLDVER=1 ;;
  1953. -i|--install) INSTALL=1 ;;
  1954. --key) shift; GPGKEY=$1 ;;
  1955. -L|--log) LOGGING=1 ;;
  1956. -m|--nocolor) USE_COLOR='n'; PACMAN_OPTS+=" --color never" ;;
  1957. --noarchive) NOARCHIVE=1 ;;
  1958. --nocheck) RUN_CHECK='n' ;;
  1959. --noprepare) RUN_PREPARE='n' ;;
  1960. --nosign) SIGNPKG='n' ;;
  1961. -o|--nobuild) NOBUILD=1 ;;
  1962. -p) shift; BUILDFILE=$1 ;;
  1963. --packagelist) PACKAGELIST=1 IGNOREARCH=1;;
  1964. --printsrcinfo) PRINTSRCINFO=1 ;;
  1965. -r|--rmdeps) RMDEPS=1 ;;
  1966. -R|--repackage) REPKG=1 ;;
  1967. --sign) SIGNPKG='y' ;;
  1968. --skipchecksums) SKIPCHECKSUMS=1 ;;
  1969. --skipinteg) SKIPCHECKSUMS=1; SKIPPGPCHECK=1 ;;
  1970. --skippgpcheck) SKIPPGPCHECK=1;;
  1971. -s|--syncdeps) DEP_BIN=1 ;;
  1972. -S|--source) SOURCEONLY=1 ;;
  1973. --verifysource) VERIFYSOURCE=1 ;;
  1974.  
  1975. -h|--help) usage; exit 0 ;; # E_OK
  1976. -V|--version) version; exit 0 ;; # E_OK
  1977.  
  1978. --) OPT_IND=0; shift; break 2;;
  1979. esac
  1980. shift
  1981. done
  1982.  
  1983. # attempt to consume any extra argv as environment variables. this supports
  1984. # overriding (e.g. CC=clang) as well as overriding (e.g. CFLAGS+=' -g').
  1985. extra_environment=()
  1986. while [[ $1 ]]; do
  1987. if [[ $1 = [_[:alpha:]]*([[:alnum:]_])?(+)=* ]]; then
  1988. extra_environment+=("$1")
  1989. fi
  1990. shift
  1991. done
  1992.  
  1993. # setup signal traps
  1994. trap 'clean_up' 0
  1995. for signal in TERM HUP QUIT; do
  1996. trap "trap_exit $signal \"$(gettext "%s signal caught. Exiting...")\" \"$signal\"" "$signal"
  1997. done
  1998. trap 'trap_exit INT "$(gettext "Aborted by user! Exiting...")"' INT
  1999. trap 'trap_exit USR1 "$(gettext "An unknown error has occurred. Exiting...")"' ERR
  2000.  
  2001. # preserve environment variables and canonicalize path
  2002. [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
  2003. [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
  2004. [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
  2005. [[ -n ${LOGDEST} ]] && _LOGDEST=$(canonicalize_path ${LOGDEST})
  2006. [[ -n ${BUILDDIR} ]] && _BUILDDIR=$(canonicalize_path ${BUILDDIR})
  2007. [[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT}
  2008. [[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT}
  2009. [[ -n ${GPGKEY} ]] && _GPGKEY=${GPGKEY}
  2010. [[ -n ${PACKAGER} ]] && _PACKAGER=${PACKAGER}
  2011. [[ -n ${CARCH} ]] && _CARCH=${CARCH}
  2012.  
  2013. # default config is makepkg.conf
  2014. MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
  2015.  
  2016. # Source the config file; fail if it is not found
  2017. if [[ -r $MAKEPKG_CONF ]]; then
  2018. source_safe "$MAKEPKG_CONF"
  2019. else
  2020. error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
  2021. plain "$(gettext "Aborting...")"
  2022. exit 1 # $E_CONFIG_ERROR
  2023. fi
  2024.  
  2025. # Source user-specific makepkg.conf overrides, but only if no override config
  2026. # file was specified
  2027. XDG_PACMAN_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/pacman"
  2028. if [[ "$MAKEPKG_CONF" = "$confdir/makepkg.conf" ]]; then
  2029. if [[ -r "$XDG_PACMAN_DIR/makepkg.conf" ]]; then
  2030. source_safe "$XDG_PACMAN_DIR/makepkg.conf"
  2031. elif [[ -r "$HOME/.makepkg.conf" ]]; then
  2032. source_safe "$HOME/.makepkg.conf"
  2033. fi
  2034. fi
  2035.  
  2036. # set pacman command if not already defined
  2037. PACMAN=${PACMAN:-pacman}
  2038. # save full path to command as PATH may change when sourcing /etc/profile
  2039. PACMAN_PATH=$(type -P $PACMAN)
  2040.  
  2041. # check if messages are to be printed using color
  2042. if [[ -t 2 && $USE_COLOR != "n" ]] && check_buildenv "color" "y"; then
  2043. colorize
  2044. else
  2045. unset ALL_OFF BOLD BLUE GREEN RED YELLOW
  2046. fi
  2047.  
  2048.  
  2049. # override settings with an environment variable for batch processing
  2050. BUILDDIR=${_BUILDDIR:-$BUILDDIR}
  2051. BUILDDIR=${BUILDDIR:-$startdir} #default to $startdir if undefined
  2052. if [[ ! -d $BUILDDIR ]]; then
  2053. if ! mkdir -p "$BUILDDIR"; then
  2054. error "$(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
  2055. plain "$(gettext "Aborting...")"
  2056. exit 1
  2057. fi
  2058. chmod a-s "$BUILDDIR"
  2059. fi
  2060. if [[ ! -w $BUILDDIR ]]; then
  2061. error "$(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR"
  2062. plain "$(gettext "Aborting...")"
  2063. exit 1
  2064. fi
  2065.  
  2066. # override settings from extra variables on commandline, if any
  2067. if (( ${#extra_environment[*]} )); then
  2068. export "${extra_environment[@]}"
  2069. fi
  2070.  
  2071. PKGDEST=${_PKGDEST:-$PKGDEST}
  2072. PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
  2073. if (( ! (NOBUILD || GENINTEG) )) && [[ ! -w $PKGDEST ]]; then
  2074. error "$(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST"
  2075. plain "$(gettext "Aborting...")"
  2076. exit 1
  2077. fi
  2078.  
  2079. SRCDEST=${_SRCDEST:-$SRCDEST}
  2080. SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
  2081. if [[ ! -w $SRCDEST ]] ; then
  2082. error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
  2083. plain "$(gettext "Aborting...")"
  2084. exit 1
  2085. fi
  2086.  
  2087. SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST}
  2088. SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
  2089. if (( SOURCEONLY )); then
  2090. if [[ ! -w $SRCPKGDEST ]]; then
  2091. error "$(gettext "You do not have write permission to store source tarballs in %s.")" "$SRCPKGDEST"
  2092. plain "$(gettext "Aborting...")"
  2093. exit 1
  2094. fi
  2095.  
  2096. # If we're only making a source tarball, then we need to ignore architecture-
  2097. # dependent behavior.
  2098. IGNOREARCH=1
  2099. fi
  2100.  
  2101. LOGDEST=${_LOGDEST:-$LOGDEST}
  2102. LOGDEST=${LOGDEST:-$startdir} #default to $startdir if undefined
  2103. if (( LOGGING )) && [[ ! -w $LOGDEST ]]; then
  2104. error "$(gettext "You do not have write permission to store logs in %s.")" "$LOGDEST"
  2105. plain "$(gettext "Aborting...")"
  2106. exit 1
  2107. fi
  2108.  
  2109. PKGEXT=${_PKGEXT:-$PKGEXT}
  2110. SRCEXT=${_SRCEXT:-$SRCEXT}
  2111. GPGKEY=${_GPGKEY:-$GPGKEY}
  2112. PACKAGER=${_PACKAGER:-$PACKAGER}
  2113. CARCH=${_CARCH:-$CARCH}
  2114.  
  2115. if (( ! INFAKEROOT )); then
  2116. if (( EUID == 0 )); then
  2117. error "$(gettext "Running %s as root is not allowed as it can cause permanent,\n\
  2118. catastrophic damage to your system.")" "makepkg"
  2119. exit 1 # $E_USER_ABORT
  2120. fi
  2121. else
  2122. if [[ -z $FAKEROOTKEY ]]; then
  2123. error "$(gettext "Do not use the %s option. This option is only for use by %s.")" "'-F'" "makepkg"
  2124. exit 1 # TODO: error code
  2125. fi
  2126. fi
  2127.  
  2128. unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
  2129. unset md5sums replaces depends conflicts backup source install changelog build
  2130. unset makedepends optdepends options noextract validpgpkeys
  2131.  
  2132. BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
  2133. if [[ ! -f $BUILDFILE ]]; then
  2134. error "$(gettext "%s does not exist.")" "$BUILDFILE"
  2135. exit 1
  2136. else
  2137. if [[ $(<"$BUILDFILE") = *$'\r'* ]]; then
  2138. error "$(gettext "%s contains %s characters and cannot be sourced.")" "$BUILDFILE" "CRLF"
  2139. exit 1
  2140. fi
  2141.  
  2142. if [[ ! $BUILDFILE -ef $PWD/${BUILDFILE##*/} ]]; then
  2143. error "$(gettext "%s must be in the current working directory.")" "$BUILDFILE"
  2144. exit 1
  2145. fi
  2146.  
  2147. if [[ ${BUILDFILE:0:1} != "/" ]]; then
  2148. BUILDFILE="$startdir/$BUILDFILE"
  2149. fi
  2150. source_buildfile "$BUILDFILE"
  2151. fi
  2152.  
  2153. pkgbase=${pkgbase:-${pkgname[0]}}
  2154.  
  2155. # check the PKGBUILD for some basic requirements
  2156. lint_pkgbuild || exit 1
  2157.  
  2158. if (( !SOURCEONLY )); then
  2159. merge_arch_attrs
  2160. fi
  2161.  
  2162. basever=$(get_full_version)
  2163.  
  2164. if [[ $BUILDDIR = "$startdir" ]]; then
  2165. srcdir="$BUILDDIR/src"
  2166. pkgdirbase="$BUILDDIR/pkg"
  2167. else
  2168. srcdir="$BUILDDIR/$pkgbase/src"
  2169. pkgdirbase="$BUILDDIR/$pkgbase/pkg"
  2170.  
  2171. fi
  2172.  
  2173. # set pkgdir to something "sensible" for (not recommended) use during build()
  2174. pkgdir="$pkgdirbase/$pkgbase"
  2175.  
  2176. if (( GENINTEG )); then
  2177. mkdir -p "$srcdir"
  2178. chmod a-s "$srcdir"
  2179. cd_safe "$srcdir"
  2180. download_sources novcs allarch
  2181. generate_checksums
  2182. exit 0 # $E_OK
  2183. fi
  2184.  
  2185. if have_function pkgver; then
  2186. PKGVERFUNC=1
  2187. fi
  2188.  
  2189. # check we have the software required to process the PKGBUILD
  2190. check_software || exit 1
  2191.  
  2192. if (( ${#pkgname[@]} > 1 )); then
  2193. SPLITPKG=1
  2194. fi
  2195.  
  2196. # test for available PKGBUILD functions
  2197. if have_function prepare; then
  2198. # "Hide" prepare() function if not going to be run
  2199. if [[ $RUN_PREPARE != "n" ]]; then
  2200. PREPAREFUNC=1
  2201. fi
  2202. fi
  2203. if have_function build; then
  2204. BUILDFUNC=1
  2205. fi
  2206. if have_function check; then
  2207. # "Hide" check() function if not going to be run
  2208. if [[ $RUN_CHECK = 'y' ]] || { ! check_buildenv "check" "n" && [[ $RUN_CHECK != "n" ]]; }; then
  2209. CHECKFUNC=1
  2210. fi
  2211. fi
  2212. if have_function package; then
  2213. PKGFUNC=1
  2214. elif [[ $SPLITPKG -eq 0 ]] && have_function package_${pkgname}; then
  2215. SPLITPKG=1
  2216. fi
  2217.  
  2218. # check if gpg signature is to be created and if signing key is valid
  2219. if { [[ -z $SIGNPKG ]] && check_buildenv "sign" "y"; } || [[ $SIGNPKG == 'y' ]]; then
  2220. SIGNPKG='y'
  2221. if ! gpg --list-key ${GPGKEY} &>/dev/null; then
  2222. if [[ ! -z $GPGKEY ]]; then
  2223. error "$(gettext "The key %s does not exist in your keyring.")" "${GPGKEY}"
  2224. else
  2225. error "$(gettext "There is no key in your keyring.")"
  2226. fi
  2227. exit 1
  2228. fi
  2229. fi
  2230.  
  2231. if (( PACKAGELIST )); then
  2232. print_all_package_names
  2233. exit 0
  2234. fi
  2235.  
  2236. if (( PRINTSRCINFO )); then
  2237. write_srcinfo_content
  2238. exit 0
  2239. fi
  2240.  
  2241. if (( ! PKGVERFUNC )); then
  2242. check_build_status
  2243. fi
  2244.  
  2245. # Run the bare minimum in fakeroot
  2246. if (( INFAKEROOT )); then
  2247. if (( SOURCEONLY )); then
  2248. create_srcpackage
  2249. msg "$(gettext "Leaving %s environment.")" "fakeroot"
  2250. exit 0 # $E_OK
  2251. fi
  2252.  
  2253. chmod 755 "$pkgdirbase"
  2254. if (( ! SPLITPKG )); then
  2255. pkgdir="$pkgdirbase/$pkgname"
  2256. mkdir "$pkgdir"
  2257. if (( PKGFUNC )); then
  2258. run_package
  2259. fi
  2260. tidy_install
  2261. lint_package
  2262. create_package
  2263. create_debug_package
  2264. else
  2265. run_split_packaging
  2266. fi
  2267.  
  2268. msg "$(gettext "Leaving %s environment.")" "fakeroot"
  2269. exit 0 # $E_OK
  2270. fi
  2271.  
  2272. msg "$(gettext "Making package: %s")" "$pkgbase $basever ($(date))"
  2273.  
  2274. # if we are creating a source-only package, go no further
  2275. if (( SOURCEONLY )); then
  2276. if [[ -f $SRCPKGDEST/${pkgbase}-${basever}${SRCEXT} ]] \
  2277. && (( ! FORCE )); then
  2278. error "$(gettext "A source package has already been built. (use %s to overwrite)")" "-f"
  2279. exit 1
  2280. fi
  2281.  
  2282. # Get back to our src directory so we can begin with sources.
  2283. mkdir -p "$srcdir"
  2284. chmod a-s "$srcdir"
  2285. cd_safe "$srcdir"
  2286. if (( SOURCEONLY == 2 )); then
  2287. download_sources allarch
  2288. elif ( (( ! SKIPCHECKSUMS )) || \
  2289. ( (( ! SKIPPGPCHECK )) && source_has_signatures ) ); then
  2290. download_sources allarch novcs
  2291. fi
  2292. check_source_integrity all
  2293. cd_safe "$startdir"
  2294.  
  2295. enter_fakeroot
  2296.  
  2297. msg "$(gettext "Source package created: %s")" "$pkgbase ($(date))"
  2298. exit 0
  2299. fi
  2300.  
  2301. if (( NODEPS || ( VERIFYSOURCE && !DEP_BIN ) )); then
  2302. if (( NODEPS )); then
  2303. warning "$(gettext "Skipping dependency checks.")"
  2304. fi
  2305. else
  2306. if (( RMDEPS && ! INSTALL )); then
  2307. original_pkglist=($(run_pacman -Qq)) # required by remove_dep
  2308. fi
  2309. deperr=0
  2310.  
  2311. msg "$(gettext "Checking runtime dependencies...")"
  2312. resolve_deps ${depends[@]} || deperr=1
  2313.  
  2314. if (( RMDEPS && INSTALL )); then
  2315. original_pkglist=($(run_pacman -Qq)) # required by remove_dep
  2316. fi
  2317.  
  2318. msg "$(gettext "Checking buildtime dependencies...")"
  2319. if (( CHECKFUNC )); then
  2320. resolve_deps "${makedepends[@]}" "${checkdepends[@]}" || deperr=1
  2321. else
  2322. resolve_deps "${makedepends[@]}" || deperr=1
  2323. fi
  2324.  
  2325. if (( RMDEPS )); then
  2326. current_pkglist=($(run_pacman -Qq)) # required by remove_deps
  2327. fi
  2328.  
  2329. if (( deperr )); then
  2330. error "$(gettext "Could not resolve all dependencies.")"
  2331. exit 1
  2332. fi
  2333. fi
  2334.  
  2335. # get back to our src directory so we can begin with sources
  2336. mkdir -p "$srcdir"
  2337. chmod a-s "$srcdir"
  2338. cd_safe "$srcdir"
  2339.  
  2340. if (( !REPKG )); then
  2341. if (( NOEXTRACT && ! VERIFYSOURCE )); then
  2342. warning "$(gettext "Using existing %s tree")" "\$srcdir/"
  2343. else
  2344. download_sources
  2345. check_source_integrity
  2346. (( VERIFYSOURCE )) && exit 0 # $E_OK
  2347.  
  2348. if (( CLEANBUILD )); then
  2349. msg "$(gettext "Removing existing %s directory...")" "\$srcdir/"
  2350. rm -rf "$srcdir"/*
  2351. fi
  2352.  
  2353. extract_sources
  2354. if (( PREPAREFUNC )); then
  2355. run_prepare
  2356. fi
  2357. fi
  2358.  
  2359. if (( PKGVERFUNC )); then
  2360. update_pkgver
  2361. basever=$(get_full_version)
  2362. check_build_status
  2363. fi
  2364. fi
  2365.  
  2366. if (( NOBUILD )); then
  2367. msg "$(gettext "Sources are ready.")"
  2368. exit 0 #E_OK
  2369. else
  2370. # clean existing pkg directory
  2371. if [[ -d $pkgdirbase ]]; then
  2372. msg "$(gettext "Removing existing %s directory...")" "\$pkgdir/"
  2373. rm -rf "$pkgdirbase"
  2374. fi
  2375. mkdir -p "$pkgdirbase"
  2376. chmod a-srw "$pkgdirbase"
  2377. cd_safe "$startdir"
  2378.  
  2379. if (( ! REPKG )); then
  2380. (( BUILDFUNC )) && run_build
  2381. (( CHECKFUNC )) && run_check
  2382. cd_safe "$startdir"
  2383. fi
  2384.  
  2385. enter_fakeroot
  2386. fi
  2387.  
  2388. # if inhibiting archive creation, go no further
  2389. if (( NOARCHIVE )); then
  2390. msg "$(gettext "Package directory is ready.")"
  2391. exit 0
  2392. fi
  2393.  
  2394. msg "$(gettext "Finished making: %s")" "$pkgbase $basever ($(date))"
  2395.  
  2396. install_package
  2397.  
  2398. exit 0 #E_OK
  2399.  
  2400. # vim: set noet:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement