1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

makepkg: use bash test operators, part one

* FS#16623, first half of makepkg
* Includes stuff like -o to ||, -a to &&, etc.
* if [ $(type ... preserved due to a bash bug with [[ and set -e and ERR traps

Signed-off-by: Isaac Good <pacman@isaac.otherinbox.com>
[Dan: made commit message useful]
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Isaac Good 2009-11-12 15:07:34 -05:00 committed by Dan McGee
parent 5d5070f47d
commit 966c815881

View File

@ -112,7 +112,7 @@ error() {
# the fakeroot call, the error message will be printed by the main call. # the fakeroot call, the error message will be printed by the main call.
## ##
trap_exit() { trap_exit() {
if [ "$INFAKEROOT" -eq 0 ]; then if (( ! INFAKEROOT )); then
echo echo
error "$@" error "$@"
fi fi
@ -126,21 +126,21 @@ trap_exit() {
clean_up() { clean_up() {
local EXIT_CODE=$? local EXIT_CODE=$?
if [ "$INFAKEROOT" -eq 1 ]; then if (( INFAKEROOT )); then
# Don't clean up when leaving fakeroot, we're not done yet. # Don't clean up when leaving fakeroot, we're not done yet.
return return
fi fi
if [ $EXIT_CODE -eq 0 -a "$CLEANUP" -eq 1 ]; then if (( ! EXIT_CODE && CLEANUP )); then
# If it's a clean exit and -c/--clean has been passed... # If it's a clean exit and -c/--clean has been passed...
msg "$(gettext "Cleaning up...")" msg "$(gettext "Cleaning up...")"
rm -rf "$pkgdir" "$srcdir" rm -rf "$pkgdir" "$srcdir"
if [ -n "$pkgbase" ]; then if [[ -n $pkgbase ]]; then
# Can't do this unless the BUILDSCRIPT has been sourced. # Can't do this unless the BUILDSCRIPT has been sourced.
rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log"* rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log"*
if [ "$PKGFUNC" -eq 1 ]; then if (( PKGFUNC )); then
rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-package.log"* rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-package.log"*
elif [ "$SPLITPKG" -eq 1 ]; then elif (( SPLITPKG )); then
for pkg in ${pkgname[@]}; do for pkg in ${pkgname[@]}; do
rm -f "${pkg}-${pkgver}-${pkgrel}-${CARCH}-package.log"* rm -f "${pkg}-${pkgver}-${pkgrel}-${CARCH}-package.log"*
done done
@ -190,14 +190,14 @@ get_url() {
## ##
check_option() { check_option() {
local ret=$(in_opt_array "$1" ${options[@]}) local ret=$(in_opt_array "$1" ${options[@]})
if [ "$ret" != '?' ]; then if [[ $ret != '?' ]]; then
echo $ret echo $ret
return return
fi fi
# fall back to makepkg.conf options # fall back to makepkg.conf options
ret=$(in_opt_array "$1" ${OPTIONS[@]}) ret=$(in_opt_array "$1" ${OPTIONS[@]})
if [ "$ret" != '?' ]; then if [[ $ret != '?' ]]; then
echo $ret echo $ret
return return
fi fi
@ -231,10 +231,10 @@ in_opt_array() {
local opt local opt
for opt in "$@"; do for opt in "$@"; do
opt="${opt,,}" opt="${opt,,}"
if [ "$opt" = "$needle" ]; then if [[ $opt = $needle ]]; then
echo 'y' # Enabled echo 'y' # Enabled
return return
elif [ "$opt" = "!$needle" ]; then elif [[ $opt = "!$needle" ]]; then
echo 'n' # Disabled echo 'n' # Disabled
return return
fi fi
@ -251,10 +251,10 @@ in_opt_array() {
## ##
in_array() { in_array() {
local needle=$1; shift local needle=$1; shift
[ -z "$1" ] && return 1 # Not Found [[ -z $1 ]] && return 1 # Not Found
local item local item
for item in "$@"; do for item in "$@"; do
[ "$item" = "$needle" ] && return 0 # Found [[ $item = $needle ]] && return 0 # Found
done done
return 1 # Not Found return 1 # Not Found
} }
@ -268,14 +268,14 @@ get_downloadclient() {
local i local i
for i in "${DLAGENTS[@]}"; do for i in "${DLAGENTS[@]}"; do
local handler="${i%%::*}" local handler="${i%%::*}"
if [ "$proto" = "$handler" ]; then if [[ $proto = $handler ]]; then
agent="${i##*::}" agent="${i##*::}"
break break
fi fi
done done
# if we didn't find an agent, return an error # if we didn't find an agent, return an error
if [ -z "$agent" ]; then if [[ -z $agent ]]; then
error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF" error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF"
plain "$(gettext "Aborting...")" plain "$(gettext "Aborting...")"
exit 1 # $E_CONFIG_ERROR exit 1 # $E_CONFIG_ERROR
@ -283,7 +283,7 @@ get_downloadclient() {
# ensure specified program is installed # ensure specified program is installed
local program="${agent%% *}" local program="${agent%% *}"
if [ ! -x "$program" ]; then if [[ ! -x $program ]]; then
local baseprog=$(basename $program) local baseprog=$(basename $program)
error "$(gettext "The download program %s is not installed.")" "$baseprog" error "$(gettext "The download program %s is not installed.")" "$baseprog"
plain "$(gettext "Aborting...")" plain "$(gettext "Aborting...")"
@ -317,25 +317,25 @@ download_file() {
local ret=0 local ret=0
eval "$dlcmd || ret=\$?" eval "$dlcmd || ret=\$?"
if [ $ret -gt 0 ]; then if (( ret )); then
[ ! -s "$dlfile" ] && rm -f -- "$dlfile" [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
return $ret return $ret
fi fi
# rename the temporary download file to the final destination # rename the temporary download file to the final destination
if [ "$dlfile" != "$file" ]; then if [[ $dlfile != $file ]]; then
mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file" mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
fi fi
} }
check_deps() { check_deps() {
[ $# -gt 0 ] || return (( $# > 0 )) || return
pmout=$(pacman $PACMAN_OPTS -T "$@") pmout=$(pacman $PACMAN_OPTS -T "$@")
ret=$? ret=$?
if [ $ret -eq 127 ]; then #unresolved deps if (( ret == 127 )); then #unresolved deps
echo "$pmout" echo "$pmout"
elif [ $ret -ne 0 ]; then elif (( ret )); then
error "$(gettext "Pacman returned a fatal error (%i): %s")" "$ret" "$pmout" error "$(gettext "Pacman returned a fatal error (%i): %s")" "$ret" "$pmout"
exit 1 exit 1
fi fi
@ -345,26 +345,26 @@ handle_deps() {
local R_DEPS_SATISFIED=0 local R_DEPS_SATISFIED=0
local R_DEPS_MISSING=1 local R_DEPS_MISSING=1
[ $# -eq 0 ] && return $R_DEPS_SATISFIED (( $# == 0 )) && return $R_DEPS_SATISFIED
local deplist="$*" local deplist="$*"
if [ "$DEP_BIN" -eq 0 ]; then if (( ! DEP_BIN )); then
return $R_DEPS_MISSING return $R_DEPS_MISSING
fi fi
if [ "$DEP_BIN" -eq 1 ]; then if (( DEP_BIN )); then
# install missing deps from binary packages (using pacman -S) # install missing deps from binary packages (using pacman -S)
msg "$(gettext "Installing missing dependencies...")" msg "$(gettext "Installing missing dependencies...")"
local ret=0 local ret=0
if [ "$ASROOT" -eq 0 ]; then if (( ! ASROOT )); then
sudo pacman $PACMAN_OPTS -S --asdeps $deplist || ret=$? sudo pacman $PACMAN_OPTS -S --asdeps $deplist || ret=$?
else else
pacman $PACMAN_OPTS -S --asdeps $deplist || ret=$? pacman $PACMAN_OPTS -S --asdeps $deplist || ret=$?
fi fi
if [ $ret -ne 0 ]; then if (( ret )); then
error "$(gettext "Pacman failed to install missing dependencies.")" error "$(gettext "Pacman failed to install missing dependencies.")"
exit 1 # TODO: error code exit 1 # TODO: error code
fi fi
@ -386,7 +386,7 @@ resolve_deps() {
local R_DEPS_MISSING=1 local R_DEPS_MISSING=1
local deplist="$(check_deps $*)" local deplist="$(check_deps $*)"
if [ -z "$deplist" ]; then if [[ -z $deplist ]]; then
return $R_DEPS_SATISFIED return $R_DEPS_SATISFIED
fi fi
@ -394,8 +394,8 @@ resolve_deps() {
pkgdeps="$pkgdeps $deplist" pkgdeps="$pkgdeps $deplist"
# check deps again to make sure they were resolved # check deps again to make sure they were resolved
deplist="$(check_deps $*)" deplist="$(check_deps $*)"
[ -z "$deplist" ] && return $R_DEPS_SATISFIED [[ -z $deplist ]] && return $R_DEPS_SATISFIED
elif [ "$DEP_BIN" -eq 1 ]; then elif (( DEP_BIN )); then
error "$(gettext "Failed to install all missing dependencies.")" error "$(gettext "Failed to install all missing dependencies.")"
fi fi
@ -411,8 +411,8 @@ resolve_deps() {
# fix flyspray bug #5923 # fix flyspray bug #5923
remove_deps() { remove_deps() {
# $pkgdeps is a GLOBAL variable, set by resolve_deps() # $pkgdeps is a GLOBAL variable, set by resolve_deps()
[ "$RMDEPS" -eq 0 ] && return (( ! RMDEPS )) && return
[ -z "$pkgdeps" ] && return [[ -z $pkgdeps ]] && return
local dep depstrip deplist local dep depstrip deplist
deplist="" deplist=""
@ -423,14 +423,14 @@ remove_deps() {
msg "Removing installed dependencies..." msg "Removing installed dependencies..."
local ret=0 local ret=0
if [ "$ASROOT" -eq 0 ]; then if (( ! ASROOT )); then
sudo pacman $PACMAN_OPTS -Rns $deplist || ret=$? sudo pacman $PACMAN_OPTS -Rns $deplist || ret=$?
else else
pacman $PACMAN_OPTS -Rns $deplist || ret=$? pacman $PACMAN_OPTS -Rns $deplist || ret=$?
fi fi
# Fixes FS#10039 - exit cleanly as package has built successfully # Fixes FS#10039 - exit cleanly as package has built successfully
if [ $ret -ne 0 ]; then if (( ret )); then
warning "$(gettext "Failed to remove installed dependencies.")" warning "$(gettext "Failed to remove installed dependencies.")"
return 0 return 0
fi fi
@ -439,7 +439,7 @@ remove_deps() {
download_sources() { download_sources() {
msg "$(gettext "Retrieving Sources...")" msg "$(gettext "Retrieving Sources...")"
if [ ! -w "$SRCDEST" ] ; then if [[ ! -w $SRCDEST ]] ; then
error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST" error "$(gettext "You do not have write permission to store downloads in %s.")" "$SRCDEST"
plain "$(gettext "Aborting...")" plain "$(gettext "Aborting...")"
exit 1 exit 1
@ -451,12 +451,12 @@ download_sources() {
for netfile in "${source[@]}"; do for netfile in "${source[@]}"; do
local file=$(get_filename "$netfile") local file=$(get_filename "$netfile")
local url=$(get_url "$netfile") local url=$(get_url "$netfile")
if [ -f "$startdir/$file" ]; then if [[ -f $startdir/$file ]]; then
msg2 "$(gettext "Found %s in build dir")" "$file" msg2 "$(gettext "Found %s in build dir")" "$file"
rm -f "$srcdir/$file" rm -f "$srcdir/$file"
ln -s "$startdir/$file" "$srcdir/" ln -s "$startdir/$file" "$srcdir/"
continue continue
elif [ -f "$SRCDEST/$file" ]; then elif [[ -f $SRCDEST/$file ]]; then
msg2 "$(gettext "Using cached copy of %s")" "$file" msg2 "$(gettext "Using cached copy of %s")" "$file"
rm -f "$srcdir/$file" rm -f "$srcdir/$file"
ln -s "$SRCDEST/$file" "$srcdir/" ln -s "$SRCDEST/$file" "$srcdir/"
@ -464,7 +464,7 @@ download_sources() {
fi fi
# if we get here, check to make sure it was a URL, else fail # if we get here, check to make sure it was a URL, else fail
if [ "$file" = "$url" ]; then if [[ $file = $url ]]; then
error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file" error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file"
exit 1 # $E_MISSING_FILE exit 1 # $E_MISSING_FILE
fi fi
@ -476,7 +476,7 @@ download_sources() {
# fix flyspray bug #3289 # fix flyspray bug #3289
local ret=0 local ret=0
download_file "$dlclient" "$url" "$file" || ret=$? download_file "$dlclient" "$url" "$file" || ret=$?
if [ $ret -gt 0 ]; then if (( ret )); then
error "$(gettext "Failure while downloading %s")" "$file" error "$(gettext "Failure while downloading %s")" "$file"
plain "$(gettext "Aborting...")" plain "$(gettext "Aborting...")"
exit 1 exit 1
@ -522,8 +522,8 @@ generate_checksums() {
for netfile in "${source[@]}"; do for netfile in "${source[@]}"; do
local file="$(get_filename "$netfile")" local file="$(get_filename "$netfile")"
if [ ! -f "$file" ] ; then if [[ ! -f $file ]] ; then
if [ ! -f "$SRCDEST/$file" ] ; then if [[ ! -f $SRCDEST/$file ]] ; then
error "$(gettext "Unable to find source file %s to generate checksum.")" "$file" error "$(gettext "Unable to find source file %s to generate checksum.")" "$file"
plain "$(gettext "Aborting...")" plain "$(gettext "Aborting...")"
exit 1 exit 1
@ -534,10 +534,10 @@ generate_checksums() {
local sum="$(openssl dgst -${integ} "$file")" local sum="$(openssl dgst -${integ} "$file")"
sum=${sum##* } sum=${sum##* }
[ $ct -gt 0 ] && echo -n "$indent" (( ct )) && echo -n "$indent"
echo -n "'$sum'" echo -n "'$sum'"
ct=$(($ct+1)) ct=$(($ct+1))
[ $ct -lt $numsrc ] && echo (( $ct < $numsrc )) && echo
done done
echo ")" echo ")"
@ -545,7 +545,7 @@ generate_checksums() {
} }
check_checksums() { check_checksums() {
[ ${#source[@]} -eq 0 ] && return 0 (( ! ${#source[@]} )) && return 0
if [ ! $(type -p openssl) ]; then if [ ! $(type -p openssl) ]; then
error "$(gettext "Cannot find openssl.")" error "$(gettext "Cannot find openssl.")"
@ -556,7 +556,7 @@ check_checksums() {
local integ required local integ required
for integ in md5 sha1 sha256 sha384 sha512; do for integ in md5 sha1 sha256 sha384 sha512; do
local integrity_sums=($(eval echo "\${${integ}sums[@]}")) local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then if (( ${#integrity_sums[@]} == ${#source[@]} )); then
msg "$(gettext "Validating source files with %s...")" "${integ}sums" msg "$(gettext "Validating source files with %s...")" "${integ}sums"
correlation=1 correlation=1
local errors=0 local errors=0
@ -567,8 +567,8 @@ check_checksums() {
file="$(get_filename "$file")" file="$(get_filename "$file")"
echo -n " $file ... " >&2 echo -n " $file ... " >&2
if [ ! -f "$file" ] ; then if [[ ! -f $file ]] ; then
if [ ! -f "$SRCDEST/$file" ] ; then if [[ ! -f $SRCDEST/$file ]] ; then
echo "$(gettext "NOT FOUND")" >&2 echo "$(gettext "NOT FOUND")" >&2
errors=1 errors=1
found=0 found=0
@ -577,11 +577,11 @@ check_checksums() {
fi fi
fi fi
if [ $found -gt 0 ] ; then if (( $found )) ; then
local expectedsum="${integrity_sums[$idx],,}" local expectedsum="${integrity_sums[$idx],,}"
local realsum="$(openssl dgst -${integ} "$file")" local realsum="$(openssl dgst -${integ} "$file")"
realsum="${realsum##* }" realsum="${realsum##* }"
if [ "$expectedsum" = "$realsum" ]; then if [[ $expectedsum = $realsum ]]; then
echo "$(gettext "Passed")" >&2 echo "$(gettext "Passed")" >&2
else else
echo "$(gettext "FAILED")" >&2 echo "$(gettext "FAILED")" >&2
@ -592,18 +592,18 @@ check_checksums() {
idx=$((idx + 1)) idx=$((idx + 1))
done done
if [ $errors -gt 0 ]; then if (( errors )); then
error "$(gettext "One or more files did not pass the validity check!")" error "$(gettext "One or more files did not pass the validity check!")"
exit 1 # TODO: error code exit 1 # TODO: error code
fi fi
elif [ ${#integrity_sums[@]} -gt 0 ]; then elif (( ${#integrity_sums[@]} )); then
error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ" error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ"
exit 1 # TODO: error code exit 1 # TODO: error code
fi fi
done done
if [ $correlation -eq 0 ]; then if (( ! correlation )); then
if [ $SKIPINTEG -eq 1 ]; then if (( SKIPINTEG )); then
warning "$(gettext "Integrity checks are missing.")" warning "$(gettext "Integrity checks are missing.")"
else else
error "$(gettext "Integrity checks are missing.")" error "$(gettext "Integrity checks are missing.")"
@ -623,8 +623,8 @@ extract_sources() {
continue continue
fi fi
if [ ! -f "$file" ] ; then if [[ ! -f $file ]] ; then
if [ ! -f "$SRCDEST/$file" ] ; then if [[ ! -f $SRCDEST/$file ]] ; then
error "$(gettext "Unable to find source file %s for extraction.")" "$file" error "$(gettext "Unable to find source file %s for extraction.")" "$file"
plain "$(gettext "Aborting...")" plain "$(gettext "Aborting...")"
exit 1 exit 1
@ -663,31 +663,31 @@ extract_sources() {
local ret=0 local ret=0
msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd" msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd"
if [ "$cmd" = "bsdtar" ]; then if [[ $cmd = bsdtar ]]; then
$cmd -xf "$file" || ret=? $cmd -xf "$file" || ret=?
else else
rm -f "${file%.*}" rm -f "${file%.*}"
$cmd -dcf "$file" > "${file%.*}" || ret=? $cmd -dcf "$file" > "${file%.*}" || ret=?
fi fi
if [ $ret -ne 0 ]; then if (( ret )); then
error "$(gettext "Failed to extract %s")" "$file" error "$(gettext "Failed to extract %s")" "$file"
plain "$(gettext "Aborting...")" plain "$(gettext "Aborting...")"
exit 1 exit 1
fi fi
done done
if [ $EUID -eq 0 ]; then if (( EUID == 0 )); then
# change perms of all source files to root user & root group # change perms of all source files to root user & root group
chown -R 0:0 "$srcdir" chown -R 0:0 "$srcdir"
fi fi
} }
error_function() { error_function() {
if [ -p "$logpipe" ]; then if [[ -p $logpipe ]]; then
rm "$logpipe" rm "$logpipe"
fi fi
# first exit all subshells, then print the error # first exit all subshells, then print the error
if [ $BASH_SUBSHELL -eq 0 ]; then if (( ! BASH_SUBSHELL )); then
plain "$(gettext "Aborting...")" plain "$(gettext "Aborting...")"
remove_deps remove_deps
fi fi
@ -695,13 +695,13 @@ error_function() {
} }
run_function() { run_function() {
if [ -z "$1" ]; then if [[ -z $1 ]]; then
return 1 return 1
fi fi
pkgfunc="$1" pkgfunc="$1"
# clear user-specified makeflags if requested # clear user-specified makeflags if requested
if [ "$(check_option makeflags)" = "n" ]; then if [[ $(check_option makeflags) = "n" ]]; then
MAKEFLAGS="" MAKEFLAGS=""
fi fi
@ -714,12 +714,12 @@ run_function() {
local shellopts=$(shopt -p) local shellopts=$(shopt -p)
local ret=0 local ret=0
if [ "$LOGGING" -eq 1 ]; then if (( LOGGING )); then
BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-$pkgfunc.log" BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-$pkgfunc.log"
if [ -f "$BUILDLOG" ]; then if [[ -f $BUILDLOG ]]; then
local i=1 local i=1
while true; do while true; do
if [ -f "$BUILDLOG.$i" ]; then if [[ -f $BUILDLOG.$i ]]; then
i=$(($i +1)) i=$(($i +1))
else else
break break
@ -753,24 +753,24 @@ run_function() {
run_build() { run_build() {
# use distcc if it is requested (check buildenv and PKGBUILD opts) # use distcc if it is requested (check buildenv and PKGBUILD opts)
if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then if [[ $(check_buildenv distcc) = "y" && $(check_option distcc) != "n" ]]; then
[ -d /usr/lib/distcc/bin ] && export PATH="/usr/lib/distcc/bin:$PATH" [[ -d /usr/lib/distcc/bin ]] && export PATH="/usr/lib/distcc/bin:$PATH"
export DISTCC_HOSTS export DISTCC_HOSTS
elif [ "$(check_option distcc)" = "n" ]; then elif [[ $(check_option distcc) = "n" ]]; then
# if it is not wanted, clear the makeflags too # if it is not wanted, clear the makeflags too
MAKEFLAGS="" MAKEFLAGS=""
fi fi
# use ccache if it is requested (check buildenv and PKGBUILD opts) # use ccache if it is requested (check buildenv and PKGBUILD opts)
if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then if [[ $(check_buildenv ccache) = "y" && $(check_option ccache) != "n" ]]; then
[ -d /usr/lib/ccache/bin ] && export PATH="/usr/lib/ccache/bin:$PATH" [[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH"
fi fi
run_function "build" run_function "build"
} }
run_package() { run_package() {
if [ -z "$1" ]; then if [[ -z $1 ]]; then
pkgfunc="package" pkgfunc="package"
else else
pkgfunc="package_$1" pkgfunc="package_$1"
@ -783,16 +783,16 @@ tidy_install() {
cd "$pkgdir" cd "$pkgdir"
msg "$(gettext "Tidying install...")" msg "$(gettext "Tidying install...")"
if [ "$(check_option docs)" = "n" -a -n "${DOC_DIRS[*]}" ]; then if [[ $(check_option docs) = "n" && -n ${DOC_DIRS[*]} ]]; then
msg2 "$(gettext "Removing doc files...")" msg2 "$(gettext "Removing doc files...")"
rm -rf ${DOC_DIRS[@]} rm -rf ${DOC_DIRS[@]}
fi fi
if [ "$(check_option purge)" = "y" -a -n "${PURGE_TARGETS[*]}" ]; then if [[ $(check_option purge) = "y" && -n ${PURGE_TARGETS[*]} ]]; then
msg2 "$(gettext "Purging other files...")" msg2 "$(gettext "Purging other files...")"
local pt local pt
for pt in "${PURGE_TARGETS[@]}"; do for pt in "${PURGE_TARGETS[@]}"; do
if [ "${pt}" = "${pt//\/}" ]; then if [[ ${pt} = ${pt//\/} ]]; then
find . -type f -name "${pt}" -exec rm -f -- '{}' \; find . -type f -name "${pt}" -exec rm -f -- '{}' \;
else else
rm -f ${pt} rm -f ${pt}
@ -800,16 +800,16 @@ tidy_install() {
done done
fi fi
if [ "$(check_option zipman)" = "y" -a -n "${MAN_DIRS[*]}" ]; then if [[ $(check_option zipman) = "y" && -n ${MAN_DIRS[*]} ]]; then
msg2 "$(gettext "Compressing man and info pages...")" msg2 "$(gettext "Compressing man and info pages...")"
local manpage ext file link hardlinks hl local manpage ext file link hardlinks hl
find ${MAN_DIRS[@]} -type f 2>/dev/null | find ${MAN_DIRS[@]} -type f 2>/dev/null |
while read manpage ; do while read manpage ; do
# check file still exists (potentially compressed with hard link) # check file still exists (potentially compressed with hard link)
if [ -f ${manpage} ]; then if [[ -f ${manpage} ]]; then
ext="${manpage##*.}" ext="${manpage##*.}"
file="${manpage##*/}" file="${manpage##*/}"
if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then if [[ $ext != gz && $ext != bz2 ]]; then
# update symlinks to this manpage # update symlinks to this manpage
find ${MAN_DIRS[@]} -lname "$file" 2>/dev/null | find ${MAN_DIRS[@]} -lname "$file" 2>/dev/null |
while read link ; do while read link ; do
@ -835,7 +835,7 @@ tidy_install() {
done done
fi fi
if [ "$(check_option strip)" = "y" -a -n "${STRIP_DIRS[*]}" ]; then if [[ $(check_option strip) = y && -n ${STRIP_DIRS[*]} ]]; then
msg2 "$(gettext "Stripping debugging symbols from binaries and libraries...")" msg2 "$(gettext "Stripping debugging symbols from binaries and libraries...")"
local binary local binary
find ${STRIP_DIRS[@]} -type f 2>/dev/null | while read binary ; do find ${STRIP_DIRS[@]} -type f 2>/dev/null | while read binary ; do
@ -852,12 +852,12 @@ tidy_install() {
done done
fi fi
if [ "$(check_option libtool)" = "n" ]; then if [[ $(check_option libtool) = "n" ]]; then
msg2 "$(gettext "Removing libtool .la files...")" msg2 "$(gettext "Removing libtool .la files...")"
find . ! -type d -name "*.la" -exec rm -f -- '{}' \; find . ! -type d -name "*.la" -exec rm -f -- '{}' \;
fi fi
if [ "$(check_option emptydirs)" = "n" ]; then if [[ $(check_option emptydirs) = "n" ]]; then
msg2 "$(gettext "Removing empty directories...")" msg2 "$(gettext "Removing empty directories...")"
find . -depth -type d -empty -delete find . -depth -type d -empty -delete
fi fi
@ -865,7 +865,7 @@ tidy_install() {
write_pkginfo() { write_pkginfo() {
local builddate=$(date -u "+%s") local builddate=$(date -u "+%s")
if [ -n "$PACKAGER" ]; then if [[ -n $PACKAGER ]]; then
local packager="$PACKAGER" local packager="$PACKAGER"
else else
local packager="Unknown Packager" local packager="Unknown Packager"
@ -875,12 +875,12 @@ write_pkginfo() {
msg2 "$(gettext "Generating .PKGINFO file...")" msg2 "$(gettext "Generating .PKGINFO file...")"
echo "# Generated by makepkg $myver" >.PKGINFO echo "# Generated by makepkg $myver" >.PKGINFO
if [ "$INFAKEROOT" -eq 1 ]; then if (( INFAKEROOT )); then
echo "# using $(fakeroot -v)" >>.PKGINFO echo "# using $(fakeroot -v)" >>.PKGINFO
fi fi
echo "# $(LC_ALL=C date -u)" >>.PKGINFO echo "# $(LC_ALL=C date -u)" >>.PKGINFO
echo "pkgname = $1" >>.PKGINFO echo "pkgname = $1" >>.PKGINFO
[ "$SPLITPKG" -eq 1 ] && echo "pkgbase = $pkgbase" >>.PKGINFO (( SPLITPKG )) && echo pkgbase = $pkgbase >>.PKGINFO
echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO
echo "pkgdesc = $pkgdesc" >>.PKGINFO echo "pkgdesc = $pkgdesc" >>.PKGINFO
echo "url = $url" >>.PKGINFO echo "url = $url" >>.PKGINFO
@ -888,7 +888,7 @@ write_pkginfo() {
echo "packager = $packager" >>.PKGINFO echo "packager = $packager" >>.PKGINFO
echo "size = $size" >>.PKGINFO echo "size = $size" >>.PKGINFO
echo "arch = $PKGARCH" >>.PKGINFO echo "arch = $PKGARCH" >>.PKGINFO
if [ "$(check_option force)" = "y" ]; then if [[ $(check_option force) = "y" ]]; then
echo "force = true" >> .PKGINFO echo "force = true" >> .PKGINFO
fi fi
@ -919,8 +919,8 @@ write_pkginfo() {
done done
for it in "${packaging_options[@]}"; do for it in "${packaging_options[@]}"; do
local ret="$(check_option $it)" local ret="$(check_option $it)"
if [ "$ret" != "?" ]; then if [[ $ret != "?" ]]; then
if [ "$ret" = "y" ]; then if [[ $ret = y ]]; then
echo "makepkgopt = $it" >>.PKGINFO echo "makepkgopt = $it" >>.PKGINFO
else else
echo "makepkgopt = !$it" >>.PKGINFO echo "makepkgopt = !$it" >>.PKGINFO
@ -930,7 +930,7 @@ write_pkginfo() {
# TODO maybe remove this at some point # TODO maybe remove this at some point
# warn if license array is not present or empty # warn if license array is not present or empty
if [ -z "$license" ]; then if [[ -z $license ]]; then
warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT" 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: license=('GPL').")"
fi fi
@ -942,14 +942,14 @@ check_package() {
# check existence of backup files # check existence of backup files
local file local file
for file in "${backup[@]}"; do for file in "${backup[@]}"; do
if [ ! -f "$file" ]; then if [[ ! -f $file ]]; then
warning "$(gettext "Invalid backup entry : %s")" "$file" warning "$(gettext "Invalid backup entry : %s")" "$file"
fi fi
done done
} }
create_package() { create_package() {
if [ ! -d "$pkgdir" ]; then if [[ ! -d $pkgdir ]]; then
error "$(gettext "Missing pkg/ directory.")" error "$(gettext "Missing pkg/ directory.")"
plain "$(gettext "Aborting...")" plain "$(gettext "Aborting...")"
exit 1 # $E_MISSING_PKGDIR exit 1 # $E_MISSING_PKGDIR
@ -960,13 +960,13 @@ create_package() {
cd "$pkgdir" cd "$pkgdir"
msg "$(gettext "Creating package...")" msg "$(gettext "Creating package...")"
if [ -z "$1" ]; then if [[ -z $1 ]]; then
nameofpkg="$pkgname" nameofpkg="$pkgname"
else else
nameofpkg="$1" nameofpkg="$1"
fi fi
if [ "$arch" = "any" ]; then if [[ $arch = "any" ]]; then
PKGARCH="any" PKGARCH="any"
else else
PKGARCH=$CARCH PKGARCH=$CARCH
@ -977,14 +977,14 @@ create_package() {
local comp_files=".PKGINFO" local comp_files=".PKGINFO"
# check for an install script # check for an install script
if [ -n "$install" ]; then if [[ -n $install ]]; then
msg2 "$(gettext "Adding install script...")" msg2 "$(gettext "Adding install script...")"
cp "$startdir/$install" .INSTALL cp "$startdir/$install" .INSTALL
comp_files="$comp_files .INSTALL" comp_files="$comp_files .INSTALL"
fi fi
# do we have a changelog? # do we have a changelog?
if [ -n "$changelog" ]; then if [[ -n $changelog ]]; then
msg2 "$(gettext "Adding package changelog...")" msg2 "$(gettext "Adding package changelog...")"
cp "$startdir/$changelog" .CHANGELOG cp "$startdir/$changelog" .CHANGELOG
comp_files="$comp_files .CHANGELOG" comp_files="$comp_files .CHANGELOG"
@ -1010,7 +1010,7 @@ create_package() {
bsdtar -cf - $comp_files * > "$pkg_file" || ret=$? bsdtar -cf - $comp_files * > "$pkg_file" || ret=$?
shopt -u nullglob shopt -u nullglob
if [ $ret -eq 0 ]; then if (( ! ret )); then
case "$PKGEXT" in case "$PKGEXT" in
*tar.gz) gzip -f -n "$pkg_file" ;; *tar.gz) gzip -f -n "$pkg_file" ;;
*tar.bz2) bzip2 -f "$pkg_file" ;; *tar.bz2) bzip2 -f "$pkg_file" ;;
@ -1019,7 +1019,7 @@ create_package() {
ret=$? ret=$?
fi fi
if [ $ret -ne 0 ]; then if (( ret )); then
error "$(gettext "Failed to create package file.")" error "$(gettext "Failed to create package file.")"
exit 1 # TODO: error code exit 1 # TODO: error code
fi fi
@ -1043,8 +1043,8 @@ create_srcpackage() {
msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT" msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}" ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
if [ -n "$install" ]; then if [[ -n $install ]]; then
if [ -f $install ]; then if [[ -f $install ]]; then
msg2 "$(gettext "Adding install script...")" msg2 "$(gettext "Adding install script...")"
ln -s "${startdir}/$install" "${srclinks}/${pkgbase}/" ln -s "${startdir}/$install" "${srclinks}/${pkgbase}/"
else else
@ -1052,8 +1052,8 @@ create_srcpackage() {
fi fi
fi fi
if [ -n "$changelog" ]; then if [[ -n $changelog ]]; then
if [ -f "$changelog" ]; then if [[ -f $changelog ]]; then
msg2 "$(gettext "Adding package changelog...")" msg2 "$(gettext "Adding package changelog...")"
ln -s "${startdir}/$changelog" "${srclinks}/${pkgbase}/" ln -s "${startdir}/$changelog" "${srclinks}/${pkgbase}/"
else else
@ -1064,10 +1064,10 @@ create_srcpackage() {
local netfile local netfile
for netfile in "${source[@]}"; do for netfile in "${source[@]}"; do
local file=$(get_filename "$netfile") local file=$(get_filename "$netfile")
if [ -f "$netfile" ]; then if [[ -f $netfile ]]; then
msg2 "$(gettext "Adding %s...")" "$netfile" msg2 "$(gettext "Adding %s...")" "$netfile"
ln -s "${startdir}/$netfile" "${srclinks}/${pkgbase}" ln -s "${startdir}/$netfile" "${srclinks}/${pkgbase}"
elif [ "$SOURCEONLY" -eq 2 -a -f "$SRCDEST/$file" ]; then elif (( SOURCEONLY == 2 )) && [[ -f $SRCDEST/$file ]]; then
msg2 "$(gettext "Adding %s...")" "$file" msg2 "$(gettext "Adding %s...")" "$file"
ln -s "$SRCDEST/$file" "${srclinks}/${pkgbase}/" ln -s "$SRCDEST/$file" "${srclinks}/${pkgbase}/"
fi fi