From 5d5070f47d6542a530c8cbe954bb331389b7393f Mon Sep 17 00:00:00 2001 From: Cedric Staniewski Date: Thu, 5 Nov 2009 16:55:48 +0100 Subject: scripts: replace test builtin [ with shell keywords [[ and (( FS#16623 suggested this change for makepkg; this patch applies it to the remaining files in the scripts directory. Signed-off-by: Cedric Staniewski Signed-off-by: Dan McGee --- scripts/pacman-optimize.sh.in | 22 ++++++------- scripts/pkgdelta.sh.in | 22 ++++++------- scripts/rankmirrors.sh.in | 12 +++---- scripts/repo-add.sh.in | 74 +++++++++++++++++++++---------------------- 4 files changed, 65 insertions(+), 65 deletions(-) diff --git a/scripts/pacman-optimize.sh.in b/scripts/pacman-optimize.sh.in index e43e946d..d9f1ca2e 100644 --- a/scripts/pacman-optimize.sh.in +++ b/scripts/pacman-optimize.sh.in @@ -74,23 +74,23 @@ die_r() { # PROGRAM START # determine whether we have gettext; make it a no-op if we do not -if [ ! $(type -t gettext) ]; then +if ! type gettext &>/dev/null; then gettext() { echo "$@" } fi -if [ "$1" = "-h" -o "$1" = "--help" ]; then +if [[ $1 = "-h" || $1 = "--help" ]]; then usage exit 0 fi -if [ "$1" = "-V" -o "$1" = "--version" ]; then +if [[ $1 = "-V" || $1 = "--version" ]]; then version exit 0 fi -if [ "$1" != "" ]; then +if [[ -n $1 ]]; then dbroot="$1" fi @@ -99,11 +99,11 @@ if ! type diff >/dev/null 2>&1; then die "$(gettext "diff tool was not found, please install diffutils.")" fi -if [ ! -d "$dbroot" ]; then +if [[ ! -d $dbroot ]]; then die "$(gettext "%s does not exist or is not a directory.")" "$dbroot" fi -if [ ! -w "$dbroot" ]; then +if [[ ! -w $dbroot ]]; then die "$(gettext "You must have correct permissions to optimize the database.")" fi @@ -113,7 +113,7 @@ dbroot="${dbroot%/}" lockfile="${dbroot}/db.lck" # make sure pacman isn't running -if [ -f "$lockfile" ]; then +if [[ -f $lockfile ]]; then die "$(gettext "Pacman lock file was found. Cannot run while pacman is running.")" fi # do not let pacman run while we do this @@ -130,7 +130,7 @@ find "$dbroot" -type f | sort | xargs md5sum > "$workdir/pacsums.old" msg "$(gettext "Tar'ing up %s...")" "$dbroot" cd "$dbroot" bsdtar -czf "$workdir/pacman-db.tar.gz" ./ -if [ $? -ne 0 ]; then +if (( $? )); then rm -rf "$workdir" die_r "$(gettext "Tar'ing up %s failed.")" "$dbroot" fi @@ -139,7 +139,7 @@ fi msg "$(gettext "Making and MD5sum'ing the new database...")" mkdir "$dbroot.new" bsdtar -xpf "$workdir/pacman-db.tar.gz" -C "$dbroot.new" -if [ $? -ne 0 ]; then +if (( $? )); then rm -rf "$workdir" die_r "$(gettext "Untar'ing %s failed.")" "$dbroot" fi @@ -152,7 +152,7 @@ find "$dbroot.new" -type f | sort | \ # step 4: compare the sums msg "$(gettext "Checking integrity...")" diff "$workdir/pacsums.old" "$workdir/pacsums.new" >/dev/null 2>&1 -if [ $? -ne 0 ]; then +if (( $? )); then # failed # leave our pacman-optimize tmpdir for checking to see what doesn't match up rm -rf "$dbroot.new" @@ -167,7 +167,7 @@ mv "$dbroot" "$dbroot.old" || fail=1 mv "$dbroot.new" "$dbroot" || fail=1 chmod --reference="$dbroot.old" "$dbroot" || fail=1 chown --reference="$dbroot.old" "$dbroot" || fail=1 -if [ $fail -ne 0 ]; then +if (( fail )); then # failure with our directory shuffle die_r "$(gettext "New database substitution failed. Check for $dbroot,\n$dbroot.old, and $dbroot.new directories.")" fi diff --git a/scripts/pkgdelta.sh.in b/scripts/pkgdelta.sh.in index 588dc49d..1550fa10 100644 --- a/scripts/pkgdelta.sh.in +++ b/scripts/pkgdelta.sh.in @@ -35,7 +35,7 @@ QUIET=0 umask 0022 msg() { - [ $QUIET -ne 0 ] && return + (( QUIET )) && return local mesg=$1; shift printf "==> ${mesg}\n" "$@" >&1 } @@ -79,7 +79,7 @@ read_pkginfo() for line in $(bsdtar -xOf "$1" .PKGINFO 2>/dev/null | grep -v "^#" | sed 's|\(\w*\)\s*=\s*\(.*\)|\1="\2"|'); do eval "$line" - if [ -n "$pkgname" -a -n "$pkgver" -a -n "$arch" ]; then + if [[ -n $pkgname && -n $pkgver && -n $arch ]]; then IFS=$OLDIFS return 0 fi @@ -108,17 +108,17 @@ create_xdelta() newver="$pkgver" newarch="$arch" - if [ "$oldname" != "$newname" ]; then + if [[ $oldname != $newname ]]; then error "$(gettext "The package names don't match : '%s' and '%s'")" "$oldname" "$newname" return 1 fi - if [ "$oldarch" != "$newarch" ]; then + if [[ $oldarch != $newarch ]]; then error "$(gettext "The package architectures don't match : '%s' and '%s'")" "$oldarch" "$newarch" return 1 fi - if [ "$oldver" == "$newver" ]; then + if [[ $oldver == $newver ]]; then error "$(gettext "Both packages have the same version : '%s'")" "$newver" return 1 fi @@ -128,12 +128,12 @@ create_xdelta() local ret=0 xdelta3 -q -f -s "$oldfile" "$newfile" "$deltafile" || ret=$? - if [ $ret -ne 0 ]; then + if (( ret )); then error "$(gettext "Delta could not be created.")" return 1 else msg "$(gettext "Generated delta : '%s'")" "$deltafile" - [ $QUIET -eq 1 ] && echo "$deltafile" + (( QUIET )) && echo "$deltafile" fi return 0 } @@ -142,22 +142,22 @@ case "$1" in -q|--quiet) QUIET=1; shift ;; esac -if [ $# -ne 2 ]; then +if (( $# != 2 )); then usage exit 0 fi -if [ ! -f "$1" ]; then +if [[ ! -f $1 ]]; then error "$(gettext "File '%s' does not exist")" "$1" exit 0 fi -if [ ! -f "$2" ]; then +if [[ ! -f $2 ]]; then error "$(gettext "File '%s' does not exist")" "$2" exit 0 fi -if [ ! "$(type -p xdelta3)" ]; then +if ! type xdelta3 &>/dev/null; then error "$(gettext "Cannot find the xdelta3 binary! Is xdelta3 installed?")" exit 1 fi diff --git a/scripts/rankmirrors.sh.in b/scripts/rankmirrors.sh.in index 015b39a7..d5cbaddd 100644 --- a/scripts/rankmirrors.sh.in +++ b/scripts/rankmirrors.sh.in @@ -56,8 +56,8 @@ err() { # returns the fetching time, or timeout, or unreachable gettime() { IFS=' ' output=( $(curl -s -m 10 -w "%{time_total} %{http_code}" "$1" -o/dev/null) ) - [[ $? = 28 ]] && echo timeout && return - [[ ${output[1]} -ge 400 || ${output[1]} -eq 0 ]] && echo unreachable && return + (( $? == 28 )) && echo timeout && return + (( ${output[1]} >= 400 || ! ${output[1]} )) && echo unreachable && return echo "${output[0]}" } @@ -96,13 +96,13 @@ finaloutput() { for line in "${sortedarray[@]}"; do echo "${line#* } : ${line% *}" ((numiterator++)) - [[ $NUM -ne 0 && $numiterator -ge $NUM ]] && break + (( NUM && numiterator >= NUM )) && break done else for line in "${sortedarray[@]}"; do echo "Server = ${line#* }" ((numiterator++)) - [[ $NUM -ne 0 && $numiterator -ge $NUM ]] && break + (( NUM && numiterator >= NUM )) && break done fi exit 0 @@ -112,7 +112,7 @@ finaloutput() { # Argument parsing [[ $1 ]] || usage while [[ $1 ]]; do - if [[ "${1:0:2}" = -- ]]; then + if [[ ${1:0:2} = -- ]]; then case "${1:2}" in help) usage ;; version) version ;; @@ -142,7 +142,7 @@ while [[ $1 ]]; do done shift $snum fi - elif [[ -f "$1" ]]; then + elif [[ -f $1 ]]; then FILE="1" IFS=$'\n' linearray=( $(<$1) ) [[ $linearray ]] || err "File is empty." diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index 3f00441a..0e46c371 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -42,7 +42,7 @@ msg() { } msg2() { - [ $QUIET -ne 0 ] && return + (( QUIET )) && return local mesg=$1; shift printf " -> ${mesg}\n" "$@" >&1 } @@ -90,7 +90,7 @@ There is NO WARRANTY, to the extent permitted by law.\n")" # arg2 - List # arg3 - File to write to write_list_entry() { - if [ -n "$2" ]; then + if [[ -n $2 ]]; then echo "%$1%" >>$3 echo -e $2 >>$3 fi @@ -102,7 +102,7 @@ find_pkgentry() local pkgentry for pkgentry in $tmpdir/$pkgname*; do name=${pkgentry##*/} - if [ "${name%-*-*}" = "$pkgname" ]; then + if [[ ${name%-*-*} = $pkgname ]]; then echo $pkgentry return 0 fi @@ -126,12 +126,12 @@ db_write_delta() pkgname="$(get_delta_pkgname $deltafile)" pkgentry=$(find_pkgentry $pkgname) - if [ -z "$pkgentry" ]; then + if [[ -z $pkgentry ]]; then return 1 fi deltas="$pkgentry/deltas" # create deltas file if it does not already exist - if [ ! -f "$deltas" ]; then + if [[ ! -f $deltas ]]; then msg2 "$(gettext "Creating 'deltas' db entry...")" echo -e "%DELTAS%" >>$deltas fi @@ -162,11 +162,11 @@ db_remove_delta() pkgname="$(get_delta_pkgname $deltafile)" pkgentry=$(find_pkgentry $pkgname) - if [ -z "$pkgentry" ]; then + if [[ -z $pkgentry ]]; then return 1 fi deltas="$pkgentry/deltas" - if [ ! -f "$deltas" ]; then + if [[ ! -f $deltas ]]; then return 1 fi if grep -q "$filename" $deltas; then @@ -219,14 +219,14 @@ db_write_entry() csize=$(@SIZECMD@ "$pkgfile") # ensure $pkgname and $pkgver variables were found - if [ -z "$pkgname" -o -z "$pkgver" ]; then + if [[ -z $pkgname || -z $pkgver ]]; then error "$(gettext "Invalid package file '%s'.")" "$pkgfile" return 1 fi cd "$tmpdir" - if [ -d "$pkgname-$pkgver" ]; then + if [[ -d $pkgname-$pkgver ]]; then warning "$(gettext "An entry for '%s' already existed")" "$pkgname-$pkgver" fi @@ -238,30 +238,30 @@ db_write_entry() cd "$pkgname-$pkgver" # restore an eventual deltas file - [ -f "../$pkgname.deltas" ] && mv "../$pkgname.deltas" deltas + [[ -f ../$pkgname.deltas ]] && mv "../$pkgname.deltas" deltas # create desc entry msg2 "$(gettext "Creating 'desc' db entry...")" echo -e "%FILENAME%\n$(basename "$1")\n" >>desc echo -e "%NAME%\n$pkgname\n" >>desc - [ -n "$pkgbase" ] && echo -e "%BASE%\n$pkgbase\n" >>desc + [[ -n $pkgbase ]] && echo -e "%BASE%\n$pkgbase\n" >>desc echo -e "%VERSION%\n$pkgver\n" >>desc - [ -n "$pkgdesc" ] && echo -e "%DESC%\n$pkgdesc\n" >>desc + [[ -n $pkgdesc ]] && echo -e "%DESC%\n$pkgdesc\n" >>desc write_list_entry "GROUPS" "$_groups" "desc" - [ -n "$csize" ] && echo -e "%CSIZE%\n$csize\n" >>desc - [ -n "$size" ] && echo -e "%ISIZE%\n$size\n" >>desc + [[ -n $csize ]] && echo -e "%CSIZE%\n$csize\n" >>desc + [[ -n $size ]] && echo -e "%ISIZE%\n$size\n" >>desc # compute checksums msg2 "$(gettext "Computing md5 checksums...")" echo -e "%MD5SUM%\n$md5sum\n" >>desc - [ -n "$url" ] && echo -e "%URL%\n$url\n" >>desc + [[ -n $url ]] && echo -e "%URL%\n$url\n" >>desc write_list_entry "LICENSE" "$_licenses" "desc" - [ -n "$arch" ] && echo -e "%ARCH%\n$arch\n" >>desc - [ -n "$builddate" ] && echo -e "%BUILDDATE%\n$builddate\n" >>desc - [ -n "$packager" ] && echo -e "%PACKAGER%\n$packager\n" >>desc + [[ -n $arch ]] && echo -e "%ARCH%\n$arch\n" >>desc + [[ -n $builddate ]] && echo -e "%BUILDDATE%\n$builddate\n" >>desc + [[ -n $packager ]] && echo -e "%PACKAGER%\n$packager\n" >>desc write_list_entry "REPLACES" "$_replaces" "desc" - [ -n "$force" ] && echo -e "%FORCE%\n" >>desc + [[ -n $force ]] && echo -e "%FORCE%\n" >>desc # create depends entry msg2 "$(gettext "Creating 'depends' db entry...")" @@ -283,9 +283,9 @@ db_remove_entry() { local pkgname=$1 local notfound=1 local pkgentry=$(find_pkgentry $pkgname) - while [ -n "$pkgentry" ]; do + while [[ -n $pkgentry ]]; do notfound=0 - if [ -f "$pkgentry/deltas" ]; then + if [[ -f $pkgentry/deltas ]]; then mv "$pkgentry/deltas" "$tmpdir/$pkgname.deltas" fi msg2 "$(gettext "Removing existing entry '%s'...")" \ @@ -303,16 +303,16 @@ check_repo_db() CLEAN_LOCK=1 else error "$(gettext "Failed to acquire lockfile: %s.")" "$LOCKFILE" - [ -f "$LOCKFILE" ] && error "$(gettext "Held by process %s")" "$(cat $LOCKFILE)" + [[ -f $LOCKFILE ]] && error "$(gettext "Held by process %s")" "$(cat $LOCKFILE)" exit 1 fi - if [ -f "$REPO_DB_FILE" ]; then + if [[ -f $REPO_DB_FILE ]]; then # there are two situations we can have here- a DB with some entries, # or a DB with no contents at all. if ! bsdtar -tqf "$REPO_DB_FILE" '*/desc' >/dev/null 2>&1; then # check empty case - if [ -n "$(bsdtar -tqf "$REPO_DB_FILE" '*' 2>/dev/null)" ]; then + if [[ -n $(bsdtar -tqf "$REPO_DB_FILE" '*' 2>/dev/null) ]]; then error "$(gettext "Repository file '%s' is not a proper pacman database.")" "$REPO_DB_FILE" exit 1 fi @@ -339,15 +339,15 @@ check_repo_db() add() { - if [ ! -f "$1" ]; then + if [[ ! -f $1 ]]; then error "$(gettext "File '%s' not found.")" "$1" return 1 fi - if [ "${1##*.}" == "delta" ]; then + if [[ ${1##*.} == "delta" ]]; then deltafile=$1 msg "$(gettext "Adding delta '%s'")" "$deltafile" - if [ ! "$(type -p xdelta3)" ]; then + if ! type xdelta3 &>/dev/null; then error "$(gettext "Cannot find the xdelta3 binary! Is xdelta3 installed?")" exit 1 fi @@ -371,7 +371,7 @@ add() remove() { - if [ "${1##*.}" == "delta" ]; then + if [[ ${1##*.} == "delta" ]]; then deltafile=$1 msg "$(gettext "Searching for delta '%s'...")" "$deltafile" if db_remove_delta "$deltafile"; then @@ -405,8 +405,8 @@ clean_up() { local exit_code=$? cd "$startdir" - [ -d "$tmpdir" ] && rm -rf "$tmpdir" - [ $CLEAN_LOCK -eq 1 -a -f "$LOCKFILE" ] && rm -f "$LOCKFILE" + [[ -d $tmpdir ]] && rm -rf "$tmpdir" + (( CLEAN_LOCK )) && [[ -f $LOCKFILE ]] && rm -f "$LOCKFILE" exit $exit_code } @@ -414,7 +414,7 @@ clean_up() { # PROGRAM START # determine whether we have gettext; make it a no-op if we do not -if [ ! $(type -t gettext) ]; then +if ! type gettext &>/dev/null; then gettext() { echo "$@" } @@ -427,7 +427,7 @@ esac # figure out what program we are cmd="$(basename $0)" -if [ "$cmd" != "repo-add" -a "$cmd" != "repo-remove" ]; then +if [[ $cmd != "repo-add" && $cmd != "repo-remove" ]]; then error "$(gettext "Invalid command name '%s' specified.")" "$cmd" exit 1 fi @@ -447,7 +447,7 @@ for arg in "$@"; do case "$arg" in -q|--quiet) QUIET=1;; *) - if [ -z "$REPO_DB_FILE" ]; then + if [[ -z $REPO_DB_FILE ]]; then REPO_DB_FILE="$arg" LOCKFILE="$REPO_DB_FILE.lck" check_repo_db @@ -462,7 +462,7 @@ for arg in "$@"; do done # if at least one operation was a success, re-zip database -if [ $success -eq 1 ]; then +if (( success )); then msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE" case "$REPO_DB_FILE" in @@ -476,7 +476,7 @@ if [ $success -eq 1 ]; then filename=$(basename "$REPO_DB_FILE") cd "$tmpdir" - if [ -n "$(ls)" ]; then + if [[ -n $(ls) ]]; then bsdtar -c${TAR_OPT}f "$filename" * else # we have no packages remaining? zip up some emptyness @@ -485,8 +485,8 @@ if [ $success -eq 1 ]; then fi cd "$startdir" - [ -f "$REPO_DB_FILE" ] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old" - [ -f "$tmpdir/$filename" ] && mv "$tmpdir/$filename" "$REPO_DB_FILE" + [[ -f $REPO_DB_FILE ]] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old" + [[ -f $tmpdir/$filename ]] && mv "$tmpdir/$filename" "$REPO_DB_FILE" else msg "$(gettext "No packages modified, nothing to do.")" exit 1 -- cgit v1.2.3-70-g09d2