commit d71c1f120351c0ab7396f5aabbe9cf0497621782 Author: Isaac Good Date: Sun Oct 25 19:19:18 2009 -0400 Signed-off-by: Isaac Good Modified makepkg to use more of [[ ]] and (( )) bash constructs Added quotes to variables in a few places that were missing them or had {} instead diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 9cd7f2e..16a4f76 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -82,22 +82,25 @@ PACMAN_OPTS= ### SUBROUTINES ### plain() { - local mesg=$1; shift + local mesg="$1"; shift printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } msg() { - local mesg=$1; shift +} + +msg() { + local mesg="$1"; shift printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } msg2() { - local mesg=$1; shift + local mesg="$1"; shift printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } warning() { - local mesg=$1; shift + local mesg="$1"; shift printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } @@ -112,7 +115,7 @@ error() { # the fakeroot call, the error message will be printed by the main call. ## trap_exit() { - if [ "$INFAKEROOT" -eq 0 ]; then + if (( ! INFAKEROOT )); then echo error "$@" fi @@ -126,22 +129,22 @@ trap_exit() { clean_up() { local EXIT_CODE=$? - if [ "$INFAKEROOT" -eq 1 ]; then + if (( INFAKEROOT )); then # Don't clean up when leaving fakeroot, we're not done yet. return 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... msg "$(gettext "Cleaning up...")" rm -rf "$pkgdir" "$srcdir" - if [ -n "$pkgbase" ]; then + if [[ -n $pkgbase ]]; then # Can't do this unless the BUILDSCRIPT has been sourced. rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log"* - if [ "$PKGFUNC" -eq 1 ]; then + if (( PKGFUNC )); then rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-package.log"* - elif [ "$SPLITPKG" -eq 1 ]; then - for pkg in ${pkgname[@]}; do + elif (( SPLITPKG )); then + for pkg in "${pkgname[@]}"; do rm -f "${pkg}-${pkgver}-${pkgrel}-${CARCH}-package.log"* done fi @@ -189,15 +192,15 @@ get_url() { # ? - not found ## check_option() { - local ret=$(in_opt_array "$1" ${options[@]}) - if [ "$ret" != '?' ]; then + local ret=$(in_opt_array "$1" "${options[@]}") + if [[ $ret != '?' ]]; then echo $ret return fi # fall back to makepkg.conf options - ret=$(in_opt_array "$1" ${OPTIONS[@]}) - if [ "$ret" != '?' ]; then + ret=$(in_opt_array "$1" "${OPTIONS[@]}") + if [[ $ret != '?' ]]; then echo $ret return fi @@ -215,7 +218,7 @@ check_option() { # ? - not found ## check_buildenv() { - echo $(in_opt_array "$1" ${BUILDENV[@]}) + echo $(in_opt_array "$1" "${BUILDENV[@]}") } @@ -234,7 +237,7 @@ in_opt_array() { if [ "$opt" = "$needle" ]; then echo 'y' # Enabled return - elif [ "$opt" = "!$needle" ]; then + elif [[ $opt = "!$needle" ]]; then echo 'n' # Disabled return fi @@ -250,11 +253,11 @@ in_opt_array() { # 1 - not found ## in_array() { - local needle=$1; shift - [ -z "$1" ] && return 1 # Not Found + local needle="$1"; shift + [[ ! $1 ]] && return 1 # Not Found local item for item in "$@"; do - [ "$item" = "$needle" ] && return 0 # Found + [[ $item = $needle ]] && return 0 # Found done return 1 # Not Found } @@ -268,14 +271,14 @@ get_downloadclient() { local i for i in "${DLAGENTS[@]}"; do local handler="${i%%::*}" - if [ "$proto" = "$handler" ]; then + if [[ $proto = $handler ]]; then agent="${i##*::}" break fi done # if we didn't find an agent, return an error - if [ -z "$agent" ]; then + if [[ ! $agent ]]; then 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 @@ -283,7 +286,7 @@ get_downloadclient() { # ensure specified program is installed local program="${agent%% *}" - if [ ! -x "$program" ]; then + if [[ ! -x $program ]]; then local baseprog=$(basename $program) error "$(gettext "The download program %s is not installed.")" "$baseprog" plain "$(gettext "Aborting...")" @@ -317,25 +320,25 @@ download_file() { local ret=0 eval "$dlcmd || ret=\$?" - if [ $ret -gt 0 ]; then + if (( ret )); then [ ! -s "$dlfile" ] && rm -f -- "$dlfile" return $ret fi # rename the temporary download file to the final destination - if [ "$dlfile" != "$file" ]; then + if [[ $dlfile != $file ]]; then mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file" fi } check_deps() { - [ $# -gt 0 ] || return + (( $# )) || return pmout=$(pacman $PACMAN_OPTS -T "$@") ret=$? - if [ $ret -eq 127 ]; then #unresolved deps + if (( ret == 127 )); then #unresolved deps echo "$pmout" - elif [ $ret -ne 0 ]; then + elif (( $ret )); then error "$(gettext "Pacman returned a fatal error (%i): %s")" "$ret" "$pmout" exit 1 fi @@ -345,26 +348,26 @@ handle_deps() { local R_DEPS_SATISFIED=0 local R_DEPS_MISSING=1 - [ $# -eq 0 ] && return $R_DEPS_SATISFIED + (( $# )) || return $R_DEPS_SATISFIED local deplist="$*" - if [ "$DEP_BIN" -eq 0 ]; then + if (( ! DEP_BIN )); then return $R_DEPS_MISSING fi - if [ "$DEP_BIN" -eq 1 ]; then + if (( DEP_BIN )); then # install missing deps from binary packages (using pacman -S) msg "$(gettext "Installing missing dependencies...")" local ret=0 - if [ "$ASROOT" -eq 0 ]; then + if (( ! ASROOT )); then sudo pacman $PACMAN_OPTS -S --asdeps $deplist || ret=$? else pacman $PACMAN_OPTS -S --asdeps $deplist || ret=$? fi - if [ $ret -ne 0 ]; then + if (( ret )); then error "$(gettext "Pacman failed to install missing dependencies.")" exit 1 # TODO: error code fi @@ -385,7 +388,7 @@ resolve_deps() { local R_DEPS_MISSING=1 local deplist="$(check_deps $*)" - if [ -z "$deplist" ]; then + if [[ ! $deplist ]]; then return $R_DEPS_SATISFIED fi @@ -393,8 +396,8 @@ resolve_deps() { pkgdeps="$pkgdeps $deplist" # check deps again to make sure they were resolved deplist="$(check_deps $*)" - [ -z "$deplist" ] && return $R_DEPS_SATISFIED - elif [ "$DEP_BIN" -eq 1 ]; then + [[ ! $deplist ]] && return $R_DEPS_SATISFIED + elif (( DEP_BIN )); then error "$(gettext "Failed to install all missing dependencies.")" fi @@ -410,8 +413,8 @@ resolve_deps() { # fix flyspray bug #5923 remove_deps() { # $pkgdeps is a GLOBAL variable, set by resolve_deps() - [ "$RMDEPS" -eq 0 ] && return - [ -z "$pkgdeps" ] && return + (( ! RMDEPS )) && return + [[ ! $pkgdeps ]] && return local dep depstrip deplist deplist="" @@ -422,14 +425,14 @@ remove_deps() { msg "Removing installed dependencies..." local ret=0 - if [ "$ASROOT" -eq 0 ]; then + if (( ! ASROOT )); then sudo pacman $PACMAN_OPTS -Rns $deplist || ret=$? else pacman $PACMAN_OPTS -Rns $deplist || ret=$? fi # 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.")" return 0 fi @@ -438,7 +441,7 @@ remove_deps() { download_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" plain "$(gettext "Aborting...")" exit 1 @@ -450,12 +453,12 @@ download_sources() { for netfile in "${source[@]}"; do local file=$(get_filename "$netfile") local url=$(get_url "$netfile") - if [ -f "$startdir/$file" ]; then + if [[ -f $startdir/$file ]]; then msg2 "$(gettext "Found %s in build dir")" "$file" rm -f "$srcdir/$file" ln -s "$startdir/$file" "$srcdir/" continue - elif [ -f "$SRCDEST/$file" ]; then + elif [[ -f $SRCDEST/$file ]]; then msg2 "$(gettext "Using cached copy of %s")" "$file" rm -f "$srcdir/$file" ln -s "$SRCDEST/$file" "$srcdir/" @@ -463,7 +466,7 @@ download_sources() { fi # 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" exit 1 # $E_MISSING_FILE fi @@ -475,7 +478,7 @@ download_sources() { # fix flyspray bug #3289 local ret=0 download_file "$dlclient" "$url" "$file" || ret=$? - if [ $ret -gt 0 ]; then + if (( ret )); then error "$(gettext "Failure while downloading %s")" "$file" plain "$(gettext "Aborting...")" exit 1 @@ -491,13 +494,13 @@ generate_checksums() { msg "$(gettext "Generating checksums for source files...")" plain "" - if [ ! $(type -p openssl) ]; then + if ! type -p openssl >/dev/null ; then error "$(gettext "Cannot find openssl.")" exit 1 # $E_MISSING_PROGRAM fi local integ - for integ in ${INTEGRITY_CHECK[@]}; do + for integ in "${INTEGRITY_CHECK[@]}"; do integ="${integ,,}" case "$integ" in md5|sha1|sha256|sha384|sha512) : ;; @@ -512,17 +515,16 @@ generate_checksums() { local i=0; local indent='' - while [ $i -lt $((${#integ}+6)) ]; do + for ((i=0; i < ${#integ} + 6; i++ )); do indent="$indent " - i=$(($i+1)) done local netfile for netfile in "${source[@]}"; do local file="$(get_filename "$netfile")" - if [ ! -f "$file" ] ; then - if [ ! -f "$SRCDEST/$file" ] ; then + if [[ ! -f $file ]] ; then + if [[ ! -f $SRCDEST/$file ]] ; then error "$(gettext "Unable to find source file %s to generate checksum.")" "$file" plain "$(gettext "Aborting...")" exit 1 @@ -531,12 +533,12 @@ generate_checksums() { fi fi - local sum="$(openssl dgst -${integ} "$file")" - sum=${sum##* } - [ $ct -gt 0 ] && echo -n "$indent" + local sum="$(openssl dgst -"$integ" "$file")" + sum="${sum##* }" + (( ct )) && echo -n "$indent" echo -n "'$sum'" - ct=$(($ct+1)) - [ $ct -lt $numsrc ] && echo + ct=$((ct+1)) + (( ct < numsrc )) && echo done echo ")" @@ -544,9 +546,9 @@ generate_checksums() { } check_checksums() { - [ ${#source[@]} -eq 0 ] && return 0 + (( ! ${#source[@]} )) && return 0 - if [ ! $(type -p openssl) ]; then + if ! type -p openssl >/dev/null; then error "$(gettext "Cannot find openssl.")" exit 1 # $E_MISSING_PROGRAM fi @@ -555,7 +557,7 @@ check_checksums() { 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 + if (( ${#integrity_sums[@]} == ${#source[@]} )); then msg "$(gettext "Validating source files with %s...")" "${integ}sums" correlation=1 local errors=0 @@ -566,8 +568,8 @@ check_checksums() { file="$(get_filename "$file")" echo -n " $file ... " >&2 - if [ ! -f "$file" ] ; then - if [ ! -f "$SRCDEST/$file" ] ; then + if [[ ! -f $file ]] ; then + if [[ ! -f $SRCDEST/$file ]] ; then echo "$(gettext "NOT FOUND")" >&2 errors=1 found=0 @@ -576,11 +578,11 @@ check_checksums() { fi fi - if [ $found -gt 0 ] ; then + if (( found )) ; then local expectedsum="${integrity_sums[$idx],,}" - local realsum="$(openssl dgst -${integ} "$file")" + local realsum="$(openssl dgst -"$integ" "$file")" realsum="${realsum##* }" - if [ "$expectedsum" = "$realsum" ]; then + if [[ $expectedsum = $realsum ]]; then echo "$(gettext "Passed")" >&2 else echo "$(gettext "FAILED")" >&2 @@ -591,18 +593,18 @@ check_checksums() { idx=$((idx + 1)) done - if [ $errors -gt 0 ]; then + if (( errors )); then error "$(gettext "One or more files did not pass the validity check!")" exit 1 # TODO: error code fi - elif [ ${#integrity_sums[@]} -gt 0 ]; then + elif (( ${#integrity_sums[@]} )); then error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ" exit 1 # TODO: error code fi done - if [ $correlation -eq 0 ]; then - if [ $SKIPINTEG -eq 1 ]; then + if (( ! correlation )); then + if (( SKIPINTEG )); then warning "$(gettext "Integrity checks are missing.")" else error "$(gettext "Integrity checks are missing.")" @@ -616,14 +618,14 @@ extract_sources() { local netfile for netfile in "${source[@]}"; do file=$(get_filename "$netfile") - if in_array "$file" ${noextract[@]}; then + if in_array "$file" "${noextract[@]}"; then #skip source files in the noextract=() array # these are marked explicitly to NOT be extracted continue fi - if [ ! -f "$file" ] ; then - if [ ! -f "$SRCDEST/$file" ] ; then + if [[ ! -f $file ]] ; then + if [[ ! -f $SRCDEST/$file ]] ; then error "$(gettext "Unable to find source file %s for extraction.")" "$file" plain "$(gettext "Aborting...")" exit 1 @@ -634,7 +636,7 @@ extract_sources() { # fix flyspray #6246 local file_type=$(file -bizL "$file") - local ext=${file##*.} + local ext="${file##*.}" local cmd='' case "$file_type" in *application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*) @@ -662,31 +664,31 @@ extract_sources() { local ret=0 msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd" - if [ "$cmd" = "bsdtar" ]; then + if [[ $cmd = "bsdtar" ]]; then $cmd -xf "$file" || ret=? else rm -f "${file%.*}" $cmd -dcf "$file" > "${file%.*}" || ret=? fi - if [ $ret -ne 0 ]; then + if (( ret )); then error "$(gettext "Failed to extract %s")" "$file" plain "$(gettext "Aborting...")" exit 1 fi done - if [ $EUID -eq 0 ]; then + if (( EUID == 0 )); then # change perms of all source files to root user & root group chown -R 0:0 "$srcdir" fi } error_function() { - if [ -p "$logpipe" ]; then + if [[ -p $logpipe ]]; then rm "$logpipe" fi # first exit all subshells, then print the error - if [ $BASH_SUBSHELL -eq 0 ]; then + if (( ! BASH_SUBSHELL )); then plain "$(gettext "Aborting...")" remove_deps fi @@ -694,13 +696,13 @@ error_function() { } run_function() { - if [ -z "$1" ]; then + if [[ ! $1 ]]; then return 1 fi pkgfunc="$1" # clear user-specified makeflags if requested - if [ "$(check_option makeflags)" = "n" ]; then + if [[ $(check_option makeflags) = n ]]; then MAKEFLAGS="" fi @@ -710,15 +712,15 @@ run_function() { # ensure all necessary build variables are exported export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST # save our shell options so pkgfunc() can't override what we need - local shellopts=$(shopt -p) + local shellopts="$(shopt -p)" local ret=0 - if [ "$LOGGING" -eq 1 ]; then + if (( LOGGING )); then BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-$pkgfunc.log" - if [ -f "$BUILDLOG" ]; then + if [[ -f $BUILDLOG ]]; then local i=1 while true; do - if [ -f "$BUILDLOG.$i" ]; then + if [[ -f $BUILDLOG.$i ]]; then i=$(($i +1)) else break @@ -735,16 +737,16 @@ run_function() { exec 1>"$logpipe" 2>"$logpipe" restoretrap=$(trap -p ERR) trap 'error_function' ERR - $pkgfunc 2>&1 - eval $restoretrap + "$pkgfunc" 2>&1 + eval "$restoretrap" sync exec 1>&3 2>&3 3>&- rm "$logpipe" else - restoretrap=$(trap -p ERR) + restoretrap="$(trap -p ERR)" trap 'error_function' ERR - $pkgfunc 2>&1 - eval $restoretrap + "$pkgfunc" 2>&1 + eval "$restoretrap" fi # reset our shell options eval "$shellopts" @@ -752,24 +754,24 @@ run_function() { run_build() { # use distcc if it is requested (check buildenv and PKGBUILD opts) - if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then - [ -d /usr/lib/distcc/bin ] && export PATH="/usr/lib/distcc/bin:$PATH" + 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 + 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) - if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then - [ -d /usr/lib/ccache/bin ] && export PATH="/usr/lib/ccache/bin:$PATH" + if [[ $(check_buildenv ccache) = "y" && $(check_option ccache) != "n" ]]; then + [[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH" fi run_function "build" } run_package() { - if [ -z "$1" ]; then + if [[ ! $1 ]]; then pkgfunc="package" else pkgfunc="package_$1" @@ -782,35 +784,35 @@ tidy_install() { cd "$pkgdir" 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...")" - rm -rf ${DOC_DIRS[@]} + rm -rf "${DOC_DIRS[@]}" 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...")" local pt for pt in "${PURGE_TARGETS[@]}"; do - if [ "${pt}" = "${pt//\/}" ]; then + if [[ ${pt} = ${pt//\/} ]]; then find . -type f -name "${pt}" -exec rm -f -- '{}' \; else - rm -f ${pt} + rm -f "$pt" fi done 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...")" 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 # check file still exists (potentially compressed with hard link) - if [ -f ${manpage} ]; then + if [[ -f $manpage ]]; then ext="${manpage##*.}" file="${manpage##*/}" - if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then + if [[ $ext != gz && $ext != bz2 ]]; then # 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 rm -f "$link" ln -sf "${file}.gz" "${link}.gz" @@ -819,25 +821,25 @@ tidy_install() { # 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 ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true - for hl in ${hardlinks}; do - rm -f "${hl}"; + for hl in "$hardlinks"; do + rm -f "$hl"; done # compress the original gzip -9 "$manpage" # recreate hard links removed earlier - for hl in ${hardlinks}; do + for hl in "$hardlinks"; do ln "${manpage}.gz" "${hl}.gz" - chmod 644 ${hl}.gz + chmod 644 "${hl}.gz" done fi fi done 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...")" 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 case "$(file -biz "$binary")" in *compressed-encoding*) # Skip compressed binaries ;; @@ -851,12 +853,12 @@ tidy_install() { done fi - if [ "$(check_option libtool)" = "n" ]; then + if [[ $(check_option libtool) = n ]]; then msg2 "$(gettext "Removing libtool .la files...")" find . ! -type d -name "*.la" -exec rm -f -- '{}' \; fi - if [ "$(check_option emptydirs)" = "n" ]; then + if [[ $(check_option emptydirs) = n ]]; then msg2 "$(gettext "Removing empty directories...")" find . -depth -type d -empty -delete fi @@ -864,7 +866,7 @@ tidy_install() { write_pkginfo() { local builddate=$(date -u "+%s") - if [ -n "$PACKAGER" ]; then + if [[ -n $PACKAGER ]]; then local packager="$PACKAGER" else local packager="Unknown Packager" @@ -874,12 +876,12 @@ write_pkginfo() { msg2 "$(gettext "Generating .PKGINFO file...")" echo "# Generated by makepkg $myver" >.PKGINFO - if [ "$INFAKEROOT" -eq 1 ]; then + if (( INFAKEROOT )); then echo "# using $(fakeroot -v)" >>.PKGINFO fi echo "# $(LC_ALL=C date -u)" >>.PKGINFO echo "pkgname = $1" >>.PKGINFO - [ "$SPLITPKG" -eq 1 ] && echo "pkgbase = $pkgbase" >>.PKGINFO + (( SPLITPKG )) && echo pkgbase = $pkgbase >>.PKGINFO echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO echo "pkgdesc = $pkgdesc" >>.PKGINFO echo "url = $url" >>.PKGINFO @@ -887,7 +889,7 @@ write_pkginfo() { echo "packager = $packager" >>.PKGINFO echo "size = $size" >>.PKGINFO echo "arch = $PKGARCH" >>.PKGINFO - if [ "$(check_option force)" = "y" ]; then + if [[ $(check_option force) = y ]]; then echo "force = true" >> .PKGINFO fi @@ -918,8 +920,8 @@ write_pkginfo() { done for it in "${packaging_options[@]}"; do local ret="$(check_option $it)" - if [ "$ret" != "?" ]; then - if [ "$ret" = "y" ]; then + if [[ $ret != ? ]]; then + if [[ $ret = y ]]; then echo "makepkgopt = $it" >>.PKGINFO else echo "makepkgopt = !$it" >>.PKGINFO @@ -929,7 +931,7 @@ write_pkginfo() { # TODO maybe remove this at some point # 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" plain "$(gettext "Example for GPL\'ed software: license=('GPL').")" fi @@ -941,14 +943,14 @@ check_package() { # check existence of backup files local file for file in "${backup[@]}"; do - if [ ! -f "$file" ]; then + if [[ ! -f $file ]]; then warning "$(gettext "Invalid backup entry : %s")" "$file" fi done } create_package() { - if [ ! -d "$pkgdir" ]; then + if [[ ! -d $pkgdir ]]; then error "$(gettext "Missing pkg/ directory.")" plain "$(gettext "Aborting...")" exit 1 # $E_MISSING_PKGDIR @@ -959,16 +961,16 @@ create_package() { cd "$pkgdir" msg "$(gettext "Creating package...")" - if [ -z "$1" ]; then + if [[ -z $1 ]]; then nameofpkg="$pkgname" else nameofpkg="$1" fi - if [ "$arch" = "any" ]; then + if [[ $arch = "any" ]]; then PKGARCH="any" else - PKGARCH=$CARCH + PKGARCH="$CARCH" fi write_pkginfo $nameofpkg @@ -976,14 +978,14 @@ create_package() { local comp_files=".PKGINFO" # check for an install script - if [ -n "$install" ]; then + if [[ -n $install ]]; then msg2 "$(gettext "Adding install script...")" cp "$startdir/$install" .INSTALL comp_files="$comp_files .INSTALL" fi # do we have a changelog? - if [ -n "$changelog" ]; then + if [[ -n $changelog ]]; then msg2 "$(gettext "Adding package changelog...")" cp "$startdir/$changelog" .CHANGELOG comp_files="$comp_files .CHANGELOG" @@ -1009,7 +1011,7 @@ create_package() { bsdtar -cf - $comp_files * > "$pkg_file" || ret=$? shopt -u nullglob - if [ $ret -eq 0 ]; then + if (( ! ret )); then case "$PKGEXT" in *tar.gz) gzip -f -n "$pkg_file" ;; *tar.bz2) bzip2 -f "$pkg_file" ;; @@ -1018,7 +1020,7 @@ create_package() { ret=$? fi - if [ $ret -ne 0 ]; then + if (( ret )); then error "$(gettext "Failed to create package file.")" exit 1 # TODO: error code fi @@ -1042,8 +1044,8 @@ create_srcpackage() { msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT" ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}" - if [ -n "$install" ]; then - if [ -f $install ]; then + if [[ -n $install ]]; then + if [[ -f $install ]]; then msg2 "$(gettext "Adding install script...")" ln -s "${startdir}/$install" "${srclinks}/${pkgbase}/" else @@ -1051,8 +1053,8 @@ create_srcpackage() { fi fi - if [ -n "$changelog" ]; then - if [ -f "$changelog" ]; then + if [[ -n $changelog ]]; then + if [[ -f $changelog ]]; then msg2 "$(gettext "Adding package changelog...")" ln -s "${startdir}/$changelog" "${srclinks}/${pkgbase}/" else @@ -1086,7 +1088,7 @@ create_srcpackage() { # tar it up msg2 "$(gettext "Compressing source package...")" cd "${srclinks}" - if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgbase}; then + if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" "${pkgbase}"; then error "$(gettext "Failed to create source package file.")" exit 1 # TODO: error code fi @@ -1095,17 +1097,17 @@ create_srcpackage() { } install_package() { - [ "$INSTALL" -eq 0 ] && return + (( ! INSTALL )) && return - if [ "$SPLITPKG" -eq 0 ]; then + if (( ! SPLITPKG )); then msg "$(gettext "Installing package ${pkgname} with pacman -U...")" else msg "$(gettext "Installing ${pkgbase} package group with pacman -U...")" fi local pkglist - for pkg in ${pkgname[@]}; do - if [ -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} ]; then + for pkg in "${pkgname[@]}"; do + if [[ -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} ]]; then pkglist="${pkglist} $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" else pkglist="${pkglist} $PKGDEST/${pkg}-${pkgver}-${pkgrel}-any${PKGEXT}" @@ -1113,13 +1115,13 @@ install_package() { done local ret=0 - if [ "$ASROOT" -eq 0 ]; then + if (( ! ASROOT )); then sudo pacman $PACMAN_OPTS -U ${pkglist} || ret=$? else - pacman $PACMAN_OPTS -U ${pkglist} || ret=$? + pacman "$PACMAN_OPTS" -U "$pkglist" || ret=$? fi - if [ $ret -ne 0 ]; then + if (( ret )); then warning "$(gettext "Failed to install built package(s).")" return 0 fi @@ -1127,45 +1129,44 @@ install_package() { check_sanity() { # check for no-no's in the build script - if [ -z "$pkgname" ]; then + if [[ -z $pkgname ]]; then error "$(gettext "%s is not allowed to be empty.")" "pkgname" return 1 fi - if [ -z "$pkgver" ]; then + if [[ -z $pkgver ]]; then error "$(gettext "%s is not allowed to be empty.")" "pkgver" return 1 fi - if [ -z "$pkgrel" ]; then + if [[ -z $pkgrel ]]; then error "$(gettext "%s is not allowed to be empty.")" "pkgrel" return 1 fi - if [ "${pkgname:0:1}" == "-" ]; then + if [[ ${pkgname:0:1} = "-" ]]; then error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname" return 1 fi - if [ "$pkgver" != "${pkgver//-/}" ]; then + if [[ $pkgver != ${pkgver//-/} ]]; then error "$(gettext "%s is not allowed to contain hyphens.")" "pkgver" return 1 fi - if [ "$pkgrel" != "${pkgrel//-/}" ]; then + if [[ $pkgrel != ${pkgrel//-/} ]]; then error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel" return 1 fi - if [ "$arch" != 'any' ]; then - if ! in_array $CARCH ${arch[@]}; then - if [ "$IGNOREARCH" -eq 0 ]; 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" - return 1 - fi + 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" + return 1 fi fi local provide - for provide in ${provides[@]}; do - if [ $provide != ${provide///} ]; then + for provide in "${provides[@]}"; do + if [[ $provide != ${provide///} ]]; then error "$(gettext "Provides array cannot contain comparison (< or >) operators.")" return 1 fi @@ -1173,7 +1174,7 @@ check_sanity() { local file for file in "${backup[@]}"; do - if [ "${file:0:1}" = "/" ]; then + if [[ ${file:0:1} = "/" ]]; then error "$(gettext "Invalid backup entry : %s")" "$file" return 1 fi @@ -1181,44 +1182,44 @@ check_sanity() { local optdepend for optdepend in "${optdepends[@]}"; do - pkg=${optdepend%%:*} + pkg="${optdepend%%:*}" if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]*$ ]]; then error "$(gettext "Invalid syntax for optdepend : '%s'")" "$optdepend" fi done - if [ "$install" -a ! -f "$install" ]; then + if [[ -n $install && ! -f $install ]]; then error "$(gettext "Install scriptlet (%s) does not exist.")" "$install" return 1 fi - if [ -n "$changelog" -a ! -f "$changelog" ]; then + if [[ -n $changelog && ! -f $changelog ]]; then error "$(gettext "Changelog file (%s) does not exist.")" "$changelog" return 1 fi local valid_options=1 local opt known kopt - for opt in ${options[@]}; do + for opt in "${options[@]}"; do known=0 # check if option matches a known option or its inverse - for kopt in ${packaging_options[@]} ${other_options[@]}; do - if [ "${opt}" = "${kopt}" -o "${opt}" = "!${kopt}" ]; then + for kopt in "${packaging_options[@]}" "${other_options[@]}"; do + if [[ ${opt} = ${kopt} || ${opt} = !${kopt} ]]; then known=1 fi done - if [ $known -eq 0 ]; then + if (( ! known )); then error "$(gettext "options array contains unknown option '%s'")" "$opt" valid_options=0 fi done - if [ $valid_options -eq 0 ]; then + if (( ! valid_options )); then return 1 fi - if [ "${#pkgname[@]}" -gt "1" ]; then - for pkg in ${pkgname[@]}; do - if [ "$(type -t package_${pkg})" != "function" ]; then + if (( ${#pkgname[@]} > 1 )); then + for pkg in "${pkgname[@]}"; do + if [[ $(type -t package_${pkg}) != function ]]; then error "$(gettext "missing package function for split package '%s'")" "$pkg" return 1 fi @@ -1233,42 +1234,42 @@ devel_check() { # Do not update pkgver if --holdver is set, when building a source package, # when reading PKGBUILD from pipe (-f), or if we cannot write to the file (-w) - if [ "$HOLDVER" -eq 1 -o "$SOURCEONLY" -ne 0 -o ! -f "$BUILDFILE" \ - -o ! -w "$BUILDFILE" ]; then + if (( HOLDVER || SOURCEONLY )) || \ + [[ ! -f $BUILDFILE || ! -w $BUILDFILE ]]; then return fi - if [ -z "$FORCE_VER" ]; then + if [[ -z $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 # 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. oldpkgver=$pkgver - if [ -n "${_darcstrunk}" -a -n "${_darcsmod}" ] ; then - [ $(type -p darcs) ] || return 0 + if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then + type -p darcs >/dev/null || return 0 msg "$(gettext "Determining latest darcs revision...")" newpkgver=$(date +%Y%m%d) - elif [ -n "${_cvsroot}" -a -n "${_cvsmod}" ] ; then - [ $(type -p cvs) ] || return 0 + elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then + type -p cvs >/dev/null || return 0 msg "$(gettext "Determining latest cvs revision...")" newpkgver=$(date +%Y%m%d) - elif [ -n "${_gitroot}" -a -n "${_gitname}" ] ; then - [ $(type -p git) ] || return 0 + elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then + type -p git >/dev/null || return 0 msg "$(gettext "Determining latest git revision...")" newpkgver=$(date +%Y%m%d) - elif [ -n "${_svntrunk}" -a -n "${_svnmod}" ] ; then - [ $(type -p svn) ] || return 0 + elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then + type -p svn >/dev/null || return 0 msg "$(gettext "Determining latest svn revision...")" newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p') - elif [ -n "${_bzrtrunk}" -a -n "${_bzrmod}" ] ; then - [ $(type -p bzr) ] || return 0 + elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then + type -p bzr >/dev/null || return 0 msg "$(gettext "Determining latest bzr revision...")" - newpkgver=$(bzr revno ${_bzrtrunk}) - elif [ -n "${_hgroot}" -a -n "${_hgrepo}" ] ; then - [ $(type -p hg) ] || return 0 + newpkgver=$(bzr revno "${_bzrtrunk}") + elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then + type -p hg >/dev/null || return 0 msg "$(gettext "Determining latest hg revision...")" - if [ -d ./src/$_hgrepo ] ; then + if [[ -d ./src/$_hgrepo ]] ; then cd ./src/$_hgrepo hg pull hg update @@ -1281,13 +1282,13 @@ devel_check() { cd ../../ fi - if [ -n "$newpkgver" ]; then + if [[ -n $newpkgver ]]; then msg2 "$(gettext "Version found: %s")" "$newpkgver" fi else # Version number retrieved from fakeroot->makepkg argument - newpkgver=$FORCE_VER + newpkgver="$FORCE_VER" fi } @@ -1301,9 +1302,9 @@ devel_update() { # ... # _foo=pkgver # - if [ -n "$newpkgver" ]; then - if [ "$newpkgver" != "$pkgver" ]; then - if [ -f "$BUILDFILE" -a -w "$BUILDFILE" ]; then + if [[ -n $newpkgver ]]; then + if [[ $newpkgver != $pkgver ]]; then + if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then @SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE" @SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE" source "$BUILDFILE" @@ -1313,16 +1314,16 @@ devel_update() { } backup_package_variables() { - for var in ${splitpkg_overrides[@]}; do + for var in "${splitpkg_overrides[@]}"; do indirect="${var}_backup" - eval "${indirect}=(\${$var[@]})" + eval "${indirect}=(\"\${$var[@]}\")" done } restore_package_variables() { - for var in ${splitpkg_overrides[@]}; do + for var in "${splitpkg_overrides[@]}"; do indirect="${var}_backup" - if [ -n "${!indirect}" ]; then + if [[ -n ${!indirect} ]]; then eval "${var}=(\${$indirect[@]})" else unset ${var} @@ -1332,31 +1333,31 @@ restore_package_variables() { # pkgdesc gets restored as an array - convert back to a string local pkgdesc_backup="${pkgdesc[@]}" unset pkgdesc - pkgdesc=${pkgdesc_backup} + pkgdesc="${pkgdesc_backup}" } # getopt like parser parse_options() { - local short_options=$1; shift; - local long_options=$1; shift; + local short_options="$1"; shift; + local long_options="$1"; shift; local ret=0; - local unused_options="" + local unused_options=() - while [ -n "$1" ]; do - if [ ${1:0:2} = '--' ]; then - if [ -n "${1:2}" ]; then + 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 + 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 + if [[ -n $match ]]; then + if [[ ${1:2} = $match ]]; then printf ' %s' "$1" else - if [ -n "$2" ]; then + if [[ -n $2 ]]; then printf ' %s' "$1" shift printf " '%s'" "$1" @@ -1373,15 +1374,15 @@ parse_options() { shift break fi - elif [ ${1:0:1} = '-' ]; then + 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 + if [[ -n ${1:$i+1} ]]; then printf ' -%s' "${1:i:1}" printf " '%s'" "${1:$i+1}" else - if [ -n "$2" ]; then + if [[ -n $2 ]]; then printf ' -%s' "${1:i:1}" shift printf " '%s'" "${1}" @@ -1400,20 +1401,18 @@ parse_options() { fi done else - unused_options="${unused_options} '$1'" + 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}" + for i in "${unused_options[@]}"; do + printf ' %s' "$i" + done + if [[ -n $1 ]]; then + while [[ -n $1 ]]; do + printf " '%s'" "$1" shift done fi @@ -1472,13 +1471,13 @@ There is NO WARRANTY, to the extent permitted by law.\n")" # PROGRAM START # determine whether we have gettext; make it a no-op if we do not -if [ ! $(type -t gettext) ]; then +if ! type -t gettext >/dev/null; then gettext() { echo "$@" } fi -ARGLIST=$@ +ARGLIST=("$@") # Parse Command Line Options. OPT_SHORT="AcCdefFghiLmop:rRsV" @@ -1538,14 +1537,14 @@ while true; do done #preserve environment variables -_PKGDEST=${PKGDEST} -_SRCDEST=${SRCDEST} +_PKGDEST="$PKGDEST" +_SRCDEST="$SRCDEST" # default config is makepkg.conf -MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf} +MAKEPKG_CONF="${MAKEPKG_CONF:-$confdir/makepkg.conf}" # Source the config file; fail if it is not found -if [ -r "$MAKEPKG_CONF" ]; then +if [[ -r $MAKEPKG_CONF ]]; then source "$MAKEPKG_CONF" else error "$(gettext "%s not found.")" "$MAKEPKG_CONF" @@ -1554,13 +1553,13 @@ else fi # Source user-specific makepkg.conf overrides -if [ -r ~/.makepkg.conf ]; then +if [[ -r ~/.makepkg.conf ]]; then source ~/.makepkg.conf fi # check if messages are to be printed using color unset ALL_OFF BOLD BLUE GREEN RED YELLOW -if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then +if [[ -t 2 && ! $USE_COLOR = "n" && $(check_buildenv color) = "y" ]]; then ALL_OFF="$(tput sgr0)" BOLD="$(tput bold)" BLUE="${BOLD}$(tput setaf 4)" @@ -1577,23 +1576,23 @@ SRCDEST=${_SRCDEST:-$SRCDEST} SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined -if [ "$HOLDVER" -eq 1 -a -n "$FORCE_VER" ]; then +if (( HOLDVER )) && [[ $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" )" exit 1 fi -if [ "$CLEANCACHE" -eq 1 ]; then +if (( CLEANCACHE )); then #fix flyspray feature request #5223 - if [ -n "$SRCDEST" -a "$SRCDEST" != "$startdir" ]; then + if [[ -n $SRCDEST && $SRCDEST != $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="${answer^^}" - if [ "$answer" = "$(gettext "YES")" -o "$answer" = "$(gettext "Y")" ]; then + if [[ $answer = $(gettext "YES") || $answer = $(gettext "Y") ]]; then rm "$SRCDEST"/* - if [ $? -ne 0 ]; then + if (( $? )); then error "$(gettext "Problem removing files; you may not have correct permissions in %s")" "$SRCDEST" exit 1 else @@ -1614,41 +1613,40 @@ if [ "$CLEANCACHE" -eq 1 ]; then fi fi -if [ "$INFAKEROOT" -eq 0 ]; then - if [ $EUID -eq 0 -a "$ASROOT" -eq 0 ]; then +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.")" exit 1 # $E_USER_ABORT - elif [ $EUID -gt 0 -a "$ASROOT" -eq 1 ]; then + 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.")" exit 1 # $E_USER_ABORT - elif [ "$(check_buildenv fakeroot)" = "y" -a $EUID -gt 0 ]; then - if [ ! $(type -p fakeroot) ]; then + 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 -gt 0 ]; then + 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" sleep 1 fi else - if [ -z "$FAKEROOTKEY" ]; then + if [[ -z $FAKEROOTKEY ]]; then error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")" exit 1 # TODO: error code fi fi # check for sudo if we will need it during makepkg execution -if [ "$ASROOT" -eq 0 \ - -a \( "$DEP_BIN" -eq 1 -o "$RMDEPS" -eq 1 -o "$INSTALL" -eq 1 \) ]; then - if [ ! "$(type -p sudo)" ]; then +if (( ! ASROOT )) && (( DEP_BIN || RMDEPS || INSTALL )); then + if ! type -p sudo >/dev/null; then error "$(gettext "Cannot find the sudo binary! Is sudo installed?")" plain "$(gettext "Missing dependencies cannot be installed or removed as a normal user")" plain "$(gettext "without sudo; install and configure sudo to auto-resolve dependencies.")" @@ -1660,9 +1658,9 @@ unset pkgname pkgbase pkgver pkgrel pkgdesc url license groups provides unset md5sums replaces depends conflicts backup source install changelog build unset makedepends optdepends options noextract -BUILDFILE=${BUILDFILE:-$BUILDSCRIPT} -if [ ! -f "$BUILDFILE" ]; then - if [ -t 0 ]; then +BUILDFILE="${BUILDFILE:-$BUILDSCRIPT}" +if [[ ! -f $BUILDFILE ]]; then + if [[ -t 0 ]]; then error "$(gettext "%s does not exist.")" "$BUILDFILE" exit 1 else @@ -1672,18 +1670,18 @@ if [ ! -f "$BUILDFILE" ]; then fi else crlftest=$(file "$BUILDFILE" | grep -F 'CRLF' || true) - if [ -n "$crlftest" ]; then + if [[ -n $crlftest ]]; then error "$(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDFILE" exit 1 fi - if [ "${BUILDFILE:0:1}" != "/" ]; then + if [[ ${BUILDFILE:0:1} != "/" ]]; then BUILDFILE="$startdir/$BUILDFILE" fi source "$BUILDFILE" fi -if [ "$GENINTEG" -eq 1 ]; then +if (( GENINTEG )); then mkdir -p "$srcdir" cd "$srcdir" download_sources @@ -1691,7 +1689,7 @@ if [ "$GENINTEG" -eq 1 ]; then exit 0 # $E_OK fi -if [ "$(type -t package)" = "function" ]; then +if [[ $(type -t package) = function ]]; then PKGFUNC=1 fi @@ -1705,17 +1703,17 @@ check_sanity || exit 1 devel_check devel_update -if [ "${#pkgname[@]}" -gt "1" ]; then +if (( ${#pkgname[@]} > 1 )); then SPLITPKG=1 fi -pkgbase=${pkgbase:-${pkgname[0]}} +pkgbase="${pkgbase:-${pkgname[0]}}" -if [ "$SPLITPKG" -eq 0 ]; then - if [ \( -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \ - -o -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-any${PKGEXT}" \) \ - -a "$FORCE" -eq 0 -a "$SOURCEONLY" -eq 0 -a "$NOBUILD" -eq 0 ]; then - if [ "$INSTALL" -eq 1 ]; then +if (( ! $SPLITPKG )); then + if [[ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \ + || -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-any${PKGEXT}" ]] \ + && (( ! FORCE && ! SOURCEONLY && ! NOBUILD )); then + if (( INSTALL )); then warning "$(gettext "A package has already been built, installing existing package...")" install_package exit $? @@ -1727,17 +1725,17 @@ if [ "$SPLITPKG" -eq 0 ]; then else allpkgbuilt=1 somepkgbuilt=0 - for pkg in ${pkgname[@]}; do - if [ \( -f "$PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \ - -o -f "$PKGDEST/${pkg}-${pkgver}-${pkgrel}-any${PKGEXT}" \) ]; then + for pkg in "${pkgname[@]}"; do + if [[ -f "$PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \ + || -f "$PKGDEST/${pkg}-${pkgver}-${pkgrel}-any${PKGEXT}" ]]; then somepkgbuilt=1 else allpkgbuilt=0 fi done - if [ "$FORCE" -eq 0 -a "$SOURCEONLY" -eq 0 -a "$NOBUILD" -eq 0 ]; then - if [ "$allpkgbuilt" -eq 1 ]; then - if [ "$INSTALL" -eq 1 ]; then + if (( FORCE == 0 && ! SOURCEONLY && ! NOBUILD )); then + if (( allpkgbuilt )); then + if (( INSTALL )); then warning "$(gettext "The package group has already been built, installing existing packages...")" install_package exit $? @@ -1746,7 +1744,7 @@ else exit 1 fi fi - if [ "$somepkgbuilt" -eq 1 ]; then + if (( somepkgbuilt )); then error "$(gettext "Part of the package group has already been built. (use -f to overwrite)")" exit 1 fi @@ -1755,10 +1753,10 @@ else fi # Run the bare minimum in fakeroot -if [ "$INFAKEROOT" -eq 1 ]; then - if [ "$SPLITPKG" -eq 0 ]; then - if [ "$PKGFUNC" -eq 0 ]; then - if [ "$REPKG" -eq 0 ]; then +if (( INFAKEROOT )); then + if (( ! SPLITPKG )); then + if (( ! PKGFUNC )); then + if (( ! REPKG )); then run_build tidy_install fi @@ -1768,13 +1766,13 @@ if [ "$INFAKEROOT" -eq 1 ]; then fi create_package else - for pkg in ${pkgname[@]}; do + for pkg in "${pkgname[@]}"; do pkgdir="$pkgdir/$pkg" mkdir -p "$pkgdir" backup_package_variables - run_package $pkg + run_package "$pkg" tidy_install - create_package $pkg + create_package "$pkg" restore_package_variables pkgdir="${pkgdir%/*}" done @@ -1787,9 +1785,9 @@ fi msg "$(gettext "Making package: %s")" "$pkgbase $pkgver-$pkgrel ($(date))" # if we are creating a source-only package, go no further -if [ "$SOURCEONLY" -ne 0 ]; then - if [ -f "$PKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}" \ - -a "$FORCE" -eq 0 ]; then +if (( SOURCEONLY )); then + if [[ -f "$PKGDEST/${pkgbase}-${pkgver}-${pkgrel}${SRCEXT}" ]] \ + && (( ! FORCE )); then error "$(gettext "A package has already been built. (use -f to overwrite)")" exit 1 fi @@ -1799,22 +1797,22 @@ if [ "$SOURCEONLY" -ne 0 ]; then fi # fix flyspray bug #5973 -if [ "$NODEPS" -eq 1 -o "$NOBUILD" -eq 1 -o "$REPKG" -eq 1 ]; then +if (( NODEPS || NOBUILD || REPKG )); then # no warning message needed for nobuild, repkg - if [ "$NODEPS" -eq 1 ]; then + if (( NODEPS )); then warning "$(gettext "Skipping dependency checks.")" fi -elif [ $(type -p pacman) ]; then +elif type -p pacman >/dev/null ; then unset pkgdeps # Set by resolve_deps() and used by remove_deps() deperr=0 msg "$(gettext "Checking Runtime Dependencies...")" - resolve_deps ${depends[@]} || deperr=1 + resolve_deps "${depends[@]}" || deperr=1 msg "$(gettext "Checking Buildtime Dependencies...")" - resolve_deps ${makedepends[@]} || deperr=1 + resolve_deps "${makedepends[@]}" || deperr=1 - if [ $deperr -eq 1 ]; then + if (( deperr )); then error "$(gettext "Could not resolve all dependencies.")" exit 1 fi @@ -1829,19 +1827,19 @@ umask 0022 mkdir -p "$srcdir" cd "$srcdir" -if [ "$NOEXTRACT" -eq 1 ]; then +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")" - if [ "$NOEXTRACT" -eq 1 -a -z "$(ls "$srcdir" 2>/dev/null)" ]; then + if (( NOEXTRACT )) && [[ -z $(ls $srcdir 2>/dev/null) ]]; then error "$(gettext "The source directory is empty, there is nothing to build!")" plain "$(gettext "Aborting...")" exit 1 fi -elif [ "$REPKG" -eq 1 ]; then - if [ "$PKGFUNC" -eq 0 -a "$SPLITPKG" -eq 0 \ - -a \( ! -d "$pkgdir" -o -z "$(ls "$pkgdir" 2>/dev/null)" \) ]; then +elif (( REPKG )); then + if (( ! PKGFUNC && ! SPLITPKG )) \ + && [[ ! -d $pkgdir || -z $(ls "$pkgdir" 2>/dev/null) ]]; then error "$(gettext "The package directory is empty, there is nothing to repackage!")" plain "$(gettext "Aborting...")" exit 1 @@ -1852,13 +1850,13 @@ else extract_sources fi -if [ "$NOBUILD" -eq 1 ]; then +if (( NOBUILD )); then msg "$(gettext "Sources are ready.")" exit 0 #E_OK else # check for existing pkg directory; don't remove if we are repackaging - if [ -d "$pkgdir" \ - -a \( "$REPKG" -eq 0 -o "$PKGFUNC" -eq 1 -o "$SPLITPKG" -eq 1 \) ]; then + if [[ -d $pkgdir ]] \ + && (( ! REPKG || PKGFUNC || SPLITPKG )); then msg "$(gettext "Removing existing pkg/ directory...")" rm -rf "$pkgdir" fi @@ -1866,33 +1864,33 @@ else 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 [ "$REPKG" -eq 0 ]; then + if [[ $(check_buildenv fakeroot) != "y" ]] || (( EUID == 0 )); then + if (( ! REPKG )); then devel_update run_build fi - if [ "$SPLITPKG" -eq 0 ]; then - if [ "$PKGFUNC" -eq 1 ]; then + if (( ! SPLITPKG )); then + if (( PKGFUNC )); then run_package tidy_install - elif [ "$REPKG" -eq 0 ]; then + elif (( ! REPKG )); then tidy_install fi create_package else - for pkg in ${pkgname[@]}; do + for pkg in "${pkgname[@]}"; do pkgdir="$pkgdir/$pkg" mkdir -p "$pkgdir" backup_package_variables - run_package $pkg + run_package "$pkg" tidy_install - create_package $pkg + create_package "$pkg" restore_package_variables pkgdir="${pkgdir%/*}" done fi else - if [ "$REPKG" -eq 0 -a \( "$PKGFUNC" -eq 1 -o "$SPLITPKG" -eq 1 \) ]; then + if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then devel_update run_build cd "$startdir" @@ -1900,10 +1898,10 @@ else msg "$(gettext "Entering fakeroot environment...")" - if [ -n "$newpkgver" ]; then - fakeroot -- $0 --forcever $newpkgver -F $ARGLIST || exit $? + if [[ -n $newpkgver ]]; then + fakeroot -- "$0" --forcever "$newpkgver" -F "${ARGLIST[@]}" || exit $? else - fakeroot -- $0 -F $ARGLIST || exit $? + fakeroot -- "$0" -F "${ARGLIST[@]}" || exit $? fi fi fi