index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | scripts/makepkg.sh.in | 848 |
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index b0b08823..8845a417 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1,4 +1,4 @@ -#!@BASH_SHELL@ -e +#!/bin/bash -e # # makepkg - make packages compatible for use with pacman # @configure_input@ @@ -28,10 +28,10 @@ # makepkg uses quite a few external programs during its execution. You # need to have at least the following installed for makepkg to function: # awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, file, find (findutils), -# gettext, grep, gzip, openssl, sed, tput (ncurses), xz +# gettext, gpg, grep, gzip, openssl, sed, tput (ncurses), xz # gettext initialization -export TEXTDOMAIN='pacman' +export TEXTDOMAIN='pacman-scripts' export TEXTDOMAINDIR='@localedir@' # file -i does not work on Mac OSX unless legacy mode is set @@ -41,25 +41,23 @@ myver='@PACKAGE_VERSION@' confdir='@sysconfdir@' BUILDSCRIPT='@BUILDSCRIPT@' startdir="$PWD" -srcdir="$startdir/src" -pkgdir="$startdir/pkg" -packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge') +packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge' 'upx') other_options=('ccache' 'distcc' 'buildflags' 'makeflags') -splitpkg_overrides=('pkgver' 'pkgrel' 'pkgdesc' 'arch' 'license' 'groups' \ - 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' \ - 'backup' 'options' 'install' 'changelog') +splitpkg_overrides=('pkgver' 'pkgrel' 'epoch' 'pkgdesc' 'arch' 'license' \ + 'groups' 'depends' 'optdepends' 'provides' 'conflicts' \ + 'replaces' 'backup' 'options' 'install' 'changelog') readonly -a packaging_options other_options splitpkg_overrides # Options ASROOT=0 CLEANUP=0 -CLEANCACHE=0 DEP_BIN=0 FORCE=0 INFAKEROOT=0 GENINTEG=0 -SKIPINTEG=0 +SKIPCHECKSUMS=0 +SKIPPGPCHECK=0 INSTALL=0 NOBUILD=0 NODEPS=0 @@ -75,6 +73,7 @@ CHECKFUNC=0 PKGFUNC=0 SPLITPKG=0 PKGLIST=() +SIGNPKG='' # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call # when dealing with svn/cvs/etc PKGBUILDs. @@ -142,8 +141,7 @@ clean_up() { msg "$(gettext "Cleaning up...")" rm -rf "$pkgdir" "$srcdir" if [[ -n $pkgbase ]]; then - # TODO: this wasn't properly fixed in commit 2020e629 - local fullver=$(get_full_version $epoch $pkgver $pkgrel) + local fullver=$(get_full_version) # Can't do this unless the BUILDSCRIPT has been sourced. if (( BUILDFUNC )); then rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"* @@ -183,6 +181,17 @@ trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR +enter_fakeroot() { + msg "$(gettext "Entering %s environment...")" "fakeroot" + + if [[ -n $newpkgver ]]; then + fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $? + else + fakeroot -- $0 -F "${ARGLIST[@]}" || exit $? + fi +} + + # a source entry can have two forms : # 1) "filename::http://path/to/file" # 2) "http://path/to/file" @@ -227,15 +236,27 @@ get_url() { } ## -# usage : get_full_version( $epoch, $pkgver, $pkgrel ) +# usage : get_full_version( [$pkgname] ) # return : full version spec, including epoch (if necessary), pkgver, pkgrel ## get_full_version() { - if [[ $1 -eq 0 ]]; then - # zero epoch case, don't include it in version - echo $2-$3 + if [[ -z $1 ]]; then + if [[ $epoch ]] && (( ! $epoch )); then + echo $pkgver-$pkgrel + else + echo $epoch:$pkgver-$pkgrel + fi else - echo $1:$2-$3 + for i in pkgver pkgrel epoch; do + local indirect="${i}_override" + eval $(declare -f package_$1 | sed -n "s/\(^[[:space:]]*$i=\)/${i}_override=/p") + [[ -z ${!indirect} ]] && eval "${indirect}=\${${i}}" + done + if (( ! $epoch_override )); then + echo $pkgver_override-$pkgrel_override + else + echo $epoch_override:$pkgver_override-$pkgrel_override + fi fi } @@ -275,7 +296,7 @@ check_option() { # ? - not found ## check_buildenv() { - echo $(in_opt_array "$1" ${BUILDENV[@]}) + in_opt_array "$1" ${BUILDENV[@]} } @@ -310,7 +331,6 @@ in_opt_array() { ## in_array() { local needle=$1; shift - [[ -z $1 ]] && return 1 # Not Found local item for item in "$@"; do [[ $item = $needle ]] && return 0 # Found @@ -318,6 +338,16 @@ in_array() { return 1 # Not Found } +source_has_signatures(){ + local file + for file in "${source[@]}"; do + if [[ $file =~ .*(sig|asc) ]]; then + return 0 + fi + done + return 1 +} + get_downloadclient() { # $1 = URL with valid protocol prefix local url=$1 @@ -391,7 +421,7 @@ run_pacman() { local cmd printf -v cmd "%q " "$PACMAN" $PACMAN_OPTS "$@" if (( ! ASROOT )) && [[ ! $1 =~ ^-(T|Qq)$ ]]; then - if [ "$(type -p sudo)" ]; then + if type -p sudo >/dev/null; then cmd="sudo $cmd" else cmd="su root -c '$cmd'" @@ -565,7 +595,7 @@ generate_checksums() { plain "" if ! type -p openssl >/dev/null; then - error "$(gettext "Cannot find openssl.")" + error "$(gettext "Cannot find the %s binary required for generating sourcefile checksums.")" "openssl" exit 1 # $E_MISSING_PROGRAM fi @@ -611,13 +641,9 @@ generate_checksums() { } check_checksums() { + (( SKIPCHECKSUMS )) && return 0 (( ! ${#source[@]} )) && return 0 - if ! type -p openssl >/dev/null; then - error "$(gettext "Cannot find openssl.")" - exit 1 # $E_MISSING_PROGRAM - fi - local correlation=0 local integ required for integ in md5 sha1 sha256 sha384 sha512; do @@ -670,6 +696,89 @@ check_checksums() { fi } +check_pgpsigs() { + (( SKIPPGPCHECK )) && return 0 + ! source_has_signatures && return 0 + + msg "$(gettext "Verifying source file signatures with %s...")" "gpg" + + local file + local warning=0 + local errors=0 + local statusfile=$(mktemp) + + for file in "${source[@]}"; do + file="$(get_filename "$file")" + if [[ ! $file =~ .*(sig|asc) ]]; then + continue + fi + + echo -n " ${file%.*} ... " >&2 + + if ! file="$(get_filepath "$file")"; then + echo "$(gettext "SIGNATURE NOT FOUND")" >&2 + errors=1 + continue + fi + + if ! sourcefile="$(get_filepath "${file%.*}")"; then + echo "$(gettext "SOURCE FILE NOT FOUND")" >&2 + errors=1 + continue + fi + + if ! gpg --quiet --batch --status-file "$statusfile" --verify "$file" "$sourcefile" 2> /dev/null; then + if grep "NO_PUBKEY" "$statusfile" > /dev/null; then + warning "$(gettext "Unknown public key") $(awk '/NO_PUBKEY/ {print $3}' $statusfile)" >&2 + warnings=1 + else + echo "$(gettext "FAILED")" >&2 + errors=1 + fi + else + if grep "REVKEYSIG" "$statusfile" > /dev/null; then + echo "$(gettext "Passed")" "-" "$(gettext "Warning: the key has been revoked.")" >&2 + errors=1 + elif grep "EXPSIG" "$statusfile" > /dev/null; then + echo "$(gettext "Passed")" "-" "$(gettext "Warning: the signature has expired.")" >&2 + warnings=1 + elif grep "EXPKEYSIG" "$statusfile" > /dev/null; then + echo "$(gettext "Passed")" "-" "$(gettext "Warning: the key has expired.")" >&2 + warnings=1 + else + echo $(gettext "Passed") >&2 + fi + fi + done + + rm -f "$statusfile" + + if (( errors )); then + error "$(gettext "One or more PGP signatures could not be verified!")" + exit 1 + fi + + if (( warnings )); then + warning "$(gettext "Warnings have occurred while verifying the signatures.")" + plain "$(gettext "Please make sure you really trust them.")" + fi +} + +check_source_integrity() { + if (( SKIPCHECKSUMS && SKIPPGPCHECK )); then + warning "$(gettext "Skipping all source file integrity checks.")" + elif (( SKIPCHECKSUMS )); then + warning "$(gettext "Skipping verification of source file checksums.")" + check_pgpsigs + elif (( SKIPPGPCHECK )); then + warning "$(gettext "Skipping verification of source file PGP signatures.")" + check_checksums + else + check_checksums + check_pgpsigs + fi +} + extract_sources() { msg "$(gettext "Extracting Sources...")" local netfile @@ -776,7 +885,7 @@ run_function() { local ret=0 local restoretrap if (( LOGGING )); then - local fullver=$(get_full_version $epoch $pkgver $pkgrel) + local fullver=$(get_full_version) local BUILDLOG="${startdir}/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log" if [[ -f $BUILDLOG ]]; then local i=1 @@ -818,9 +927,6 @@ run_build() { if [[ $(check_buildenv distcc) = "y" && $(check_option distcc) != "n" ]]; then [[ -d /usr/lib/distcc/bin ]] && export PATH="/usr/lib/distcc/bin:$PATH" export DISTCC_HOSTS - elif [[ $(check_option distcc) = "n" ]]; then - # if it is not wanted, clear the makeflags too - MAKEFLAGS="" fi # use ccache if it is requested (check buildenv and PKGBUILD opts) @@ -856,7 +962,7 @@ tidy_install() { fi if [[ $(check_option purge) = "y" && -n ${PURGE_TARGETS[*]} ]]; then - msg2 "$(gettext "Purging other files...")" + msg2 "$(gettext "Purging unwanted files...")" local pt for pt in "${PURGE_TARGETS[@]}"; do if [[ ${pt} = ${pt//\/} ]]; then @@ -922,7 +1028,7 @@ tidy_install() { fi if [[ $(check_option libtool) = "n" ]]; then - msg2 "$(gettext "Removing libtool .la files...")" + msg2 "$(gettext "Removing "%s" files...")" "libtool" find . ! -type d -name "*.la" -exec rm -f -- '{}' \; fi @@ -930,6 +1036,69 @@ tidy_install() { msg2 "$(gettext "Removing empty directories...")" find . -depth -type d -empty -delete fi + + if [[ $(check_option upx) = "y" ]]; then + msg2 "$(gettext "Compressing binaries with %s...")" "UPX" + local binary + find . -type f -perm -u+w 2>/dev/null | while read binary ; do + if [[ $(file -bi "$binary") = *'application/x-executable'* ]]; then + upx $UPXFLAGS "$binary" &>/dev/null || + warning "$(gettext "Could not compress binary : %s")" "${binary/$pkgdir\//}" + fi + done + fi +} + +find_libdepends() { + local libdepends + find "$pkgdir" -type f -perm -u+x | while read filename + do + # get architecture of the file; if soarch is empty it's not an ELF binary + soarch=$(LC_ALL=C readelf -h "$filename" 2>/dev/null | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p') + [ -n "$soarch" ] || continue + # process all libraries needed by the binary + for sofile in $(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p') + do + # extract the library name: libfoo.so + soname="${sofile%%\.so\.*}.so" + # extract the major version: 1 + soversion="${sofile##*\.so\.}" + if in_array "${soname}" ${depends[@]}; then + if ! in_array "${soname}=${soversion}-${soarch}" ${libdepends[@]}; then + # libfoo.so=1-64 + echo "${soname}=${soversion}-${soarch}" + libdepends=(${libdepends[@]} "${soname}=${soversion}-${soarch}") + fi + fi + done + done +} + +find_libprovides() { + local libprovides + find "$pkgdir" -type f -name \*.so\* | while read filename + do + # check if we really have a shared object + if LC_ALL=C readelf -h "$filename" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then + # 64 + soarch=$(LC_ALL=C readelf -h "$filename" | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p') + # get the string binaries link to: libfoo.so.1.2 -> libfoo.so.1 + sofile=$(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p') + [ -z "$sofile" ] && sofile="${filename##*/}" + + # extract the library name: libfoo.so + soname="${sofile%%\.so\.*}.so" + # extract the major version: 1 + soversion="${sofile##*\.so\.}" + if in_array "${soname}" ${provides[@]}; then + if ! in_array "${soname}=${soversion}-${soarch}" ${libprovides[@]}; then + # libfoo.so=1-64 + echo "${soname}=${soversion}-${soarch}" + libprovides=(${libprovides[@]} "${soname}=${soversion}-${soarch}") + fi + fi + fi + done } write_pkginfo() { @@ -942,7 +1111,7 @@ write_pkginfo() { local size="$(@DUPATH@ -sk)" size="$(( ${size%%[^0-9]*} * 1024 ))" - msg2 "$(gettext "Generating .PKGINFO file...")" + msg2 "$(gettext "Generating %s file...")" ".PKGINFO" echo "# Generated by makepkg $myver" if (( INFAKEROOT )); then echo "# using $(fakeroot -v)" @@ -950,7 +1119,7 @@ write_pkginfo() { echo "# $(LC_ALL=C date -u)" echo "pkgname = $1" (( SPLITPKG )) && echo pkgbase = $pkgbase - echo "pkgver = $(get_full_version $epoch $pkgver $pkgrel)" + echo "pkgver = $(get_full_version)" echo "pkgdesc = $pkgdesc" echo "url = $url" echo "builddate = $builddate" @@ -961,13 +1130,44 @@ write_pkginfo() { [[ $license ]] && printf "license = %s\n" "${license[@]}" [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}" [[ $groups ]] && printf "group = %s\n" "${groups[@]}" - [[ $depends ]] && printf "depend = %s\n" "${depends[@]}" [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]}" [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}" - [[ $provides ]] && printf "provides = %s\n" "${provides[@]}" [[ $backup ]] && printf "backup = %s\n" "${backup[@]}" local it + + libprovides=$(find_libprovides) + libdepends=$(find_libdepends) + provides=("${provides[@]}" ${libprovides}) + depends=("${depends[@]}" ${libdepends}) + + for it in "${depends[@]}"; do + if [[ $it = *.so ]]; then + # check if the entry has been found by find_libdepends + # if not, it's unneeded; tell the user so he can remove it + if [[ ! $libdepends =~ (^|\s)${it}=.* ]]; then + error "$(gettext "Cannot find library listed in %s: %s")" "'depends'" "$it" + return 1 + fi + else + echo "depend = $it" + fi + done + + for it in "${provides[@]}"; do + # ignore versionless entires (those come from the PKGBUILD) + if [[ $it = *.so ]]; then + # check if the entry has been found by find_libprovides + # if not, it's unneeded; tell the user so he can remove it + if [[ ! $libprovides =~ (^|\s)${it}=.* ]]; then + error "$(gettext "Cannot find library listed in %s: %s")" "'provides'" "$it" + return 1 + fi + else + echo "provides = $it" + fi + done + for it in "${packaging_options[@]}"; do local ret="$(check_option $it)" if [[ $ret != "?" ]]; then @@ -983,7 +1183,7 @@ write_pkginfo() { # warn if license array is not present or empty if [[ -z $license ]]; then warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT" - plain "$(gettext "Example for GPL\'ed software: license=('GPL').")" + plain "$(gettext "Example for GPL\'ed software: %s.")" "license=('GPL')" fi } @@ -994,7 +1194,7 @@ check_package() { local file for file in "${backup[@]}"; do if [[ ! -f $file ]]; then - warning "$(gettext "Backup entry file not in package : %s")" "$file" + warning "$(gettext "%s entry file not in package : %s")" "backup" "$file" fi done @@ -1010,7 +1210,7 @@ check_package() { create_package() { if [[ ! -d $pkgdir ]]; then - error "$(gettext "Missing pkg/ directory.")" + error "$(gettext "Missing %s directory.")" "pkg/" plain "$(gettext "Aborting...")" exit 1 # $E_MISSING_PKGDIR fi @@ -1039,7 +1239,7 @@ create_package() { # check for changelog/install files for i in 'changelog/.CHANGELOG' 'install/.INSTALL'; do - IFS='/' read -r orig dest <<< "$i" + IFS='/' read -r orig dest < <(printf '%s\n' "$i") if [[ -n ${!orig} ]]; then msg2 "$(gettext "Adding %s file...")" "$orig" @@ -1057,15 +1257,19 @@ create_package() { *tar.gz) EXT=${PKGEXT%.gz} ;; *tar.bz2) EXT=${PKGEXT%.bz2} ;; *tar.xz) EXT=${PKGEXT%.xz} ;; + *tar.Z) EXT=${PKGEXT%.Z} ;; *tar) EXT=${PKGEXT} ;; *) warning "$(gettext "'%s' is not a valid archive extension.")" \ "$PKGEXT" ; EXT=$PKGEXT ;; esac - local fullver=$(get_full_version $epoch $pkgver $pkgrel) + local fullver=$(get_full_version) local pkg_file="$PKGDEST/${nameofpkg}-${fullver}-${PKGARCH}${PKGEXT}" local ret=0 + [[ -f $pkg_file ]] && rm -f "$pkg_file" + [[ -f $pkg_file.sig ]] && rm -f "$pkg_file.sig" + # when fileglobbing, we want * in an empty directory to expand to # the null string rather than itself shopt -s nullglob @@ -1076,6 +1280,7 @@ create_package() { *tar.gz) gzip -c -f -n ;; *tar.bz2) bzip2 -c -f ;; *tar.xz) xz -c -z - ;; + *tar.Z) compress -c -f ;; *tar) cat ;; esac > "${pkg_file}" || ret=$? @@ -1087,10 +1292,16 @@ create_package() { exit 1 # TODO: error code fi + create_signature "$pkg_file" + if (( ! ret )) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then rm -f "${pkg_file/$PKGDEST/$startdir}" ln -s "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}" ret=$? + if [[ -f $pkg_file.sig ]]; then + rm -f "${pkg_file/$PKGDEST/$startdir}.sig" + ln -s "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig" + fi fi if (( ret )); then @@ -1098,24 +1309,30 @@ create_package() { fi } -create_srcpackage() { - cd "$startdir" +create_signature() { + if [[ $SIGNPKG != 'y' ]]; then + return + fi + local ret=0 + local filename="$1" + msg "$(gettext "Signing package...")" - # Get back to our src directory so we can begin with sources. - mkdir -p "$srcdir" - chmod a-s "$srcdir" - cd "$srcdir" - if (( ! SKIPINTEG || SOURCEONLY == 2 )); then - download_sources + local SIGNWITHKEY="" + if [[ -n $GPGKEY ]]; then + SIGNWITHKEY="-u ${GPGKEY}" fi - if (( ! SKIPINTEG )); then - # We can only check checksums if we have all files. - check_checksums + # The signature will be generated directly in ascii-friendly format + gpg --detach-sign --use-agent ${SIGNWITHKEY} "$filename" &>/dev/null || ret=$? + + + if (( ! ret )); then + msg2 "$(gettext "Created signature file %s.")" "$filename.sig" else - warning "$(gettext "Skipping integrity checks.")" + warning "$(gettext "Failed to sign package file.")" fi - cd "$startdir" +} +create_srcpackage() { msg "$(gettext "Creating source package...")" local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)" mkdir "${srclinks}"/${pkgbase} @@ -1159,7 +1376,7 @@ create_srcpackage() { "$SRCEXT" ;; esac - local fullver=$(get_full_version $epoch $pkgver $pkgrel) + local fullver=$(get_full_version) local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}" # tar it up @@ -1188,15 +1405,14 @@ install_package() { (( ! INSTALL )) && return if (( ! SPLITPKG )); then - msg "$(gettext "Installing package %s with %s -U...")" "$pkgname" "$PACMAN" + msg "$(gettext "Installing package %s with %s...")" "$pkgname" "$PACMAN -U" else - msg "$(gettext "Installing %s package group with %s -U...")" "$pkgbase" "$PACMAN" + msg "$(gettext "Installing %s package group with %s...")" "$pkgbase" "$PACMAN -U" fi local fullver pkg pkglist for pkg in ${pkgname[@]}; do - # TODO: this wasn't properly fixed in commit 2020e629 - fullver=$(get_full_version $epoch $pkgver $pkgrel) + fullver=$(get_full_version $pkg) if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} ]]; then pkglist+=" $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT}" else @@ -1232,37 +1448,63 @@ check_sanity() { error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgbase" ret=1 fi - if [[ $pkgver =~ [:-] ]]; then - error "$(gettext "%s is not allowed to contain colons or hyphens.")" "pkgver" - ret=1 - fi - if [[ $pkgrel != ${pkgrel//-/} ]]; then - error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel" - ret=1 - fi - if [[ ! $epoch =~ ^[0-9]*$ ]]; then - error "$(gettext "%s must be an integer.")" "epoch" - ret=1 - fi + awk -F'=' '/^[[:space:]]*pkgver=/ { $1=""; print $0 }' "$BUILDFILE" | + while read i _; do + if [[ $i =~ [[:space:]:-] ]]; then + error "$(gettext "%s is not allowed to contain colons, hyphens or whitespace.")" "pkgver" + return 1 + fi + done || ret=1 + + awk -F'=' '/^[[:space:]]*pkgrel=/ { $1=""; print $0 }' "$BUILDFILE" | + while read i _; do + if [[ $i =~ [[:space:]-] ]]; then + error "$(gettext "%s is not allowed to contain hyphens or whitespace.")" "pkgrel" + return 1 + fi + done || ret=1 + + awk -F'=' '/^[[:space:]]*epoch=/ { $1=""; print $0 }' "$BUILDFILE" | + while read i _; do + if [[ ! $i =~ ^[0-9]*$ ]]; then + error "$(gettext "%s must be an integer.")" "epoch" + return 1 + fi + done || ret=1 if [[ $arch != 'any' ]]; then if ! in_array $CARCH ${arch[@]}; then if (( ! IGNOREARCH )); then error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH" plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT" - plain "$(gettext "such as arch=('%s').")" "$CARCH" + plain "$(gettext "such as %s.")" "arch=('$CARCH')" ret=1 fi fi fi + if (( ${#pkgname[@]} > 1 )); then + for i in ${pkgname[@]}; do + local arch_list="" + eval $(declare -f package_${i} | sed -n 's/\(^[[:space:]]*arch=\)/arch_list=/p') + if [[ ${arch_list[@]} && ${arch_list} != 'any' ]]; then + if ! in_array $CARCH ${arch_list[@]}; then + if (( ! IGNOREARCH )); then + error "$(gettext "%s is not available for the '%s' architecture.")" "$i" "$CARCH" + ret=1 + fi + fi + fi + done + fi + local provides_list=() eval $(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \ sed -e "s/provides=/provides_list+=/" -e "s/#.*//" -e 's/\\$//') for i in ${provides_list[@]}; do if [[ $i != ${i//</} || $i != ${i//>/} ]]; then - error "$(gettext "Provides array cannot contain comparison (< or >) operators.")" + error "$(gettext "%s array cannot contain comparison (< or >) operators.")" "provides" ret=1 fi done @@ -1272,7 +1514,7 @@ check_sanity() { sed -e "s/backup=/backup_list+=/" -e "s/#.*//" -e 's/\\$//') for i in "${backup_list[@]}"; do if [[ ${i:0:1} = "/" ]]; then - error "$(gettext "Backup entry should not contain leading slash : %s")" "$i" + error "$(gettext "%s entry should not contain leading slash : %s")" "backup" "$i" ret=1 fi done @@ -1283,7 +1525,7 @@ check_sanity() { for i in "${optdepends_list[@]}"; do local pkg=${i%%:*} if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]+$ ]]; then - error "$(gettext "Invalid syntax for optdepend : '%s'")" "$i" + error "$(gettext "Invalid syntax for %s : '%s'")" "optdepend" "$i" ret=1 fi done @@ -1314,7 +1556,7 @@ check_sanity() { fi done if (( ! known )); then - error "$(gettext "options array contains unknown option '%s'")" "$i" + error "$(gettext "%s array contains unknown option '%s'")" "options" "$i" valid_options=0 fi done @@ -1325,7 +1567,7 @@ check_sanity() { if (( ${#pkgname[@]} > 1 )); then for i in ${pkgname[@]}; do if ! declare -f package_${i} >/dev/null; then - error "$(gettext "missing package function for split package '%s'")" "$i" + error "$(gettext "Missing %s function for split package '%s'")" "package_$i()" "$i" ret=1 fi done @@ -1333,7 +1575,7 @@ check_sanity() { for i in ${PKGLIST[@]}; do if ! in_array $i ${pkgname[@]}; then - error "$(gettext "requested package %s is not provided in %s")" "$i" "$BUILDFILE" + error "$(gettext "Requested package %s is not provided in %s")" "$i" "$BUILDFILE" ret=1 fi done @@ -1341,13 +1583,99 @@ check_sanity() { return $ret } +check_software() { + # check for needed software + local ret=0 + + # check for sudo if we will need it during makepkg execution + if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then + if ! type -p sudo >/dev/null; then + warning "$(gettext "Sudo can not be found. Will use su to acquire root privileges.")" + fi + fi + + # fakeroot - building as non-root user + if [[ $(check_buildenv fakeroot) = "y" ]] && (( EUID > 0 )); then + if ! type -p fakeroot >/dev/null; then + error "$(gettext "Cannot find the %s binary required for building as non-root user.")" "fakeroot" + ret=1 + fi + fi + + # gpg - package signing + if [[ $SIGNPKG == 'y' || (-z "$SIGNPKG" && $(check_buildenv sign) == 'y') ]]; then + if ! type -p gpg >/dev/null; then + error "$(gettext "Cannot find the %s binary required for signing packages.")" "gpg" + ret=1 + fi + fi + + # gpg - source verification + if (( ! SKIPPGPCHECK )) && [[ source_has_signatures ]]; then + if ! type -p gpg >/dev/null; then + error "$(gettext "Cannot find the %s binary required for verifying source files.")" "gpg" + ret=1 + fi + fi + + # openssl - checksum operations + if (( ! SKIPCHECKSUMS )); then + if ! type -p openssl >/dev/null; then + error "$(gettext "Cannot find the %s binary required for validating sourcefile checksums.")" "openssl" + ret=1 + fi + fi + + # upx - binary compression + if [[ $(check_option upx) == 'y' ]]; then + if ! type -p upx >/dev/null; then + error "$(gettext "Cannot find the %s binary required for compressing binaries.")" "upx" + ret=1 + fi + fi + + # distcc - compilation with distcc + if [[ $(check_buildenv distcc) = "y" && $(check_option distcc) != "n" ]]; then + if ! type -p distcc >/dev/null; then + error "$(gettext "Cannot find the %s binary required for distributed compilation.")" "distcc" + ret=1 + fi + fi + + # ccache - compilation with ccache + if [[ $(check_buildenv ccache) = "y" && $(check_option ccache) != "n" ]]; then + if ! type -p ccache >/dev/null; then + error "$(gettext "Cannot find the %s binary required for compiler cache usage.")" "ccache" + ret=1 + fi + fi + + # strip - strip symbols from binaries/libraries + if [[ $(check_option strip) = "y" ]]; then + if ! type -p strip >/dev/null; then + error "$(gettext "Cannot find the %s binary required for object file stripping.")" "strip" + ret=1 + fi + fi + + # gzip - compressig man and info pages + if [[ $(check_option zipman) = "y" ]]; then + if ! type -p gzip >/dev/null; then + error "$(gettext "Cannot find the %s binary required for compressing man and info pages.")" "gzip" + ret=1 + fi + fi + + return $ret +} + devel_check() { newpkgver="" # Do not update pkgver if --holdver is set, when building a source package, repackaging, # reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w) - if (( HOLDVER || SOURCEONLY || REPKG )) \ - || [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then + if (( HOLDVER || SOURCEONLY || REPKG )) || + [[ ! -f $BUILDFILE || ! -w $BUILDFILE || $BUILDFILE = /dev/stdin ]]; then return fi @@ -1356,30 +1684,48 @@ devel_check() { # This will only be used on the first call to makepkg; subsequent # calls to makepkg via fakeroot will explicitly pass the version # number to avoid having to determine the version number twice. - # Also do a brief check to make sure we have the VCS tool available. + # Also do a check to make sure we have the VCS tool available. oldpkgver=$pkgver if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then - type -p darcs >/dev/null || return 0 + if ! type -p darcs >/dev/null; then + warning "$(gettext "Cannot find the %s binary required to determine latest %s revision.")" "darcs" "darcs" + return 0 + fi msg "$(gettext "Determining latest %s revision...")" 'darcs' newpkgver=$(date +%Y%m%d) elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then - type -p cvs >/dev/null || return 0 + if ! type -p cvs >/dev/null; then + warning "$(gettext "Cannot find the %s binary required to determine latest %s revision.")" "cvs" "cvs" + return 0 + fi msg "$(gettext "Determining latest %s revision...")" 'cvs' newpkgver=$(date +%Y%m%d) elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then - type -p git >/dev/null || return 0 + if ! type -p git >/dev/null; then + warning "$(gettext "Cannot find the %s binary required to determine latest %s revision.")" "git" "git" + return 0 + fi msg "$(gettext "Determining latest %s revision...")" 'git' newpkgver=$(date +%Y%m%d) elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then - type -p svn >/dev/null || return 0 + if ! type -p svn >/dev/null; then + warning "$(gettext "Cannot find the %s binary required to determine latest %s revision.")" "svn" "svn" + return 0 + fi msg "$(gettext "Determining latest %s revision...")" 'svn' newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p') elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then - type -p bzr >/dev/null || return 0 + if ! type -p bzr >/dev/null; then + warning "$(gettext "Cannot find the %s binary required to determine latest %s revision.")" "bzr" "bzr" + return 0 + fi msg "$(gettext "Determining latest %s revision...")" 'bzr' newpkgver=$(bzr revno ${_bzrtrunk}) elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then - type -p hg >/dev/null || return 0 + if ! type -p hg >/dev/null; then + warning "$(gettext "Cannot find the %s binary required to determine latest %s revision.")" "hg" "hg" + return 0 + fi msg "$(gettext "Determining latest %s revision...")" 'hg' if [[ -d ./src/$_hgrepo ]] ; then cd ./src/$_hgrepo @@ -1475,93 +1821,7 @@ canonicalize_path() { fi } -# getopt like parser -parse_options() { - local short_options=$1; shift; - local long_options=$1; shift; - local ret=0; - local unused_options="" - local i - - while [[ -n $1 ]]; do - if [[ ${1:0:2} = '--' ]]; then - if [[ -n ${1:2} ]]; then - local match="" - for i in ${long_options//,/ }; do - if [[ ${1:2} = ${i//:} ]]; then - match=$i - break - fi - done - if [[ -n $match ]]; then - if [[ ${1:2} = $match ]]; then - printf ' %s' "$1" - else - if [[ -n $2 ]]; then - printf ' %s' "$1" - shift - printf " '%s'" "$1" - else - echo "makepkg: option '$1' $(gettext "requires an argument")" >&2 - ret=1 - fi - fi - else - echo "makepkg: $(gettext "unrecognized option") '$1'" >&2 - ret=1 - fi - else - shift - break - fi - elif [[ ${1:0:1} = '-' ]]; then - for ((i=1; i<${#1}; i++)); do - if [[ $short_options =~ ${1:i:1} ]]; then - if [[ $short_options =~ ${1:i:1}: ]]; then - if [[ -n ${1:$i+1} ]]; then - printf ' -%s' "${1:i:1}" - printf " '%s'" "${1:$i+1}" - else - if [[ -n $2 ]]; then - printf ' -%s' "${1:i:1}" - shift - printf " '%s'" "${1}" - else - echo "makepkg: option $(gettext "requires an argument") -- '${1:i:1}'" >&2 - ret=1 - fi - fi - break - else - printf ' -%s' "${1:i:1}" - fi - else - echo "makepkg: $(gettext "invalid option") -- '${1:i:1}'" >&2 - ret=1 - fi - done - else - unused_options="${unused_options} '$1'" - fi - shift - done - - printf " --" - if [[ -n $unused_options ]]; then - for i in ${unused_options[@]}; do - printf ' %s' "$i" - done - fi - if [[ -n $1 ]]; then - while [[ -n $1 ]]; do - printf " '%s'" "${1}" - shift - done - fi - printf "\n" - - return $ret -} +m4_include(library/parse_options.sh) usage() { printf "makepkg (pacman) %s\n" "$myver" @@ -1569,14 +1829,13 @@ usage() { printf "$(gettext "Usage: %s [options]")\n" "$0" echo echo "$(gettext "Options:")" - printf "$(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT" + printf "$(gettext " -A, --ignorearch Ignore incomplete %s field in %s")\n" "arch" "$BUILDSCRIPT" echo "$(gettext " -c, --clean Clean up work files after build")" - echo "$(gettext " -C, --cleancache Clean up source files from the cache")" echo "$(gettext " -d, --nodeps Skip all dependency checks")" - echo "$(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")" + printf "$(gettext " -e, --noextract Do not extract source files (use existing %s dir)")\n" "src/" echo "$(gettext " -f, --force Overwrite existing package")" echo "$(gettext " -g, --geninteg Generate integrity checks for source files")" - echo "$(gettext " -h, --help This help")" + echo "$(gettext " -h, --help Show this help message and exit")" echo "$(gettext " -i, --install Install package after successful build")" echo "$(gettext " -L, --log Log package build process")" echo "$(gettext " -m, --nocolor Disable colorized output messages")" @@ -1584,23 +1843,28 @@ usage() { printf "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT" echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")" echo "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")" - echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman")" + printf "$(gettext " -s, --syncdeps Install missing dependencies with %s")\n" "pacman" echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources")" - echo "$(gettext " --asroot Allow makepkg to run as root user")" - printf "$(gettext " --check Run the check() function in the %s")\n" "$BUILDSCRIPT" + printf "$(gettext " --asroot Allow %s to run as root user")\n" "makepkg" + printf "$(gettext " --check Run the %s function in the %s")\n" "check()" "$BUILDSCRIPT" printf "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf" printf "$(gettext " --holdver Prevent automatic version bumping for development %ss")\n" "$BUILDSCRIPT" - printf "$(gettext " --nocheck Do not run the check() function in the %s")\n" "$BUILDSCRIPT" + printf "$(gettext " --key <key> Specify a key to use for %s signing instead of the default")\n" "gpg" + printf "$(gettext " --nocheck Do not run the %s function in the %s")\n" "check()" "$BUILDSCRIPT" + echo "$(gettext " --nosign Do not create a signature for the package")" echo "$(gettext " --pkg <list> Only build listed packages from a split package")" - echo "$(gettext " --skipinteg Do not fail when integrity checks are missing")" + printf "$(gettext " --sign Sign the resulting package with %s")\n" "gpg" + echo "$(gettext " --skipchecksums Do not verify checksums of the source files")" + echo "$(gettext " --skipinteg Do not perform any verification checks on source files")" + echo "$(gettext " --skippgpcheck Do not verify source files with PGP signatures")" echo "$(gettext " --source Generate a source-only tarball without downloaded sources")" echo - echo "$(gettext "These options can be passed to pacman:")" + printf "$(gettext "These options can be passed to %s:")\n" "pacman" echo echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")" echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")" echo - printf "$(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT" + printf "$(gettext "If %s is not specified, %s will look for '%s'")\n" "-p" "makepkg" "$BUILDSCRIPT" echo } @@ -1625,16 +1889,16 @@ fi ARGLIST=("$@") # Parse Command Line Options. -OPT_SHORT="AcCdefFghiLmop:rRsV" -OPT_LONG="allsource,asroot,ignorearch,check,clean,cleancache,nodeps" -OPT_LONG+=",noextract,force,forcever:,geninteg,help,holdver" -OPT_LONG+=",install,log,nocolor,nobuild,nocheck,pkg:,rmdeps" -OPT_LONG+=",repackage,skipinteg,source,syncdeps,version,config:" +OPT_SHORT="AcdefFghiLmop:rRsV" +OPT_LONG="allsource,asroot,ignorearch,check,clean,nodeps" +OPT_LONG+=",noextract,force,forcever:,geninteg,help,holdver,skippgpcheck" +OPT_LONG+=",install,key:,log,nocolor,nobuild,nocheck,nosign,pkg:,rmdeps" +OPT_LONG+=",repackage,skipchecksums,skipinteg,skippgpcheck,sign,source,syncdeps" +OPT_LONG+=",version,config:" + # Pacman Options OPT_LONG+=",noconfirm,noprogressbar" -OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')" -if [[ $OPT_TEMP = *'PARSE_OPTIONS FAILED'* ]]; then - # This is a small hack to stop the script bailing with 'set -e' +if ! OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@")"; then echo; usage; exit 1 # E_INVALID_OPTION; fi eval set -- "$OPT_TEMP" @@ -1651,7 +1915,6 @@ while true; do --asroot) ASROOT=1 ;; -A|--ignorearch) IGNOREARCH=1 ;; -c|--clean) CLEANUP=1 ;; - -C|--cleancache) CLEANCACHE=1 ;; --check) RUN_CHECK='y' ;; --config) shift; MAKEPKG_CONF=$1 ;; -d|--nodeps) NODEPS=1 ;; @@ -1663,15 +1926,20 @@ while true; do -g|--geninteg) GENINTEG=1 ;; --holdver) HOLDVER=1 ;; -i|--install) INSTALL=1 ;; + --key) shift; GPGKEY=$1 ;; -L|--log) LOGGING=1 ;; -m|--nocolor) USE_COLOR='n' ;; --nocheck) RUN_CHECK='n' ;; + --nosign) SIGNPKG='n' ;; -o|--nobuild) NOBUILD=1 ;; -p) shift; BUILDFILE=$1 ;; --pkg) shift; PKGLIST=($1) ;; -r|--rmdeps) RMDEPS=1 ;; -R|--repackage) REPKG=1 ;; - --skipinteg) SKIPINTEG=1 ;; + --skipchecksums) SKIPCHECKSUMS=1 ;; + --skipinteg) SKIPCHECKSUMS=1; SKIPPGPCHECK=1 ;; + --skippgpcheck) SKIPPGPCHECK=1;; + --sign) SIGNPKG='y' ;; --source) SOURCEONLY=1 ;; -s|--syncdeps) DEP_BIN=1 ;; @@ -1688,6 +1956,10 @@ done [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST}) [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST}) [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST}) +[[ -n ${BUILDDIR} ]] && _BUILDDIR=$(canonicalize_path ${BUILDDIR}) +[[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT} +[[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT} +[[ -n ${GPGKEY} ]] && _GPGKEY=${GPGKEY} # default config is makepkg.conf MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf} @@ -1701,8 +1973,9 @@ else exit 1 # $E_CONFIG_ERROR fi -# Source user-specific makepkg.conf overrides -if [[ -r ~/.makepkg.conf ]]; then +# Source user-specific makepkg.conf overrides, but only if no override config +# file was specified +if [[ $MAKEPKG_CONF = "$confdir/makepkg.conf" && -r ~/.makepkg.conf ]]; then source ~/.makepkg.conf fi @@ -1732,9 +2005,24 @@ fi readonly ALL_OFF BOLD BLUE GREEN RED YELLOW # override settings with an environment variable for batch processing +BUILDDIR=${_BUILDDIR:-$BUILDDIR} +BUILDDIR=${BUILDDIR:-$startdir} #default to $startdir if undefined +if [[ ! -d $BUILDDIR ]]; then + mkdir -p "$BUILDDIR" || + error "$(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR" + chmod a-s "$BUILDDIR" +fi +if [[ ! -w $BUILDDIR ]]; then + error "$(gettext "You do not have write permission to create packages in %s.")" "$BUILDDIR" + plain "$(gettext "Aborting...")" + exit 1 +fi +srcdir="$BUILDDIR/src" +pkgdir="$BUILDDIR/pkg" + PKGDEST=${_PKGDEST:-$PKGDEST} PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined -if [[ ! -w $PKGDEST ]]; then +if (( ! (NOBUILD || GENINTEG) )) && [[ ! -w $PKGDEST ]]; then error "$(gettext "You do not have write permission to store packages in %s.")" "$PKGDEST" plain "$(gettext "Aborting...")" exit 1 @@ -1751,82 +2039,41 @@ fi SRCPKGDEST=${_SRCPKGDEST:-$SRCPKGDEST} SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined +PKGEXT=${_PKGEXT:-$PKGEXT} +SRCEXT=${_SRCEXT:-$SRCEXT} +GPGKEY=${_GPGKEY:-$GPGKEY} if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then # The '\\0' is here to prevent gettext from thinking --holdver is an option - error "$(gettext "\\0--holdver and --forcever cannot both be specified" )" + error "$(gettext "\\0%s and %s cannot both be specified" )" "--holdver" "--forcever" exit 1 fi -if (( CLEANCACHE )); then - #fix flyspray feature request #5223 - if [[ -n $SRCDEST && ! $SRCDEST -ef "${startdir}" ]]; then - msg "$(gettext "Cleaning up ALL files from %s.")" "$SRCDEST" - echo -n "$(gettext " Are you sure you wish to do this? ")" - echo -n "$(gettext "[y/N]")" - read answer - answer=$(tr '[:lower:]' '[:upper:]' <<< "$answer") - if [[ $answer = $(gettext YES) || $answer = $(gettext Y) ]]; then - rm "$SRCDEST"/* - if (( $? )); then - error "$(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST" - exit 1 - else - # removal worked - msg "$(gettext "Source cache cleaned.")" - exit 0 - fi - else - # answer = no - msg "$(gettext "No files have been removed.")" - exit 0 - fi - else - # $SRCDEST is $startdir, two possibilities - error "$(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF" - plain "$(gettext "In addition, please run makepkg -C outside of your cache directory.")" - exit 1 - fi -fi - if (( ! INFAKEROOT )); then if (( EUID == 0 && ! ASROOT )); then # Warn those who like to live dangerously. - error "$(gettext "Running makepkg as root is a BAD idea and can cause")" - plain "$(gettext "permanent, catastrophic damage to your system. If you")" - plain "$(gettext "wish to run as root, please use the --asroot option.")" + error "$(gettext "Running %s as root is a BAD idea and can cause permanent,\n\ +catastrophic damage to your system. If you wish to run as root, please\n\ +use the %s option.")" "makepkg" "--asroot" exit 1 # $E_USER_ABORT elif (( EUID > 0 && ASROOT )); then # Warn those who try to use the --asroot option when they are not root - error "$(gettext "The --asroot option is meant for the root user only.")" - plain "$(gettext "Please rerun makepkg without the --asroot flag.")" + error "$(gettext "The %s option is meant for the root user only. Please\n\ +rerun %s without the %s flag.")" "--asroot" "makepkg" "--asroot" exit 1 # $E_USER_ABORT - elif [[ $(check_buildenv fakeroot) = "y" ]] && (( EUID > 0 )); then - if ! type -p fakeroot >/dev/null; then - error "$(gettext "Fakeroot must be installed if using the 'fakeroot' option")" - plain "$(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF" - exit 1 - fi - elif (( EUID > 0 )); then - warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")" - plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment by")" - plain "$(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF" + elif (( EUID > 0 )) && [[ $(check_buildenv fakeroot) != "y" ]]; then + warning "$(gettext "Running %s as an unprivileged user will result in non-root\n\ +ownership of the packaged files. Try using the %s environment by\n\ +placing %s in the %s array in %s.")" "makepkg" "fakeroot" "'fakeroot'" "BUILDENV" "$MAKEPKG_CONF" sleep 1 fi else if [[ -z $FAKEROOTKEY ]]; then - error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")" + error "$(gettext "Do not use the %s option. This option is only for use by %s.")" "'-F'" "makepkg" exit 1 # TODO: error code fi fi -# check for sudo if we will need it during makepkg execution -if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then - if ! type -p sudo >/dev/null; then - warning "$(gettext "Sudo can not be found. Will use su to acquire root privileges.")" - fi -fi - unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides unset md5sums replaces depends conflicts backup source install changelog build unset makedepends optdepends options noextract @@ -1844,7 +2091,7 @@ if [[ ! -f $BUILDFILE ]]; then else crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true) if [[ -n $crlftest ]]; then - error "$(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDFILE" + error "$(gettext "%s contains %s characters and cannot be sourced.")" "$BUILDFILE" "CRLF" exit 1 fi @@ -1870,6 +2117,9 @@ fi # check the PKGBUILD for some basic requirements check_sanity || exit 1 +# check we have the software required to process the PKGBUILD +check_software || exit 1 + # We need to run devel_update regardless of whether we are in the fakeroot # build process so that if the user runs makepkg --forcever manually, we # 1) output the correct pkgver, and 2) use the correct filename when @@ -1902,8 +2152,22 @@ if [[ -n "${PKGLIST[@]}" ]]; then pkgname=("${PKGLIST[@]}") fi +# check if gpg signature is to be created and if signing key is valid +[[ -z $SIGNPKG ]] && SIGNPKG=$(check_buildenv sign) +if [[ $SIGNPKG == 'y' ]]; then + if ! gpg --list-key ${GPGKEY} &>/dev/null; then + if [[ ! -z $GPGKEY ]]; then + error "$(gettext "The key %s does not exist in your keyring.")" "${GPGKEY}" + else + error "$(gettext "There is no key in your keyring.")" + fi + exit 1 + fi +fi + + if (( ! SPLITPKG )); then - fullver=$(get_full_version $epoch $pkgver $pkgrel) + fullver=$(get_full_version) if [[ -f $PKGDEST/${pkgname}-${fullver}-${CARCH}${PKGEXT} \ || -f $PKGDEST/${pkgname}-${fullver}-any${PKGEXT} ]] \ && ! (( FORCE || SOURCEONLY || NOBUILD )); then @@ -1912,7 +2176,7 @@ if (( ! SPLITPKG )); then install_package exit $? else - error "$(gettext "A package has already been built. (use -f to overwrite)")" + error "$(gettext "A package has already been built. (use %s to overwrite)")" "-f" exit 1 fi fi @@ -1920,8 +2184,7 @@ else allpkgbuilt=1 somepkgbuilt=0 for pkg in ${pkgname[@]}; do - # TODO: this wasn't properly fixed in commit 2020e629 - fullver=$(get_full_version $epoch $pkgver $pkgrel) + fullver=$(get_full_version $pkg) if [[ -f $PKGDEST/${pkg}-${fullver}-${CARCH}${PKGEXT} \ || -f $PKGDEST/${pkg}-${fullver}-any${PKGEXT} ]]; then somepkgbuilt=1 @@ -1936,12 +2199,12 @@ else install_package exit $? else - error "$(gettext "The package group has already been built. (use -f to overwrite)")" + error "$(gettext "The package group has already been built. (use %s to overwrite)")" "-f" exit 1 fi fi if (( somepkgbuilt )); then - error "$(gettext "Part of the package group has already been built. (use -f to overwrite)")" + error "$(gettext "Part of the package group has already been built. (use %s to overwrite)")" "-f" exit 1 fi fi @@ -1950,6 +2213,12 @@ fi # Run the bare minimum in fakeroot if (( INFAKEROOT )); then + if (( SOURCEONLY )); then + create_srcpackage + msg "$(gettext "Leaving %s environment.")" "fakeroot" + exit 0 # $E_OK + fi + if (( ! SPLITPKG )); then if (( ! PKGFUNC )); then if (( ! REPKG )); then @@ -1959,7 +2228,7 @@ if (( INFAKEROOT )); then tidy_install fi else - warning "$(gettext "Repackaging without the use of a package() function is deprecated.")" + warning "$(gettext "Repackaging without the use of a %s function is deprecated.")" "package()" plain "$(gettext "File permissions may not be preserved.")" fi else @@ -1971,21 +2240,40 @@ if (( INFAKEROOT )); then run_split_packaging fi - msg "$(gettext "Leaving fakeroot environment.")" + msg "$(gettext "Leaving %s environment.")" "fakeroot" exit 0 # $E_OK fi -fullver=$(get_full_version $epoch $pkgver $pkgrel) +fullver=$(get_full_version) msg "$(gettext "Making package: %s")" "$pkgbase $fullver ($(date))" # if we are creating a source-only package, go no further if (( SOURCEONLY )); then if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \ && (( ! FORCE )); then - error "$(gettext "A source package has already been built. (use -f to overwrite)")" + error "$(gettext "A source package has already been built. (use %s to overwrite)")" "-f" exit 1 fi - create_srcpackage + + # Get back to our src directory so we can begin with sources. + mkdir -p "$srcdir" + chmod a-s "$srcdir" + cd "$srcdir" + if ( (( ! SKIPCHECKSUMS )) || \ + ( (( ! SKIPPGPCHECK )) && source_has_signatures ) ) || \ + (( SOURCEONLY == 2 )); then + download_sources + fi + check_source_integrity + cd "$startdir" + + # if we are root or if fakeroot is not enabled, then we don't use it + if [[ $(check_buildenv fakeroot) != "y" ]] || (( EUID == 0 )); then + create_srcpackage + else + enter_fakeroot + fi + msg "$(gettext "Source package created: %s")" "$pkgbase ($(date))" exit 0 fi @@ -2020,7 +2308,7 @@ elif type -p "${PACMAN%% *}" >/dev/null; then exit 1 fi else - warning "$(gettext "%s was not found in PATH; skipping dependency checks.")" "${PACMAN%% *}" + warning "$(gettext "%s was not found in %s; skipping dependency checks.")" "${PACMAN%% *}" "PATH" fi # ensure we have a sane umask set @@ -2032,9 +2320,9 @@ chmod a-s "$srcdir" cd "$srcdir" if (( NOEXTRACT )); then - warning "$(gettext "Skipping source retrieval -- using existing src/ tree")" - warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")" - warning "$(gettext "Skipping source extraction -- using existing src/ tree")" + warning "$(gettext "Skipping source retrieval -- using existing %s tree")" "src/" + warning "$(gettext "Skipping source integrity checks -- using existing %s tree")" "src/" + warning "$(gettext "Skipping source extraction -- using existing %s tree")" "src/" if (( NOEXTRACT )) && [[ -z $(ls "$srcdir" 2>/dev/null) ]]; then error "$(gettext "The source directory is empty, there is nothing to build!")" @@ -2050,11 +2338,7 @@ elif (( REPKG )); then fi else download_sources - if (( ! SKIPINTEG )); then - check_checksums - else - warning "$(gettext "Skipping integrity checks.")" - fi + check_source_integrity extract_sources fi @@ -2064,7 +2348,7 @@ if (( NOBUILD )); then else # check for existing pkg directory; don't remove if we are repackaging if [[ -d $pkgdir ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then - msg "$(gettext "Removing existing pkg/ directory...")" + msg "$(gettext "Removing existing %s directory...")" "pkg/" rm -rf "$pkgdir" fi mkdir -p "$pkgdir" @@ -2086,7 +2370,7 @@ else if (( ! REPKG )); then tidy_install else - warning "$(gettext "Repackaging without the use of a package() function is deprecated.")" + warning "$(gettext "Repackaging without the use of a %s function is deprecated.")" "package()" plain "$(gettext "File permissions may not be preserved.")" fi fi @@ -2102,17 +2386,11 @@ else cd "$startdir" fi - msg "$(gettext "Entering fakeroot environment...")" - - if [[ -n $newpkgver ]]; then - fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $? - else - fakeroot -- $0 -F "${ARGLIST[@]}" || exit $? - fi + enter_fakeroot fi fi -fullver=$(get_full_version $epoch $pkgver $pkgrel) +fullver=$(get_full_version) msg "$(gettext "Finished making: %s")" "$pkgbase $fullver ($(date))" install_package |