>From e3e5bb93cb2b33315a8d6eff8956aa5b6c74d28d Mon Sep 17 00:00:00 2001
From: Isaac Good <pacman@isaac.otherinbox.com>
Date: Thu, 12 Nov 2009 15:09:05 -0500
Subject: [PATCH 2/2] Changing [ to [[ and (( - Part Two - Amended
Second half of makepkg
This replaces any prior patches of mine
Includes stuff like -o to || and -a to && etc
if [ $(type .. were preserved due to a bash bug with [[ and set -e and ERR trap
Signed-off-by: Isaac Good <pacman@isaac.otherinbox.com>
---
scripts/makepkg.sh.in | 216 ++++++++++++++++++++++++-------------------------
1 files changed, 107 insertions(+), 109 deletions(-)
- 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...")"
@@ -1105,7 +1105,7 @@ install_package() {
local pkglist
for pkg in ${pkgname[@]}; do
- if [ -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} ]; then
+ 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 +1113,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=$?
fi
- if [ $ret -ne 0 ]; then
+ if (( ret )); then
warning "$(gettext "Failed to install built package(s).")"
return 0
fi
@@ -1127,34 +1127,34 @@ 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 [[ $arch != 'any' ]]; then
if ! in_array $CARCH ${arch[@]}; then
- if [ "$IGNOREARCH" -eq 0 ]; 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"
@@ -1165,7 +1165,7 @@ check_sanity() {
local provide
for provide in ${provides[@]}; do
- if [ $provide != ${provide//</} -o $provide != ${provide//>/} ]; then
+ if [[ $provide != ${provide//</} || $provide != ${provide//>/} ]]; then
error "$(gettext "Provides array cannot contain comparison (< or >) operators.")"
return 1
fi
@@ -1173,7 +1173,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
@@ -1187,12 +1187,12 @@ check_sanity() {
fi
done
- if [ "$install" -a ! -f "$install" ]; then
+ if [[ $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
@@ -1203,20 +1203,20 @@ check_sanity() {
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
+ 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
+ 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"
@@ -1233,42 +1233,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
+ if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
[ $(type -p darcs) ] || return 0
msg "$(gettext "Determining latest darcs revision...")"
newpkgver=$(date +%Y%m%d)
- elif [ -n "${_cvsroot}" -a -n "${_cvsmod}" ] ; then
+ elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
[ $(type -p cvs) ] || return 0
msg "$(gettext "Determining latest cvs revision...")"
newpkgver=$(date +%Y%m%d)
- elif [ -n "${_gitroot}" -a -n "${_gitname}" ] ; then
+ elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
[ $(type -p git) ] || return 0
msg "$(gettext "Determining latest git revision...")"
newpkgver=$(date +%Y%m%d)
- elif [ -n "${_svntrunk}" -a -n "${_svnmod}" ] ; then
+ elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
[ $(type -p svn) ] || 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
+ elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
[ $(type -p bzr) ] || return 0
msg "$(gettext "Determining latest bzr revision...")"
newpkgver=$(bzr revno ${_bzrtrunk})
- elif [ -n "${_hgroot}" -a -n "${_hgrepo}" ] ; then
+ elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
[ $(type -p hg) ] || 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,7 +1281,7 @@ devel_check() {
cd ../../
fi
- if [ -n "$newpkgver" ]; then
+ if [[ -n $newpkgver ]]; then
msg2 "$(gettext "Version found: %s")" "$newpkgver"
fi
@@ -1301,9 +1301,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"
@@ -1322,7 +1322,7 @@ backup_package_variables() {
restore_package_variables() {
for var in ${splitpkg_overrides[@]}; do
indirect="${var}_backup"
- if [ -n "${!indirect}" ]; then
+ if [[ -n ${!indirect} ]]; then
eval "${var}=("${$indirect[@]}")"
else
unset ${var}
@@ -1337,21 +1337,21 @@ parse_options() {
local ret=0;
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
+ 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"
@@ -1368,15 +1368,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 [[ $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
+ if [[ -n $2 ]]; then
printf ' -%s' "${1:i:1}"
shift
printf " '%s'" "${1}"
@@ -1401,13 +1401,13 @@ parse_options() {
done
printf " --"
- if [ -n "$unused_options" ]; then
+ if [[ -n $unused_options ]]; then
for i in ${unused_options[@]}; do
printf ' %s' "$i"
done
fi
- if [ -n "$1" ]; then
- while [ -n "$1" ]; do
+ if [[ -n $1 ]]; then
+ while [[ -n $1 ]]; do
printf " '%s'" "${1}"
shift
done
@@ -1540,7 +1540,7 @@ _SRCDEST=${SRCDEST}
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"
@@ -1549,13 +1549,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)"
@@ -1572,23 +1572,23 @@ SRCDEST=${_SRCDEST:-$SRCDEST}
SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
-if [ "$HOLDVER" -eq 1 -a -n "$FORCE_VER" ]; then
+if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
# The ' ' is here to prevent gettext from thinking --holdver is an option
error "$(gettext "