scripts: always use printf with embedded gettext

This addresses two problems:

1) echo's behavior is inconsistent when dealing with flags, and can
potentially be problematic.

  $ echo -n
  $ echo -- -n
  -- -n

2) Always using the end of options markers prevents translated strings
from throwing errors, as shown in FS#28069.

The remaining "inconsistencies" are because printf is being used in a
guaranteed safe manner, e.g.

  printf '%s\n' "$(gettext "--this can never break")"

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dave Reisner 2012-01-23 17:14:25 -05:00 committed by Dan McGee
parent 7ff1b945f6
commit 9e9835f464
6 changed files with 96 additions and 96 deletions

View file

@ -664,7 +664,7 @@ check_checksums() {
echo -n " $file ... " >&2 echo -n " $file ... " >&2
if ! file="$(get_filepath "$file")"; then if ! file="$(get_filepath "$file")"; then
echo "$(gettext "NOT FOUND")" >&2 printf -- "$(gettext "NOT FOUND")\n" >&2
errors=1 errors=1
found=0 found=0
fi fi
@ -674,9 +674,9 @@ check_checksums() {
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 printf -- "$(gettext "Passed")\n" >&2
else else
echo "$(gettext "FAILED")" >&2 printf -- "$(gettext "FAILED")\n" >&2
errors=1 errors=1
fi fi
fi fi
@ -1827,51 +1827,51 @@ m4_include(library/parse_options.sh)
usage() { usage() {
printf "makepkg (pacman) %s\n" "$myver" printf "makepkg (pacman) %s\n" "$myver"
echo echo
printf "$(gettext "Usage: %s [options]")\n" "$0" printf -- "$(gettext "Usage: %s [options]")\n" "$0"
echo echo
echo "$(gettext "Options:")" printf -- "$(gettext "Options:")"
printf "$(gettext " -A, --ignorearch Ignore incomplete %s field in %s")\n" "arch" "$BUILDSCRIPT" printf -- "$(gettext " -A, --ignorearch Ignore incomplete %s field in %s")\n" "arch" "$BUILDSCRIPT"
echo "$(gettext " -c, --clean Clean up work files after build")" printf -- "$(gettext " -c, --clean Clean up work files after build")\n"
echo "$(gettext " -d, --nodeps Skip all dependency checks")" printf -- "$(gettext " -d, --nodeps Skip all dependency checks")\n"
printf "$(gettext " -e, --noextract Do not extract source files (use existing %s dir)")\n" "src/" printf -- "$(gettext " -e, --noextract Do not extract source files (use existing %s dir)")\n" "src/"
echo "$(gettext " -f, --force Overwrite existing package")" printf -- "$(gettext " -f, --force Overwrite existing package")\n"
echo "$(gettext " -g, --geninteg Generate integrity checks for source files")" printf -- "$(gettext " -g, --geninteg Generate integrity checks for source files")\n"
echo "$(gettext " -h, --help Show this help message and exit")" printf -- "$(gettext " -h, --help Show this help message and exit")\n"
echo "$(gettext " -i, --install Install package after successful build")" printf -- "$(gettext " -i, --install Install package after successful build")\n"
echo "$(gettext " -L, --log Log package build process")" printf -- "$(gettext " -L, --log Log package build process")\n"
echo "$(gettext " -m, --nocolor Disable colorized output messages")" printf -- "$(gettext " -m, --nocolor Disable colorized output messages")\n"
echo "$(gettext " -o, --nobuild Download and extract files only")" printf -- "$(gettext " -o, --nobuild Download and extract files only")\n"
printf "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT" printf -- "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")" printf -- "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")\n"
echo "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")" printf -- "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")\n"
printf "$(gettext " -s, --syncdeps Install missing dependencies with %s")\n" "pacman" printf -- "$(gettext " -s, --syncdeps Install missing dependencies with %s")\n" "pacman"
echo "$(gettext " -S, --source Generate a source-only tarball without downloaded sources")" printf -- "$(gettext " -S, --source Generate a source-only tarball without downloaded sources")\n"
echo "$(gettext " --allsource Generate a source-only tarball including downloaded sources")" printf -- "$(gettext " --allsource Generate a source-only tarball including downloaded sources")\n"
printf "$(gettext " --asroot Allow %s to run as root user")\n" "makepkg" printf -- "$(gettext " --asroot Allow %s to run as root user")\n" "makepkg"
printf "$(gettext " --check Run the %s function in the %s")\n" "check()" "$BUILDSCRIPT" printf -- "$(gettext " --check Run the %s function in the %s")\n" "check()" "$BUILDSCRIPT"
printf "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf" printf -- "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf"
printf "$(gettext " --holdver Prevent automatic version bumping for development %ss")\n" "$BUILDSCRIPT" printf -- "$(gettext " --holdver Prevent automatic version bumping for development %ss")\n" "$BUILDSCRIPT"
printf "$(gettext " --key <key> Specify a key to use for %s signing instead of the default")\n" "gpg" printf -- "$(gettext " --key <key> Specify a key to use for %s signing instead of the default")\n" "gpg"
printf "$(gettext " --nocheck Do not run the %s function in the %s")\n" "check()" "$BUILDSCRIPT" printf -- "$(gettext " --nocheck Do not run the %s function in the %s")\n" "check()" "$BUILDSCRIPT"
echo "$(gettext " --nosign Do not create a signature for the package")" printf -- "$(gettext " --nosign Do not create a signature for the package")\n"
echo "$(gettext " --pkg <list> Only build listed packages from a split package")" printf -- "$(gettext " --pkg <list> Only build listed packages from a split package")\n"
printf "$(gettext " --sign Sign the resulting package with %s")\n" "gpg" printf -- "$(gettext " --sign Sign the resulting package with %s")\n" "gpg"
echo "$(gettext " --skipchecksums Do not verify checksums of the source files")" printf -- "$(gettext " --skipchecksums Do not verify checksums of the source files")\n"
echo "$(gettext " --skipinteg Do not perform any verification checks on source files")" printf -- "$(gettext " --skipinteg Do not perform any verification checks on source files")\n"
echo "$(gettext " --skippgpcheck Do not verify source files with PGP signatures")" printf -- "$(gettext " --skippgpcheck Do not verify source files with PGP signatures")\n"
echo echo
printf "$(gettext "These options can be passed to %s:")\n" "pacman" printf -- "$(gettext "These options can be passed to %s:")\n" "pacman"
echo echo
echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")" printf -- "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")\n"
echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")" printf -- "$(gettext " --noprogressbar Do not show a progress bar when downloading files")\n"
echo echo
printf "$(gettext "If %s is not specified, %s will look for '%s'")\n" "-p" "makepkg" "$BUILDSCRIPT" printf -- "$(gettext "If %s is not specified, %s will look for '%s'")\n" "-p" "makepkg" "$BUILDSCRIPT"
echo echo
} }
version() { version() {
printf "makepkg (pacman) %s\n" "$myver" printf "makepkg (pacman) %s\n" "$myver"
printf "$(gettext "\ printf -- "$(gettext "\
Copyright (c) 2006-2012 Pacman Development Team <pacman-dev@archlinux.org>.\n\ Copyright (c) 2006-2012 Pacman Development Team <pacman-dev@archlinux.org>.\n\
Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\ Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
This is free software; see the source for copying conditions.\n\ This is free software; see the source for copying conditions.\n\

View file

@ -32,12 +32,12 @@ m4_include(library/output_format.sh)
usage() { usage() {
printf "pacman-db-upgrade (pacman) %s\n\n" "$myver" printf "pacman-db-upgrade (pacman) %s\n\n" "$myver"
printf "$(gettext "Usage: %s [pacman_db_root]")\n\n" "$0" printf -- "$(gettext "Usage: %s [pacman_db_root]")\n\n" "$0"
} }
version() { version() {
printf "pacman-db-upgrade (pacman) %s\n" "$myver" printf "pacman-db-upgrade (pacman) %s\n" "$myver"
printf "$(gettext "\ printf -- "$(gettext "\
Copyright (c) 2010-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\ Copyright (c) 2010-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
This is free software; see the source for copying conditions.\n\ This is free software; see the source for copying conditions.\n\
There is NO WARRANTY, to the extent permitted by law.\n")" There is NO WARRANTY, to the extent permitted by law.\n")"

View file

@ -54,40 +54,40 @@ m4_include(library/parse_options.sh)
usage() { usage() {
printf "pacman-key (pacman) %s\n" ${myver} printf "pacman-key (pacman) %s\n" ${myver}
echo echo
printf "$(gettext "Usage: %s [options]")\n" $(basename $0) printf -- "$(gettext "Usage: %s [options]")\n" $(basename $0)
echo echo
printf "$(gettext "Manage pacman's list of trusted keys")\n" printf -- "$(gettext "Manage pacman's list of trusted keys")\n"
echo echo
echo "$(gettext "Options:")" printf -- "$(gettext "Options:")\n"
echo "$(gettext " -a, --add [file(s)] Add the specified keys (empty for stdin)")" printf -- "$(gettext " -a, --add [file(s)] Add the specified keys (empty for stdin)")\n"
echo "$(gettext " -d, --delete <keyid(s)> Remove the specified keyids")" printf -- "$(gettext " -d, --delete <keyid(s)> Remove the specified keyids")\n"
echo "$(gettext " -e, --export [keyid(s)] Export the specified or all keyids")" printf -- "$(gettext " -e, --export [keyid(s)] Export the specified or all keyids")\n"
echo "$(gettext " -f, --finger [keyid(s)] List fingerprint for specified or all keyids")" printf -- "$(gettext " -f, --finger [keyid(s)] List fingerprint for specified or all keyids")\n"
echo "$(gettext " -h, --help Show this help message and exit")" printf -- "$(gettext " -h, --help Show this help message and exit")\n"
echo "$(gettext " -l, --list-keys [keyid(s)] List the specified or all keys")" printf -- "$(gettext " -l, --list-keys [keyid(s)] List the specified or all keys")\n"
echo "$(gettext " -r, --recv-keys <keyid(s)> Fetch the specified keyids")" printf -- "$(gettext " -r, --recv-keys <keyid(s)> Fetch the specified keyids")\n"
echo "$(gettext " -u, --updatedb Update the trustdb of pacman")" printf -- "$(gettext " -u, --updatedb Update the trustdb of pacman")\n"
echo "$(gettext " -v, --verify <signature> Verify the file specified by the signature")" printf -- "$(gettext " -v, --verify <signature> Verify the file specified by the signature")\n"
echo "$(gettext " -V, --version Show program version")" printf -- "$(gettext " -V, --version Show program version")\n"
printf "$(gettext " --config <file> Use an alternate config file (instead of\n\ printf -- "$(gettext " --config <file> Use an alternate config file (instead of\n\
'%s')")\n" "@sysconfdir@/pacman.conf" '%s')")\n" "@sysconfdir@/pacman.conf"
echo "$(gettext " --edit-key <keyid(s)> Present a menu for key management task on keyids")" printf -- "$(gettext " --edit-key <keyid(s)> Present a menu for key management task on keyids")\n"
printf "$(gettext " --gpgdir <dir> Set an alternate directory for GnuPG (instead\n\ printf -- "$(gettext " --gpgdir <dir> Set an alternate directory for GnuPG (instead\n\
of '%s')")\n" "@sysconfdir@/pacman.d/gnupg" of '%s')")\n" "@sysconfdir@/pacman.d/gnupg"
echo "$(gettext " --import <dir(s)> Imports pubring.gpg from dir(s)")" printf -- "$(gettext " --import <dir(s)> Imports pubring.gpg from dir(s)")\n"
echo "$(gettext " --import-trustdb <dir(s)> Imports ownertrust values from trustdb.gpg in dir(s)")" printf -- "$(gettext " --import-trustdb <dir(s)> Imports ownertrust values from trustdb.gpg in dir(s)")\n"
echo "$(gettext " --init Ensure the keyring is properly initialized")" printf -- "$(gettext " --init Ensure the keyring is properly initialized")\n"
echo "$(gettext " --keyserver Specify a keyserver to use if necessary")" printf -- "$(gettext " --keyserver Specify a keyserver to use if necessary")\n"
echo "$(gettext " --list-sigs [keyid(s)] List keys and their signatures")" printf -- "$(gettext " --list-sigs [keyid(s)] List keys and their signatures")\n"
echo "$(gettext " --lsign-key <keyid> Locally sign the specified keyid")" printf -- "$(gettext " --lsign-key <keyid> Locally sign the specified keyid")\n"
printf "$(gettext " --populate [keyring(s)] Reload the default keys from the (given) keyrings\n\ printf -- "$(gettext " --populate [keyring(s)] Reload the default keys from the (given) keyrings\n\
in '%s'")\n" "@pkgdatadir@/keyrings" in '%s'")\n" "@pkgdatadir@/keyrings"
echo "$(gettext " --refresh-keys [keyid(s)] Update specified or all keys from a keyserver")" printf -- "$(gettext " --refresh-keys [keyid(s)] Update specified or all keys from a keyserver")\n"
} }
version() { version() {
printf "pacman-key (pacman) %s\n" "${myver}" printf "pacman-key (pacman) %s\n" "${myver}"
printf "$(gettext "\ printf -- "$(gettext "\
Copyright (c) 2010-2012 Pacman Development Team <pacman-dev@archlinux.org>.\n\ Copyright (c) 2010-2012 Pacman Development Team <pacman-dev@archlinux.org>.\n\
This is free software; see the source for copying conditions.\n\ This is free software; see the source for copying conditions.\n\
There is NO WARRANTY, to the extent permitted by law.\n")" There is NO WARRANTY, to the extent permitted by law.\n")"

View file

@ -33,11 +33,11 @@ m4_include(library/output_format.sh)
usage() { usage() {
printf "pacman-optimize (pacman) %s\n\n" "$myver" printf "pacman-optimize (pacman) %s\n\n" "$myver"
printf "$(gettext "Usage: %s [pacman_db_root]")\n\n" "$0" printf -- "$(gettext "Usage: %s [pacman_db_root]")\n\n" "$0"
printf "$(gettext "\ printf -- "$(gettext "\
pacman-optimize is a little hack that should improve the performance\n\ pacman-optimize is a little hack that should improve the performance\n\
of pacman when reading/writing to its filesystem-based database.\n\n")" of pacman when reading/writing to its filesystem-based database.\n\n")"
printf "$(gettext "\ printf -- "$(gettext "\
Because pacman uses many small files to keep track of packages,\n\ Because pacman uses many small files to keep track of packages,\n\
there is a tendency for these files to become fragmented over time.\n\ there is a tendency for these files to become fragmented over time.\n\
This script attempts to relocate these small files into one\n\ This script attempts to relocate these small files into one\n\
@ -48,7 +48,7 @@ does not have to move around the disk as much.\n")"
version() { version() {
printf "pacman-optimize (pacman) %s\n" "$myver" printf "pacman-optimize (pacman) %s\n" "$myver"
printf "$(gettext "\ printf -- "$(gettext "\
Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\ Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\ Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
This is free software; see the source for copying conditions.\n\ This is free software; see the source for copying conditions.\n\

View file

@ -38,16 +38,16 @@ m4_include(library/output_format.sh)
# print usage instructions # print usage instructions
usage() { usage() {
printf "pkgdelta (pacman) %s\n\n" "$myver" printf "pkgdelta (pacman) %s\n\n" "$myver"
printf "$(gettext "Usage: pkgdelta [-q] <package1> <package2>\n")" printf -- "$(gettext "Usage: pkgdelta [-q] <package1> <package2>\n")"
printf "$(gettext "\ printf -- "$(gettext "\
pkgdelta will create a delta file between two packages.\n\ pkgdelta will create a delta file between two packages.\n\
This delta file can then be added to a database using repo-add.\n\n")" This delta file can then be added to a database using repo-add.\n\n")"
echo "$(gettext "Example: pkgdelta pacman-3.0.0.pkg.tar.gz pacman-3.0.1.pkg.tar.gz")" printf -- "$(gettext "Example: pkgdelta pacman-3.0.0.pkg.tar.gz pacman-3.0.1.pkg.tar.gz")\n"
} }
version() { version() {
printf "pkgdelta (pacman) %s\n\n" "$myver" printf "pkgdelta (pacman) %s\n\n" "$myver"
printf "$(gettext "\ printf -- "$(gettext "\
Copyright (c) 2009 Xavier Chantry <shiningxc@gmail.com>.\n\n\ Copyright (c) 2009 Xavier Chantry <shiningxc@gmail.com>.\n\n\
This is free software; see the source for copying conditions.\n\ This is free software; see the source for copying conditions.\n\
There is NO WARRANTY, to the extent permitted by law.\n")" There is NO WARRANTY, to the extent permitted by law.\n")"

View file

@ -45,48 +45,48 @@ m4_include(library/output_format.sh)
# print usage instructions # print usage instructions
usage() { usage() {
cmd=${0##*/} cmd=${0##*/}
printf "%s (pacman) %s\n\n" "$cmd" "$myver" printf -- "%s (pacman) %s\n\n" "$cmd" "$myver"
if [[ $cmd == "repo-add" ]] ; then if [[ $cmd == "repo-add" ]] ; then
printf "$(gettext "Usage: repo-add [options] <path-to-db> <package|delta> ...\n")" printf -- "$(gettext "Usage: repo-add [options] <path-to-db> <package|delta> ...\n")"
printf "\n" printf -- "\n"
printf "$(gettext "\ printf -- "$(gettext "\
repo-add will update a package database by reading a package file.\n\ repo-add will update a package database by reading a package file.\n\
Multiple packages to add can be specified on the command line.\n")" Multiple packages to add can be specified on the command line.\n")"
printf "\n" printf -- "\n"
printf "$(gettext "Options:\n")" printf -- "$(gettext "Options:\n")"
printf "$(gettext " -d, --delta generate and add delta for package update\n")" printf -- "$(gettext " -d, --delta generate and add delta for package update\n")"
printf "$(gettext " -f, --files update database's file list\n")" printf -- "$(gettext " -f, --files update database's file list\n")"
elif [[ $cmd == "repo-remove" ]] ; then elif [[ $cmd == "repo-remove" ]] ; then
printf "$(gettext "Usage: repo-remove [options] <path-to-db> <packagename|delta> ...\n")" printf -- "$(gettext "Usage: repo-remove [options] <path-to-db> <packagename|delta> ...\n")"
printf "\n" printf -- "\n"
printf "$(gettext "\ printf -- "$(gettext "\
repo-remove will update a package database by removing the package name\n\ repo-remove will update a package database by removing the package name\n\
specified on the command line from the given repo database. Multiple\n\ specified on the command line from the given repo database. Multiple\n\
packages to remove can be specified on the command line.\n")" packages to remove can be specified on the command line.\n")"
printf "\n" printf -- "\n"
printf "$(gettext "Options:\n")" printf -- "$(gettext "Options:\n")"
else else
printf "$(gettext "Please move along, there is nothing to see here.\n")" printf -- "$(gettext "Please move along, there is nothing to see here.\n")"
return return
fi fi
printf "$(gettext " -q, --quiet minimize output\n")" printf -- "$(gettext " -q, --quiet minimize output\n")"
printf "$(gettext " -s, --sign sign database with GnuPG after update\n")" printf -- "$(gettext " -s, --sign sign database with GnuPG after update\n")"
printf "$(gettext " -k, --key <key> use the specified key to sign the database\n")" printf -- "$(gettext " -k, --key <key> use the specified key to sign the database\n")"
printf "$(gettext " -v, --verify verify database's signature before update\n")" printf -- "$(gettext " -v, --verify verify database's signature before update\n")"
printf "$(gettext "\n\ printf -- "$(gettext "\n\
See %s(8) for more details and descriptions of the available options.\n")" $cmd See %s(8) for more details and descriptions of the available options.\n")" $cmd
printf "\n" printf "\n"
if [[ $cmd == "repo-add" ]] ; then if [[ $cmd == "repo-add" ]] ; then
printf "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0-1-i686.pkg.tar.gz\n")" printf -- "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0-1-i686.pkg.tar.gz\n")"
elif [[ $cmd == "repo-remove" ]] ; then elif [[ $cmd == "repo-remove" ]] ; then
printf "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26\n")" printf -- "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26\n")"
fi fi
} }
version() { version() {
cmd=${0##*/} cmd=${0##*/}
printf "%s (pacman) %s\n\n" "$cmd" "$myver" printf "%s (pacman) %s\n\n" "$cmd" "$myver"
printf "$(gettext "\ printf -- "$(gettext "\
Copyright (c) 2006-2012 Pacman Development Team <pacman-dev@archlinux.org>\n\n\ Copyright (c) 2006-2012 Pacman Development Team <pacman-dev@archlinux.org>\n\n\
This is free software; see the source for copying conditions.\n\ This is free software; see the source for copying conditions.\n\
There is NO WARRANTY, to the extent permitted by law.\n")" There is NO WARRANTY, to the extent permitted by law.\n")"