diff options
Diffstat (limited to 'scripts/makepkg.sh.in')
-rw-r--r-- | scripts/makepkg.sh.in | 240 |
1 files changed, 140 insertions, 100 deletions
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 04d2aca1..da7e71f3 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -38,11 +38,13 @@ export COMMAND_MODE='legacy' myver='@PACKAGE_VERSION@' confdir='@sysconfdir@' +BUILDSCRIPT='@BUILDSCRIPT@' startdir="$PWD" srcdir="$startdir/src" pkgdir="$startdir/pkg" -known_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'ccache' 'distcc' 'makeflags' 'force') -readonly -a known_options +packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge') +other_options=('ccache' 'distcc' 'makeflags' 'force') +readonly -a packaging_options other_options # Options ASROOT=0 @@ -278,7 +280,7 @@ get_downloadclient() { # if we didn't find an agent, return an error if [ -z "$agent" ]; then - error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$confdir/makepkg.conf" + error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF" plain "$(gettext "Aborting...")" exit 1 # $E_CONFIG_ERROR fi @@ -488,6 +490,11 @@ generate_checksums() { msg "$(gettext "Generating checksums for source files...")" plain "" + if [ ! $(type -p openssl) ]; then + error "$(gettext "Cannot find openssl.")" + exit 1 # $E_MISSING_PROGRAM + fi + local integ for integ in ${INTEGRITY_CHECK[@]}; do integ="$(echo $integ | tr '[:upper:]' '[:lower:]')" @@ -498,11 +505,6 @@ generate_checksums() { exit 1;; # $E_CONFIG_ERROR esac - if [ ! $(type -p openssl) ]; then - error "$(gettext "Cannot find openssl.")" - exit 1 # $E_MISSING_PROGRAM - fi - local ct=0 local numsrc=${#source[@]} echo -n "${integ}sums=(" @@ -540,21 +542,13 @@ generate_checksums() { } check_checksums() { - local integ - for integ in ${INTEGRITY_CHECK[@]}; do - integ="$(echo $integ | tr '[:upper:]' '[:lower:]')" - case "$integ" in - md5|sha1|sha256|sha384|sha512) : ;; - *) - error "$(gettext "Invalid integrity algorithm '%s' specified")" "$integ" - exit 1;; # $E_CONFIG_ERROR - esac - - if [ ! $(type -p openssl) ]; then - error "$(gettext "Cannot find openssl.")" - exit 1 # $E_MISSING_PROGRAM - fi + if [ ! $(type -p openssl) ]; then + error "$(gettext "Cannot find openssl.")" + exit 1 # $E_MISSING_PROGRAM + fi + local integ required + for integ in md5 sha1 sha256 sha384 sha512; do local integrity_sums=($(eval echo "\${${integ}sums[@]}")) if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then msg "$(gettext "Validating source files with %s...")" "${integ}sums" @@ -592,7 +586,13 @@ check_checksums() { exit 1 # TODO: error code fi else - warning "$(gettext "Integrity checks (%s) are missing or incomplete.")" "$integ" + for required in ${INTEGRITY_CHECK[@]}; do + required="$(echo $required | tr '[:upper:]' '[:lower:]')" + if [ "$integ" = "$required" ]; then + warning "$(gettext "Integrity checks (%s) are missing or incomplete.")" "$integ" + break + fi + done fi done } @@ -674,7 +674,7 @@ run_build() { cd "$srcdir" # ensure all necessary build variables are exported - export CFLAGS CXXFLAGS MAKEFLAGS CHOST + export CFLAGS CXXFLAGS MAKEFLAGS LDFLAGS CHOST # save our shell options so build() can't override what we need local shellopts=$(shopt -p) @@ -712,17 +712,27 @@ tidy_install() { cd "$pkgdir" msg "$(gettext "Tidying install...")" - if [ "$(check_option docs)" = "n" ]; then - msg2 "$(gettext "Removing info/doc files...")" - #fix flyspray bug #5021 + if [ "$(check_option docs)" = "n" -a -n "${DOC_DIRS[*]}" ]; then + msg2 "$(gettext "Removing doc files...")" rm -rf ${DOC_DIRS[@]} fi - if [ "$(check_option zipman)" = "y" ]; then - msg2 "$(gettext "Compressing man pages...")" - local manpage mandirs ext file link hardlinks hl - mandirs="usr/man usr/share/man usr/local/man usr/local/share/man opt/*/man" - find ${mandirs} -type f 2>/dev/null | + if [ "$(check_option purge)" = "y" -a -n "${PURGE_TARGETS[*]}" ]; then + msg2 "$(gettext "Purging other files...")" + local pt + for pt in "${PURGE_TARGETS[@]}"; do + if [ "${pt}" == "${pt//\/}" ]; then + find . -type f -name "${pt}" -exec rm -f -- '{}' \; + else + rm -f ${pt} + fi + done + fi + + if [ "$(check_option zipman)" = "y" -a -n "${MAN_DIRS[*]}" ]; then + msg2 "$(gettext "Compressing man and info pages...")" + local manpage ext file link hardlinks hl + find ${MAN_DIRS[@]} -type f 2>/dev/null | while read manpage ; do # check file still exists (potentially compressed with hard link) if [ -f ${manpage} ]; then @@ -730,7 +740,7 @@ tidy_install() { file="${manpage##*/}" if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then # update symlinks to this manpage - find ${mandirs} -lname "$file" 2>/dev/null | + find ${MAN_DIRS[@]} -lname "$file" 2>/dev/null | while read link ; do rm -f "$link" ln -sf "${file}.gz" "${link}.gz" @@ -738,7 +748,7 @@ tidy_install() { # find hard links and remove them # the '|| true' part keeps the script from bailing if find returned an # error, such as when one of the man directories doesn't exist - hardlinks="$(find ${mandirs} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true + hardlinks="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true for hl in ${hardlinks}; do rm -f "${hl}"; done @@ -754,15 +764,9 @@ tidy_install() { done fi - - if [ "$(check_option strip)" = "y" ]; then + if [ "$(check_option strip)" = "y" -a -n "${STRIP_DIRS[*]}" ]; then msg2 "$(gettext "Stripping debugging symbols from binaries and libraries...")" local binary - if [ -z "${STRIP_DIRS[*]}" ]; then - # fall back to default value - STRIP_DIRS=(bin lib sbin usr/{bin,lib,sbin,local/{bin,lib,sbin}} - opt/*/{bin,lib,sbin}) - fi find ${STRIP_DIRS[@]} -type f 2>/dev/null | while read binary ; do case "$(file -biz "$binary")" in *application/x-sharedlib*) # Libraries (.so) @@ -850,6 +854,16 @@ create_package() { for it in "${backup[@]}"; do echo "backup = $it" >>.PKGINFO done + for it in "${packaging_options[@]}"; do + local ret="$(check_option $it)" + if [ "$ret" != "?" ]; then + if [ "$ret" = "y" ]; then + echo "makepkgopt = $it" >>.PKGINFO + else + echo "makepkgopt = !$it" >>.PKGINFO + fi + fi + done # TODO maybe remove this at some point # warn if license array is not present or empty @@ -877,13 +891,21 @@ create_package() { # tar it up msg2 "$(gettext "Compressing package...")" + local TAR_OPT + case "$PKGEXT" in + *tar.gz) TAR_OPT="z" ;; + *tar.bz2) TAR_OPT="j" ;; + *) warning "$(gettext "'%s' is not a valid archive extension.")" \ + "$PKGEXT" ;; + esac + local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" # when fileglobbing, we want * in an empty directory to expand to # the null string rather than itself shopt -s nullglob - if ! bsdtar -czf "$pkg_file" $comp_files *; then + if ! bsdtar -c${TAR_OPT}f "$pkg_file" $comp_files *; then error "$(gettext "Failed to create package file.")" exit 1 # TODO: error code fi @@ -998,12 +1020,20 @@ create_srcpackage() { fi done + local TAR_OPT + case "$SRCEXT" in + *tar.gz) TAR_OPT="z" ;; + *tar.bz2) TAR_OPT="j" ;; + *) warning "$(gettext "'%s' is not a valid archive extension.")" \ + "$SRCEXT" ;; + esac + local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}${SRCEXT}" # tar it up msg2 "$(gettext "Compressing source package...")" cd "${srclinks}" - if ! bsdtar -czLf "$pkg_file" ${pkgname}; then + if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgname}; then error "$(gettext "Failed to create source package file.")" exit 1 # TODO: error code fi @@ -1027,6 +1057,10 @@ devel_check() { if [ "$HOLDVER" = "1" ]; then return fi + # Cannot update pkgver/pkgrel if reading PKGBUILD from pipe + if [ ! -f "./$BUILDSCRIPT" ]; then + return + fi if [ "$FORCE_VER" = "" ]; then # Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so. # This will only be used on the first call to makepkg; subsequent @@ -1094,9 +1128,11 @@ devel_update() { # if [ "$newpkgver" != "" ]; then if [ "$newpkgver" != "$pkgver" ]; then - sed -i "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "./$BUILDSCRIPT" - sed -i "s/^pkgrel=[^ ]*/pkgrel=1/" "./$BUILDSCRIPT" - source "$BUILDSCRIPT" + if [ -f "./$BUILDSCRIPT" ]; then + sed -i "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "./$BUILDSCRIPT" + sed -i "s/^pkgrel=[^ ]*/pkgrel=1/" "./$BUILDSCRIPT" + source "$BUILDSCRIPT" + fi fi fi } @@ -1197,6 +1233,7 @@ usage() { printf "$(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT" echo "$(gettext " -c, --clean Clean up work files after build")" echo "$(gettext " -C, --cleancache Clean up source files from the cache")" + printf "$(gettext " --config <config> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf" echo "$(gettext " -d, --nodeps Skip all dependency checks")" echo "$(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")" echo "$(gettext " -f, --force Overwrite existing package")" @@ -1244,36 +1281,12 @@ fi ARGLIST=$@ -#preserve environment variables -_PKGDEST=${PKGDEST} -_SRCDEST=${SRCDEST} - -# Source makepkg.conf; fail if it is not found -if [ -r "$confdir/makepkg.conf" ]; then - source "$confdir/makepkg.conf" -else - error "$(gettext "%s not found.")" "$confdir/makepkg.conf" - plain "$(gettext "Aborting...")" - exit 1 # $E_CONFIG_ERROR -fi - -# Source user-specific makepkg.conf overrides -if [ -r ~/.makepkg.conf ]; then - source ~/.makepkg.conf -fi - -# override settings with an environment variable for batch processing -PKGDEST=${_PKGDEST:-$PKGDEST} -PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined -SRCDEST=${_SRCDEST:-$SRCDEST} -SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined - # Parse Command Line Options. OPT_SHORT="AbcCdefFghiLmop:rRsV" OPT_LONG="allsource,asroot,ignorearch,builddeps,clean,cleancache,nodeps" OPT_LONG="$OPT_LONG,noextract,force,forcever:,geninteg,help,holdver" OPT_LONG="$OPT_LONG,install,log,nocolor,nobuild,rmdeps,repackage,source" -OPT_LONG="$OPT_LONG,syncdeps,version" +OPT_LONG="$OPT_LONG,syncdeps,version,config:" # Pacman Options OPT_LONG="$OPT_LONG,noconfirm,noprogressbar" OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')" @@ -1296,6 +1309,7 @@ while true; do -A|--ignorearch) IGNOREARCH=1 ;; -c|--clean) CLEANUP=1 ;; -C|--cleancache) CLEANCACHE=1 ;; + --config) shift; MAKEPKG_CONF=$1 ;; -d|--nodeps) NODEPS=1 ;; -e|--noextract) NOEXTRACT=1 ;; -f|--force) FORCE=1 ;; @@ -1323,6 +1337,34 @@ while true; do shift done +#preserve environment variables +_PKGDEST=${PKGDEST} +_SRCDEST=${SRCDEST} + +# default config is makepkg.conf +MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf} + +# Source the config file; fail if it is not found +if [ -r "$MAKEPKG_CONF" ]; then + source "$MAKEPKG_CONF" +else + error "$(gettext "%s not found.")" "$MAKEPKG_CONF" + plain "$(gettext "Aborting...")" + exit 1 # $E_CONFIG_ERROR +fi + +# Source user-specific makepkg.conf overrides +if [ -r ~/.makepkg.conf ]; then + source ~/.makepkg.conf +fi + +# override settings with an environment variable for batch processing +PKGDEST=${_PKGDEST:-$PKGDEST} +PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined +SRCDEST=${_SRCDEST:-$SRCDEST} +SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined + + if [ "$HOLDVER" = "1" -a "$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" )" @@ -1354,14 +1396,14 @@ if [ "$CLEANCACHE" = "1" ]; then fi else # $SRCDEST is $startdir, two possibilities - error "$(gettext "Source destination must be defined in makepkg.conf.")" + 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 [ -z "$BUILDSCRIPT" ]; then - error "$(gettext "BUILDSCRIPT is undefined! Ensure you have updated %s.")" "$confdir/makepkg.conf" + error "$(gettext "BUILDSCRIPT is undefined! Ensure you have updated %s.")" "$MAKEPKG_CONF" exit 1 fi @@ -1380,13 +1422,13 @@ if [ "$INFAKEROOT" = "0" ]; then elif [ "$(check_buildenv fakeroot)" = "y" -a $EUID -gt 0 ]; then if [ ! $(type -p fakeroot) ]; then error "$(gettext "Fakeroot must be installed if using the 'fakeroot' option")" - plain "$(gettext "in the BUILDENV array in %s.")" "$confdir/makepkg.conf" + plain "$(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF" exit 1 fi elif [ $EUID -gt 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 makepkg.conf.")" + plain "$(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF" sleep 1 fi else @@ -1412,8 +1454,19 @@ unset replaces depends conflicts backup source install build makedepends unset optdepends options noextract if [ ! -f "$BUILDSCRIPT" ]; then - error "$(gettext "%s does not exist.")" "$BUILDSCRIPT" - exit 1 + if [ -t 0 ]; then + error "$(gettext "%s does not exist.")" "$BUILDSCRIPT" + exit 1 + else + # PKGBUILD passed through a pipe + BUILDSCRIPT=/dev/stdin + fi +else + crlftest=$(file $BUILDSCRIPT | grep -F 'CRLF' || true) + if [ "$crlftest" != "" ]; then + error "$(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDSCRIPT" + exit 1 + fi fi source "$BUILDSCRIPT" @@ -1458,10 +1511,6 @@ if ! in_array $CARCH ${arch[@]}; then plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT" plain "$(gettext "such as arch=('%s').")" "$CARCH" exit 1 - else - warning "$(gettext "%s is not available for the '%s' architecture.")" "$pkgname" "$CARCH" - plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT" - plain "$(gettext "such as arch=('%s').")" "$CARCH" fi fi @@ -1482,7 +1531,7 @@ valid_options=1 for opt in ${options[@]}; do known=0 # check if option matches a known option or its inverse - for kopt in ${known_options[@]}; do + for kopt in ${packaging_options[@]} ${other_options[@]}; do if [ "${opt}" = "${kopt}" -o "${opt}" = "!${kopt}" ]; then known=1 fi @@ -1517,11 +1566,8 @@ if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \ fi # Run the bare minimum in fakeroot -# fix flyspray bug 6208 -- using makepkg with fakeroot gives an error if [ "$INFAKEROOT" = "1" ]; then - if [ "$REPKG" = "1" ]; then - warning "$(gettext "Skipping build.")" - else + if [ "$REPKG" = "0" ]; then run_build tidy_install fi @@ -1534,10 +1580,6 @@ fi msg "$(gettext "Making package: %s")" "$pkgname $pkgver-$pkgrel $CARCH ($(date))" -if [ $EUID -eq 0 ]; then - warning "$(gettext "Running makepkg as root...")" -fi - # if we are creating a source-only package, go no further if [ "$SOURCEONLY" != "0" ]; then if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}${SRCEXT}" \ @@ -1552,10 +1594,10 @@ fi # fix flyspray bug #5973 if [ "$NODEPS" = "1" -o "$NOBUILD" = "1" -o "$REPKG" = "1" ]; then + # no warning message needed for nobuild, repkg if [ "$NODEPS" = "1" ]; then warning "$(gettext "Skipping dependency checks.")" fi - # skip printing a warning message for the others: nobuild, repkg elif [ $(type -p pacman) ]; then unset pkgdeps # Set by resolve_deps() and used by remove_deps() deperr=0 @@ -1581,7 +1623,7 @@ umask 0022 mkdir -p "$srcdir" cd "$srcdir" -if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then +if [ "$NOEXTRACT" = "1" ]; 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")" @@ -1590,11 +1632,11 @@ if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then error "$(gettext "The source directory is empty, there is nothing to build!")" plain "$(gettext "Aborting...")" exit 1 - elif [ "$REPKG" = "1" -a \( ! -d "$pkgdir" -o "$(ls "$pkgdir" 2>/dev/null)" = "" \) ]; then - error "$(gettext "The package directory is empty, there is nothing to repackage!")" - plain "$(gettext "Aborting...")" - exit 1 fi +elif [ "$REPKG" = "1" -a \( ! -d "$pkgdir" -o "$(ls "$pkgdir" 2>/dev/null)" = "" \) ]; then + error "$(gettext "The package directory is empty, there is nothing to repackage!")" + plain "$(gettext "Aborting...")" + exit 1 else download_sources check_checksums @@ -1613,11 +1655,9 @@ else mkdir -p "$pkgdir" cd "$startdir" + # if we are root or if fakeroot is not enabled, then we don't use it if [ "$(check_buildenv fakeroot)" != "y" -o $EUID -eq 0 ]; then - # if we are root or if fakeroot is not enabled, then we don't use it - if [ "$REPKG" = "1" ]; then - warning "$(gettext "Skipping build.")" - else + if [ "$REPKG" = "0" ]; then devel_update run_build tidy_install |