Re: [pacman-dev] [RFC v3 06/13] paccache: streamline usage function

2016-09-30 Thread Gordian Edenhofer
On Fri, 2016-09-30 at 08:14 -0400, Dave Reisner wrote:
> On Fri, Sep 30, 2016 at 01:47:54PM +0200, Gordian Edenhofer wrote:
> > 
> > Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
> > ---
> >  contrib/paccache.sh.in | 83 
> > --
> >  1 file changed, 53 insertions(+), 30 deletions(-)
> > 
> > diff --git a/contrib/paccache.sh.in b/contrib/paccache.sh.in
> > index 02fae52..78f566f 100644
> > --- a/contrib/paccache.sh.in
> > +++ b/contrib/paccache.sh.in
> > @@ -30,6 +30,17 @@ declaredelim=$'\n' keep=3 movedir= scanarch=
> >  QUIET=0
> >  USE_COLOR='y'
> >  
> > +# gettext initialization
> > +export TEXTDOMAIN='pacman'
> > +export TEXTDOMAINDIR='@localedir@'
> > +
> > +# Determine whether we have gettext; make it a no-op if we do not
> > +if ! type -p gettext >/dev/null; then
> > +   gettext() {
> > +   printf "%s\n" "$@"
> > +   }
> > +fi
> > +
> >  m4_include(../scripts/library/output_format.sh)
> >  m4_include(../scripts/library/parseopts.sh)
> >  
> > @@ -172,36 +183,48 @@ summarize() {
> >  }
> >  
> >  usage() {
> > -   cat < > -${myname} (pacman) v${myver}
> > -
> > -A flexible pacman cache cleaning utility.
> > -
> > -Usage: ${myname}  [options] [targets...]
> > -
> > -  Operations:
> > --d, --dryrun  perform a dry run, only finding
> > candidate packages.
> > --m, --move   move candidate packages to "dir".
> > --r, --remove  remove candidate packages.
> > -
> > -  Options:
> > --a, --arch  scan for "arch" (default: all
> > architectures).
> > --c, --cachedir   scan "dir" for packages. can be used
> > more than once.
> > -  (default: read from
> > @sysconfdir@/pacman.conf).
> > --f, --force   apply force to mv(1) and rm(1)
> > operations.
> > --h, --helpdisplay this help message and exit.
> > --i, --ignore    ignore "pkgs", comma-separated.
> > Alternatively, specify
> > -  "-" to read package names from stdin,
> > newline-
> > -  delimited.
> > --k, --keep   keep "num" of each package in the cache
> > (default: 3).
> > ---nocolor remove color from output.
> > --q, --quiet   minimize output
> > --u, --uninstalled target uninstalled packages.
> > --v, --verbose increase verbosity. specify up to 3
> > times.
> > --z, --nulluse null delimiters for candidate names
> > (only with -v
> > -  and -vv).
> > -
> > -EOF
> > +   printf "%s (pacman) %s\n" "$myname" "$myver"
> > +   echo
> > +   printf -- "$(gettext "A flexible pacman cache cleaning
> > utility")\n"
> > +   echo
> > +   printf -- "$(gettext "Usage: %s  [options]
> > [targets...]")\n" "$0"
> > +   echo
> > +   printf -- "$(gettext "Operations:")\n"
> > +   printf -- "  -d, --dryrun  "
> > +   printf -- "$(gettext "Perform a dry run, only finding
> > candidate packages")\n"
> > +   printf -- "  -m, --move   "
> > +   printf -- "$(gettext "Move candidate packages to
> > \"dir\"")\n"
> > +   printf -- "  -r, --remove  "
> > +   printf -- "$(gettext "Remove candidate packages")\n"
> > +   echo
> > +   printf -- "$(gettext "Options:")\n"
> > +   printf -- "  -a, --arch  "
> > +   printf -- "$(gettext "Scan for \"arch\" (default: all
> > architectures)")\n"
> > +   printf -- "  -c, --cachedir   "
> > +   printf -- "$(gettext "Scan \"dir\" for packages. Can be
> > used more than once.\n\
> > +   (default: read from %s).")\n"
> > "@sysconfdir@/pacman.conf"
> > +   printf -- "  -f, --force   "
> > +   printf -- "$(gettext "Apply force to mv(1) and rm(1)
> > operations")\n" "\$srcdir/"
> > +   printf -- "  -h, --help"
> > +   printf -- "$(gettext "Display this help message and
> > exit")\n&quo

Re: [pacman-dev] [RFC v3 13/13] bacman: make gettext useful

2016-09-30 Thread Gordian Edenhofer
On Fri, 2016-09-30 at 08:14 -0400, Dave Reisner wrote:
> On Fri, Sep 30, 2016 at 01:48:01PM +0200, Gordian Edenhofer wrote:
> > 
> > Export TEXTDOMAIN and TEXTDOMAINDIR in order for the strings to be
> > translatable with gettext.
> > ---
> >  contrib/bacman.sh.in | 28 ++--
> >  1 file changed, 22 insertions(+), 6 deletions(-)
> > 
> > diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
> > index 39fbe99..cc243c9 100644
> > --- a/contrib/bacman.sh.in
> > +++ b/contrib/bacman.sh.in
> > @@ -32,6 +32,17 @@ QUIET=0
> >  # Required for fakeroot because options are shifted off the array.
> >  ARGS=("$@")
> >  
> > +# gettext initialization
> > +export TEXTDOMAIN='pacman'
> > +export TEXTDOMAINDIR='@localedir@'
> > +
> > +# Determine whether we have gettext; make it a no-op if we do not
> > +if ! type -p gettext >/dev/null; then
> > +   gettext() {
> > +   printf "%s\n" "$@"
> 
> Not sure if this is copypasted from somewhere, but it's wrong.
> Consider
> the output of:
> 
>   printf '%s\n' 1 2 3
> 
> vs.
> 
>   printf '%s\n' '1 2 3'
> 
> You probably wanted this to be: printf '%s\n' "$*"

Yes, this is indeed copy-pasted from makepkg [1] since I though it
would be properly scripted there.

> > +   }
> > +fi
> > +
> >  m4_include(../scripts/library/output_format.sh)
> >  m4_include(../scripts/library/parseopts.sh)
> >  
> > @@ -54,13 +65,18 @@ usage() {
> >     printf -- "$(gettext "Usage: %s [options]
> > <package(s)>")\n" "$0"
> >     echo
> >     printf -- "$(gettext "Options:")\n"
> > -   printf -- "$(gettext "  -h, --help   Show this help
> > message and exit")\n"
> > -   printf -- "$(gettext "  -q, --quiet  Silence most of
> > the status reporting")\n"
> > -   printf -- "$(gettext "  -m, --nocolorDisable colorized
> > output messages")\n"
> > -   printf -- "$(gettext "  -o, --out   Write output to
> > specified directory (instead of \$PKGDEST)")\n"
> > -   printf -- "$(gettext "  --pacnew Package .pacnew
> > files")\n"
> > +   printf -- "  -h, --help   "
> > +   printf -- "$(gettext "Show this help message and exit")\n"
> 
> This splitting/wrapping doesn't really make me think that this is an
> improvement. Other patches are subjectively worse IMO -- particularly
> cases where the usage wraps onto multiple lines and you're adding
> arbitrary amounts of whitespace wrapping. It's hard to get right and
> I
> suspect it'll be broken in the future. There's a reason I used a
> heredoc
> for paccache's usage function. It's natural, reads easily, and is
> easy
> to extend.
> 
> Still wondering if we actually care about translations for contrib,
> or
> if we care about contrib at all.

I really like heredocs and initially submitted my bacman patch using
them for the very same reasons you mentioned. However I was advised to
follow the style from scripts like makepkg, repo-add etc.

[1] https://git.archlinux.org/pacman.git/tree/scripts/makepkg.sh.in#n12
26

signature.asc
Description: This is a digitally signed message part


[pacman-dev] [RFC v3 13/13] bacman: make gettext useful

2016-09-30 Thread Gordian Edenhofer
Export TEXTDOMAIN and TEXTDOMAINDIR in order for the strings to be
translatable with gettext.
---
 contrib/bacman.sh.in | 28 ++--
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 39fbe99..cc243c9 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -32,6 +32,17 @@ QUIET=0
 # Required for fakeroot because options are shifted off the array.
 ARGS=("$@")
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+   gettext() {
+   printf "%s\n" "$@"
+   }
+fi
+
 m4_include(../scripts/library/output_format.sh)
 m4_include(../scripts/library/parseopts.sh)
 
@@ -54,13 +65,18 @@ usage() {
printf -- "$(gettext "Usage: %s [options] ")\n" "$0"
echo
printf -- "$(gettext "Options:")\n"
-   printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
-   printf -- "$(gettext "  -q, --quiet  Silence most of the status 
reporting")\n"
-   printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
-   printf -- "$(gettext "  -o, --out   Write output to specified 
directory (instead of \$PKGDEST)")\n"
-   printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
+   printf -- "  -h, --help   "
+   printf -- "$(gettext "Show this help message and exit")\n"
+   printf -- "  -q, --quiet  "
+   printf -- "$(gettext "Silence most of the status reporting")\n"
+   printf -- "  -m, --nocolor"
+   printf -- "$(gettext "Disable colorized output messages")\n"
+   printf -- "  -o, --out   "
+   printf -- "$(gettext "Write output to specified directory (instead of 
%s)")\n" "\$PKGDEST"
+   printf -- "  --pacnew "
+   printf -- "$(gettext "Package .pacnew files")\n"
echo
-   printf -- "$(gettext "Examples:")" 
+   printf -- "$(gettext "Examples:")"
printf -- "%s linux-headers\n" "$myname"
printf -- "%s -o ~/packages libarchive\n" "$myname"
printf -- "%s --nocolor --pacnew gzip make binutils\n" "$myname"
-- 
2.10.0


[pacman-dev] [RFC v3 12/13] rankmirrors: streamline usage function

2016-09-30 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/rankmirrors.sh.in | 48 ++-
 1 file changed, 35 insertions(+), 13 deletions(-)

diff --git a/contrib/rankmirrors.sh.in b/contrib/rankmirrors.sh.in
index 0988fe9..e1e0503 100644
--- a/contrib/rankmirrors.sh.in
+++ b/contrib/rankmirrors.sh.in
@@ -24,23 +24,45 @@ trap finaloutput INT
 declare -r myname='rankmirrors'
 declare -r myver='@PACKAGE_VERSION@'
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+   gettext() {
+   printf "%s\n" "$@"
+   }
+fi
+
+m4_include(../scripts/library/parseopts.sh)
+
 usage() {
-   echo "${myname} (pacman) v${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
+   echo
+   printf -- "$(gettext "\
+Ranks pacman mirrors by their connection and opening speed. Pacman mirror\n\
+files are located in %s. It can also rank one mirror if the URL is\n\
+provided")\n" "@sysconfdir@/pacman.d/"
echo
-   echo "Ranks pacman mirrors by their connection and opening speed. 
Pacman mirror"
-   echo "files are located in @sysconfdir@/pacman.d/. It can also rank one 
mirror if the URL is"
-   echo "provided."
+   printf -- "$(gettext "Usage: %s [options] <mirrorfile|URL>")\n" "$0"
echo
-   echo "Usage: ${myname} [options] MIRRORFILE | URL"
+   printf -- "$(gettext "Options:")\n"
+   printf -- "  -h, --help "
+   printf -- "$(gettext "Show this help message and exit")\n"
+   printf -- "  -n  "
+   printf -- "$(gettext "Number of servers to output, 0 for all")\n"
+   printf -- "  -t, --times"
+   printf -- "$(gettext "Only output mirrors and their response times")\n"
+   printf -- "  -u, --url  "
+   printf -- "$(gettext "Test a specific URL")\n"
+   printf -- "  -v, --verbose  "
+   printf -- "$(gettext "Be verbose in ouptut")\n"
+   printf -- "  -r, --repo   "
+   printf -- "$(gettext "Specify a repository name instead of guessing")\n"
+   printf -- "  --version  "
+   printf -- "$(gettext "Show program's version number and exit")\n"
echo
-   echo "Options:"
-   echo "  --version  show program's version number and exit"
-   echo "  -h, --help show this help message and exit"
-   echo "  -n NUM number of servers to output, 0 for all"
-   echo "  -t, --timesonly output mirrors and their response times"
-   echo "  -u, --url  test a specific URL"
-   echo "  -v, --verbose  be verbose in ouptut"
-   echo "  -r, --repo specify a repository name instead of guessing"
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [RFC v3 09/13] paclog-pkglist: streamline usage function

2016-09-30 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/paclog-pkglist.sh.in | 25 ++---
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/contrib/paclog-pkglist.sh.in b/contrib/paclog-pkglist.sh.in
index 847b389..065210c 100644
--- a/contrib/paclog-pkglist.sh.in
+++ b/contrib/paclog-pkglist.sh.in
@@ -20,20 +20,31 @@
 declare -r myname='paclog-pkglist'
 declare -r myver='@PACKAGE_VERSION@'
 
-export TEXTDOMAIN='pacman'
-export TEXTDOMAINDIR='/usr/share/locale'
 declare logfile=${1:-@localstatedir@/log/pacman.log}
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+   gettext() {
+   printf "%s\n" "$@"
+   }
+fi
+
 usage() {
-   printf "%s (pacman) v%s\n" "${myname}" "${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
+   echo
+   printf -- "$(gettext "Parse a log file into a list of currently 
installed packages")\n"
echo
-   echo "Parse a log file into a list of currently installed packages"
+   printf -- "$(gettext "Usage: %s [path to pacman log]")\n" "$0"
echo
-   printf "Usage: %s [path to pacman log]\n" "${myname}"
+   printf -- "$(gettext "Examples:")"
+   printf -- "%s @localstatedir@/log/pacman.log\n" "$myname"
echo
-   printf "Example: %s @localstatedir@/log/pacman.log\n" "${myname}"
+   printf -- "$(gettext "Defaults to: %s")\n" 
"@localstatedir@/log/pacman.log"
echo
-   echo 'Defaults to: @localstatedir@/log/pacman.log'
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [RFC v3 02/13] pacdiff: streamline option syntax with makepkg

2016-09-30 Thread Gordian Edenhofer
Allow for '-m' as abbreviation for '--nocolor'.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/pacdiff.sh.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in
index cd93164..3394993 100644
--- a/contrib/pacdiff.sh.in
+++ b/contrib/pacdiff.sh.in
@@ -47,7 +47,7 @@ Search Options: select one (default: --pacmandb)
 
 General Options:
   -o/--output   print files instead of merging them
-  --nocolor remove colors from output
+  -m/--nocolor  remove colors from output
 
 Environment Variables:
   DIFFPROG  override the merge program: (default: 'vim -d')
@@ -96,7 +96,7 @@ cmd() {
 }
 
 # Parse arguments
-OPT_SHORT='lfpoVh'
+OPT_SHORT='lfpomVh'
 OPT_LONG=('locate' 'find' 'pacmandb' 'output' 'nocolor' 'version' 'help')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
@@ -115,7 +115,7 @@ while :; do
USE_PACDB=1;;
-o|--output)
OUTPUTONLY=1;;
-   --nocolor)
+   -m|--nocolor)
USE_COLOR='n';;
-V|--version)
version
-- 
2.10.0


[pacman-dev] [RFC v3 11/13] updpkgsums: streamline usage function

2016-09-30 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/updpkgsums.sh.in | 35 ++-
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/contrib/updpkgsums.sh.in b/contrib/updpkgsums.sh.in
index c571d29..132c192 100644
--- a/contrib/updpkgsums.sh.in
+++ b/contrib/updpkgsums.sh.in
@@ -22,20 +22,37 @@ shopt -s extglob
 declare -r myname='updpkgsums'
 declare -r myver='@PACKAGE_VERSION@'
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+   gettext() {
+   printf "%s\n" "$@"
+   }
+fi
+
 usage() {
-   printf "%s (pacman) v%s\n" "${myname}" "${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
+   echo
+   printf -- "$(gettext "\
+%s will perform an in place update of the checksums in the\n\
+path specified by [build file], defaulting to PKGBUILD in the current\n\
+working directory")\n" "$myname"
echo
-   printf "%s will perform an in place update of the checksums in the\n" 
"${myname}"
-   echo "path specified by [build file], defaulting to PKGBUILD in the 
current"
-   echo "working directory."
+   printf -- "$(gettext "Usage: %s [options] [build file]")\n" "$0"
echo
-   printf "Usage: %s [options] [build file]\n" "${myname}"
+   printf -- "$(gettext "Options:")\n"
+   printf -- "  -h, --help"
+   printf -- "$(gettext "Display this help message and exit")\n"
+   printf -- "  -V, --version "
+   printf -- "$(gettext "Display version information and exit")\n"
echo
-   echo "-h, --helpdisplay this help message and exit"
-   echo "-V, --version display version information and exit"
+   printf -- "$(gettext "These options can be passed to makepkg:")\n"
+   printf -- "  -m, --nocolor "
+   printf -- "$(gettext "Disable colorized output messages")\n"
echo
-   echo "These options can be passed to makepkg:"
-   echo "-m, --nocolor disable colorized output messages"
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [RFC v3 10/13] pacscripts: streamline usage function

2016-09-30 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/pacscripts.sh.in | 31 +++
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/contrib/pacscripts.sh.in b/contrib/pacscripts.sh.in
index 4a1e0c5..0c5e926 100644
--- a/contrib/pacscripts.sh.in
+++ b/contrib/pacscripts.sh.in
@@ -27,6 +27,17 @@ set -o errexit
 declare -r myname='pacscripts'
 declare -r myver='@PACKAGE_VERSION@'
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+   gettext() {
+   printf "%s\n" "$@"
+   }
+fi
+
 conf="@sysconfdir@/pacman.conf"
 
 if [ ! -r "$conf" ]; then
@@ -45,18 +56,22 @@ error() {
 }
 
 usage() {
-   echo "${myname} (pacman) v${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
+   echo
+   printf -- "$(gettext "Prints the {pre,post}_{install,remove,upgrade} 
scripts of a given package")\n"
echo
-   echo "Prints the {pre,post}_{install,remove,upgrade} scripts of a given 
package."
+   printf -- "$(gettext "Usage: %s <pkgname|pkgfile>")\n" "$0"
echo
-   echo "Usage: ${myname} <pkgname|pkgfile>"
+   printf -- "$(gettext "Options:")\n"
+   printf -- "  -h, --help "
+   printf -- "$(gettext "Print this help message")\n"
+   printf -- "  -v, --version  "
+   printf -- "$(gettext "Print program name and version")\n"
echo
-   echo " Options:"
-   echo "  -h, --help Print this help message"
-   echo "  -v, --version  Print program name and version"
+   printf -- "$(gettext "Examples:")"
+   printf -- "  %s gconf-editor\n" "$myname"
+   printf -- "  %s gconf-editor-3.0.1-3-x86_64.pkg.tar.xz\n" "$myname"
echo
-   echo "Example: ${myname} gconf-editor"
-   echo "Example: ${myname} gconf-editor-3.0.1-3-x86_64.pkg.tar.xz"
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [RFC v3 06/13] paccache: streamline usage function

2016-09-30 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/paccache.sh.in | 83 --
 1 file changed, 53 insertions(+), 30 deletions(-)

diff --git a/contrib/paccache.sh.in b/contrib/paccache.sh.in
index 02fae52..78f566f 100644
--- a/contrib/paccache.sh.in
+++ b/contrib/paccache.sh.in
@@ -30,6 +30,17 @@ declaredelim=$'\n' keep=3 movedir= scanarch=
 QUIET=0
 USE_COLOR='y'
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+   gettext() {
+   printf "%s\n" "$@"
+   }
+fi
+
 m4_include(../scripts/library/output_format.sh)
 m4_include(../scripts/library/parseopts.sh)
 
@@ -172,36 +183,48 @@ summarize() {
 }
 
 usage() {
-   cat < [options] [targets...]
-
-  Operations:
--d, --dryrun  perform a dry run, only finding candidate packages.
--m, --move   move candidate packages to "dir".
--r, --remove  remove candidate packages.
-
-  Options:
--a, --arch  scan for "arch" (default: all architectures).
--c, --cachedir   scan "dir" for packages. can be used more than once.
-  (default: read from @sysconfdir@/pacman.conf).
--f, --force   apply force to mv(1) and rm(1) operations.
--h, --helpdisplay this help message and exit.
--i, --ignoreignore "pkgs", comma-separated. Alternatively, 
specify
-  "-" to read package names from stdin, newline-
-  delimited.
--k, --keep   keep "num" of each package in the cache (default: 3).
---nocolor remove color from output.
--q, --quiet   minimize output
--u, --uninstalled target uninstalled packages.
--v, --verbose increase verbosity. specify up to 3 times.
--z, --nulluse null delimiters for candidate names (only with -v
-  and -vv).
-
-EOF
+   printf "%s (pacman) %s\n" "$myname" "$myver"
+   echo
+   printf -- "$(gettext "A flexible pacman cache cleaning utility")\n"
+   echo
+   printf -- "$(gettext "Usage: %s  [options] [targets...]")\n" 
"$0"
+   echo
+   printf -- "$(gettext "Operations:")\n"
+   printf -- "  -d, --dryrun  "
+   printf -- "$(gettext "Perform a dry run, only finding candidate 
packages")\n"
+   printf -- "  -m, --move   "
+   printf -- "$(gettext "Move candidate packages to \"dir\"")\n"
+   printf -- "  -r, --remove  "
+   printf -- "$(gettext "Remove candidate packages")\n"
+   echo
+   printf -- "$(gettext "Options:")\n"
+   printf -- "  -a, --arch  "
+   printf -- "$(gettext "Scan for \"arch\" (default: all 
architectures)")\n"
+   printf -- "  -c, --cachedir   "
+   printf -- "$(gettext "Scan \"dir\" for packages. Can be used more than 
once.\n\
+   (default: read from %s).")\n" 
"@sysconfdir@/pacman.conf"
+   printf -- "  -f, --force   "
+   printf -- "$(gettext "Apply force to mv(1) and rm(1) operations")\n" 
"\$srcdir/"
+   printf -- "  -h, --help"
+   printf -- "$(gettext "Display this help message and exit")\n"
+   printf -- "  -i, --ignore"
+   printf -- "$(gettext "Ignore \"pkgs\", comma-separated. Alternatively, 
specify\n\
+   \"-\" to read package names from stdin, 
newline-\n\
+   delimited.")\n" "\$srcdir/"
+   printf -- "  -k, --keep   "
+   printf -- "$(gettext "Keep \"num\" of each package in the cache 
(default: 3)")\n"
+   printf -- "  -q, --quiet   "
+   printf -- "$(gettext "Minimize output")\n"
+   printf -- "  -u, --uninstalled "
+   printf -- "$(gettext "Target uninstalled packages")\n"
+   printf -- "  -v, --verbose "
+   printf -- "$(gettext "Increase verbosity. specify up to 3 times.")\n"
+   printf -- "  -z, --null"
+   printf -- "$(gettext "Use null delimiters for candidate names (only 
with -v\n\
+   and -vv)")\n"
+   printf -- "  --nocolor "
+   printf -- "$(gettext "Remove color from output")\n"
+   echo
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [RFC v3 05/13] checkupdates: streamline usage function

2016-09-30 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/checkupdates.sh.in | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/contrib/checkupdates.sh.in b/contrib/checkupdates.sh.in
index ff62891..40a13ec 100644
--- a/contrib/checkupdates.sh.in
+++ b/contrib/checkupdates.sh.in
@@ -21,17 +21,29 @@
 declare -r myname='checkupdates'
 declare -r myver='@PACKAGE_VERSION@'
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+   gettext() {
+   printf "%s\n" "$@"
+   }
+fi
+
 m4_include(../scripts/library/output_format.sh)
 m4_include(../scripts/library/term_colors.sh)
 
 if (( $# > 0 )); then
-   echo "${myname} (pacman) v${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
+   echo
+   printf -- "$(gettext "Safely print a list of pending updates")\n"
echo
-   echo "Safely print a list of pending updates"
+   printf -- "$(gettext "Usage: %s")\n" "$0"
echo
-   echo "Usage: ${myname}"
+   printf -- "$(gettext "Note: Export the "%s" variable to change the path 
of the temporary database.")\n" "CHECKUPDATES_DB"
echo
-   echo 'Note: Export the "CHECKUPDATES_DB" variable to change the path of 
the temporary database.'
exit 0
 fi
 
-- 
2.10.0


[pacman-dev] [RFC v3 04/13] contrib: support localedir config in Makefile

2016-09-30 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/Makefile.am | 1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index 897cd85..0754c0d 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -60,6 +60,7 @@ REAL_PACKAGE_VERSION = $(PACKAGE_VERSION)
 endif
 
 edit = sed \
+   -e 's|@localedir[@]|$(localedir)|g' \
-e 's|@sysconfdir[@]|$(sysconfdir)|g' \
-e 's|@localstatedir[@]|$(localstatedir)|g' \
-e 's|@PACKAGE_VERSION[@]|$(REAL_PACKAGE_VERSION)|g' \
-- 
2.10.0


[pacman-dev] [RFC v3 07/13] pacdiff: streamline usage function

2016-09-30 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/pacdiff.sh.in | 67 ---
 1 file changed, 42 insertions(+), 25 deletions(-)

diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in
index 3394993..b9b15b8 100644
--- a/contrib/pacdiff.sh.in
+++ b/contrib/pacdiff.sh.in
@@ -29,35 +29,52 @@ USE_COLOR='y'
 declare -a oldsaves
 declare -i USE_FIND=0 USE_LOCATE=0 USE_PACDB=0 OUTPUTONLY=0
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+   gettext() {
+   printf "%s\n" "$@"
+   }
+fi
+
 m4_include(../scripts/library/output_format.sh)
 m4_include(../scripts/library/parseopts.sh)
 
 usage() {
-   cat < [options]")\n" "$0"
+   echo
+   printf -- "$(gettext "Search Options:")\n"
+   printf -- "  -l, --locate  "
+   printf -- "$(gettext "Scan using locate")\n"
+   printf -- "  -f, --find"
+   printf -- "$(gettext "Scan using find")\n"
+   printf -- "  -p, --pacmandb"
+   printf -- "$(gettext "Scan active config files from pacman database")\n"
+   echo
+   printf -- "$(gettext "Options:")\n"
+   printf -- "  -o, --output  "
+   printf -- "$(gettext "Print files instead of merging them")\n"
+   printf -- "  -m, --nocolor "
+   printf -- "$(gettext "Remove colors from output")\n"
+   echo
+   printf -- "$(gettext "Environment Variables:")\n"
+   printf -- "  DIFFPROG  "
+   printf -- "$(gettext "Override the merge program: (default: '%s')")\n" 
"vim -d"
+   printf -- "  DIFFSEARCHPATH"
+   printf -- "$(gettext "Override the search path. (only when using 
find)\n\
+   (default: %s)")\n" "/etc"
+   echo
+   printf -- "$(gettext "Examples:")"
+   printf -- "DIFFPROG=meld DIFFSEARCHPATH=\"/boot /etc /usr\" %s\n" 
"$myname"
+   printf -- "%s --output --locate\n" "$myname"
+   echo
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [RFC v3 08/13] paclist: streamline usage function

2016-09-30 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/paclist.sh.in | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/contrib/paclist.sh.in b/contrib/paclist.sh.in
index f4fd540..47589f7 100644
--- a/contrib/paclist.sh.in
+++ b/contrib/paclist.sh.in
@@ -20,24 +20,27 @@
 declare -r myname='paclist'
 declare -r myver='@PACKAGE_VERSION@'
 
+# gettext initialization
 export TEXTDOMAIN='pacman'
-export TEXTDOMAINDIR='/usr/share/locale'
+export TEXTDOMAINDIR='@localedir@'
 
 # determine whether we have gettext; make it a no-op if we do not
-if ! type gettext &>/dev/null; then
+if ! type -p gettext >/dev/null; then
gettext() {
-   echo "$@"
+   printf "%s\n" "$@"
}
 fi
 
 usage() {
-   printf "%s (pacman) v%s\n" "${myname}" "${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
echo
-   printf "List all packages installed from a given repository\n" 
"${myname}"
+   printf -- "$(gettext "List all packages installed from a given 
repository")\n"
echo
-   printf "Usage: %s \n" "${myname}"
+   printf -- "$(gettext "Usage: %s ")\n" "$0"
+   echo
+   printf -- "$(gettext "Examples:")"
+   printf -- "%s testing\n" "$myname"
echo
-   printf "Example: %s testing\n" "${myname}"
 }
 
 version() {
-- 
2.10.0


Re: [pacman-dev] [PATCH 00/11] Streamline syntax of contrib scripts

2016-09-30 Thread Gordian Edenhofer
On Thu, 2016-09-29 at 09:56 -0400, Dave Reisner wrote:
> On Thu, Sep 29, 2016 at 03:30:30PM +0200, Gordian Edenhofer wrote:
> > 
> > On Thu, 2016-09-29 at 09:04 -0400, Dave Reisner wrote:
> > > 
> > > On Thu, Sep 29, 2016 at 12:23:00PM +0200, Gordian Edenhofer
> > > wrote:
> > > > 
> > > > 
> > > > Reorganize scripts in contrib to fit the syntax and style of
> > > > makepkg.
> > > > Unify multiple different approaches to e.g. write a usage
> > > > function,
> > > > handle
> > > > options and differences in naming schemas for options.
> > > 
> > > Again, you're still putting flag names in the translatable
> > > strings.
> > > This
> > > will only ever end badly.
> > 
> > It has worked great for makepkg, see the git repo for dozens of
> > examples [1].
> > 
> > [1] https://git.archlinux.org/pacman.git/tree/scripts/makepkg.sh.in
> > #n11
> > 66
> 
> Has it worked great?
> 
> - id.po contains --noprapare instead of --noprepare
> - da.po contains --finer instead of --finger
> - sv.po contains --inout instead of --input
> 
> Repeating this mistake of allowing flags to be translated is purely
> cargo-cult nonsense. Please don't do it.

Ok, I will resubmit a new version with non-translatable flags.

signature.asc
Description: This is a digitally signed message part


Re: [pacman-dev] [PATCH 00/11] Streamline syntax of contrib scripts

2016-09-29 Thread Gordian Edenhofer
On Thu, 2016-09-29 at 09:04 -0400, Dave Reisner wrote:
> On Thu, Sep 29, 2016 at 12:23:00PM +0200, Gordian Edenhofer wrote:
> > 
> > Reorganize scripts in contrib to fit the syntax and style of
> > makepkg.
> > Unify multiple different approaches to e.g. write a usage function,
> > handle
> > options and differences in naming schemas for options.
> 
> Again, you're still putting flag names in the translatable strings.
> This
> will only ever end badly.

It has worked great for makepkg, see the git repo for dozens of
examples [1].

[1] https://git.archlinux.org/pacman.git/tree/scripts/makepkg.sh.in#n11
66

signature.asc
Description: This is a digitally signed message part


[pacman-dev] [RFC v2 07/13] pacdiff: streamline usage function

2016-09-29 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/pacdiff.sh.in | 61 ++-
 1 file changed, 36 insertions(+), 25 deletions(-)

diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in
index 3394993..80fd1f8 100644
--- a/contrib/pacdiff.sh.in
+++ b/contrib/pacdiff.sh.in
@@ -29,35 +29,46 @@ USE_COLOR='y'
 declare -a oldsaves
 declare -i USE_FIND=0 USE_LOCATE=0 USE_PACDB=0 OUTPUTONLY=0
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+   gettext() {
+   printf "%s\n" "$@"
+   }
+fi
+
 m4_include(../scripts/library/output_format.sh)
 m4_include(../scripts/library/parseopts.sh)
 
 usage() {
-   cat < [options]")\n" "$0"
+   echo
+   printf -- "$(gettext "Search Options:")\n"
+   printf -- "$(gettext "  -l, --locate  Scan using locate")\n"
+   printf -- "$(gettext "  -f, --findScan using find")\n"
+   printf -- "$(gettext "  -p, --pacmandbScan active config files from 
pacman database")\n"
+   echo
+   printf -- "$(gettext "Options:")\n"
+   printf -- "$(gettext "  -o, --output  Print files instead of 
merging them")\n"
+   printf -- "$(gettext "  -m, --nocolor Remove colors from output")\n"
+   echo
+   printf -- "$(gettext "Environment Variables:")\n"
+   printf -- "$(gettext "  DIFFPROG  Override the merge program: 
(default: 'vim -d')")\n"
+   printf -- "$(gettext "\
+  DIFFSEARCHPATHOverride the search path. (only when using find)\n\
+(default: /etc)")\n"
+   echo
+   printf -- "$(gettext "Examples:")"
+   printf -- "DIFFPROG=meld DIFFSEARCHPATH=\"/boot /etc /usr\" %s\n" 
"$myname"
+   printf -- "%s --output --locate\n" "$myname"
+   echo
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [RFC v2 09/13] paclog-pkglist: streamline usage function

2016-09-29 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/paclog-pkglist.sh.in | 25 ++---
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/contrib/paclog-pkglist.sh.in b/contrib/paclog-pkglist.sh.in
index 847b389..040e183 100644
--- a/contrib/paclog-pkglist.sh.in
+++ b/contrib/paclog-pkglist.sh.in
@@ -20,20 +20,31 @@
 declare -r myname='paclog-pkglist'
 declare -r myver='@PACKAGE_VERSION@'
 
-export TEXTDOMAIN='pacman'
-export TEXTDOMAINDIR='/usr/share/locale'
 declare logfile=${1:-@localstatedir@/log/pacman.log}
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+   gettext() {
+   printf "%s\n" "$@"
+   }
+fi
+
 usage() {
-   printf "%s (pacman) v%s\n" "${myname}" "${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
+   echo
+   printf -- "$(gettext "Parse a log file into a list of currently 
installed packages")\n"
echo
-   echo "Parse a log file into a list of currently installed packages"
+   printf -- "$(gettext "Usage: %s [path to pacman log]")\n" "$0"
echo
-   printf "Usage: %s [path to pacman log]\n" "${myname}"
+   printf -- "$(gettext "Examples:")"
+   printf -- "%s @localstatedir@/log/pacman.log\n" "$myname"
echo
-   printf "Example: %s @localstatedir@/log/pacman.log\n" "${myname}"
+   printf -- "$(gettext "Defaults to: @localstatedir@/log/pacman.log")\n"
echo
-   echo 'Defaults to: @localstatedir@/log/pacman.log'
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [RFC v2 13/13] bacman: make gettext useful

2016-09-29 Thread Gordian Edenhofer
Export TEXTDOMAIN and TEXTDOMAINDIR in order for the strings to be
translatable with gettext.
---
 contrib/bacman.sh.in | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 39fbe99..cce5a1e 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -32,6 +32,17 @@ QUIET=0
 # Required for fakeroot because options are shifted off the array.
 ARGS=("$@")
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+   gettext() {
+   printf "%s\n" "$@"
+   }
+fi
+
 m4_include(../scripts/library/output_format.sh)
 m4_include(../scripts/library/parseopts.sh)
 
-- 
2.10.0


[pacman-dev] [RFC v2 12/13] rankmirrors: streamline usage function

2016-09-29 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/rankmirrors.sh.in | 41 -
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/contrib/rankmirrors.sh.in b/contrib/rankmirrors.sh.in
index 0988fe9..bd65d73 100644
--- a/contrib/rankmirrors.sh.in
+++ b/contrib/rankmirrors.sh.in
@@ -24,23 +24,38 @@ trap finaloutput INT
 declare -r myname='rankmirrors'
 declare -r myver='@PACKAGE_VERSION@'
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+   gettext() {
+   printf "%s\n" "$@"
+   }
+fi
+
+m4_include(../scripts/library/parseopts.sh)
+
 usage() {
-   echo "${myname} (pacman) v${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
+   echo
+   printf -- "$(gettext "\
+Ranks pacman mirrors by their connection and opening speed. Pacman mirror\n\
+files are located in @sysconfdir@/pacman.d/. It can also rank one mirror if 
the URL is\n\
+provided")\n"
echo
-   echo "Ranks pacman mirrors by their connection and opening speed. 
Pacman mirror"
-   echo "files are located in @sysconfdir@/pacman.d/. It can also rank one 
mirror if the URL is"
-   echo "provided."
+   printf -- "$(gettext "Usage: %s [options] <mirrorfile|URL>")\n" "$0"
echo
-   echo "Usage: ${myname} [options] MIRRORFILE | URL"
+   printf -- "$(gettext "Options:")\n"
+   printf -- "$(gettext "  -h, --help Show this help message and 
exit")\n"
+   printf -- "$(gettext "  -n  Number of servers to output, 
0 for all")\n"
+   printf -- "$(gettext "  -t, --timesOnly output mirrors and 
their response times")\n"
+   printf -- "$(gettext "  -u, --url  Test a specific URL")\n"
+   printf -- "$(gettext "  -v, --verbose  Be verbose in ouptut")\n"
+   printf -- "$(gettext "  -r, --repo   Specify a repository name 
instead of guessing")\n"
+   printf -- "$(gettext "  --version  Show program's version 
number and exit")\n"
echo
-   echo "Options:"
-   echo "  --version  show program's version number and exit"
-   echo "  -h, --help show this help message and exit"
-   echo "  -n NUM number of servers to output, 0 for all"
-   echo "  -t, --timesonly output mirrors and their response times"
-   echo "  -u, --url  test a specific URL"
-   echo "  -v, --verbose  be verbose in ouptut"
-   echo "  -r, --repo specify a repository name instead of guessing"
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [RFC v2 10/13] pacscripts: streamline usage function

2016-09-29 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/pacscripts.sh.in | 29 +
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/contrib/pacscripts.sh.in b/contrib/pacscripts.sh.in
index 4a1e0c5..40fd4be 100644
--- a/contrib/pacscripts.sh.in
+++ b/contrib/pacscripts.sh.in
@@ -27,6 +27,17 @@ set -o errexit
 declare -r myname='pacscripts'
 declare -r myver='@PACKAGE_VERSION@'
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+   gettext() {
+   printf "%s\n" "$@"
+   }
+fi
+
 conf="@sysconfdir@/pacman.conf"
 
 if [ ! -r "$conf" ]; then
@@ -45,18 +56,20 @@ error() {
 }
 
 usage() {
-   echo "${myname} (pacman) v${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
+   echo
+   printf -- "$(gettext "Prints the {pre,post}_{install,remove,upgrade} 
scripts of a given package")\n"
echo
-   echo "Prints the {pre,post}_{install,remove,upgrade} scripts of a given 
package."
+   printf -- "$(gettext "Usage: %s <pkgname|pkgfile>")\n" "$0"
echo
-   echo "Usage: ${myname} <pkgname|pkgfile>"
+   printf -- "$(gettext "Options:")\n"
+   printf -- "$(gettext "  -h, --help Print this help message")\n"
+   printf -- "$(gettext "  -v, --version  Print program name and 
version")\n"
echo
-   echo " Options:"
-   echo "  -h, --help Print this help message"
-   echo "  -v, --version  Print program name and version"
+   printf -- "$(gettext "Examples:")"
+   printf -- "  %s gconf-editor\n" "$myname"
+   printf -- "  %s gconf-editor-3.0.1-3-x86_64.pkg.tar.xz\n" "$myname"
echo
-   echo "Example: ${myname} gconf-editor"
-   echo "Example: ${myname} gconf-editor-3.0.1-3-x86_64.pkg.tar.xz"
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [RFC v2 06/13] paccache: streamline usage function

2016-09-29 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/paccache.sh.in | 72 +-
 1 file changed, 42 insertions(+), 30 deletions(-)

diff --git a/contrib/paccache.sh.in b/contrib/paccache.sh.in
index 02fae52..59ebbac 100644
--- a/contrib/paccache.sh.in
+++ b/contrib/paccache.sh.in
@@ -30,6 +30,17 @@ declaredelim=$'\n' keep=3 movedir= scanarch=
 QUIET=0
 USE_COLOR='y'
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+   gettext() {
+   printf "%s\n" "$@"
+   }
+fi
+
 m4_include(../scripts/library/output_format.sh)
 m4_include(../scripts/library/parseopts.sh)
 
@@ -172,36 +183,37 @@ summarize() {
 }
 
 usage() {
-   cat < [options] [targets...]
-
-  Operations:
--d, --dryrun  perform a dry run, only finding candidate packages.
--m, --move   move candidate packages to "dir".
--r, --remove  remove candidate packages.
-
-  Options:
--a, --arch  scan for "arch" (default: all architectures).
--c, --cachedir   scan "dir" for packages. can be used more than once.
-  (default: read from @sysconfdir@/pacman.conf).
--f, --force   apply force to mv(1) and rm(1) operations.
--h, --helpdisplay this help message and exit.
--i, --ignoreignore "pkgs", comma-separated. Alternatively, 
specify
-  "-" to read package names from stdin, newline-
-  delimited.
--k, --keep   keep "num" of each package in the cache (default: 3).
---nocolor remove color from output.
--q, --quiet   minimize output
--u, --uninstalled target uninstalled packages.
--v, --verbose increase verbosity. specify up to 3 times.
--z, --nulluse null delimiters for candidate names (only with -v
-  and -vv).
-
-EOF
+   printf "%s (pacman) %s\n" "$myname" "$myver"
+   echo
+   printf -- "$(gettext "A flexible pacman cache cleaning utility")\n"
+   echo
+   printf -- "$(gettext "Usage: %s  [options] [targets...]")\n" 
"$0"
+   echo
+   printf -- "$(gettext "Operations:")\n"
+   printf -- "$(gettext "  -d, --dryrun  Perform a dry run, only 
finding candidate packages")\n"
+   printf -- "$(gettext "  -m, --move   Move candidate packages 
to \"dir\"")\n"
+   printf -- "$(gettext "  -r, --remove  Remove candidate 
packages")\n"
+   echo
+   printf -- "$(gettext "Options:")\n"
+   printf -- "$(gettext "  -a, --arch  Scan for \"arch\" 
(default: all architectures)")\n"
+   printf -- "$(gettext "\
+  -c, --cachedir   Scan \"dir\" for packages. Can be used more than 
once.\n\
+(default: read from @sysconfdir@/pacman.conf).")\n"
+   printf -- "$(gettext "  -f, --force   Apply force to mv(1) and 
rm(1) operations")\n" "\$srcdir/"
+   printf -- "$(gettext "  -h, --helpDisplay this help message 
and exit")\n"
+   printf -- "$(gettext "\
+  -i, --ignoreIgnore \"pkgs\", comma-separated. Alternatively, 
specify\n\
+\"-\" to read package names from stdin, newline-\n\
+delimited.")\n" "\$srcdir/"
+   printf -- "$(gettext "  -k, --keep   Keep \"num\" of each 
package in the cache (default: 3)")\n"
+   printf -- "$(gettext "  -q, --quiet   Minimize output")\n"
+   printf -- "$(gettext "  -u, --uninstalled Target uninstalled 
packages")\n"
+   printf -- "$(gettext "  -v, --verbose Increase verbosity. 
specify up to 3 times.")\n"
+   printf -- "$(gettext "\
+  -z, --nullUse null delimiters for candidate names (only with 
-v\n\
+and -vv)")\n"
+   printf -- "$(gettext "  --nocolor Remove color from 
output")\n"
+   echo
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [RFC v2 08/13] paclist: streamline usage function

2016-09-29 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/paclist.sh.in | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/contrib/paclist.sh.in b/contrib/paclist.sh.in
index f4fd540..47589f7 100644
--- a/contrib/paclist.sh.in
+++ b/contrib/paclist.sh.in
@@ -20,24 +20,27 @@
 declare -r myname='paclist'
 declare -r myver='@PACKAGE_VERSION@'
 
+# gettext initialization
 export TEXTDOMAIN='pacman'
-export TEXTDOMAINDIR='/usr/share/locale'
+export TEXTDOMAINDIR='@localedir@'
 
 # determine whether we have gettext; make it a no-op if we do not
-if ! type gettext &>/dev/null; then
+if ! type -p gettext >/dev/null; then
gettext() {
-   echo "$@"
+   printf "%s\n" "$@"
}
 fi
 
 usage() {
-   printf "%s (pacman) v%s\n" "${myname}" "${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
echo
-   printf "List all packages installed from a given repository\n" 
"${myname}"
+   printf -- "$(gettext "List all packages installed from a given 
repository")\n"
echo
-   printf "Usage: %s \n" "${myname}"
+   printf -- "$(gettext "Usage: %s ")\n" "$0"
+   echo
+   printf -- "$(gettext "Examples:")"
+   printf -- "%s testing\n" "$myname"
echo
-   printf "Example: %s testing\n" "${myname}"
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [RFC v2 04/13] contrib: support localedir config in Makefile

2016-09-29 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/Makefile.am | 1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index 897cd85..0754c0d 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -60,6 +60,7 @@ REAL_PACKAGE_VERSION = $(PACKAGE_VERSION)
 endif
 
 edit = sed \
+   -e 's|@localedir[@]|$(localedir)|g' \
-e 's|@sysconfdir[@]|$(sysconfdir)|g' \
-e 's|@localstatedir[@]|$(localstatedir)|g' \
-e 's|@PACKAGE_VERSION[@]|$(REAL_PACKAGE_VERSION)|g' \
-- 
2.10.0


[pacman-dev] [RFC v2 05/13] checkupdates: streamline usage function

2016-09-29 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/checkupdates.sh.in | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/contrib/checkupdates.sh.in b/contrib/checkupdates.sh.in
index ff62891..40a13ec 100644
--- a/contrib/checkupdates.sh.in
+++ b/contrib/checkupdates.sh.in
@@ -21,17 +21,29 @@
 declare -r myname='checkupdates'
 declare -r myver='@PACKAGE_VERSION@'
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+   gettext() {
+   printf "%s\n" "$@"
+   }
+fi
+
 m4_include(../scripts/library/output_format.sh)
 m4_include(../scripts/library/term_colors.sh)
 
 if (( $# > 0 )); then
-   echo "${myname} (pacman) v${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
+   echo
+   printf -- "$(gettext "Safely print a list of pending updates")\n"
echo
-   echo "Safely print a list of pending updates"
+   printf -- "$(gettext "Usage: %s")\n" "$0"
echo
-   echo "Usage: ${myname}"
+   printf -- "$(gettext "Note: Export the "%s" variable to change the path 
of the temporary database.")\n" "CHECKUPDATES_DB"
echo
-   echo 'Note: Export the "CHECKUPDATES_DB" variable to change the path of 
the temporary database.'
exit 0
 fi
 
-- 
2.10.0


[pacman-dev] [RFC v2 02/13] pacdiff: streamline option syntax with makepkg

2016-09-29 Thread Gordian Edenhofer
Allow for '-m' as abbreviation for '--nocolor'.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/pacdiff.sh.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in
index cd93164..3394993 100644
--- a/contrib/pacdiff.sh.in
+++ b/contrib/pacdiff.sh.in
@@ -47,7 +47,7 @@ Search Options: select one (default: --pacmandb)
 
 General Options:
   -o/--output   print files instead of merging them
-  --nocolor remove colors from output
+  -m/--nocolor  remove colors from output
 
 Environment Variables:
   DIFFPROG  override the merge program: (default: 'vim -d')
@@ -96,7 +96,7 @@ cmd() {
 }
 
 # Parse arguments
-OPT_SHORT='lfpoVh'
+OPT_SHORT='lfpomVh'
 OPT_LONG=('locate' 'find' 'pacmandb' 'output' 'nocolor' 'version' 'help')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
@@ -115,7 +115,7 @@ while :; do
USE_PACDB=1;;
-o|--output)
OUTPUTONLY=1;;
-   --nocolor)
+   -m|--nocolor)
USE_COLOR='n';;
-V|--version)
version
-- 
2.10.0


[pacman-dev] [RFC v2 03/13] rankmirrors: proper option handling

2016-09-29 Thread Gordian Edenhofer
Switch to parseopts.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/rankmirrors.sh.in | 102 +-
 1 file changed, 46 insertions(+), 56 deletions(-)

diff --git a/contrib/rankmirrors.sh.in b/contrib/rankmirrors.sh.in
index 7b50eb2..0988fe9 100644
--- a/contrib/rankmirrors.sh.in
+++ b/contrib/rankmirrors.sh.in
@@ -41,7 +41,6 @@ usage() {
echo "  -u, --url  test a specific URL"
echo "  -v, --verbose  be verbose in ouptut"
echo "  -r, --repo specify a repository name instead of guessing"
-   exit 0
 }
 
 version() {
@@ -120,68 +119,59 @@ finaloutput() {
exit 0
 }
 
-
-# Argument parsing
-[[ $1 ]] || usage
-while [[ $1 ]]; do
-   if [[ ${1:0:2} = -- ]]; then
-   case "${1:2}" in
-   help) usage ;;
-   version) version ;;
-   times) TIMESONLY=1 ; shift ;;
-   verbose) VERBOSE=1 ; shift ;;
-   url)
-   CHECKURL=1;
-   [[ $2 ]] || err "Must specify URL.";
-   URL="$2";
-   shift 2;;
-   repo)
-   [[ $2 ]] || err "Must specify repository name.";
-   TARGETREPO="$2";
-   shift 2;;
-   *) err "'$1' is an invalid argument."
-   esac
-   elif [[ ${1:0:1} = - ]]; then
-
-   if [[ ! ${1:1:1} ]]; then
-   [[ -t 0 ]] && err "Stdin is empty."
-   IFS=$'\n' linearray=( $(

[pacman-dev] [RFC v2 01/13] pacdiff: proper option handling

2016-09-29 Thread Gordian Edenhofer
Switch to parseopts.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/pacdiff.sh.in | 24 +++-
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in
index dff2115..cd93164 100644
--- a/contrib/pacdiff.sh.in
+++ b/contrib/pacdiff.sh.in
@@ -30,6 +30,7 @@ declare -a oldsaves
 declare -i USE_FIND=0 USE_LOCATE=0 USE_PACDB=0 OUTPUTONLY=0
 
 m4_include(../scripts/library/output_format.sh)
+m4_include(../scripts/library/parseopts.sh)
 
 usage() {
cat <

Re: [pacman-dev] [PATCH 00/11] Streamline syntax of contrib scripts

2016-09-29 Thread Gordian Edenhofer
On Thu, 2016-09-29 at 21:39 +1000, Allan McRae wrote:
> On 29/09/16 21:25, Gordian Edenhofer wrote:
> > 
> > On Thu, 2016-09-29 at 20:40 +1000, Dave Reisner wrote:
> > > 
> > > On Sep 29, 2016 06:23, "Gordian Edenhofer" <gordian.edenhofer@gma
> > > il.c
> > > om>
> > > wrote:
> > > 
> > > Reorganize scripts in contrib to fit the syntax and style of
> > > makepkg.
> > > Unify multiple different approaches to e.g. write a usage
> > > function,
> > > handle
> > > options and differences in naming schemas for options.
> > > 
> > > 
> > > None of your changes which add gettext support are useful in
> > > their
> > > current
> > > form as you do not export TEXTDOMAIN or TEXTDOMAINDIR.
> > 
> > Thanks for the hint! I forgot about that.
> > Btw. paclist [1] already defined it.
> > 
> > [1] https://git.archlinux.org/pacman.git/tree/contrib/paclist.sh.in
> > #n23
> > 
> 
> It only works for paclist because it uses translations already
> provided
> by pacman.  This will not work for anything else because strings from
> the contrib files are not added to the pacman translation.
> 
> A new translation domain for contrib needs set-up if this is to work.

Thanks for the explanation.
To be honest I don't know how to setup a translation domain since I
haven't read any documentation about this matter yet. I would
appreciate if anybody could help me with this. Until then I will
resumbit this patch as RFC once more and order commits according to
whether they touch usage.
An alternative approach would be to strip all gettext invocations and
simply not make contrib script translatable.

signature.asc
Description: This is a digitally signed message part


Re: [pacman-dev] [PATCH 01/11] checkupdates: streamline usage function

2016-09-29 Thread Gordian Edenhofer
On Thu, 2016-09-29 at 20:41 +1000, Allan McRae wrote:
> On 29/09/16 20:37, Dave Reisner wrote:
> > 
> > On Sep 29, 2016 06:23, "Gordian Edenhofer" <gordian.edenhofer@gmail
> > .com>
> > wrote:
> > 
> > Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
> > ---
> >  contrib/checkupdates.sh.in | 9 +
> >  1 file changed, 5 insertions(+), 4 deletions(-)
> > 
> > diff --git a/contrib/checkupdates.sh.in
> > b/contrib/checkupdates.sh.in
> > index ff62891..8c04370 100644
> > --- a/contrib/checkupdates.sh.in
> > +++ b/contrib/checkupdates.sh.in
> > @@ -25,13 +25,14 @@ m4_include(../scripts/library/output_format.sh)
> >  m4_include(../scripts/library/term_colors.sh)
> > 
> >  if (( $# > 0 )); then
> > -   echo "${myname} (pacman) v${myver}"
> > +   printf "%s (pacman) %s\n" "$myname" "$myver"
> > echo
> > -   echo "Safely print a list of pending updates"
> > +   printf -- "$(gettext "Safely print a list of pending
> > updates")\n"
> > echo
> > -   echo "Usage: ${myname}"
> > +   printf -- "$(gettext "Usage: %s")\n" "$0"
> > +   echo
> > +   printf -- "$(gettext "Note: Export the "CHECKUPDATES_DB"
> > variable
> > to change the path of the temporary database.")\n"
> > 
> > 
> > This is broken -- double quotes do not nest like this, and they're
> > effectively dropped. I also question the value of adding gettext
> > support to
> > untranslated scripts and including flag/envvar names as part of the
> > translatable strings -- that won't end well as some translator
> > *will* get
> > it wrong.

Right, that envvar does not belong there. Thanks again!
However the quotation thing is done exactly the same in makepkg [1].

> Worse than that...  contrib is not set up as translatable at all.   I
> missed that when reviewing the bacman patches.

Sorry about that! I though gettext was ok, since paclist [2] uses it as
well.

[1] https://git.archlinux.org/pacman.git/tree/scripts/makepkg.sh.in#n11
66
[2] https://git.archlinux.org/pacman.git/tree/contrib/paclist.sh.in#n23

signature.asc
Description: This is a digitally signed message part


Re: [pacman-dev] [PATCH 00/11] Streamline syntax of contrib scripts

2016-09-29 Thread Gordian Edenhofer
On Thu, 2016-09-29 at 20:40 +1000, Dave Reisner wrote:
> On Sep 29, 2016 06:23, "Gordian Edenhofer" <gordian.edenhofer@gmail.c
> om>
> wrote:
> 
> Reorganize scripts in contrib to fit the syntax and style of makepkg.
> Unify multiple different approaches to e.g. write a usage function,
> handle
> options and differences in naming schemas for options.
> 
> 
> None of your changes which add gettext support are useful in their
> current
> form as you do not export TEXTDOMAIN or TEXTDOMAINDIR.

Thanks for the hint! I forgot about that.
Btw. paclist [1] already defined it.

[1] https://git.archlinux.org/pacman.git/tree/contrib/paclist.sh.in#n23

signature.asc
Description: This is a digitally signed message part


[pacman-dev] [PATCH 04/11] pacdiff: proper option handling

2016-09-29 Thread Gordian Edenhofer
Switch to parseopts.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/pacdiff.sh.in | 24 +++-
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in
index 840e36f..bed9ea3 100644
--- a/contrib/pacdiff.sh.in
+++ b/contrib/pacdiff.sh.in
@@ -30,6 +30,7 @@ declare -a oldsaves
 declare -i USE_FIND=0 USE_LOCATE=0 USE_PACDB=0 OUTPUTONLY=0
 
 m4_include(../scripts/library/output_format.sh)
+m4_include(../scripts/library/parseopts.sh)
 
 usage() {
printf "%s (pacman) %s\n" "$myname" "$myver"
@@ -94,7 +95,17 @@ cmd() {
fi
 }
 
-while [[ -n "$1" ]]; do
+# Parse arguments
+OPT_SHORT='lfpoVh'
+OPT_LONG=('locate' 'find' 'pacmandb' 'output' 'nocolor' 'version' 'help')
+if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
+   usage
+   exit 1
+fi
+set -- "${OPTRET[@]}"
+unset OPT_SHORT OPT_LONG OPTRET
+
+while :; do
case "$1" in
-l|--locate)
USE_LOCATE=1;;
@@ -107,11 +118,14 @@ while [[ -n "$1" ]]; do
--nocolor)
USE_COLOR='n';;
-V|--version)
-   version; exit 0;;
+   version
+   exit 0;;
-h|--help)
-   usage; exit 0;;
-   *)
-   usage; exit 1;;
+   usage
+   exit 0;;
+   --)
+   shift
+   break 2;;
esac
shift
 done
-- 
2.10.0


[pacman-dev] [PATCH 09/11] updpkgsums: streamline usage function

2016-09-29 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/updpkgsums.sh.in | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/contrib/updpkgsums.sh.in b/contrib/updpkgsums.sh.in
index c571d29..5b68765 100644
--- a/contrib/updpkgsums.sh.in
+++ b/contrib/updpkgsums.sh.in
@@ -23,19 +23,22 @@ declare -r myname='updpkgsums'
 declare -r myver='@PACKAGE_VERSION@'
 
 usage() {
-   printf "%s (pacman) v%s\n" "${myname}" "${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
echo
-   printf "%s will perform an in place update of the checksums in the\n" 
"${myname}"
-   echo "path specified by [build file], defaulting to PKGBUILD in the 
current"
-   echo "working directory."
+   printf -- "$(gettext "\
+%s will perform an in place update of the checksums in the\n\
+path specified by [build file], defaulting to PKGBUILD in the current\n\
+working directory")\n" "$myname"
echo
-   printf "Usage: %s [options] [build file]\n" "${myname}"
+   printf -- "$(gettext "Usage: %s [options] [build file]")\n" "$0"
echo
-   echo "-h, --helpdisplay this help message and exit"
-   echo "-V, --version display version information and exit"
+   printf -- "$(gettext "Options:")\n"
+   printf -- "$(gettext "  -h, --helpDisplay this help message and 
exit")\n"
+   printf -- "$(gettext "  -V, --version Display version information 
and exit")\n"
+   echo
+   printf -- "$(gettext "These options can be passed to makepkg:")\n"
+   printf -- "$(gettext "  -m, --nocolor Disable colorized output 
messages")\n"
echo
-   echo "These options can be passed to makepkg:"
-   echo "-m, --nocolor disable colorized output messages"
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [PATCH 08/11] pacscripts: streamline usage function

2016-09-29 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/pacscripts.sh.in | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/contrib/pacscripts.sh.in b/contrib/pacscripts.sh.in
index 4a1e0c5..de94843 100644
--- a/contrib/pacscripts.sh.in
+++ b/contrib/pacscripts.sh.in
@@ -45,18 +45,20 @@ error() {
 }
 
 usage() {
-   echo "${myname} (pacman) v${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
echo
-   echo "Prints the {pre,post}_{install,remove,upgrade} scripts of a given 
package."
+   printf -- "$(gettext "Prints the {pre,post}_{install,remove,upgrade} 
scripts of a given package")\n"
echo
-   echo "Usage: ${myname} <pkgname|pkgfile>"
+   printf -- "$(gettext "Usage: %s <pkgname|pkgfile>")\n" "$0"
echo
-   echo " Options:"
-   echo "  -h, --help Print this help message"
-   echo "  -v, --version  Print program name and version"
+   printf -- "$(gettext "Options:")\n"
+   printf -- "$(gettext "  -h, --help Print this help message")\n"
+   printf -- "$(gettext "  -v, --version  Print program name and 
version")\n"
+   echo
+   printf -- "$(gettext "Examples:")"
+   printf -- "  %s gconf-editor\n" "$myname"
+   printf -- "  %s gconf-editor-3.0.1-3-x86_64.pkg.tar.xz\n" "$myname"
echo
-   echo "Example: ${myname} gconf-editor"
-   echo "Example: ${myname} gconf-editor-3.0.1-3-x86_64.pkg.tar.xz"
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [PATCH 11/11] rankmirrors: proper option handling

2016-09-29 Thread Gordian Edenhofer
Switch to parseopts.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/rankmirrors.sh.in | 104 +-
 1 file changed, 48 insertions(+), 56 deletions(-)

diff --git a/contrib/rankmirrors.sh.in b/contrib/rankmirrors.sh.in
index 6ded91f..c0f2316 100644
--- a/contrib/rankmirrors.sh.in
+++ b/contrib/rankmirrors.sh.in
@@ -24,6 +24,8 @@ trap finaloutput INT
 declare -r myname='rankmirrors'
 declare -r myver='@PACKAGE_VERSION@'
 
+m4_include(../scripts/library/parseopts.sh)
+
 usage() {
printf "%s (pacman) %s\n" "$myname" "$myver"
echo
@@ -43,7 +45,6 @@ provided")\n"
printf -- "$(gettext "  -r, --repo   Specify a repository name 
instead of guessing")\n"
printf -- "$(gettext "  --version  Show program's version 
number and exit")\n"
echo
-   exit 0
 }
 
 version() {
@@ -122,68 +123,59 @@ finaloutput() {
exit 0
 }
 
-
-# Argument parsing
-[[ $1 ]] || usage
-while [[ $1 ]]; do
-   if [[ ${1:0:2} = -- ]]; then
-   case "${1:2}" in
-   help) usage ;;
-   version) version ;;
-   times) TIMESONLY=1 ; shift ;;
-   verbose) VERBOSE=1 ; shift ;;
-   url)
-   CHECKURL=1;
-   [[ $2 ]] || err "Must specify URL.";
-   URL="$2";
-   shift 2;;
-   repo)
-   [[ $2 ]] || err "Must specify repository name.";
-   TARGETREPO="$2";
-   shift 2;;
-   *) err "'$1' is an invalid argument."
-   esac
-   elif [[ ${1:0:1} = - ]]; then
-
-   if [[ ! ${1:1:1} ]]; then
-   [[ -t 0 ]] && err "Stdin is empty."
-   IFS=$'\n' linearray=( $(

[pacman-dev] [PATCH 07/11] paclog-pkglist: streamline usage function

2016-09-29 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/paclog-pkglist.sh.in | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/contrib/paclog-pkglist.sh.in b/contrib/paclog-pkglist.sh.in
index 847b389..6e9bced 100644
--- a/contrib/paclog-pkglist.sh.in
+++ b/contrib/paclog-pkglist.sh.in
@@ -25,15 +25,17 @@ export TEXTDOMAINDIR='/usr/share/locale'
 declare logfile=${1:-@localstatedir@/log/pacman.log}
 
 usage() {
-   printf "%s (pacman) v%s\n" "${myname}" "${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
echo
-   echo "Parse a log file into a list of currently installed packages"
+   printf -- "$(gettext "Parse a log file into a list of currently 
installed packages")\n"
echo
-   printf "Usage: %s [path to pacman log]\n" "${myname}"
+   printf -- "$(gettext "Usage: %s [path to pacman log]")\n" "$0"
echo
-   printf "Example: %s @localstatedir@/log/pacman.log\n" "${myname}"
+   printf -- "$(gettext "Examples:")"
+   printf -- "%s @localstatedir@/log/pacman.log\n" "$myname"
+   echo
+   printf -- "$(gettext "Defaults to: @localstatedir@/log/pacman.log")\n"
echo
-   echo 'Defaults to: @localstatedir@/log/pacman.log'
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [PATCH 03/11] pacdiff: streamline usage function

2016-09-29 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/pacdiff.sh.in | 50 +-
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in
index dff2115..840e36f 100644
--- a/contrib/pacdiff.sh.in
+++ b/contrib/pacdiff.sh.in
@@ -32,31 +32,31 @@ declare -i USE_FIND=0 USE_LOCATE=0 USE_PACDB=0 OUTPUTONLY=0
 m4_include(../scripts/library/output_format.sh)
 
 usage() {
-   cat < [options]")\n" "$0"
+   echo
+   printf -- "$(gettext "Search Options:")\n"
+   printf -- "$(gettext "  -l, --locate  Scan using locate")\n"
+   printf -- "$(gettext "  -f, --findScan using find")\n"
+   printf -- "$(gettext "  -p, --pacmandbScan active config files from 
pacman database")\n"
+   echo
+   printf -- "$(gettext "Options:")\n"
+   printf -- "$(gettext "  -o, --output  Print files instead of 
merging them")\n"
+   printf -- "$(gettext "  -m, --nocolor Remove colors from output")\n"
+   echo
+   printf -- "$(gettext "Environment Variables:")\n"
+   printf -- "$(gettext "  DIFFPROG  Override the merge program: 
(default: 'vim -d')")\n"
+   printf -- "$(gettext "\
+  DIFFSEARCHPATHOverride the search path. (only when using find)\n\
+(default: /etc)")\n"
+   echo
+   printf -- "$(gettext "Examples:")"
+   printf -- "DIFFPROG=meld DIFFSEARCHPATH=\"/boot /etc /usr\" %s\n" 
"$myname"
+   printf -- "%s --output --locate\n" "$myname"
+   echo
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [PATCH 06/11] paclist: streamline usage function

2016-09-29 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/paclist.sh.in | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/contrib/paclist.sh.in b/contrib/paclist.sh.in
index f4fd540..156f9d3 100644
--- a/contrib/paclist.sh.in
+++ b/contrib/paclist.sh.in
@@ -31,13 +31,15 @@ if ! type gettext &>/dev/null; then
 fi
 
 usage() {
-   printf "%s (pacman) v%s\n" "${myname}" "${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
echo
-   printf "List all packages installed from a given repository\n" 
"${myname}"
+   printf -- "$(gettext "List all packages installed from a given 
repository")\n"
echo
-   printf "Usage: %s \n" "${myname}"
+   printf -- "$(gettext "Usage: %s ")\n" "$0"
+   echo
+   printf -- "$(gettext "Examples:")"
+   printf -- "%s testing\n" "$myname"
echo
-   printf "Example: %s testing\n" "${myname}"
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [PATCH 02/11] paccache: streamline usage function

2016-09-29 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/paccache.sh.in | 61 +-
 1 file changed, 31 insertions(+), 30 deletions(-)

diff --git a/contrib/paccache.sh.in b/contrib/paccache.sh.in
index 02fae52..85fff55 100644
--- a/contrib/paccache.sh.in
+++ b/contrib/paccache.sh.in
@@ -172,36 +172,37 @@ summarize() {
 }
 
 usage() {
-   cat < [options] [targets...]
-
-  Operations:
--d, --dryrun  perform a dry run, only finding candidate packages.
--m, --move   move candidate packages to "dir".
--r, --remove  remove candidate packages.
-
-  Options:
--a, --arch  scan for "arch" (default: all architectures).
--c, --cachedir   scan "dir" for packages. can be used more than once.
-  (default: read from @sysconfdir@/pacman.conf).
--f, --force   apply force to mv(1) and rm(1) operations.
--h, --helpdisplay this help message and exit.
--i, --ignoreignore "pkgs", comma-separated. Alternatively, 
specify
-  "-" to read package names from stdin, newline-
-  delimited.
--k, --keep   keep "num" of each package in the cache (default: 3).
---nocolor remove color from output.
--q, --quiet   minimize output
--u, --uninstalled target uninstalled packages.
--v, --verbose increase verbosity. specify up to 3 times.
--z, --nulluse null delimiters for candidate names (only with -v
-  and -vv).
-
-EOF
+   printf "%s (pacman) %s\n" "$myname" "$myver"
+   echo
+   printf -- "$(gettext "A flexible pacman cache cleaning utility")\n"
+   echo
+   printf -- "$(gettext "Usage: %s  [options] [targets...]")\n" 
"$0"
+   echo
+   printf -- "$(gettext "Operations:")\n"
+   printf -- "$(gettext "  -d, --dryrun  Perform a dry run, only 
finding candidate packages")\n"
+   printf -- "$(gettext "  -m, --move   Move candidate packages 
to \"dir\"")\n"
+   printf -- "$(gettext "  -r, --remove  Remove candidate 
packages")\n"
+   echo
+   printf -- "$(gettext "Options:")\n"
+   printf -- "$(gettext "  -a, --arch  Scan for \"arch\" 
(default: all architectures)")\n"
+   printf -- "$(gettext "\
+  -c, --cachedir   Scan \"dir\" for packages. Can be used more than 
once.\n\
+(default: read from @sysconfdir@/pacman.conf).")\n"
+   printf -- "$(gettext "  -f, --force   Apply force to mv(1) and 
rm(1) operations")\n" "\$srcdir/"
+   printf -- "$(gettext "  -h, --helpDisplay this help message 
and exit")\n"
+   printf -- "$(gettext "\
+  -i, --ignoreIgnore \"pkgs\", comma-separated. Alternatively, 
specify\n\
+\"-\" to read package names from stdin, newline-\n\
+delimited.")\n" "\$srcdir/"
+   printf -- "$(gettext "  -k, --keep   Keep \"num\" of each 
package in the cache (default: 3)")\n"
+   printf -- "$(gettext "  -q, --quiet   Minimize output")\n"
+   printf -- "$(gettext "  -u, --uninstalled Target uninstalled 
packages")\n"
+   printf -- "$(gettext "  -v, --verbose Increase verbosity. 
specify up to 3 times.")\n"
+   printf -- "$(gettext "\
+  -z, --nullUse null delimiters for candidate names (only with 
-v\n\
+and -vv)")\n"
+   printf -- "$(gettext "  --nocolor Remove color from 
output")\n"
+   echo
 }
 
 version() {
-- 
2.10.0


[pacman-dev] [PATCH 00/11] Streamline syntax of contrib scripts

2016-09-29 Thread Gordian Edenhofer
Reorganize scripts in contrib to fit the syntax and style of makepkg.
Unify multiple different approaches to e.g. write a usage function, handle
options and differences in naming schemas for options.

Gordian Edenhofer (11):
  checkupdates: streamline usage function
  paccache: streamline usage function
  pacdiff: streamline usage function
  pacdiff: proper option handling
  pacdiff: streamline option syntax with makepkg
  paclist: streamline usage function
  paclog-pkglist: streamline usage function
  pacscripts: streamline usage function
  updpkgsums: streamline usage function
  rankmirrors: streamline usage function
  rankmirrors: proper option handling

 contrib/checkupdates.sh.in   |   9 +--
 contrib/paccache.sh.in   |  61 ++--
 contrib/pacdiff.sh.in|  76 +++--
 contrib/paclist.sh.in|  10 ++--
 contrib/paclog-pkglist.sh.in |  12 ++--
 contrib/pacscripts.sh.in |  18 +++---
 contrib/rankmirrors.sh.in| 132 +--
 contrib/updpkgsums.sh.in |  21 ---
 8 files changed, 179 insertions(+), 160 deletions(-)

--
2.10.0


[pacman-dev] [PATCH 01/11] checkupdates: streamline usage function

2016-09-29 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/checkupdates.sh.in | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/contrib/checkupdates.sh.in b/contrib/checkupdates.sh.in
index ff62891..8c04370 100644
--- a/contrib/checkupdates.sh.in
+++ b/contrib/checkupdates.sh.in
@@ -25,13 +25,14 @@ m4_include(../scripts/library/output_format.sh)
 m4_include(../scripts/library/term_colors.sh)
 
 if (( $# > 0 )); then
-   echo "${myname} (pacman) v${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
echo
-   echo "Safely print a list of pending updates"
+   printf -- "$(gettext "Safely print a list of pending updates")\n"
echo
-   echo "Usage: ${myname}"
+   printf -- "$(gettext "Usage: %s")\n" "$0"
+   echo
+   printf -- "$(gettext "Note: Export the "CHECKUPDATES_DB" variable to 
change the path of the temporary database.")\n"
echo
-   echo 'Note: Export the "CHECKUPDATES_DB" variable to change the path of 
the temporary database.'
exit 0
 fi
 
-- 
2.10.0


[pacman-dev] [PATCH 05/11] pacdiff: streamline option syntax with makepkg

2016-09-29 Thread Gordian Edenhofer
Allow for '-m' as abbreviation for '--nocolor'.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/pacdiff.sh.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in
index bed9ea3..8336706 100644
--- a/contrib/pacdiff.sh.in
+++ b/contrib/pacdiff.sh.in
@@ -96,7 +96,7 @@ cmd() {
 }
 
 # Parse arguments
-OPT_SHORT='lfpoVh'
+OPT_SHORT='lfpomVh'
 OPT_LONG=('locate' 'find' 'pacmandb' 'output' 'nocolor' 'version' 'help')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
@@ -115,7 +115,7 @@ while :; do
USE_PACDB=1;;
-o|--output)
OUTPUTONLY=1;;
-   --nocolor)
+   -m|--nocolor)
USE_COLOR='n';;
-V|--version)
version
-- 
2.10.0


Re: [pacman-dev] Versioned packages

2016-09-22 Thread Gordian Edenhofer
On Wed, 2016-09-21 at 23:28 -0400, Eli Schwartz wrote:
> On 09/21/2016 05:56 AM, Gordian Edenhofer wrote:
> > 
> > You bar for insanity is whether the debian folks do it? Please
> > explain
> > yourself why do you think this is the wrong approach for the
> > problem.
> > My reasoning would be that packaging a dummy package would result
> > in
> > the same 'renamed' package on the system but would require the
> > package
> > maintainer to take action.
> 
> Well, I can usually count on them to be over-engineered.
> 
> But in all seriousness, then. :)
> Building in to the package manager, a capacity for retroactively
> modifying the definition of a specific package, seems to me to be a
> clear case of over-engineering. And just a bad idea in principle.
> 
> If you want to do that, it is because you are already doing
> *something*
> wrong.

I wouldn't assume that the user has done anything wrong, rather
something with the system is wrong if one feels the need to 'backup'
packages.

> Because, you should not have to change your mind about what these
> particular files actually are, and start calling them something else
> on

Since one is intending to backup a package one should be highly aware
of the purpose of the package.

> a whim. Particularly as it disappears from the repositories, stops
> being
> trusted as signed by a central authority (the TUs), cannot be
> reinstalled...

The provide field makes sure that it is still treated the same. But to
allow backups for all packages, the user has to live with them not
being signed-off.

> > Btw. my Arch system is rock solid and I am not especially
> > interested in
> > dummy packages on my system but for those who need it it can be a
> > huge
> > difference. Therefore it makes sense to give those specific user
> > base
> > the ability to do so on their own. It wouldn't even be a dangerous
> > operation since by adding a provide field one should be unable to
> > brick
> > the system.
> > However I admit that it would require some additions to pacman
> > which is
> > obviously an argument against this but the way packages are treated
> > would stay the same.
> > Currently I don't see a reason why one should change the way of
> > packaging just to circumvent the underlying problem.
> 
> I am a bit confused as to what this all means...
> 
> Do you prefer dummy packages which pull in versioned kernels and
> depend
> on changing the packaging (for that specific package)?
> Or do you prefer additions to pacman while "treating the packages the
> same"?

I dislike dummy packages and therefore would keep the current way of
creating e.g. the linux package.
If using dummy packages the main question becomes where to draw the
line. You are currently referring to linux as "for that specific
package" but what if users need different versions for another
package... The system of everyone else would become more and more
cluttered with dummy packages.

> I think we may have a drastically different idea of what constitutes
> "circumventing the underlying problem".
> To be specific, we both seem to think the other is the one
> circumventing
> the underlying problem.

That's true :D

signature.asc
Description: This is a digitally signed message part


Re: [pacman-dev] [PATCH v8 01/12] bacman: allow for multiple packages as arguments

2016-09-21 Thread Gordian Edenhofer
On Wed, 2016-09-21 at 00:08 +1000, Allan McRae wrote:
> On 09/09/16 16:21, Allan McRae wrote:
> > 
> > Correct - most changes will be pulled from this patchset.  Just not
> > the
> > parallelization patches.  I will pull the other patches to my
> > patchqueue
> > branch soon.
> 
> You can now see what I intend to commit on my "bacman" branch:
> 
> https://git.archlinux.org/users/allan/pacman.git/log/?h=bacman

You forgot to change `pacman -Qsq` to `pacman -Qq` in the usage
function.
Besides that it looks good to me. Sorry for hiccups in the patchset.

signature.asc
Description: This is a digitally signed message part


Re: [pacman-dev] Versioned packages

2016-09-21 Thread Gordian Edenhofer
On Tue, 2016-09-20 at 21:41 -0400, Eli Schwartz wrote:
> On 09/19/2016 11:49 AM, Gordian Edenhofer wrote:
> > 
> > What about adding a new option to pacman's '-D, --database'
> > operator
> > which would enable users to rename packages and add a corresponding
> > provide field. This would empower everyone to decide on their own
> > which
> > packages they want in different versions and which they don't want.
> > Pacman would handle file conflicts as usual without introducing a
> > new
> > kind of packages. Plus it would avoid discussions about which
> > package
> > should be a dummy package and which shouldn't be.
> 
> Was that meant to be some sort of a joke? Because even Debian is not
> that insane, AFAIK.

You bar for insanity is whether the debian folks do it? Please explain
yourself why do you think this is the wrong approach for the problem.
My reasoning would be that packaging a dummy package would result in
the same 'renamed' package on the system but would require the package
maintainer to take action.
Btw. my Arch system is rock solid and I am not especially interested in
dummy packages on my system but for those who need it it can be a huge
difference. Therefore it makes sense to give those specific user base
the ability to do so on their own. It wouldn't even be a dangerous
operation since by adding a provide field one should be unable to brick
the system.
However I admit that it would require some additions to pacman which is
obviously an argument against this but the way packages are treated
would stay the same.
Currently I don't see a reason why one should change the way of
packaging just to circumvent the underlying problem.

signature.asc
Description: This is a digitally signed message part


Re: [pacman-dev] Versioned packages

2016-09-19 Thread Gordian Edenhofer
On Mon, 2016-09-12 at 21:33 -0400, Eli Schwartz wrote:
> On 09/12/2016 06:51 PM, Allan McRae wrote:
> > 
> > This discussion has nothing to do with Arch.  It is about whether
> > this
> > feature needs implemented in pacman.
> 
> Which of course it doesn't. All we need is for the kernel maintainer
> to
> start packaging a dummy linux package that depends on linux-$pkgver
> packages.
> 
> As originally recommended by the bugtracker item which spawned this
> odd
> thread.
> 
> ...
> 
> I am not quite sure what is currently blocking such a resolution, but
> that is already supposedly being discussed on the bugtracker.
> 
> Meanwhile let us listen to people proposing convoluted workarounds
> that
> evade the issue entirely and are far less likely to actually be
> accepted...

What about adding a new option to pacman's '-D, --database' operator
which would enable users to rename packages and add a corresponding
provide field. This would empower everyone to decide on their own which
packages they want in different versions and which they don't want.
Pacman would handle file conflicts as usual without introducing a new
kind of packages. Plus it would avoid discussions about which package
should be a dummy package and which shouldn't be.

Best Regards,
Gordian Edenhofer

signature.asc
Description: This is a digitally signed message part


Re: [pacman-dev] [PATCH v8 01/12] bacman: allow for multiple packages as arguments

2016-09-04 Thread Gordian Edenhofer
On Sun, 2016-09-04 at 11:21 -0500, Doug Newgard wrote:
> On Sun,  4 Sep 2016 18:13:56 +0200
> Gordian Edenhofer <gordian.edenho...@gmail.com> wrote:
> 
> > 
> > To enable the creation of multiple packages with one command move
> > the
> > assembly process into its own function.
> > 
> 
> Why do you keep sending these? Allan has already said they will not
> be merged.

Allen objected parallelization as far as I understood him not the
patches as a whole. What harm should a man page and the use of
parseopts bring?
Most of the recent mails were in reply to proposed amendments and the
patchset should be properly split up into different parts by now to
allow for cherry-picking the parts that are acceptable. Since I moved
some things into the wrong commit when I divided 3 patches into 12 I
had to submit it a couple of more times and I am sorry for spamming the
mailing list with those mails.
Furthermore until recently I was still fighting for parallelization but
after talking to Allen on IRC I realised this is a lost case. Therefore
upon request I will submit the patches once more without support
for parallelization.

Once again, please excuse me for sending those many mails.

Best Regards,
Gordian Edenhofer

signature.asc
Description: This is a digitally signed message part


[pacman-dev] [PATCH v8 12/12] bacman man page: describe the jobs option

2016-09-04 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/doc/bacman.8.txt | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/contrib/doc/bacman.8.txt b/contrib/doc/bacman.8.txt
index a9d7ba9..4738189 100644
--- a/contrib/doc/bacman.8.txt
+++ b/contrib/doc/bacman.8.txt
@@ -35,6 +35,9 @@ Options
 *-m, \--nocolor*::
Disable colored output.
 
+*-j, \--jobs *::
+   Assemble multiple packages in parallel.
+
 *-o, \--out *::
Write the assembled package(s) to the specified directory.
 
@@ -53,10 +56,11 @@ Recreate the package ``linux-headers''.
 Assemble the packages gzip munge binutils and place the packages at
 ``~/Downloads''.
 
-'bacman' --nocolor --pacnew -o ~/backup $(pacman -Qsq)
+'bacman' --nocolor --pacnew -o ~/backup -j 5 $(pacman -Qsq)
 
-Assemble all currently installed packages using ``.pacnew'' whenever available,
-suppress colored output and place the desired packages in ``~/backup''.
+Assemble all currently installed packages using 5 concurrent jobs, use
+``.pacnew'' whenever available, suppress colored output and place the desired
+packages in ``~/backup''.
 
 
 See Also
-- 
2.9.3


[pacman-dev] [PATCH v8 11/12] bacman: add manual page

2016-09-04 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/doc/.gitignore   |  1 +
 contrib/doc/Makefile.am  |  5 +++-
 contrib/doc/bacman.8.txt | 66 
 3 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 contrib/doc/bacman.8.txt

diff --git a/contrib/doc/.gitignore b/contrib/doc/.gitignore
index c5612bc..3ab2035 100644
--- a/contrib/doc/.gitignore
+++ b/contrib/doc/.gitignore
@@ -1 +1,2 @@
 verify-pacman-repo-db.1
+bacman.8
diff --git a/contrib/doc/Makefile.am b/contrib/doc/Makefile.am
index 4c316bb..d5725b1 100644
--- a/contrib/doc/Makefile.am
+++ b/contrib/doc/Makefile.am
@@ -4,12 +4,14 @@
 # man_MANS if --enable-asciidoc and/or --enable-doxygen are used.
 
 ASCIIDOC_MANS = \
-   verify-pacman-repo-db.1
+   verify-pacman-repo-db.1 \
+   bacman.8
 
 EXTRA_DIST = \
asciidoc.conf \
footer.txt \
verify-pacman-repo-db.1.txt \
+   bacman.8.txt \
$(ASCIIDOC_MANS)
 
 # Files that should be removed, but which Automake does not know.
@@ -53,5 +55,6 @@ $(ASCIIDOC_MANS): asciidoc.conf footer.txt Makefile.am
 
 # Dependency rules
 verify-pacman-repo-db.1: verify-pacman-repo-db.1.txt
+bacman.8: bacman.8.txt
 
 # vim:set noet:
diff --git a/contrib/doc/bacman.8.txt b/contrib/doc/bacman.8.txt
new file mode 100644
index 000..a9d7ba9
--- /dev/null
+++ b/contrib/doc/bacman.8.txt
@@ -0,0 +1,66 @@
+/
+vim:set ts=4 sw=4 syntax=asciidoc noet spell spelllang=en_us:
+/
+bacman(8)
+==
+
+Name
+
+bacman - recreate installed packages
+
+
+Synopsis
+
+'bacman' [options] <package(s)>
+
+
+Description
+---
+'bacman' was designed to reassemble installed packages from its deliverd files.
+It comes in handy if there is no internet connection available and you have no
+access to a up-to-date package cache.
+
+'bacman' fully honors linkman:makepkg.conf[8] and all compression environment
+variables, notably ``XZ_OPT''.
+
+
+Options
+---
+*-h, \--help*::
+   Display usage information.
+
+*-q, \--quiet*::
+   Silence most of the status reporting.
+
+*-m, \--nocolor*::
+   Disable colored output.
+
+*-o, \--out *::
+   Write the assembled package(s) to the specified directory.
+
+*\--pacnew*::
+   Package .pacnew files instead of the concerning files currently in 
place.
+
+
+Examples
+
+'bacman' linux-headers
+
+Recreate the package ``linux-headers''.
+
+'bacman' gzip munge binutils -o ~/Downloads
+
+Assemble the packages gzip munge binutils and place the packages at
+``~/Downloads''.
+
+'bacman' --nocolor --pacnew -o ~/backup $(pacman -Qsq)
+
+Assemble all currently installed packages using ``.pacnew'' whenever available,
+suppress colored output and place the desired packages in ``~/backup''.
+
+
+See Also
+
+linkman:makepkg[8], linkman:pacman[8]
+
+include::footer.txt[]
-- 
2.9.3


[pacman-dev] [PATCH v8 06/12] bacman: code structuring

2016-09-04 Thread Gordian Edenhofer
Adding and clarifying comments.
Adding and removing some new lines.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 25 -
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 5045d6e..7bf1aa0 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -44,9 +44,7 @@ clean_up() {
 # Trap termination signals
 trap clean_up SIGHUP SIGINT SIGTERM
 
-#
-# User Friendliness
-#
+# Print usage information
 usage() {
printf "%s (pacman) %s\n" "$myname" "$myver"
echo
@@ -65,6 +63,7 @@ usage() {
echo
 }
 
+# Print version information
 version() {
printf "%s %s\n" "$myname" "$myver"
echo 'Copyright (C) 2008 locci '
@@ -112,9 +111,7 @@ if [[ ${#pkg_list[@]} == 0 ]]; then
exit 1
 fi
 
-#
-# Fakeroot support
-#
+# Run with fake root privileges if EUID is not root
 if (( EUID )); then
if [[ -f /usr/bin/fakeroot ]]; then
msg "Entering fakeroot environment"
@@ -127,33 +124,25 @@ if (( EUID )); then
fi
 fi
 
-#
-# Setting environmental variables
-#
+# Source environmental variables and specify fallbacks
 if [[ ! -r @sysconfdir@/pacman.conf ]]; then
error "unable to read @sysconfdir@/pacman.conf"
exit 1
 fi
-
 eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
 pac_db="${DBPath:-@localstatedir@/lib/pacman/}/local"
-
 if [[ ! -r @sysconfdir@/makepkg.conf ]]; then
error "unable to read @sysconfdir@/makepkg.conf"
exit 1
 fi
-
 source "@sysconfdir@/makepkg.conf"
 if [[ -r ~/.makepkg.conf ]]; then
source ~/.makepkg.conf
 fi
-
 pkg_dest="${PKGDEST:-$PWD}"
 pkg_pkger=${PACKAGER:-'Unknown Packager'}
 
-#
-# Checks everything is in place
-#
+# Check for an existing database
 if [[ ! -d $pac_db ]]; then
error "pacman database directory ${pac_db} not found"
exit 1
@@ -185,6 +174,7 @@ fakebuild() {
 
# Assemble list of files which belong to the package and tar them
msg2 "Copying package files..."
+
while read i; do
if [[ -z $i ]]; then
continue
@@ -351,6 +341,7 @@ fakebuild() {
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
ret=0
 
+   # Move compressed package to destination
# TODO: Maybe this can be set globally for robustness
shopt -s -o pipefail
bsdtar -cf - $comp_files * |
@@ -364,7 +355,7 @@ fakebuild() {
"$PKGEXT"; cat ;;
esac > "${pkg_file}"; ret=$?
 
-   # Move compressed package to destination
+   # Evaluate return code
if (( ret )); then
error "Unable to write package to $pkg_dest"
plain "   Maybe the disk is full or you do not have write 
access"
-- 
2.9.3


[pacman-dev] [PATCH v8 04/12] bacman: proper option handling

2016-09-04 Thread Gordian Edenhofer
Switch to parseopts instead of merely checking the first argument.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
Use parseopts to quit in case no argument was given instead of manual checking.

 contrib/bacman.sh.in | 58 +---
 1 file changed, 37 insertions(+), 21 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 0c71541..e56f31b 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -32,6 +32,7 @@ INCLUDE_PACNEW='n'
 ARGS=("$@")
 
 m4_include(../scripts/library/output_format.sh)
+m4_include(../scripts/library/parseopts.sh)
 
 # Lazy recursive clean up of temporary dirs
 work_dir_root="${TMPDIR:-/tmp}/bacman"
@@ -62,32 +63,45 @@ version() {
echo 'Copyright (C) 2008-2016 Pacman Development Team 
<pacman-dev@archlinux.org>'
 }
 
-while [[ ! -z $1 ]]; do
-   if [[ $1 == "--nocolor" ]]; then
-   USE_COLOR='n'
-   shift
-   elif [[ $1 == "--pacnew" ]]; then
-   INCLUDE_PACNEW='y'
-   shift
-   else
-   break
-   fi
-done
-
+# Configure colored output
 m4_include(../scripts/library/term_colors.sh)
 
-# Break if no argument was given
-if (( $# < 1 )); then
+# Printing the usage information takes precedence over every other parameter
+for option in "$@"; do
+   [[ $option == "-h" || $option == "--help" ]] && usage && exit 0
+done
+
+# Parse arguments
+OPT_SHORT=':mv'
+OPT_LONG=('nocolor' 'pacnew' 'version')
+if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
 fi
+set -- "${OPTRET[@]}"
+unset OPT_SHORT OPT_LONG OPTRET
+
+while :; do
+   case "$1" in
+   -m|--nocolor)
+   USE_COLOR='n' ;;
+   --pacnew)
+   INCLUDE_PACNEW='y' ;;
+   -v|--version)
+   version
+   exit 0 ;;
+   --)
+   shift
+   break 2 ;;
+   esac
+   shift
+done
 
-if [[ $1 = -@(h|-help) ]]; then
+# Retrieve the list of packages to be assembled and break if none was specified
+pkg_list=($*)
+if [[ ${#pkg_list[@]} == 0 ]]; then
usage
-   exit 0
-elif [[ $1 = -@(V|-version) ]]; then
-   version
-   exit 0
+   exit 1
 fi
 
 #
@@ -373,9 +387,11 @@ parallelize() {
 
 # Initiate assembly function
 if [[ $MAX_JOBS -gt "1" ]]; then
-   parallelize "$@"
+   parallelize "${pkg_list[@]}"
 else
-   for PKG in $@; do fakebuild $PKG; done
+   for PKG in ${pkg_list[@]}; do
+   fakebuild $PKG
+   done
 fi
 msg "Done."
 
-- 
2.9.3


[pacman-dev] [PATCH v8 09/12] bacman: add otpion to alter the output directory

2016-09-04 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 4e9e0a3..7e511d6 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -57,10 +57,12 @@ usage() {
printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
printf -- "$(gettext "  -q, --quiet  Silence most of the status 
reporting")\n"
printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
+   printf -- "$(gettext "  -o, --out   Write output to specified 
directory (instead of \$PKGDEST)")\n"
printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
echo
printf -- "$(gettext "Examples:  %s linux-headers")\n" "$myname"
-   printf -- "$(gettext "  %s --nocolor --pacnew gzip munge binutils")\n" 
"$myname"
+   printf -- "$(gettext "  %s gzip munge binutils -o ~/Downloads")\n" 
"$myname"
+   printf -- "$(gettext "  %s --nocolor --pacnew -o /tmp gzip munge 
binutils")\n" "$myname"
printf -- "$(gettext "  %s \$(pacman -Qsq)")\n" "$myname"
echo
 }
@@ -81,8 +83,8 @@ for option in "$@"; do
 done
 
 # Parse arguments
-OPT_SHORT=':qmv'
-OPT_LONG=('quiet' 'nocolor' 'pacnew' 'version')
+OPT_SHORT=':o:qmv'
+OPT_LONG=('out:' 'quiet' 'nocolor' 'pacnew' 'version')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
@@ -92,6 +94,10 @@ unset OPT_SHORT OPT_LONG OPTRET
 
 while :; do
case "$1" in
+   -o|--out)
+   pkg_dest=$2
+   [[ ! -d "$2" ]] && echo -e "The directory 
\e[39;1m$2\e[0m does not exist!" && exit 3
+   shift ;;
-q|--quiet)
QUIET=1 ;;
-m|--nocolor)
@@ -143,7 +149,8 @@ source "@sysconfdir@/makepkg.conf"
 if [[ -r ~/.makepkg.conf ]]; then
source ~/.makepkg.conf
 fi
-pkg_dest="${PKGDEST:-$PWD}"
+PKGDEST="${PKGDEST:-$PWD}"
+pkg_dest="${pkg_dest:-$PKGDEST}"
 pkg_pkger="${PACKAGER:-'Unknown Packager'}"
 
 # Check for an existing database
-- 
2.9.3


[pacman-dev] [PATCH v8 10/12] bacman: add option to specify the number of jobs

2016-09-04 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 33 +++--
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 7e511d6..d0c15c9 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -57,12 +57,13 @@ usage() {
printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
printf -- "$(gettext "  -q, --quiet  Silence most of the status 
reporting")\n"
printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
+   printf -- "$(gettext "  -j, --jobsBuild in parallel with N jobs 
- you may want to set XZ_OPT")\n"
printf -- "$(gettext "  -o, --out   Write output to specified 
directory (instead of \$PKGDEST)")\n"
printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
echo
printf -- "$(gettext "Examples:  %s linux-headers")\n" "$myname"
printf -- "$(gettext "  %s gzip munge binutils -o ~/Downloads")\n" 
"$myname"
-   printf -- "$(gettext "  %s --nocolor --pacnew -o /tmp gzip munge 
binutils")\n" "$myname"
+   printf -- "$(gettext "  %s --nocolor --pacnew -o /tmp -j 5 gzip munge 
binutils")\n" "$myname"
printf -- "$(gettext "  %s \$(pacman -Qsq)")\n" "$myname"
echo
 }
@@ -83,8 +84,8 @@ for option in "$@"; do
 done
 
 # Parse arguments
-OPT_SHORT=':o:qmv'
-OPT_LONG=('out:' 'quiet' 'nocolor' 'pacnew' 'version')
+OPT_SHORT=':o:j:qmv'
+OPT_LONG=('out:' 'jobs:' 'quiet' 'nocolor' 'pacnew' 'version')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
@@ -98,6 +99,14 @@ while :; do
pkg_dest=$2
[[ ! -d "$2" ]] && echo -e "The directory 
\e[39;1m$2\e[0m does not exist!" && exit 3
shift ;;
+   -j|--jobs)
+   if [[ $2 =~ ^-?[0-9]+$ ]]; then
+   MAX_JOBS=$2
+   else
+   echo -e "\e[39;1m$2\e[0m is not a valid 
integer!"
+   exit -1
+   fi
+   shift ;;
-q|--quiet)
QUIET=1 ;;
-m|--nocolor)
@@ -184,7 +193,11 @@ fakebuild() {
cd "$work_dir" || exit 1
 
# Assemble list of files which belong to the package and tar them
-   msg2 "Copying package files..."
+   if [[ $MAX_JOBS -gt 1 ]]; then
+   msg2 "${pkg_name}: Copying package files..."
+   else
+   msg2 "Copying package files..."
+   fi
 
while read i; do
if [[ -z $i ]]; then
@@ -259,7 +272,11 @@ fakebuild() {
 
# Reconstruct .PKGINFO from database
# TODO adopt makepkg's write_pkginfo() into this or scripts/library
-   msg2 "Generating .PKGINFO metadata..."
+   if [[ $MAX_JOBS -gt 1 ]]; then
+   msg2 "${pkg_name}: Generating .PKGINFO metadata..."
+   else
+   msg2 "Generating .PKGINFO metadata..."
+   fi
echo "# Generated by $myname $myver"> .PKGINFO
if [[ $INFAKEROOT == "1" ]]; then
echo "# Using $(fakeroot -v)">> .PKGINFO
@@ -347,7 +364,11 @@ fakebuild() {
chmod 644 "$work_dir"/{.PKGINFO,.CHANGELOG,.INSTALL} 2> /dev/null
 
# Generate the package
-   msg2 "Generating the package..."
+   if [[ $MAX_JOBS -gt 1 ]]; then
+   msg2 "${pkg_name}: Generating the package..."
+   else
+   msg2 "Generating the package..."
+   fi
 
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
ret=0
-- 
2.9.3


[pacman-dev] [PATCH v8 08/12] bacman: add option to print fewer status updates

2016-09-04 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index d98088a..4e9e0a3 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -28,6 +28,7 @@ declare -r myname='bacman'
 declare -r myver='@PACKAGE_VERSION@'
 USE_COLOR='y'
 INCLUDE_PACNEW='n'
+QUIET=0
 # Required for fakeroot because options are shifted off the array.
 ARGS=("$@")
 
@@ -54,6 +55,7 @@ usage() {
echo
printf -- "$(gettext "Options:")\n"
printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
+   printf -- "$(gettext "  -q, --quiet  Silence most of the status 
reporting")\n"
printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
echo
@@ -79,8 +81,8 @@ for option in "$@"; do
 done
 
 # Parse arguments
-OPT_SHORT=':mv'
-OPT_LONG=('nocolor' 'pacnew' 'version')
+OPT_SHORT=':qmv'
+OPT_LONG=('quiet' 'nocolor' 'pacnew' 'version')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
@@ -90,6 +92,8 @@ unset OPT_SHORT OPT_LONG OPTRET
 
 while :; do
case "$1" in
+   -q|--quiet)
+   QUIET=1 ;;
-m|--nocolor)
USE_COLOR='n' ;;
--pacnew)
-- 
2.9.3


[pacman-dev] [PATCH v8 03/12] bacman: parallel packaging

2016-09-04 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index e7a7f57..0c71541 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -354,8 +354,29 @@ fakebuild() {
rm -rf "$work_dir"
 }
 
+# Run fakebuild in parralel with at maximum $MAX_JOBS jobs
+# By default only run one job
+MAX_JOBS=${MAX_JOBS:-1}
+# TODO: Use wait -n instead of this hack as soon as it is ok
+# to bump the version of the bash dependency
+parallelize() {
+   while [[ $# -gt 0 ]]; do
+   job_count=($(jobs -p))
+   if [[ ${#job_count[@]} -lt $MAX_JOBS ]] ; then
+   fakebuild "$1" &
+   shift
+   fi
+   sleep 0.1
+   done
+   wait
+}
 
-for PKG in $@; do fakebuild $PKG; done
+# Initiate assembly function
+if [[ $MAX_JOBS -gt "1" ]]; then
+   parallelize "$@"
+else
+   for PKG in $@; do fakebuild $PKG; done
+fi
 msg "Done."
 
 exit 0
-- 
2.9.3


[pacman-dev] [PATCH v8 02/12] bacman: handle SIGHUP, SIGINT, SIGTERM signals

2016-09-04 Thread Gordian Edenhofer
Trap SIGHUP, SIGINT, SIGTERM and remove working directories accordingly.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 5e6fce5..e7a7f57 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -33,6 +33,16 @@ ARGS=("$@")
 
 m4_include(../scripts/library/output_format.sh)
 
+# Lazy recursive clean up of temporary dirs
+work_dir_root="${TMPDIR:-/tmp}/bacman"
+clean_up() {
+   rm -rf "$work_dir_root".*
+   echo
+   exit
+}
+# Trap termination signals
+trap clean_up SIGHUP SIGINT SIGTERM
+
 #
 # User Friendliness
 #
-- 
2.9.3


[pacman-dev] [PATCH v8 07/12] bacman: quote pkg_pkger variable

2016-09-04 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 7bf1aa0..d98088a 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -140,7 +140,7 @@ if [[ -r ~/.makepkg.conf ]]; then
source ~/.makepkg.conf
 fi
 pkg_dest="${PKGDEST:-$PWD}"
-pkg_pkger=${PACKAGER:-'Unknown Packager'}
+pkg_pkger="${PACKAGER:-'Unknown Packager'}"
 
 # Check for an existing database
 if [[ ! -d $pac_db ]]; then
-- 
2.9.3


[pacman-dev] [PATCH v8 05/12] bacman: rewrite usage function

2016-09-04 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index e56f31b..5045d6e 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -48,13 +48,21 @@ trap clean_up SIGHUP SIGINT SIGTERM
 # User Friendliness
 #
 usage() {
-   echo "${myname} (pacman) v${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
echo
-   echo "Recreate a package using pacman's database and system files"
+   printf -- "$(gettext "Recreate packages using pacman's database and 
system files")\n"
echo
-   echo "Usage: ${myname} [--nocolor] [--pacnew] "
+   printf -- "$(gettext "Usage: %s [options] <package(s)>")\n" "$0"
+   echo
+   printf -- "$(gettext "Options:")\n"
+   printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
+   printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
+   printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
+   echo
+   printf -- "$(gettext "Examples:  %s linux-headers")\n" "$myname"
+   printf -- "$(gettext "  %s --nocolor --pacnew gzip munge binutils")\n" 
"$myname"
+   printf -- "$(gettext "  %s \$(pacman -Qsq)")\n" "$myname"
echo
-   echo "Example: ${myname} linux-headers"
 }
 
 version() {
-- 
2.9.3


[pacman-dev] [PATCH v8 01/12] bacman: allow for multiple packages as arguments

2016-09-04 Thread Gordian Edenhofer
To enable the creation of multiple packages with one command move the
assembly process into its own function.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 405 +--
 1 file changed, 200 insertions(+), 205 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index a611c1a..5e6fce5 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -66,7 +66,8 @@ done
 
 m4_include(../scripts/library/term_colors.sh)
 
-if (( $# != 1 )); then
+# Break if no argument was given
+if (( $# < 1 )); then
usage
exit 1
 fi
@@ -118,10 +119,6 @@ fi
 pkg_dest="${PKGDEST:-$PWD}"
 pkg_pkger=${PACKAGER:-'Unknown Packager'}
 
-pkg_name="$1"
-pkg_dir=("$pac_db/$pkg_name"-+([^-])-+([^-]))
-pkg_namver=("${pkg_dir[@]##*/}")
-
 #
 # Checks everything is in place
 #
@@ -130,227 +127,225 @@ if [[ ! -d $pac_db ]]; then
exit 1
 fi
 
-if (( ${#pkg_dir[@]} != 1 )); then
-   error "%d entries for package %s found in pacman database" \
-   ${#pkg_dir[@]} "${pkg_name}"
-   msg2 "%s" "${pkg_dir[@]}"
-   exit 1
-fi
-
-if [[ ! -d $pkg_dir ]]; then
-   error "package %s is found in pacman database," "${pkg_name}"
-   plain "   but '%s' is not a directory" "${pkg_dir}"
-   exit 1
-fi
-
-#
-# Begin
-#
-msg "Package: ${pkg_namver}"
-work_dir=$(mktemp -d "${TMPDIR:-/tmp}/bacman.XX")
-cd "$work_dir" || exit 1
-
-#
-# File copying
-#
-msg2 "Copying package files..."
-
-while read i; do
-   if [[ -z $i ]]; then
-   continue
+# Assemble a single package: $1 = pkgname
+fakebuild() {
+   pkg_name="$1"
+   pkg_dir=("$pac_db/$pkg_name"-+([^-])-+([^-]))
+   pkg_namver=("${pkg_dir[@]##*/}")
+
+   # Checks database for specified package
+   if (( ${#pkg_dir[@]} != 1 )); then
+   error "%d entries for package %s found in pacman database" \
+   ${#pkg_dir[@]} "${pkg_name}"
+   msg2 "%s" "${pkg_dir[@]}"
+   exit 1
fi
-
-   if [[ $i == %+([A-Z])% ]]; then
-   current=$i
-   continue
+   if [[ ! -d $pkg_dir ]]; then
+   error "package %s is found in pacman database," "${pkg_name}"
+   plain "   but '%s' is not a directory" "${pkg_dir}"
+   exit 1
fi
 
-   case "$current" in
-   %FILES%)
-   local_file="/$i"
-   package_file="$work_dir/$i"
+   # Create working directory
+   msg "Package: ${pkg_namver}"
+   work_dir=$(mktemp -d "${work_dir_root}.XX")
+   cd "$work_dir" || exit 1
 
-   if [[ ! -e $local_file ]]; then
-   warning "package file $local_file is missing"
-   continue
-   fi
-   ;;
-
-   %BACKUP%)
-   # Get the MD5 checksum.
-   original_md5="${i##*$'\t'}"
-   # Strip the md5sum after the tab.
-   i="${i%$'\t'*}"
-   local_file="/$i.pacnew"
-   package_file="$work_dir/$i"
-
-   # Include unmodified .pacnew files.
-   local_md5="$(md5sum "$local_file" | cut -d' ' -f1)"
-   if [[ $INCLUDE_PACNEW == 'n' ]] \
-   || [[ ! -e $local_file ]] \
-   || [[ $local_md5 != $original_md5 ]]; then
-   # Warn about modified files.
-   local_md5="$(md5sum "/$i" | cut -d' ' -f1)"
-   if [[ $local_md5 != $original_md5 ]]; then
-   warning "package file /$i has been 
modified"
-   fi
-   # Let the normal file be included in the 
%FILES% list.
-   continue
-   fi
-   ;;
+   # Assemble list of files which belong to the package and tar them
+   msg2 "Copying package files..."
+   while read i; do
+   if [[ -z $i ]]; then
+   continue
+   fi
 
-   *)
+   if [[ $i == %+([A-Z])% ]]; then
+   current=$i
continue
-   ;;
-   esac
+

[pacman-dev] [PATCH v7 12/12] bacman man page: describe the jobs option

2016-09-03 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/doc/bacman.8.txt | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/contrib/doc/bacman.8.txt b/contrib/doc/bacman.8.txt
index a9d7ba9..4738189 100644
--- a/contrib/doc/bacman.8.txt
+++ b/contrib/doc/bacman.8.txt
@@ -35,6 +35,9 @@ Options
 *-m, \--nocolor*::
Disable colored output.
 
+*-j, \--jobs *::
+   Assemble multiple packages in parallel.
+
 *-o, \--out *::
Write the assembled package(s) to the specified directory.
 
@@ -53,10 +56,11 @@ Recreate the package ``linux-headers''.
 Assemble the packages gzip munge binutils and place the packages at
 ``~/Downloads''.
 
-'bacman' --nocolor --pacnew -o ~/backup $(pacman -Qsq)
+'bacman' --nocolor --pacnew -o ~/backup -j 5 $(pacman -Qsq)
 
-Assemble all currently installed packages using ``.pacnew'' whenever available,
-suppress colored output and place the desired packages in ``~/backup''.
+Assemble all currently installed packages using 5 concurrent jobs, use
+``.pacnew'' whenever available, suppress colored output and place the desired
+packages in ``~/backup''.
 
 
 See Also
-- 
2.9.3


[pacman-dev] [PATCH v7 10/12] bacman: add option to specify the number of jobs

2016-09-03 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 33 +++--
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index b92b4e4..7ae9058 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -57,12 +57,13 @@ usage() {
printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
printf -- "$(gettext "  -q, --quiet  Silence most of the status 
reporting")\n"
printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
+   printf -- "$(gettext "  -j, --jobsBuild in parallel with N jobs 
- you may want to set XZ_OPT")\n"
printf -- "$(gettext "  -o, --out   Write output to specified 
directory (instead of \$PKGDEST)")\n"
printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
echo
printf -- "$(gettext "Examples:  %s linux-headers")\n" "$myname"
printf -- "$(gettext "  %s gzip munge binutils -o ~/Downloads")\n" 
"$myname"
-   printf -- "$(gettext "  %s --nocolor --pacnew -o /tmp gzip munge 
binutils")\n" "$myname"
+   printf -- "$(gettext "  %s --nocolor --pacnew -o /tmp -j 5 gzip munge 
binutils")\n" "$myname"
printf -- "$(gettext "  %s \$(pacman -Qsq)")\n" "$myname"
echo
 }
@@ -89,8 +90,8 @@ for option in "$@"; do
 done
 
 # Parse arguments
-OPT_SHORT='o:qmv'
-OPT_LONG=('out:' 'quiet' 'nocolor' 'pacnew' 'version')
+OPT_SHORT='o:j:qmv'
+OPT_LONG=('out:' 'jobs:' 'quiet' 'nocolor' 'pacnew' 'version')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
@@ -104,6 +105,14 @@ while :; do
pkg_dest=$2
[[ ! -d "$2" ]] && echo -e "The directory 
\e[39;1m$2\e[0m does not exist!" && exit 3
shift ;;
+   -j|--jobs)
+   if [[ $2 =~ ^-?[0-9]+$ ]]; then
+   MAX_JOBS=$2
+   else
+   echo -e "\e[39;1m$2\e[0m is not a valid 
integer!"
+   exit -1
+   fi
+   shift ;;
-q|--quiet)
QUIET=1 ;;
-m|--nocolor)
@@ -190,7 +199,11 @@ fakebuild() {
cd "$work_dir" || exit 1
 
# Assemble list of files which belong to the package and tar them
-   msg2 "Copying package files..."
+   if [[ $MAX_JOBS -gt 1 ]]; then
+   msg2 "${pkg_name}: Copying package files..."
+   else
+   msg2 "Copying package files..."
+   fi
 
while read i; do
if [[ -z $i ]]; then
@@ -265,7 +278,11 @@ fakebuild() {
 
# Reconstruct .PKGINFO from database
# TODO adopt makepkg's write_pkginfo() into this or scripts/library
-   msg2 "Generating .PKGINFO metadata..."
+   if [[ $MAX_JOBS -gt 1 ]]; then
+   msg2 "${pkg_name}: Generating .PKGINFO metadata..."
+   else
+   msg2 "Generating .PKGINFO metadata..."
+   fi
echo "# Generated by $myname $myver"> .PKGINFO
if [[ $INFAKEROOT == "1" ]]; then
echo "# Using $(fakeroot -v)">> .PKGINFO
@@ -353,7 +370,11 @@ fakebuild() {
chmod 644 "$work_dir"/{.PKGINFO,.CHANGELOG,.INSTALL} 2> /dev/null
 
# Generate the package
-   msg2 "Generating the package..."
+   if [[ $MAX_JOBS -gt 1 ]]; then
+   msg2 "${pkg_name}: Generating the package..."
+   else
+   msg2 "Generating the package..."
+   fi
 
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
ret=0
-- 
2.9.3


[pacman-dev] [PATCH v7 09/12] bacman: add otpion to alter the output directory

2016-09-03 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 94b09d7..b92b4e4 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -57,10 +57,12 @@ usage() {
printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
printf -- "$(gettext "  -q, --quiet  Silence most of the status 
reporting")\n"
printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
+   printf -- "$(gettext "  -o, --out   Write output to specified 
directory (instead of \$PKGDEST)")\n"
printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
echo
printf -- "$(gettext "Examples:  %s linux-headers")\n" "$myname"
-   printf -- "$(gettext "  %s --nocolor --pacnew gzip munge binutils")\n" 
"$myname"
+   printf -- "$(gettext "  %s gzip munge binutils -o ~/Downloads")\n" 
"$myname"
+   printf -- "$(gettext "  %s --nocolor --pacnew -o /tmp gzip munge 
binutils")\n" "$myname"
printf -- "$(gettext "  %s \$(pacman -Qsq)")\n" "$myname"
echo
 }
@@ -87,8 +89,8 @@ for option in "$@"; do
 done
 
 # Parse arguments
-OPT_SHORT='qmv'
-OPT_LONG=('quiet' 'nocolor' 'pacnew' 'version')
+OPT_SHORT='o:qmv'
+OPT_LONG=('out:' 'quiet' 'nocolor' 'pacnew' 'version')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
@@ -98,6 +100,10 @@ unset OPT_SHORT OPT_LONG OPTRET
 
 while :; do
case "$1" in
+   -o|--out)
+   pkg_dest=$2
+   [[ ! -d "$2" ]] && echo -e "The directory 
\e[39;1m$2\e[0m does not exist!" && exit 3
+   shift ;;
-q|--quiet)
QUIET=1 ;;
-m|--nocolor)
@@ -149,7 +155,8 @@ source "@sysconfdir@/makepkg.conf"
 if [[ -r ~/.makepkg.conf ]]; then
source ~/.makepkg.conf
 fi
-pkg_dest="${PKGDEST:-$PWD}"
+PKGDEST="${PKGDEST:-$PWD}"
+pkg_dest="${pkg_dest:-$PKGDEST}"
 pkg_pkger="${PACKAGER:-'Unknown Packager'}"
 
 # Check for an existing database
-- 
2.9.3


[pacman-dev] [PATCH v7 11/12] bacman: add manual page

2016-09-03 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/doc/.gitignore   |  1 +
 contrib/doc/Makefile.am  |  5 +++-
 contrib/doc/bacman.8.txt | 66 
 3 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 contrib/doc/bacman.8.txt

diff --git a/contrib/doc/.gitignore b/contrib/doc/.gitignore
index c5612bc..3ab2035 100644
--- a/contrib/doc/.gitignore
+++ b/contrib/doc/.gitignore
@@ -1 +1,2 @@
 verify-pacman-repo-db.1
+bacman.8
diff --git a/contrib/doc/Makefile.am b/contrib/doc/Makefile.am
index 4c316bb..d5725b1 100644
--- a/contrib/doc/Makefile.am
+++ b/contrib/doc/Makefile.am
@@ -4,12 +4,14 @@
 # man_MANS if --enable-asciidoc and/or --enable-doxygen are used.
 
 ASCIIDOC_MANS = \
-   verify-pacman-repo-db.1
+   verify-pacman-repo-db.1 \
+   bacman.8
 
 EXTRA_DIST = \
asciidoc.conf \
footer.txt \
verify-pacman-repo-db.1.txt \
+   bacman.8.txt \
$(ASCIIDOC_MANS)
 
 # Files that should be removed, but which Automake does not know.
@@ -53,5 +55,6 @@ $(ASCIIDOC_MANS): asciidoc.conf footer.txt Makefile.am
 
 # Dependency rules
 verify-pacman-repo-db.1: verify-pacman-repo-db.1.txt
+bacman.8: bacman.8.txt
 
 # vim:set noet:
diff --git a/contrib/doc/bacman.8.txt b/contrib/doc/bacman.8.txt
new file mode 100644
index 000..a9d7ba9
--- /dev/null
+++ b/contrib/doc/bacman.8.txt
@@ -0,0 +1,66 @@
+/
+vim:set ts=4 sw=4 syntax=asciidoc noet spell spelllang=en_us:
+/
+bacman(8)
+==
+
+Name
+
+bacman - recreate installed packages
+
+
+Synopsis
+
+'bacman' [options] <package(s)>
+
+
+Description
+---
+'bacman' was designed to reassemble installed packages from its deliverd files.
+It comes in handy if there is no internet connection available and you have no
+access to a up-to-date package cache.
+
+'bacman' fully honors linkman:makepkg.conf[8] and all compression environment
+variables, notably ``XZ_OPT''.
+
+
+Options
+---
+*-h, \--help*::
+   Display usage information.
+
+*-q, \--quiet*::
+   Silence most of the status reporting.
+
+*-m, \--nocolor*::
+   Disable colored output.
+
+*-o, \--out *::
+   Write the assembled package(s) to the specified directory.
+
+*\--pacnew*::
+   Package .pacnew files instead of the concerning files currently in 
place.
+
+
+Examples
+
+'bacman' linux-headers
+
+Recreate the package ``linux-headers''.
+
+'bacman' gzip munge binutils -o ~/Downloads
+
+Assemble the packages gzip munge binutils and place the packages at
+``~/Downloads''.
+
+'bacman' --nocolor --pacnew -o ~/backup $(pacman -Qsq)
+
+Assemble all currently installed packages using ``.pacnew'' whenever available,
+suppress colored output and place the desired packages in ``~/backup''.
+
+
+See Also
+
+linkman:makepkg[8], linkman:pacman[8]
+
+include::footer.txt[]
-- 
2.9.3


[pacman-dev] [PATCH v7 08/12] bacman: add option to print fewer status updates

2016-09-03 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
Move indentation fixes into its own commit.

 contrib/bacman.sh.in | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 6f943a1..94b09d7 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -28,6 +28,7 @@ declare -r myname='bacman'
 declare -r myver='@PACKAGE_VERSION@'
 USE_COLOR='y'
 INCLUDE_PACNEW='n'
+QUIET=0
 # Required for fakeroot because options are shifted off the array.
 ARGS=("$@")
 
@@ -54,6 +55,7 @@ usage() {
echo
printf -- "$(gettext "Options:")\n"
printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
+   printf -- "$(gettext "  -q, --quiet  Silence most of the status 
reporting")\n"
printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
echo
@@ -85,8 +87,8 @@ for option in "$@"; do
 done
 
 # Parse arguments
-OPT_SHORT='mv'
-OPT_LONG=('nocolor' 'pacnew' 'version')
+OPT_SHORT='qmv'
+OPT_LONG=('quiet' 'nocolor' 'pacnew' 'version')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
@@ -96,6 +98,8 @@ unset OPT_SHORT OPT_LONG OPTRET
 
 while :; do
case "$1" in
+   -q|--quiet)
+   QUIET=1 ;;
-m|--nocolor)
USE_COLOR='n' ;;
--pacnew)
-- 
2.9.3


[pacman-dev] [PATCH v7 05/12] bacman: rewrite usage function

2016-09-03 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
Move indentation fixes into its own commit.

 contrib/bacman.sh.in | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 639a538..c853958 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -48,13 +48,21 @@ trap clean_up SIGHUP SIGINT SIGTERM
 # User Friendliness
 #
 usage() {
-   echo "${myname} (pacman) v${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
echo
-   echo "Recreate a package using pacman's database and system files"
+   printf -- "$(gettext "Recreate packages using pacman's database and 
system files")\n"
echo
-   echo "Usage: ${myname} [--nocolor] [--pacnew] "
+   printf -- "$(gettext "Usage: %s [options] <package(s)>")\n" "$0"
+   echo
+   printf -- "$(gettext "Options:")\n"
+   printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
+   printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
+   printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
+   echo
+   printf -- "$(gettext "Examples:  %s linux-headers")\n" "$myname"
+   printf -- "$(gettext "  %s --nocolor --pacnew gzip munge binutils")\n" 
"$myname"
+   printf -- "$(gettext "  %s \$(pacman -Qsq)")\n" "$myname"
echo
-   echo "Example: ${myname} linux-headers"
 }
 
 version() {
-- 
2.9.3


[pacman-dev] [PATCH v7 06/12] bacman: code structuring

2016-09-03 Thread Gordian Edenhofer
Adding and clarifying comments.
Adding and removing some new lines.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 25 -
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index c853958..d0309b6 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -44,9 +44,7 @@ clean_up() {
 # Trap termination signals
 trap clean_up SIGHUP SIGINT SIGTERM
 
-#
-# User Friendliness
-#
+# Print usage information
 usage() {
printf "%s (pacman) %s\n" "$myname" "$myver"
echo
@@ -65,6 +63,7 @@ usage() {
echo
 }
 
+# Print version information
 version() {
printf "%s %s\n" "$myname" "$myver"
echo 'Copyright (C) 2008 locci '
@@ -118,9 +117,7 @@ if [[ ${#pkg_list[@]} == 0 ]]; then
exit 1
 fi
 
-#
-# Fakeroot support
-#
+# Run with fake root privileges if EUID is not root
 if (( EUID )); then
if [[ -f /usr/bin/fakeroot ]]; then
msg "Entering fakeroot environment"
@@ -133,33 +130,25 @@ if (( EUID )); then
fi
 fi
 
-#
-# Setting environmental variables
-#
+# Source environmental variables and specify fallbacks
 if [[ ! -r @sysconfdir@/pacman.conf ]]; then
error "unable to read @sysconfdir@/pacman.conf"
exit 1
 fi
-
 eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
 pac_db="${DBPath:-@localstatedir@/lib/pacman/}/local"
-
 if [[ ! -r @sysconfdir@/makepkg.conf ]]; then
error "unable to read @sysconfdir@/makepkg.conf"
exit 1
 fi
-
 source "@sysconfdir@/makepkg.conf"
 if [[ -r ~/.makepkg.conf ]]; then
source ~/.makepkg.conf
 fi
-
 pkg_dest="${PKGDEST:-$PWD}"
 pkg_pkger=${PACKAGER:-'Unknown Packager'}
 
-#
-# Checks everything is in place
-#
+# Check for an existing database
 if [[ ! -d $pac_db ]]; then
error "pacman database directory ${pac_db} not found"
exit 1
@@ -191,6 +180,7 @@ fakebuild() {
 
# Assemble list of files which belong to the package and tar them
msg2 "Copying package files..."
+
while read i; do
if [[ -z $i ]]; then
continue
@@ -357,6 +347,7 @@ fakebuild() {
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
ret=0
 
+   # Move compressed package to destination
# TODO: Maybe this can be set globally for robustness
shopt -s -o pipefail
bsdtar -cf - $comp_files * |
@@ -370,7 +361,7 @@ fakebuild() {
"$PKGEXT"; cat ;;
esac > "${pkg_file}"; ret=$?
 
-   # Move compressed package to destination
+   # Evaluate return code
if (( ret )); then
error "Unable to write package to $pkg_dest"
plain "   Maybe the disk is full or you do not have write 
access"
-- 
2.9.3


[pacman-dev] [PATCH v7 07/12] bacman: quote pkg_pkger variable

2016-09-03 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index d0309b6..6f943a1 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -146,7 +146,7 @@ if [[ -r ~/.makepkg.conf ]]; then
source ~/.makepkg.conf
 fi
 pkg_dest="${PKGDEST:-$PWD}"
-pkg_pkger=${PACKAGER:-'Unknown Packager'}
+pkg_pkger="${PACKAGER:-'Unknown Packager'}"
 
 # Check for an existing database
 if [[ ! -d $pac_db ]]; then
-- 
2.9.3


[pacman-dev] [PATCH v7 04/12] bacman: proper option handling

2016-09-03 Thread Gordian Edenhofer
Switch to parseopts instead of merely checking the first argument.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 62 +++-
 1 file changed, 42 insertions(+), 20 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 0c71541..639a538 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -32,6 +32,7 @@ INCLUDE_PACNEW='n'
 ARGS=("$@")
 
 m4_include(../scripts/library/output_format.sh)
+m4_include(../scripts/library/parseopts.sh)
 
 # Lazy recursive clean up of temporary dirs
 work_dir_root="${TMPDIR:-/tmp}/bacman"
@@ -62,32 +63,51 @@ version() {
echo 'Copyright (C) 2008-2016 Pacman Development Team 
<pacman-dev@archlinux.org>'
 }
 
-while [[ ! -z $1 ]]; do
-   if [[ $1 == "--nocolor" ]]; then
-   USE_COLOR='n'
-   shift
-   elif [[ $1 == "--pacnew" ]]; then
-   INCLUDE_PACNEW='y'
-   shift
-   else
-   break
-   fi
-done
-
+# Configure colored output
 m4_include(../scripts/library/term_colors.sh)
 
 # Break if no argument was given
-if (( $# < 1 )); then
+if (( $# == 0 )); then
+   usage
+   exit 1
+fi
+
+# Printing the usage information takes precedence over every other parameter
+for option in "$@"; do
+   [[ $option == "-h" || $option == "--help" ]] && usage && exit 0
+done
+
+# Parse arguments
+OPT_SHORT='mv'
+OPT_LONG=('nocolor' 'pacnew' 'version')
+if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
 fi
+set -- "${OPTRET[@]}"
+unset OPT_SHORT OPT_LONG OPTRET
+
+while :; do
+   case "$1" in
+   -m|--nocolor)
+   USE_COLOR='n' ;;
+   --pacnew)
+   INCLUDE_PACNEW='y' ;;
+   -v|--version)
+   version
+   exit 0 ;;
+   --)
+   shift
+   break 2 ;;
+   esac
+   shift
+done
 
-if [[ $1 = -@(h|-help) ]]; then
+# Retrieve the list of packages to be assembled and break if none was specified
+pkg_list=($*)
+if [[ ${#pkg_list[@]} == 0 ]]; then
usage
-   exit 0
-elif [[ $1 = -@(V|-version) ]]; then
-   version
-   exit 0
+   exit 1
 fi
 
 #
@@ -373,9 +393,11 @@ parallelize() {
 
 # Initiate assembly function
 if [[ $MAX_JOBS -gt "1" ]]; then
-   parallelize "$@"
+   parallelize "${pkg_list[@]}"
 else
-   for PKG in $@; do fakebuild $PKG; done
+   for PKG in ${pkg_list[@]}; do
+   fakebuild $PKG
+   done
 fi
 msg "Done."
 
-- 
2.9.3


[pacman-dev] [PATCH v7 02/12] bacman: handle SIGHUP, SIGINT, SIGTERM signals

2016-09-03 Thread Gordian Edenhofer
Trap SIGHUP, SIGINT, SIGTERM and remove working directories accordingly.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 5e6fce5..e7a7f57 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -33,6 +33,16 @@ ARGS=("$@")
 
 m4_include(../scripts/library/output_format.sh)
 
+# Lazy recursive clean up of temporary dirs
+work_dir_root="${TMPDIR:-/tmp}/bacman"
+clean_up() {
+   rm -rf "$work_dir_root".*
+   echo
+   exit
+}
+# Trap termination signals
+trap clean_up SIGHUP SIGINT SIGTERM
+
 #
 # User Friendliness
 #
-- 
2.9.3


[pacman-dev] [PATCH v7 01/12] bacman: allow for multiple packages as arguments

2016-09-03 Thread Gordian Edenhofer
To enable the creation of multiple packages with one command move the
assembly process into its own function.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
Split up first commit into three distinct parts:
Moving stuff into function, handle abort signals, write and alter some comments.
Merge the altered comments into the code structuring commit.

 contrib/bacman.sh.in | 405 +--
 1 file changed, 200 insertions(+), 205 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index a611c1a..5e6fce5 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -66,7 +66,8 @@ done
 
 m4_include(../scripts/library/term_colors.sh)
 
-if (( $# != 1 )); then
+# Break if no argument was given
+if (( $# < 1 )); then
usage
exit 1
 fi
@@ -118,10 +119,6 @@ fi
 pkg_dest="${PKGDEST:-$PWD}"
 pkg_pkger=${PACKAGER:-'Unknown Packager'}
 
-pkg_name="$1"
-pkg_dir=("$pac_db/$pkg_name"-+([^-])-+([^-]))
-pkg_namver=("${pkg_dir[@]##*/}")
-
 #
 # Checks everything is in place
 #
@@ -130,227 +127,225 @@ if [[ ! -d $pac_db ]]; then
exit 1
 fi
 
-if (( ${#pkg_dir[@]} != 1 )); then
-   error "%d entries for package %s found in pacman database" \
-   ${#pkg_dir[@]} "${pkg_name}"
-   msg2 "%s" "${pkg_dir[@]}"
-   exit 1
-fi
-
-if [[ ! -d $pkg_dir ]]; then
-   error "package %s is found in pacman database," "${pkg_name}"
-   plain "   but '%s' is not a directory" "${pkg_dir}"
-   exit 1
-fi
-
-#
-# Begin
-#
-msg "Package: ${pkg_namver}"
-work_dir=$(mktemp -d "${TMPDIR:-/tmp}/bacman.XX")
-cd "$work_dir" || exit 1
-
-#
-# File copying
-#
-msg2 "Copying package files..."
-
-while read i; do
-   if [[ -z $i ]]; then
-   continue
+# Assemble a single package: $1 = pkgname
+fakebuild() {
+   pkg_name="$1"
+   pkg_dir=("$pac_db/$pkg_name"-+([^-])-+([^-]))
+   pkg_namver=("${pkg_dir[@]##*/}")
+
+   # Checks database for specified package
+   if (( ${#pkg_dir[@]} != 1 )); then
+   error "%d entries for package %s found in pacman database" \
+   ${#pkg_dir[@]} "${pkg_name}"
+   msg2 "%s" "${pkg_dir[@]}"
+   exit 1
fi
-
-   if [[ $i == %+([A-Z])% ]]; then
-   current=$i
-   continue
+   if [[ ! -d $pkg_dir ]]; then
+   error "package %s is found in pacman database," "${pkg_name}"
+   plain "   but '%s' is not a directory" "${pkg_dir}"
+   exit 1
fi
 
-   case "$current" in
-   %FILES%)
-   local_file="/$i"
-   package_file="$work_dir/$i"
+   # Create working directory
+   msg "Package: ${pkg_namver}"
+   work_dir=$(mktemp -d "${work_dir_root}.XX")
+   cd "$work_dir" || exit 1
 
-   if [[ ! -e $local_file ]]; then
-   warning "package file $local_file is missing"
-   continue
-   fi
-   ;;
-
-   %BACKUP%)
-   # Get the MD5 checksum.
-   original_md5="${i##*$'\t'}"
-   # Strip the md5sum after the tab.
-   i="${i%$'\t'*}"
-   local_file="/$i.pacnew"
-   package_file="$work_dir/$i"
-
-   # Include unmodified .pacnew files.
-   local_md5="$(md5sum "$local_file" | cut -d' ' -f1)"
-   if [[ $INCLUDE_PACNEW == 'n' ]] \
-   || [[ ! -e $local_file ]] \
-   || [[ $local_md5 != $original_md5 ]]; then
-   # Warn about modified files.
-   local_md5="$(md5sum "/$i" | cut -d' ' -f1)"
-   if [[ $local_md5 != $original_md5 ]]; then
-   warning "package file /$i has been 
modified"
-   fi
-   # Let the normal file be included in the 
%FILES% list.
-   continue
-   fi
-   ;;
+   # Assemble list of files which belong to the package and tar them
+   msg2 "Copying package files..."
+   while read i; do
+   if [[ -z $i ]]; then
+   continue
+   fi
 
-   *)
+   

Re: [pacman-dev] [PATCH v5 4/8] bacman: rewrite usage page and version information

2016-09-02 Thread Gordian Edenhofer
On Fri, 2016-09-02 at 23:37 +1000, Allan McRae wrote:
> On 02/09/16 22:51, Gordian Edenhofer wrote:
> > 
> >     echo 'Copyright (C) 2008 locci
> > '
> > +   echo 'Copyright (C) 2016 Gordian Edenhofer  > f...@gmail.com>'
> >     echo 'Copyright (C) 2008-2016 Pacman Development Team  > man-...@archlinux.org>'
> 
> 
> You want your name included beyond the "Pacman Development
> Team".  There
> are currently 11 other contributors to that script beyond the
> original
> author (who has their own copyright line).

I did not intended to insult anyone or diminish other contributions.
I just though of the patch as a significant revamp considering the
patch allows for multiple packages, handles abort signals, added
various options and introduced a man page.
Since apparently this seems to offend you, I removed my name.

signature.asc
Description: This is a digitally signed message part


[pacman-dev] [PATCH v6 8/9] bacman: add manual page

2016-09-02 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
Remove a reference to the Arch Linux Archive.
Reorder some options according to the usage function.
Add -m the abbreviated form of --nocolor.

 contrib/doc/.gitignore   |  1 +
 contrib/doc/Makefile.am  |  5 +++-
 contrib/doc/bacman.8.txt | 66 
 3 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 contrib/doc/bacman.8.txt

diff --git a/contrib/doc/.gitignore b/contrib/doc/.gitignore
index c5612bc..3ab2035 100644
--- a/contrib/doc/.gitignore
+++ b/contrib/doc/.gitignore
@@ -1 +1,2 @@
 verify-pacman-repo-db.1
+bacman.8
diff --git a/contrib/doc/Makefile.am b/contrib/doc/Makefile.am
index 4c316bb..d5725b1 100644
--- a/contrib/doc/Makefile.am
+++ b/contrib/doc/Makefile.am
@@ -4,12 +4,14 @@
 # man_MANS if --enable-asciidoc and/or --enable-doxygen are used.
 
 ASCIIDOC_MANS = \
-   verify-pacman-repo-db.1
+   verify-pacman-repo-db.1 \
+   bacman.8
 
 EXTRA_DIST = \
asciidoc.conf \
footer.txt \
verify-pacman-repo-db.1.txt \
+   bacman.8.txt \
$(ASCIIDOC_MANS)
 
 # Files that should be removed, but which Automake does not know.
@@ -53,5 +55,6 @@ $(ASCIIDOC_MANS): asciidoc.conf footer.txt Makefile.am
 
 # Dependency rules
 verify-pacman-repo-db.1: verify-pacman-repo-db.1.txt
+bacman.8: bacman.8.txt
 
 # vim:set noet:
diff --git a/contrib/doc/bacman.8.txt b/contrib/doc/bacman.8.txt
new file mode 100644
index 000..a9d7ba9
--- /dev/null
+++ b/contrib/doc/bacman.8.txt
@@ -0,0 +1,66 @@
+/
+vim:set ts=4 sw=4 syntax=asciidoc noet spell spelllang=en_us:
+/
+bacman(8)
+==
+
+Name
+
+bacman - recreate installed packages
+
+
+Synopsis
+
+'bacman' [options] <package(s)>
+
+
+Description
+---
+'bacman' was designed to reassemble installed packages from its deliverd files.
+It comes in handy if there is no internet connection available and you have no
+access to a up-to-date package cache.
+
+'bacman' fully honors linkman:makepkg.conf[8] and all compression environment
+variables, notably ``XZ_OPT''.
+
+
+Options
+---
+*-h, \--help*::
+   Display usage information.
+
+*-q, \--quiet*::
+   Silence most of the status reporting.
+
+*-m, \--nocolor*::
+   Disable colored output.
+
+*-o, \--out *::
+   Write the assembled package(s) to the specified directory.
+
+*\--pacnew*::
+   Package .pacnew files instead of the concerning files currently in 
place.
+
+
+Examples
+
+'bacman' linux-headers
+
+Recreate the package ``linux-headers''.
+
+'bacman' gzip munge binutils -o ~/Downloads
+
+Assemble the packages gzip munge binutils and place the packages at
+``~/Downloads''.
+
+'bacman' --nocolor --pacnew -o ~/backup $(pacman -Qsq)
+
+Assemble all currently installed packages using ``.pacnew'' whenever available,
+suppress colored output and place the desired packages in ``~/backup''.
+
+
+See Also
+
+linkman:makepkg[8], linkman:pacman[8]
+
+include::footer.txt[]
-- 
2.9.3


[pacman-dev] [PATCH v6 4/9] bacman: rewrite usage page and version information

2016-09-02 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 24 
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 8656c5c..f5807b5 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -41,19 +41,26 @@ clean_up() {
echo
exit
 }
-
 # Trap termination signals
 trap clean_up SIGHUP SIGINT SIGTERM
 
 # Print usage information
 usage() {
-   echo "${myname} (pacman) v${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
+   echo
+   printf -- "$(gettext "Recreate packages using pacman's database and 
system files")\n"
+   echo
+   printf -- "$(gettext "Usage: %s [options] <package(s)>")\n" "$0"
echo
-   echo "Recreate a package using pacman's database and system files"
+   printf -- "$(gettext "Options:")\n"
+   printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
+   printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
+   printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
echo
-   echo "Usage: ${myname} [--nocolor] [--pacnew] "
+   printf -- "$(gettext "Examples:  %s linux-headers")\n" "$myname"
+   printf -- "$(gettext "  %s --nocolor --pacnew gzip munge binutils")\n" 
"$myname"
+   printf -- "$(gettext "  %s \$(pacman -Qsq)")\n" "$myname"
echo
-   echo "Example: ${myname} linux-headers"
 }
 
 # Print version information
@@ -123,7 +130,7 @@ if (( EUID )); then
fi
 fi
 
-# Source environmental variables and specify fallbacks
+# Read in environmental variables
 if [[ ! -r @sysconfdir@/pacman.conf ]]; then
error "unable to read @sysconfdir@/pacman.conf"
exit 1
@@ -139,7 +146,7 @@ if [[ -r ~/.makepkg.conf ]]; then
source ~/.makepkg.conf
 fi
 pkg_dest="${PKGDEST:-$PWD}"
-pkg_pkger=${PACKAGER:-'Unknown Packager'}
+pkg_pkger="${PACKAGER:-'Unknown Packager'}"
 
 # Check for an existing database
 if [[ ! -d $pac_db ]]; then
@@ -339,6 +346,7 @@ fakebuild() {
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
ret=0
 
+   # Move compressed package to destination
# TODO: Maybe this can be set globally for robustness
shopt -s -o pipefail
bsdtar -cf - $comp_files * |
@@ -352,7 +360,7 @@ fakebuild() {
"$PKGEXT"; cat ;;
esac > "${pkg_file}"; ret=$?
 
-   # Move compressed package to destination
+   # Evaluate return code
if (( ret )); then
error "Unable to write package to $pkg_dest"
plain "   Maybe the disk is full or you do not have write 
access"
-- 
2.9.3


[pacman-dev] [PATCH v6 9/9] bacman man page: describe the jobs option

2016-09-02 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
Move the description of the jobs option into its own commit.

 contrib/doc/bacman.8.txt | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/contrib/doc/bacman.8.txt b/contrib/doc/bacman.8.txt
index a9d7ba9..4738189 100644
--- a/contrib/doc/bacman.8.txt
+++ b/contrib/doc/bacman.8.txt
@@ -35,6 +35,9 @@ Options
 *-m, \--nocolor*::
Disable colored output.
 
+*-j, \--jobs *::
+   Assemble multiple packages in parallel.
+
 *-o, \--out *::
Write the assembled package(s) to the specified directory.
 
@@ -53,10 +56,11 @@ Recreate the package ``linux-headers''.
 Assemble the packages gzip munge binutils and place the packages at
 ``~/Downloads''.
 
-'bacman' --nocolor --pacnew -o ~/backup $(pacman -Qsq)
+'bacman' --nocolor --pacnew -o ~/backup -j 5 $(pacman -Qsq)
 
-Assemble all currently installed packages using ``.pacnew'' whenever available,
-suppress colored output and place the desired packages in ``~/backup''.
+Assemble all currently installed packages using 5 concurrent jobs, use
+``.pacnew'' whenever available, suppress colored output and place the desired
+packages in ``~/backup''.
 
 
 See Also
-- 
2.9.3


[pacman-dev] [PATCH v6 5/9] bacman: add option to print fewer status updates

2016-09-02 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index f5807b5..a567e7d 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -28,6 +28,7 @@ declare -r myname='bacman'
 declare -r myver='@PACKAGE_VERSION@'
 USE_COLOR='y'
 INCLUDE_PACNEW='n'
+QUIET=0
 # Required for fakeroot because options are shifted off the array.
 ARGS=("$@")
 
@@ -54,6 +55,7 @@ usage() {
echo
printf -- "$(gettext "Options:")\n"
printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
+   printf -- "$(gettext "  -q, --quiet  Silence most of the status 
reporting")\n"
printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
echo
@@ -85,8 +87,8 @@ for option in "$@"; do
 done
 
 # Parse arguments
-OPT_SHORT='mv'
-OPT_LONG=('nocolor' 'pacnew' 'version')
+OPT_SHORT='qmv'
+OPT_LONG=('quiet' 'nocolor' 'pacnew' 'version')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
@@ -96,6 +98,8 @@ unset OPT_SHORT OPT_LONG OPTRET
 
 while :; do
case "$1" in
+   -q|--quiet)
+   QUIET=1 ;;
-m|--nocolor)
USE_COLOR='n' ;;
--pacnew)
@@ -180,6 +184,7 @@ fakebuild() {
 
# Assemble list of files which belong to the package and tar them
msg2 "Copying package files..."
+
while read i; do
if [[ -z $i ]]; then
continue
-- 
2.9.3


[pacman-dev] [PATCH v6 6/9] bacman: add otpion to alter the output directory

2016-09-02 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index a567e7d..b636cb6 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -57,10 +57,12 @@ usage() {
printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
printf -- "$(gettext "  -q, --quiet  Silence most of the status 
reporting")\n"
printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
+   printf -- "$(gettext "  -o, --out   Write output to specified 
directory (instead of \$PKGDEST)")\n"
printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
echo
printf -- "$(gettext "Examples:  %s linux-headers")\n" "$myname"
-   printf -- "$(gettext "  %s --nocolor --pacnew gzip munge binutils")\n" 
"$myname"
+   printf -- "$(gettext "  %s gzip munge binutils -o ~/Downloads")\n" 
"$myname"
+   printf -- "$(gettext "  %s --nocolor --pacnew -o /tmp gzip munge 
binutils")\n" "$myname"
printf -- "$(gettext "  %s \$(pacman -Qsq)")\n" "$myname"
echo
 }
@@ -87,8 +89,8 @@ for option in "$@"; do
 done
 
 # Parse arguments
-OPT_SHORT='qmv'
-OPT_LONG=('quiet' 'nocolor' 'pacnew' 'version')
+OPT_SHORT='o:qmv'
+OPT_LONG=('out:' 'quiet' 'nocolor' 'pacnew' 'version')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
@@ -98,6 +100,10 @@ unset OPT_SHORT OPT_LONG OPTRET
 
 while :; do
case "$1" in
+   -o|--out)
+   pkg_dest=$2
+   [[ ! -d "$2" ]] && echo -e "The directory 
\e[39;1m$2\e[0m does not exist!" && exit 3
+   shift ;;
-q|--quiet)
QUIET=1 ;;
-m|--nocolor)
@@ -149,7 +155,8 @@ source "@sysconfdir@/makepkg.conf"
 if [[ -r ~/.makepkg.conf ]]; then
source ~/.makepkg.conf
 fi
-pkg_dest="${PKGDEST:-$PWD}"
+PKGDEST="${PKGDEST:-$PWD}"
+pkg_dest="${pkg_dest:-$PKGDEST}"
 pkg_pkger="${PACKAGER:-'Unknown Packager'}"
 
 # Check for an existing database
-- 
2.9.3


[pacman-dev] [PATCH v6 7/9] bacman: add option to specify the number of jobs

2016-09-02 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 33 +++--
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index b636cb6..120bece 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -57,12 +57,13 @@ usage() {
printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
printf -- "$(gettext "  -q, --quiet  Silence most of the status 
reporting")\n"
printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
+   printf -- "$(gettext "  -j, --jobsBuild in parallel with N jobs 
- you may want to set XZ_OPT")\n"
printf -- "$(gettext "  -o, --out   Write output to specified 
directory (instead of \$PKGDEST)")\n"
printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
echo
printf -- "$(gettext "Examples:  %s linux-headers")\n" "$myname"
printf -- "$(gettext "  %s gzip munge binutils -o ~/Downloads")\n" 
"$myname"
-   printf -- "$(gettext "  %s --nocolor --pacnew -o /tmp gzip munge 
binutils")\n" "$myname"
+   printf -- "$(gettext "  %s --nocolor --pacnew -o /tmp -j 5 gzip munge 
binutils")\n" "$myname"
printf -- "$(gettext "  %s \$(pacman -Qsq)")\n" "$myname"
echo
 }
@@ -89,8 +90,8 @@ for option in "$@"; do
 done
 
 # Parse arguments
-OPT_SHORT='o:qmv'
-OPT_LONG=('out:' 'quiet' 'nocolor' 'pacnew' 'version')
+OPT_SHORT='o:j:qmv'
+OPT_LONG=('out:' 'jobs:' 'quiet' 'nocolor' 'pacnew' 'version')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
@@ -104,6 +105,14 @@ while :; do
pkg_dest=$2
[[ ! -d "$2" ]] && echo -e "The directory 
\e[39;1m$2\e[0m does not exist!" && exit 3
shift ;;
+   -j|--jobs)
+   if [[ $2 =~ ^-?[0-9]+$ ]]; then
+   MAX_JOBS=$2
+   else
+   echo -e "\e[39;1m$2\e[0m is not a valid 
integer!"
+   exit -1
+   fi
+   shift ;;
-q|--quiet)
QUIET=1 ;;
-m|--nocolor)
@@ -190,7 +199,11 @@ fakebuild() {
cd "$work_dir" || exit 1
 
# Assemble list of files which belong to the package and tar them
-   msg2 "Copying package files..."
+   if [[ $MAX_JOBS -gt 1 ]]; then
+   msg2 "${pkg_name}: Copying package files..."
+   else
+   msg2 "Copying package files..."
+   fi
 
while read i; do
if [[ -z $i ]]; then
@@ -265,7 +278,11 @@ fakebuild() {
 
# Reconstruct .PKGINFO from database
# TODO adopt makepkg's write_pkginfo() into this or scripts/library
-   msg2 "Generating .PKGINFO metadata..."
+   if [[ $MAX_JOBS -gt 1 ]]; then
+   msg2 "${pkg_name}: Generating .PKGINFO metadata..."
+   else
+   msg2 "Generating .PKGINFO metadata..."
+   fi
echo "# Generated by $myname $myver"> .PKGINFO
if [[ $INFAKEROOT == "1" ]]; then
echo "# Using $(fakeroot -v)">> .PKGINFO
@@ -353,7 +370,11 @@ fakebuild() {
chmod 644 "$work_dir"/{.PKGINFO,.CHANGELOG,.INSTALL} 2> /dev/null
 
# Generate the package
-   msg2 "Generating the package..."
+   if [[ $MAX_JOBS -gt 1 ]]; then
+   msg2 "${pkg_name}: Generating the package..."
+   else
+   msg2 "Generating the package..."
+   fi
 
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
ret=0
-- 
2.9.3


[pacman-dev] [PATCH v6 3/9] bacman: proper option handling

2016-09-02 Thread Gordian Edenhofer
Switch to parseopts instead of merely checking the first argument.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 63 ++--
 1 file changed, 41 insertions(+), 22 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index a718a18..8656c5c 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -32,6 +32,7 @@ INCLUDE_PACNEW='n'
 ARGS=("$@")
 
 m4_include(../scripts/library/output_format.sh)
+m4_include(../scripts/library/parseopts.sh)
 
 # Lazy recursive clean up of temporary dirs
 work_dir_root="${TMPDIR:-/tmp}/bacman"
@@ -62,35 +63,51 @@ version() {
echo 'Copyright (C) 2008-2016 Pacman Development Team 
<pacman-dev@archlinux.org>'
 }
 
-# Check for specified arguments
-while [[ ! -z $1 ]]; do
-   if [[ $1 == "--nocolor" ]]; then
-   USE_COLOR='n'
-   shift
-   elif [[ $1 == "--pacnew" ]]; then
-   INCLUDE_PACNEW='y'
-   shift
-   else
-   break
-   fi
-done
-
 # Configure colored output
 m4_include(../scripts/library/term_colors.sh)
 
 # Break if no argument was given
-if (( $# < 1 )); then
+if (( $# == 0 )); then
+   usage
+   exit 1
+fi
+
+# Printing the usage information takes precedence over every other parameter
+for option in "$@"; do
+   [[ $option == "-h" || $option == "--help" ]] && usage && exit 0
+done
+
+# Parse arguments
+OPT_SHORT='mv'
+OPT_LONG=('nocolor' 'pacnew' 'version')
+if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
 fi
+set -- "${OPTRET[@]}"
+unset OPT_SHORT OPT_LONG OPTRET
+
+while :; do
+   case "$1" in
+   -m|--nocolor)
+   USE_COLOR='n' ;;
+   --pacnew)
+   INCLUDE_PACNEW='y' ;;
+   -v|--version)
+   version
+   exit 0 ;;
+   --)
+   shift
+   break 2 ;;
+   esac
+   shift
+done
 
-# Print usage or version if requested
-if [[ $1 = -@(h|-help) ]]; then
+# Retrieve the list of packages to be assembled and break if none was specified
+pkg_list=($*)
+if [[ ${#pkg_list[@]} == 0 ]]; then
usage
-   exit 0
-elif [[ $1 = -@(V|-version) ]]; then
-   version
-   exit 0
+   exit 1
 fi
 
 # Run with fake root privileges if EUID is not root
@@ -366,9 +383,11 @@ parallelize() {
 
 # Initiate assembly function
 if [[ $MAX_JOBS -gt "1" ]]; then
-   parallelize "$@"
+   parallelize "${pkg_list[@]}"
 else
-   for PKG in $@; do fakebuild $PKG; done
+   for PKG in ${pkg_list[@]}; do
+   fakebuild $PKG
+   done
 fi
 msg "Done."
 
-- 
2.9.3


[pacman-dev] [PATCH v6 1/9] bacman: allow for multiple packages as arguments

2016-09-02 Thread Gordian Edenhofer
To enable the creation of multiple packages with one command move the
assembly process into its own function.
Handle SIGHUP, SIGINT, SIGTERM and remove working directories
accordingly.
Add some comments.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 440 +--
 1 file changed, 219 insertions(+), 221 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index a611c1a..512973a 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -33,9 +33,18 @@ ARGS=("$@")
 
 m4_include(../scripts/library/output_format.sh)
 
-#
-# User Friendliness
-#
+# Lazy recursive clean up of temporary dirs
+work_dir_root="${TMPDIR:-/tmp}/bacman"
+clean_up() {
+   rm -rf "$work_dir_root".*
+   echo
+   exit
+}
+
+# Trap termination signals
+trap clean_up SIGHUP SIGINT SIGTERM
+
+# Print usage information
 usage() {
echo "${myname} (pacman) v${myver}"
echo
@@ -46,12 +55,14 @@ usage() {
echo "Example: ${myname} linux-headers"
 }
 
+# Print version information
 version() {
printf "%s %s\n" "$myname" "$myver"
echo 'Copyright (C) 2008 locci '
echo 'Copyright (C) 2008-2016 Pacman Development Team 
<pacman-dev@archlinux.org>'
 }
 
+# Check for specified arguments
 while [[ ! -z $1 ]]; do
if [[ $1 == "--nocolor" ]]; then
USE_COLOR='n'
@@ -64,13 +75,16 @@ while [[ ! -z $1 ]]; do
fi
 done
 
+# Configure colored output
 m4_include(../scripts/library/term_colors.sh)
 
-if (( $# != 1 )); then
+# Break if no argument was given
+if (( $# < 1 )); then
usage
exit 1
 fi
 
+# Print usage or version if requested
 if [[ $1 = -@(h|-help) ]]; then
usage
exit 0
@@ -79,9 +93,7 @@ elif [[ $1 = -@(V|-version) ]]; then
exit 0
 fi
 
-#
-# Fakeroot support
-#
+# Run with fake root privileges if EUID is not root
 if (( EUID )); then
if [[ -f /usr/bin/fakeroot ]]; then
msg "Entering fakeroot environment"
@@ -94,263 +106,249 @@ if (( EUID )); then
fi
 fi
 
-#
-# Setting environmental variables
-#
+# Source environmental variables and specify fallbacks
 if [[ ! -r @sysconfdir@/pacman.conf ]]; then
error "unable to read @sysconfdir@/pacman.conf"
exit 1
 fi
-
 eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
 pac_db="${DBPath:-@localstatedir@/lib/pacman/}/local"
-
 if [[ ! -r @sysconfdir@/makepkg.conf ]]; then
error "unable to read @sysconfdir@/makepkg.conf"
exit 1
 fi
-
 source "@sysconfdir@/makepkg.conf"
 if [[ -r ~/.makepkg.conf ]]; then
source ~/.makepkg.conf
 fi
-
 pkg_dest="${PKGDEST:-$PWD}"
 pkg_pkger=${PACKAGER:-'Unknown Packager'}
 
-pkg_name="$1"
-pkg_dir=("$pac_db/$pkg_name"-+([^-])-+([^-]))
-pkg_namver=("${pkg_dir[@]##*/}")
-
-#
-# Checks everything is in place
-#
+# Check for an existing database
 if [[ ! -d $pac_db ]]; then
error "pacman database directory ${pac_db} not found"
exit 1
 fi
 
-if (( ${#pkg_dir[@]} != 1 )); then
-   error "%d entries for package %s found in pacman database" \
-   ${#pkg_dir[@]} "${pkg_name}"
-   msg2 "%s" "${pkg_dir[@]}"
-   exit 1
-fi
-
-if [[ ! -d $pkg_dir ]]; then
-   error "package %s is found in pacman database," "${pkg_name}"
-   plain "   but '%s' is not a directory" "${pkg_dir}"
-   exit 1
-fi
-
-#
-# Begin
-#
-msg "Package: ${pkg_namver}"
-work_dir=$(mktemp -d "${TMPDIR:-/tmp}/bacman.XX")
-cd "$work_dir" || exit 1
-
-#
-# File copying
-#
-msg2 "Copying package files..."
-
-while read i; do
-   if [[ -z $i ]]; then
-   continue
+# Assemble a single package: $1 = pkgname
+fakebuild() {
+   pkg_name="$1"
+   pkg_dir=("$pac_db/$pkg_name"-+([^-])-+([^-]))
+   pkg_namver=("${pkg_dir[@]##*/}")
+
+   # Checks database for specified package
+   if (( ${#pkg_dir[@]} != 1 )); then
+   error "%d entries for package %s found in pacman database" \
+   ${#pkg_dir[@]} "${pkg_name}"
+   msg2 "%s" "${pkg_dir[@]}"
+   exit 1
fi
-
-   if [[ $i == %+([A-Z])% ]]; then
-   current=$i
-   continue
+   if [[ ! -d $pkg_dir ]]; then
+   error "package %s is found in pacman database," "${pkg_name}"
+   plain "   but '%s' is not a directory" "${pkg_dir}"
+   exit 1
fi
 
-   case "$current" in
-   %FILES%)
-   

[pacman-dev] [PATCH v6 2/9] bacman: parallel packaging

2016-09-02 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 512973a..a718a18 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -347,8 +347,29 @@ fakebuild() {
rm -rf "$work_dir"
 }
 
+# Run fakebuild in parralel with at maximum $MAX_JOBS jobs
+# By default only run one job
+MAX_JOBS=${MAX_JOBS:-1}
+# TODO: Use wait -n instead of this hack as soon as it is ok
+# to bump the version of the bash dependency
+parallelize() {
+   while [[ $# -gt 0 ]]; do
+   job_count=($(jobs -p))
+   if [[ ${#job_count[@]} -lt $MAX_JOBS ]] ; then
+   fakebuild "$1" &
+   shift
+   fi
+   sleep 0.1
+   done
+   wait
+}
 
-for PKG in $@; do fakebuild $PKG; done
+# Initiate assembly function
+if [[ $MAX_JOBS -gt "1" ]]; then
+   parallelize "$@"
+else
+   for PKG in $@; do fakebuild $PKG; done
+fi
 msg "Done."
 
 exit 0
-- 
2.9.3


[pacman-dev] [PATCH v5 1/8] bacman: allow for multiple packages as arguments

2016-09-02 Thread Gordian Edenhofer
To enable the creation of multiple packages with one command move the
assembly process into its own function.
Handle SIGHUP, SIGINT, SIGTERM and remove working directories
accordingly.
Add some comments.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 440 +--
 1 file changed, 219 insertions(+), 221 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index a611c1a..512973a 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -33,9 +33,18 @@ ARGS=("$@")
 
 m4_include(../scripts/library/output_format.sh)
 
-#
-# User Friendliness
-#
+# Lazy recursive clean up of temporary dirs
+work_dir_root="${TMPDIR:-/tmp}/bacman"
+clean_up() {
+   rm -rf "$work_dir_root".*
+   echo
+   exit
+}
+
+# Trap termination signals
+trap clean_up SIGHUP SIGINT SIGTERM
+
+# Print usage information
 usage() {
echo "${myname} (pacman) v${myver}"
echo
@@ -46,12 +55,14 @@ usage() {
echo "Example: ${myname} linux-headers"
 }
 
+# Print version information
 version() {
printf "%s %s\n" "$myname" "$myver"
echo 'Copyright (C) 2008 locci '
echo 'Copyright (C) 2008-2016 Pacman Development Team 
<pacman-dev@archlinux.org>'
 }
 
+# Check for specified arguments
 while [[ ! -z $1 ]]; do
if [[ $1 == "--nocolor" ]]; then
USE_COLOR='n'
@@ -64,13 +75,16 @@ while [[ ! -z $1 ]]; do
fi
 done
 
+# Configure colored output
 m4_include(../scripts/library/term_colors.sh)
 
-if (( $# != 1 )); then
+# Break if no argument was given
+if (( $# < 1 )); then
usage
exit 1
 fi
 
+# Print usage or version if requested
 if [[ $1 = -@(h|-help) ]]; then
usage
exit 0
@@ -79,9 +93,7 @@ elif [[ $1 = -@(V|-version) ]]; then
exit 0
 fi
 
-#
-# Fakeroot support
-#
+# Run with fake root privileges if EUID is not root
 if (( EUID )); then
if [[ -f /usr/bin/fakeroot ]]; then
msg "Entering fakeroot environment"
@@ -94,263 +106,249 @@ if (( EUID )); then
fi
 fi
 
-#
-# Setting environmental variables
-#
+# Source environmental variables and specify fallbacks
 if [[ ! -r @sysconfdir@/pacman.conf ]]; then
error "unable to read @sysconfdir@/pacman.conf"
exit 1
 fi
-
 eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
 pac_db="${DBPath:-@localstatedir@/lib/pacman/}/local"
-
 if [[ ! -r @sysconfdir@/makepkg.conf ]]; then
error "unable to read @sysconfdir@/makepkg.conf"
exit 1
 fi
-
 source "@sysconfdir@/makepkg.conf"
 if [[ -r ~/.makepkg.conf ]]; then
source ~/.makepkg.conf
 fi
-
 pkg_dest="${PKGDEST:-$PWD}"
 pkg_pkger=${PACKAGER:-'Unknown Packager'}
 
-pkg_name="$1"
-pkg_dir=("$pac_db/$pkg_name"-+([^-])-+([^-]))
-pkg_namver=("${pkg_dir[@]##*/}")
-
-#
-# Checks everything is in place
-#
+# Check for an existing database
 if [[ ! -d $pac_db ]]; then
error "pacman database directory ${pac_db} not found"
exit 1
 fi
 
-if (( ${#pkg_dir[@]} != 1 )); then
-   error "%d entries for package %s found in pacman database" \
-   ${#pkg_dir[@]} "${pkg_name}"
-   msg2 "%s" "${pkg_dir[@]}"
-   exit 1
-fi
-
-if [[ ! -d $pkg_dir ]]; then
-   error "package %s is found in pacman database," "${pkg_name}"
-   plain "   but '%s' is not a directory" "${pkg_dir}"
-   exit 1
-fi
-
-#
-# Begin
-#
-msg "Package: ${pkg_namver}"
-work_dir=$(mktemp -d "${TMPDIR:-/tmp}/bacman.XX")
-cd "$work_dir" || exit 1
-
-#
-# File copying
-#
-msg2 "Copying package files..."
-
-while read i; do
-   if [[ -z $i ]]; then
-   continue
+# Assemble a single package: $1 = pkgname
+fakebuild() {
+   pkg_name="$1"
+   pkg_dir=("$pac_db/$pkg_name"-+([^-])-+([^-]))
+   pkg_namver=("${pkg_dir[@]##*/}")
+
+   # Checks database for specified package
+   if (( ${#pkg_dir[@]} != 1 )); then
+   error "%d entries for package %s found in pacman database" \
+   ${#pkg_dir[@]} "${pkg_name}"
+   msg2 "%s" "${pkg_dir[@]}"
+   exit 1
fi
-
-   if [[ $i == %+([A-Z])% ]]; then
-   current=$i
-   continue
+   if [[ ! -d $pkg_dir ]]; then
+   error "package %s is found in pacman database," "${pkg_name}"
+   plain "   but '%s' is not a directory" "${pkg_dir}"
+   exit 1
fi
 
-   case "$current" in
-   %FILES%)
-   

[pacman-dev] [PATCH v5 4/8] bacman: rewrite usage page and version information

2016-09-02 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
Use the same format for the usage section as makepkg.

 contrib/bacman.sh.in | 25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 8656c5c..3868750 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -41,25 +41,33 @@ clean_up() {
echo
exit
 }
-
 # Trap termination signals
 trap clean_up SIGHUP SIGINT SIGTERM
 
 # Print usage information
 usage() {
-   echo "${myname} (pacman) v${myver}"
+   printf "%s (pacman) %s\n" "$myname" "$myver"
+   echo
+   printf -- "$(gettext "Recreate packages using pacman's database and 
system files")\n"
+   echo
+   printf -- "$(gettext "Usage: %s [options] <package(s)>")\n" "$0"
echo
-   echo "Recreate a package using pacman's database and system files"
+   printf -- "$(gettext "Options:")\n"
+   printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
+   printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
+   printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
echo
-   echo "Usage: ${myname} [--nocolor] [--pacnew] "
+   printf -- "$(gettext "Examples:  %s linux-headers")\n" "$myname"
+   printf -- "$(gettext "  %s --nocolor --pacnew gzip munge binutils")\n" 
"$myname"
+   printf -- "$(gettext "  %s \$(pacman -Qsq)")\n" "$myname"
echo
-   echo "Example: ${myname} linux-headers"
 }
 
 # Print version information
 version() {
printf "%s %s\n" "$myname" "$myver"
echo 'Copyright (C) 2008 locci '
+   echo 'Copyright (C) 2016 Gordian Edenhofer 
<gordian.edenho...@gmail.com>'
echo 'Copyright (C) 2008-2016 Pacman Development Team 
<pacman-dev@archlinux.org>'
 }
 
@@ -123,7 +131,7 @@ if (( EUID )); then
fi
 fi
 
-# Source environmental variables and specify fallbacks
+# Read in environmental variables
 if [[ ! -r @sysconfdir@/pacman.conf ]]; then
error "unable to read @sysconfdir@/pacman.conf"
exit 1
@@ -139,7 +147,7 @@ if [[ -r ~/.makepkg.conf ]]; then
source ~/.makepkg.conf
 fi
 pkg_dest="${PKGDEST:-$PWD}"
-pkg_pkger=${PACKAGER:-'Unknown Packager'}
+pkg_pkger="${PACKAGER:-'Unknown Packager'}"
 
 # Check for an existing database
 if [[ ! -d $pac_db ]]; then
@@ -339,6 +347,7 @@ fakebuild() {
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
ret=0
 
+   # Move compressed package to destination
# TODO: Maybe this can be set globally for robustness
shopt -s -o pipefail
bsdtar -cf - $comp_files * |
@@ -352,7 +361,7 @@ fakebuild() {
"$PKGEXT"; cat ;;
esac > "${pkg_file}"; ret=$?
 
-   # Move compressed package to destination
+   # Evaluate return code
if (( ret )); then
error "Unable to write package to $pkg_dest"
plain "   Maybe the disk is full or you do not have write 
access"
-- 
2.9.3


[pacman-dev] [PATCH v5 6/8] bacman: add otpion to alter the output directory

2016-09-02 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index da5d30d..5c59758 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -57,10 +57,12 @@ usage() {
printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
printf -- "$(gettext "  -q, --quiet  Silence most of the status 
reporting")\n"
printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
+   printf -- "$(gettext "  -o, --out   Write output to specified 
directory (instead of \$PKGDEST)")\n"
printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
echo
printf -- "$(gettext "Examples:  %s linux-headers")\n" "$myname"
-   printf -- "$(gettext "  %s --nocolor --pacnew gzip munge binutils")\n" 
"$myname"
+   printf -- "$(gettext "  %s gzip munge binutils -o ~/Downloads")\n" 
"$myname"
+   printf -- "$(gettext "  %s --nocolor --pacnew -o /tmp gzip munge 
binutils")\n" "$myname"
printf -- "$(gettext "  %s \$(pacman -Qsq)")\n" "$myname"
echo
 }
@@ -88,8 +90,8 @@ for option in "$@"; do
 done
 
 # Parse arguments
-OPT_SHORT='qmv'
-OPT_LONG=('quiet' 'nocolor' 'pacnew' 'version')
+OPT_SHORT='o:qmv'
+OPT_LONG=('out:' 'quiet' 'nocolor' 'pacnew' 'version')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
@@ -99,6 +101,10 @@ unset OPT_SHORT OPT_LONG OPTRET
 
 while :; do
case "$1" in
+   -o|--out)
+   pkg_dest=$2
+   [[ ! -d "$2" ]] && echo -e "The directory 
\e[39;1m$2\e[0m does not exist!" && exit 3
+   shift ;;
-q|--quiet)
QUIET=1 ;;
-m|--nocolor)
@@ -150,7 +156,8 @@ source "@sysconfdir@/makepkg.conf"
 if [[ -r ~/.makepkg.conf ]]; then
source ~/.makepkg.conf
 fi
-pkg_dest="${PKGDEST:-$PWD}"
+PKGDEST="${PKGDEST:-$PWD}"
+pkg_dest="${pkg_dest:-$PKGDEST}"
 pkg_pkger="${PACKAGER:-'Unknown Packager'}"
 
 # Check for an existing database
-- 
2.9.3


[pacman-dev] [PATCH v5 8/8] bacman: add manual page

2016-09-02 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/doc/.gitignore   |  1 +
 contrib/doc/Makefile.am  |  5 +++-
 contrib/doc/bacman.8.txt | 71 
 3 files changed, 76 insertions(+), 1 deletion(-)
 create mode 100644 contrib/doc/bacman.8.txt

diff --git a/contrib/doc/.gitignore b/contrib/doc/.gitignore
index c5612bc..3ab2035 100644
--- a/contrib/doc/.gitignore
+++ b/contrib/doc/.gitignore
@@ -1 +1,2 @@
 verify-pacman-repo-db.1
+bacman.8
diff --git a/contrib/doc/Makefile.am b/contrib/doc/Makefile.am
index 4c316bb..d5725b1 100644
--- a/contrib/doc/Makefile.am
+++ b/contrib/doc/Makefile.am
@@ -4,12 +4,14 @@
 # man_MANS if --enable-asciidoc and/or --enable-doxygen are used.
 
 ASCIIDOC_MANS = \
-   verify-pacman-repo-db.1
+   verify-pacman-repo-db.1 \
+   bacman.8
 
 EXTRA_DIST = \
asciidoc.conf \
footer.txt \
verify-pacman-repo-db.1.txt \
+   bacman.8.txt \
$(ASCIIDOC_MANS)
 
 # Files that should be removed, but which Automake does not know.
@@ -53,5 +55,6 @@ $(ASCIIDOC_MANS): asciidoc.conf footer.txt Makefile.am
 
 # Dependency rules
 verify-pacman-repo-db.1: verify-pacman-repo-db.1.txt
+bacman.8: bacman.8.txt
 
 # vim:set noet:
diff --git a/contrib/doc/bacman.8.txt b/contrib/doc/bacman.8.txt
new file mode 100644
index 000..2c3112f
--- /dev/null
+++ b/contrib/doc/bacman.8.txt
@@ -0,0 +1,71 @@
+/
+vim:set ts=4 sw=4 syntax=asciidoc noet spell spelllang=en_us:
+/
+bacman(8)
+==
+
+Name
+
+bacman - reassemble installed packages
+
+
+Synopsis
+
+'bacman' [options] <package(s)>
+
+
+Description
+---
+'bacman' was designed to reassemble installed packages from its deliverd files.
+It comes in handy if there is no internet connection available and you have no
+access to a up-to-date package cache. Otherwise packages from the Arch Linux
+Archive should always be preferred.
+
+'bacman' fully honors linkman:makepkg.conf[8] and all compression environment
+variables, notably ``XZ_OPT''.
+
+
+Options
+---
+*-h, \--help*::
+   Display usage information.
+
+*-q, \--quiet*::
+   Silence most of the status reporting.
+
+*\--nocolor*::
+   Disable colored output.
+
+*\--pacnew*::
+   Package .pacnew files instead of the concerning files currently in 
place.
+
+*-j, \--jobs *::
+   Assemble multiple packages in parallel.
+
+*-o, \--out *::
+   Write the assembled package(s) to the specified directory.
+
+
+Examples
+
+'bacman' linux-headers
+
+Recreate the package ``linux-headers''.
+
+'bacman' gzip munge binutils -o ~/Downloads
+
+Assemble the packages gzip munge binutils and place the packages at
+``~/Downloads''.
+
+'bacman' --nocolor --pacnew -o ~/backup -j 5 $(pacman -Qsq)
+
+Assemble all currently installed packages using 5 concurrent jobs, use
+``.pacnew'' whenever available, suppress colored output and place the desired
+packages in ``~/backup''.
+
+
+See Also
+
+linkman:makepkg[8], linkman:pacman[8]
+
+include::footer.txt[]
-- 
2.9.3


[pacman-dev] [PATCH v5 3/8] bacman: proper option handling

2016-09-02 Thread Gordian Edenhofer
Switch to parseopts instead of merely checking the first argument.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 63 ++--
 1 file changed, 41 insertions(+), 22 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index a718a18..8656c5c 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -32,6 +32,7 @@ INCLUDE_PACNEW='n'
 ARGS=("$@")
 
 m4_include(../scripts/library/output_format.sh)
+m4_include(../scripts/library/parseopts.sh)
 
 # Lazy recursive clean up of temporary dirs
 work_dir_root="${TMPDIR:-/tmp}/bacman"
@@ -62,35 +63,51 @@ version() {
echo 'Copyright (C) 2008-2016 Pacman Development Team 
<pacman-dev@archlinux.org>'
 }
 
-# Check for specified arguments
-while [[ ! -z $1 ]]; do
-   if [[ $1 == "--nocolor" ]]; then
-   USE_COLOR='n'
-   shift
-   elif [[ $1 == "--pacnew" ]]; then
-   INCLUDE_PACNEW='y'
-   shift
-   else
-   break
-   fi
-done
-
 # Configure colored output
 m4_include(../scripts/library/term_colors.sh)
 
 # Break if no argument was given
-if (( $# < 1 )); then
+if (( $# == 0 )); then
+   usage
+   exit 1
+fi
+
+# Printing the usage information takes precedence over every other parameter
+for option in "$@"; do
+   [[ $option == "-h" || $option == "--help" ]] && usage && exit 0
+done
+
+# Parse arguments
+OPT_SHORT='mv'
+OPT_LONG=('nocolor' 'pacnew' 'version')
+if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
 fi
+set -- "${OPTRET[@]}"
+unset OPT_SHORT OPT_LONG OPTRET
+
+while :; do
+   case "$1" in
+   -m|--nocolor)
+   USE_COLOR='n' ;;
+   --pacnew)
+   INCLUDE_PACNEW='y' ;;
+   -v|--version)
+   version
+   exit 0 ;;
+   --)
+   shift
+   break 2 ;;
+   esac
+   shift
+done
 
-# Print usage or version if requested
-if [[ $1 = -@(h|-help) ]]; then
+# Retrieve the list of packages to be assembled and break if none was specified
+pkg_list=($*)
+if [[ ${#pkg_list[@]} == 0 ]]; then
usage
-   exit 0
-elif [[ $1 = -@(V|-version) ]]; then
-   version
-   exit 0
+   exit 1
 fi
 
 # Run with fake root privileges if EUID is not root
@@ -366,9 +383,11 @@ parallelize() {
 
 # Initiate assembly function
 if [[ $MAX_JOBS -gt "1" ]]; then
-   parallelize "$@"
+   parallelize "${pkg_list[@]}"
 else
-   for PKG in $@; do fakebuild $PKG; done
+   for PKG in ${pkg_list[@]}; do
+   fakebuild $PKG
+   done
 fi
 msg "Done."
 
-- 
2.9.3


[pacman-dev] [PATCH v5 5/8] bacman: add option to print fewer status updates

2016-09-02 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 3868750..da5d30d 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -28,6 +28,7 @@ declare -r myname='bacman'
 declare -r myver='@PACKAGE_VERSION@'
 USE_COLOR='y'
 INCLUDE_PACNEW='n'
+QUIET=0
 # Required for fakeroot because options are shifted off the array.
 ARGS=("$@")
 
@@ -54,6 +55,7 @@ usage() {
echo
printf -- "$(gettext "Options:")\n"
printf -- "$(gettext "  -h, --help   Show this help message and 
exit")\n"
+   printf -- "$(gettext "  -q, --quiet  Silence most of the status 
reporting")\n"
printf -- "$(gettext "  -m, --nocolorDisable colorized output 
messages")\n"
printf -- "$(gettext "  --pacnew Package .pacnew files")\n"
echo
@@ -86,8 +88,8 @@ for option in "$@"; do
 done
 
 # Parse arguments
-OPT_SHORT='mv'
-OPT_LONG=('nocolor' 'pacnew' 'version')
+OPT_SHORT='qmv'
+OPT_LONG=('quiet' 'nocolor' 'pacnew' 'version')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
@@ -97,6 +99,8 @@ unset OPT_SHORT OPT_LONG OPTRET
 
 while :; do
case "$1" in
+   -q|--quiet)
+   QUIET=1 ;;
-m|--nocolor)
USE_COLOR='n' ;;
--pacnew)
@@ -181,6 +185,7 @@ fakebuild() {
 
# Assemble list of files which belong to the package and tar them
msg2 "Copying package files..."
+
while read i; do
if [[ -z $i ]]; then
continue
-- 
2.9.3


[pacman-dev] [PATCH v5 2/8] bacman: parallel packaging

2016-09-02 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 512973a..a718a18 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -347,8 +347,29 @@ fakebuild() {
rm -rf "$work_dir"
 }
 
+# Run fakebuild in parralel with at maximum $MAX_JOBS jobs
+# By default only run one job
+MAX_JOBS=${MAX_JOBS:-1}
+# TODO: Use wait -n instead of this hack as soon as it is ok
+# to bump the version of the bash dependency
+parallelize() {
+   while [[ $# -gt 0 ]]; do
+   job_count=($(jobs -p))
+   if [[ ${#job_count[@]} -lt $MAX_JOBS ]] ; then
+   fakebuild "$1" &
+   shift
+   fi
+   sleep 0.1
+   done
+   wait
+}
 
-for PKG in $@; do fakebuild $PKG; done
+# Initiate assembly function
+if [[ $MAX_JOBS -gt "1" ]]; then
+   parallelize "$@"
+else
+   for PKG in $@; do fakebuild $PKG; done
+fi
 msg "Done."
 
 exit 0
-- 
2.9.3


[pacman-dev] [PATCH v4 7/8] bacman: add option to specify the number of jobs

2016-09-01 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 31 ++-
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index fef5e78..6158a2c 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -57,6 +57,7 @@ usage() {
-q, --quiet silence most of the status reporting
--nocolor   turn off color in output
--pacnewpackage .pacnew files
+   -j, --jobsbuild in parallel - you may want to set 
XZ_OPT
-o, --out  write output to 
 
Examples:   # $myname linux-headers
@@ -89,8 +90,8 @@ for option in "$@"; do
 done
 
 # Parse arguments
-OPT_SHORT='o:qv'
-OPT_LONG=('out:' 'quiet' 'nocolor' 'pacnew' 'version')
+OPT_SHORT='o:j:qv'
+OPT_LONG=('out:' 'jobs:' 'quiet' 'nocolor' 'pacnew' 'version')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
@@ -104,6 +105,14 @@ while :; do
pkg_dest=$2
[[ ! -d "$2" ]] && echo -e "The directory 
\e[39;1m$2\e[0m does not exist!" && exit 3
shift ;;
+   -j|--jobs)
+   if [[ $2 =~ ^-?[0-9]+$ ]]; then
+   MAX_JOBS=$2
+   else
+   echo -e "\e[39;1m$2\e[0m is not a valid 
integer!"
+   exit -1
+   fi
+   shift ;;
-q|--quiet)
QUIET=1 ;;
--nocolor)
@@ -190,7 +199,11 @@ fakebuild() {
cd "$work_dir" || exit 1
 
# Assemble list of files which belong to the package and tar them
-   msg2 "Copying package files..."
+   if [[ $MAX_JOBS -gt 1 ]]; then
+   msg2 "${pkg_name}: Copying package files..."
+   else
+   msg2 "Copying package files..."
+   fi
 
while read i; do
if [[ -z $i ]]; then
@@ -265,7 +278,11 @@ fakebuild() {
 
# Reconstruct .PKGINFO from database
# TODO adopt makepkg's write_pkginfo() into this or scripts/library
-   msg2 "Generating .PKGINFO metadata..."
+   if [[ $MAX_JOBS -gt 1 ]]; then
+   msg2 "${pkg_name}: Generating .PKGINFO metadata..."
+   else
+   msg2 "Generating .PKGINFO metadata..."
+   fi
echo "# Generated by $myname $myver"> .PKGINFO
if [[ $INFAKEROOT == "1" ]]; then
echo "# Using $(fakeroot -v)">> .PKGINFO
@@ -353,7 +370,11 @@ fakebuild() {
chmod 644 "$work_dir"/{.PKGINFO,.CHANGELOG,.INSTALL} 2> /dev/null
 
# Generate the package
-   msg2 "Generating the package..."
+   if [[ $MAX_JOBS -gt 1 ]]; then
+   msg2 "${pkg_name}: Generating the package..."
+   else
+   msg2 "Generating the package..."
+   fi
 
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
ret=0
-- 
2.9.3


[pacman-dev] [PATCH v4 6/8] bacman: add otpion to alter the output directory

2016-09-01 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
Switch to the build-in check for a directory existance instead of using 
'readlink -e'.

 contrib/bacman.sh.in | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 0ae9da0..fef5e78 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -57,9 +57,11 @@ usage() {
-q, --quiet silence most of the status reporting
--nocolor   turn off color in output
--pacnewpackage .pacnew files
+   -o, --out  write output to 
 
Examples:   # $myname linux-headers
-   # $myname --nocolor --pacnew gzip munge binutils
+   # $myname gzip munge binutils -o ~/Downloads
+   # $myname --nocolor --pacnew -o /tmp -j 5 gzip munge 
binutils
# $myname \$(pacman -Qsq)
EOF
 }
@@ -87,8 +89,8 @@ for option in "$@"; do
 done
 
 # Parse arguments
-OPT_SHORT='qv'
-OPT_LONG=('quiet' 'nocolor' 'pacnew' 'version')
+OPT_SHORT='o:qv'
+OPT_LONG=('out:' 'quiet' 'nocolor' 'pacnew' 'version')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
@@ -98,6 +100,10 @@ unset OPT_SHORT OPT_LONG OPTRET
 
 while :; do
case "$1" in
+   -o|--out)
+   pkg_dest=$2
+   [[ ! -d "$2" ]] && echo -e "The directory 
\e[39;1m$2\e[0m does not exist!" && exit 3
+   shift ;;
-q|--quiet)
QUIET=1 ;;
--nocolor)
@@ -149,7 +155,8 @@ source "@sysconfdir@/makepkg.conf"
 if [[ -r ~/.makepkg.conf ]]; then
source ~/.makepkg.conf
 fi
-pkg_dest="${PKGDEST:-$PWD}"
+PKGDEST="${PKGDEST:-$PWD}"
+pkg_dest="${pkg_dest:-$PKGDEST}"
 pkg_pkger="${PACKAGER:-'Unknown Packager'}"
 
 # Check for an existing database
-- 
2.9.3


[pacman-dev] [PATCH v4 8/8] bacman: add manual page

2016-09-01 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/doc/.gitignore   |  1 +
 contrib/doc/Makefile.am  |  5 +++-
 contrib/doc/bacman.8.txt | 71 
 3 files changed, 76 insertions(+), 1 deletion(-)
 create mode 100644 contrib/doc/bacman.8.txt

diff --git a/contrib/doc/.gitignore b/contrib/doc/.gitignore
index c5612bc..3ab2035 100644
--- a/contrib/doc/.gitignore
+++ b/contrib/doc/.gitignore
@@ -1 +1,2 @@
 verify-pacman-repo-db.1
+bacman.8
diff --git a/contrib/doc/Makefile.am b/contrib/doc/Makefile.am
index 4c316bb..d5725b1 100644
--- a/contrib/doc/Makefile.am
+++ b/contrib/doc/Makefile.am
@@ -4,12 +4,14 @@
 # man_MANS if --enable-asciidoc and/or --enable-doxygen are used.
 
 ASCIIDOC_MANS = \
-   verify-pacman-repo-db.1
+   verify-pacman-repo-db.1 \
+   bacman.8
 
 EXTRA_DIST = \
asciidoc.conf \
footer.txt \
verify-pacman-repo-db.1.txt \
+   bacman.8.txt \
$(ASCIIDOC_MANS)
 
 # Files that should be removed, but which Automake does not know.
@@ -53,5 +55,6 @@ $(ASCIIDOC_MANS): asciidoc.conf footer.txt Makefile.am
 
 # Dependency rules
 verify-pacman-repo-db.1: verify-pacman-repo-db.1.txt
+bacman.8: bacman.8.txt
 
 # vim:set noet:
diff --git a/contrib/doc/bacman.8.txt b/contrib/doc/bacman.8.txt
new file mode 100644
index 000..2c3112f
--- /dev/null
+++ b/contrib/doc/bacman.8.txt
@@ -0,0 +1,71 @@
+/
+vim:set ts=4 sw=4 syntax=asciidoc noet spell spelllang=en_us:
+/
+bacman(8)
+==
+
+Name
+
+bacman - reassemble installed packages
+
+
+Synopsis
+
+'bacman' [options] <package(s)>
+
+
+Description
+---
+'bacman' was designed to reassemble installed packages from its deliverd files.
+It comes in handy if there is no internet connection available and you have no
+access to a up-to-date package cache. Otherwise packages from the Arch Linux
+Archive should always be preferred.
+
+'bacman' fully honors linkman:makepkg.conf[8] and all compression environment
+variables, notably ``XZ_OPT''.
+
+
+Options
+---
+*-h, \--help*::
+   Display usage information.
+
+*-q, \--quiet*::
+   Silence most of the status reporting.
+
+*\--nocolor*::
+   Disable colored output.
+
+*\--pacnew*::
+   Package .pacnew files instead of the concerning files currently in 
place.
+
+*-j, \--jobs *::
+   Assemble multiple packages in parallel.
+
+*-o, \--out *::
+   Write the assembled package(s) to the specified directory.
+
+
+Examples
+
+'bacman' linux-headers
+
+Recreate the package ``linux-headers''.
+
+'bacman' gzip munge binutils -o ~/Downloads
+
+Assemble the packages gzip munge binutils and place the packages at
+``~/Downloads''.
+
+'bacman' --nocolor --pacnew -o ~/backup -j 5 $(pacman -Qsq)
+
+Assemble all currently installed packages using 5 concurrent jobs, use
+``.pacnew'' whenever available, suppress colored output and place the desired
+packages in ``~/backup''.
+
+
+See Also
+
+linkman:makepkg[8], linkman:pacman[8]
+
+include::footer.txt[]
-- 
2.9.3


[pacman-dev] [PATCH v4 4/8] bacman: rewrite usage page and version information

2016-09-01 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
Move the '-o' occurrance in the usage page to its corresponding commit.
Use the old descrption instead of the new one. (Fixes typo)
Thanks again Allan!

 contrib/bacman.sh.in | 30 +++---
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 51283f3..20f5939 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -41,25 +41,32 @@ clean_up() {
echo
exit
 }
-
 # Trap termination signals
 trap clean_up SIGHUP SIGINT SIGTERM
 
 # Print usage information
 usage() {
-   echo "${myname} (pacman) v${myver}"
-   echo
-   echo "Recreate a package using pacman's database and system files"
-   echo
-   echo "Usage: ${myname} [--nocolor] [--pacnew] "
-   echo
-   echo "Example: ${myname} linux-headers"
+   cat <<-EOF
+   $myname (pacman) v$myver
+   Recreate packages using pacman's database and system files
+
+   Usage: $myname [options] <package(s)>
+
+   -h, --help  display this help message and exit
+   --nocolor   turn off color in output
+   --pacnewpackage .pacnew files
+
+   Examples:   # $myname linux-headers
+   # $myname --nocolor --pacnew gzip munge binutils
+   # $myname \$(pacman -Qsq)
+   EOF
 }
 
 # Print version information
 version() {
printf "%s %s\n" "$myname" "$myver"
    echo 'Copyright (C) 2008 locci '
+   echo 'Copyright (C) 2016 Gordian Edenhofer 
<gordian.edenho...@gmail.com>'
echo 'Copyright (C) 2008-2016 Pacman Development Team 
<pacman-dev@archlinux.org>'
 }
 
@@ -123,7 +130,7 @@ if (( EUID )); then
fi
 fi
 
-# Source environmental variables and specify fallbacks
+# Read in environmental variables
 if [[ ! -r @sysconfdir@/pacman.conf ]]; then
error "unable to read @sysconfdir@/pacman.conf"
exit 1
@@ -139,7 +146,7 @@ if [[ -r ~/.makepkg.conf ]]; then
source ~/.makepkg.conf
 fi
 pkg_dest="${PKGDEST:-$PWD}"
-pkg_pkger=${PACKAGER:-'Unknown Packager'}
+pkg_pkger="${PACKAGER:-'Unknown Packager'}"
 
 # Check for an existing database
 if [[ ! -d $pac_db ]]; then
@@ -339,6 +346,7 @@ fakebuild() {
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
ret=0
 
+   # Move compressed package to destination
# TODO: Maybe this can be set globally for robustness
shopt -s -o pipefail
bsdtar -cf - $comp_files * |
@@ -352,7 +360,7 @@ fakebuild() {
"$PKGEXT"; cat ;;
esac > "${pkg_file}"; ret=$?
 
-   # Move compressed package to destination
+   # Evaluate return code
if (( ret )); then
error "Unable to write package to $pkg_dest"
plain "   Maybe the disk is full or you do not have write 
access"
-- 
2.9.3


[pacman-dev] [PATCH v4 3/8] bacman: proper option handling

2016-09-01 Thread Gordian Edenhofer
Switch to parseopts instead of merely checking the first argument.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
Remove the leading colon in the OPT_SHORT variable.
Thanks Allen for the hint.

 contrib/bacman.sh.in | 63 ++--
 1 file changed, 41 insertions(+), 22 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index a718a18..51283f3 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -32,6 +32,7 @@ INCLUDE_PACNEW='n'
 ARGS=("$@")
 
 m4_include(../scripts/library/output_format.sh)
+m4_include(../scripts/library/parseopts.sh)
 
 # Lazy recursive clean up of temporary dirs
 work_dir_root="${TMPDIR:-/tmp}/bacman"
@@ -62,35 +63,51 @@ version() {
echo 'Copyright (C) 2008-2016 Pacman Development Team 
<pacman-dev@archlinux.org>'
 }
 
-# Check for specified arguments
-while [[ ! -z $1 ]]; do
-   if [[ $1 == "--nocolor" ]]; then
-   USE_COLOR='n'
-   shift
-   elif [[ $1 == "--pacnew" ]]; then
-   INCLUDE_PACNEW='y'
-   shift
-   else
-   break
-   fi
-done
-
 # Configure colored output
 m4_include(../scripts/library/term_colors.sh)
 
 # Break if no argument was given
-if (( $# < 1 )); then
+if (( $# == 0 )); then
+   usage
+   exit 1
+fi
+
+# Printing the usage information takes precedence over every other parameter
+for option in "$@"; do
+   [[ $option == "-h" || $option == "--help" ]] && usage && exit 0
+done
+
+# Parse arguments
+OPT_SHORT='v'
+OPT_LONG=('nocolor' 'pacnew' 'version')
+if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
 fi
+set -- "${OPTRET[@]}"
+unset OPT_SHORT OPT_LONG OPTRET
+
+while :; do
+   case "$1" in
+   --nocolor)
+   USE_COLOR='n' ;;
+   --pacnew)
+   INCLUDE_PACNEW='y' ;;
+   -v|--version)
+   version
+   exit 0 ;;
+   --)
+   shift
+   break 2 ;;
+   esac
+   shift
+done
 
-# Print usage or version if requested
-if [[ $1 = -@(h|-help) ]]; then
+# Retrieve the list of packages to be assembled and break if none was specified
+pkg_list=($*)
+if [[ ${#pkg_list[@]} == 0 ]]; then
usage
-   exit 0
-elif [[ $1 = -@(V|-version) ]]; then
-   version
-   exit 0
+   exit 1
 fi
 
 # Run with fake root privileges if EUID is not root
@@ -366,9 +383,11 @@ parallelize() {
 
 # Initiate assembly function
 if [[ $MAX_JOBS -gt "1" ]]; then
-   parallelize "$@"
+   parallelize "${pkg_list[@]}"
 else
-   for PKG in $@; do fakebuild $PKG; done
+   for PKG in ${pkg_list[@]}; do
+   fakebuild $PKG
+   done
 fi
 msg "Done."
 
-- 
2.9.3


[pacman-dev] [PATCH v4 2/8] bacman: parallel packaging

2016-09-01 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 512973a..a718a18 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -347,8 +347,29 @@ fakebuild() {
rm -rf "$work_dir"
 }
 
+# Run fakebuild in parralel with at maximum $MAX_JOBS jobs
+# By default only run one job
+MAX_JOBS=${MAX_JOBS:-1}
+# TODO: Use wait -n instead of this hack as soon as it is ok
+# to bump the version of the bash dependency
+parallelize() {
+   while [[ $# -gt 0 ]]; do
+   job_count=($(jobs -p))
+   if [[ ${#job_count[@]} -lt $MAX_JOBS ]] ; then
+   fakebuild "$1" &
+   shift
+   fi
+   sleep 0.1
+   done
+   wait
+}
 
-for PKG in $@; do fakebuild $PKG; done
+# Initiate assembly function
+if [[ $MAX_JOBS -gt "1" ]]; then
+   parallelize "$@"
+else
+   for PKG in $@; do fakebuild $PKG; done
+fi
 msg "Done."
 
 exit 0
-- 
2.9.3


Re: [pacman-dev] [PATCH v3 4/8] bacman: rewrite usage page and version information

2016-09-01 Thread Gordian Edenhofer
On Thu, 2016-09-01 at 13:59 +1000, Allan McRae wrote:
> On 01/09/16 07:05, Gordian Edenhofer wrote:
> > 
> > Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
> > ---
> >  contrib/bacman.sh.in | 33 +
> >  1 file changed, 21 insertions(+), 12 deletions(-)
> > 
> 
> The format for the header is the same for all scripts in the pacman
> codebase.  Do not change the format. You may add examples onto the
> end.

The currently used format is consistent with the one used by paccache.
However I have no problem reverting back to the old format, just say
the word.

signature.asc
Description: This is a digitally signed message part


Re: [pacman-dev] [PATCH v2 1/3] bacman: allow for parallel packaging

2016-08-31 Thread Gordian Edenhofer
On Thu, 2016-09-01 at 08:28 +1000, Allan McRae wrote:
> On 01/09/16 08:08, Dave Reisner wrote:
> > 
> > On Wed, Aug 31, 2016 at 11:18:32PM +0200, Gordian Edenhofer wrote:
> > > 
> > > > 
> > > > > 
> > > > > > 
> > > > > > The second probably would not be accepted...
> > > > > 
> > > > > I urge you to reconsider. Parallelization increases the speed
> > > > > of
> > > > > this
> > > > 
> > > > I don't think anyone is suggesting that packaging multiple
> > > > things in
> > > > parallel isn't useful. I already suggested that nothing needs
> > > > to be
> > > > implemented in bacman proper in order for you to parallelize
> > > > the
> > > > work.
> > > > You can write your own "pbacman" as simply as:
> > > > 
> > > >   for arg; do bacman "$arg" & done; wait
> > > 
> > > There is a huge difference between flooding your system with
> > > ~1000 jobs
> > > and tightly controlling the maximum number. Adjusting the precise
> > > number of jobs enables you to organize your resources which
> > > itself is
> > > desirable.
> > 
> > Then use a program like 'parallel' which has this sort of knob. I
> > really
> > wonder what it is you're doing that requires running bacman with a
> > large
> > number of packages with any regularity.
> > 
> 
> Gathering the files etc takes no time.  It is really the compression
> that is being made parallel.  If only there was a way to set
> compression
> to use mutlithreading...

The actual compression using xz (default) is not necessary the most
time intensive part. The linux-headers package for example is
compressed within a few seconds but the whole process before xz is run
takes way longer. This can be seen with top as an illustration or
simply by running bacman one time without compression and the other
with.
Moreover using bacman to parallelize makes it completely independent
from the archive format used and still brings gains when recreating
multiple packages. At the very least it would fill the gap in between
the compression of multiple packages. Therefore it would be beneficial
even if compression would take the longest which is doesn't always do.

Best Regards,
Gordian Edenhofer

signature.asc
Description: This is a digitally signed message part


Re: [pacman-dev] [PATCH v2 1/3] bacman: allow for parallel packaging

2016-08-31 Thread Gordian Edenhofer
> > > The second probably would not be accepted...
> > 
> > I urge you to reconsider. Parallelization increases the speed of
> > this
> 
> I don't think anyone is suggesting that packaging multiple things in
> parallel isn't useful. I already suggested that nothing needs to be
> implemented in bacman proper in order for you to parallelize the
> work.
> You can write your own "pbacman" as simply as:
> 
>   for arg; do bacman "$arg" & done; wait

There is a huge difference between flooding your system with ~1000 jobs
and tightly controlling the maximum number. Adjusting the precise
number of jobs enables you to organize your resources which itself is
desirable.
Even if there would be a perfect wrapper for bacman - which there is
none - it would still make sense to implement easily understandable
options into bacman for everyone to use simply to spare others the time
of coming up with one.

Best Regards,
Gordian Edenhofer

signature.asc
Description: This is a digitally signed message part


[pacman-dev] [PATCH v3 7/8] bacman: add option to specify the number of jobs

2016-08-31 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 27 +--
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 706c6fb..e8e53ea 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -57,11 +57,12 @@ usage() {
-q, --quiet silence most of the status reporting
--nocolor   turn off color in output
--pacnewpackage .pacnew files
+   -j, --jobsbuild in parallel - you may want to set 
XZ_OPT
-o, --out  write output to 
 
Examples:   # $myname linux-headers
# $myname gzip munge binutils -o ~/Downloads
-   # $myname --nocolor --pacnew -o /tmp gzip munge binutils
+   # $myname --nocolor --pacnew -o /tmp -j 5 gzip munge 
binutils
# $myname \$(pacman -Qsq)
EOF
 }
@@ -89,8 +90,8 @@ for option in "$@"; do
 done
 
 # Parse arguments
-OPT_SHORT=':o:qv'
-OPT_LONG=('out:' 'quiet' 'nocolor' 'pacnew' 'version')
+OPT_SHORT=':o:j:qv'
+OPT_LONG=('out:' 'jobs:' 'quiet' 'nocolor' 'pacnew' 'version')
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
@@ -104,6 +105,14 @@ while :; do
pkg_dest="$(readlink -e $2)"
[[ $? -ne 0 ]] && echo -e "The directory 
\e[39;1m$2\e[0m does not exist!" && exit 3
shift ;;
+   -j|--jobs)
+   if [[ $2 =~ ^-?[0-9]+$ ]]; then
+   MAX_JOBS=$2
+   else
+   echo -e "\e[39;1m$2\e[0m is not a valid 
integer!"
+   exit -1
+   fi
+   shift ;;
-q|--quiet)
QUIET='y' ;;
--nocolor)
@@ -190,7 +199,9 @@ fakebuild() {
cd "$work_dir" || exit 1
 
# Assemble list of files which belong to the package and tar them
-   if [[ "$QUIET" != "y" ]]; then
+   if [[ $MAX_JOBS -gt 1 && "$QUIET" != "y" ]]; then
+   msg2 "${pkg_name}: Copying package files..."
+   elif [[ "$QUIET" != "y" ]]; then
msg2 "Copying package files..."
fi
 
@@ -267,7 +278,9 @@ fakebuild() {
 
# Reconstruct .PKGINFO from database
# TODO adopt makepkg's write_pkginfo() into this or scripts/library
-   if [[ "$QUIET" != "y" ]]; then
+   if [[ $MAX_JOBS -gt 1 && "$QUIET" != "y" ]]; then
+   msg2 "${pkg_name}: Generating .PKGINFO metadata..."
+   elif [[ "$QUIET" != "y" ]]; then
msg2 "Generating .PKGINFO metadata..."
fi
echo "# Generated by $myname $myver"> .PKGINFO
@@ -357,7 +370,9 @@ fakebuild() {
chmod 644 "$work_dir"/{.PKGINFO,.CHANGELOG,.INSTALL} 2> /dev/null
 
# Generate the package
-   if [[ "$QUIET" != "y" ]]; then
+   if [[ $MAX_JOBS -gt 1 && "$QUIET" != "y" ]]; then
+   msg2 "${pkg_name}: Generating the package..."
+   elif [[ "$QUIET" != "y" ]]; then
msg2 "Generating the package..."
fi
 
-- 
2.9.3


[pacman-dev] [PATCH v3 8/8] bacman: add manual page

2016-08-31 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/doc/.gitignore   |  1 +
 contrib/doc/Makefile.am  |  5 +++-
 contrib/doc/bacman.8.txt | 71 
 3 files changed, 76 insertions(+), 1 deletion(-)
 create mode 100644 contrib/doc/bacman.8.txt

diff --git a/contrib/doc/.gitignore b/contrib/doc/.gitignore
index c5612bc..3ab2035 100644
--- a/contrib/doc/.gitignore
+++ b/contrib/doc/.gitignore
@@ -1 +1,2 @@
 verify-pacman-repo-db.1
+bacman.8
diff --git a/contrib/doc/Makefile.am b/contrib/doc/Makefile.am
index 4c316bb..d5725b1 100644
--- a/contrib/doc/Makefile.am
+++ b/contrib/doc/Makefile.am
@@ -4,12 +4,14 @@
 # man_MANS if --enable-asciidoc and/or --enable-doxygen are used.
 
 ASCIIDOC_MANS = \
-   verify-pacman-repo-db.1
+   verify-pacman-repo-db.1 \
+   bacman.8
 
 EXTRA_DIST = \
asciidoc.conf \
footer.txt \
verify-pacman-repo-db.1.txt \
+   bacman.8.txt \
$(ASCIIDOC_MANS)
 
 # Files that should be removed, but which Automake does not know.
@@ -53,5 +55,6 @@ $(ASCIIDOC_MANS): asciidoc.conf footer.txt Makefile.am
 
 # Dependency rules
 verify-pacman-repo-db.1: verify-pacman-repo-db.1.txt
+bacman.8: bacman.8.txt
 
 # vim:set noet:
diff --git a/contrib/doc/bacman.8.txt b/contrib/doc/bacman.8.txt
new file mode 100644
index 000..2c3112f
--- /dev/null
+++ b/contrib/doc/bacman.8.txt
@@ -0,0 +1,71 @@
+/
+vim:set ts=4 sw=4 syntax=asciidoc noet spell spelllang=en_us:
+/
+bacman(8)
+==
+
+Name
+
+bacman - reassemble installed packages
+
+
+Synopsis
+
+'bacman' [options] <package(s)>
+
+
+Description
+---
+'bacman' was designed to reassemble installed packages from its deliverd files.
+It comes in handy if there is no internet connection available and you have no
+access to a up-to-date package cache. Otherwise packages from the Arch Linux
+Archive should always be preferred.
+
+'bacman' fully honors linkman:makepkg.conf[8] and all compression environment
+variables, notably ``XZ_OPT''.
+
+
+Options
+---
+*-h, \--help*::
+   Display usage information.
+
+*-q, \--quiet*::
+   Silence most of the status reporting.
+
+*\--nocolor*::
+   Disable colored output.
+
+*\--pacnew*::
+   Package .pacnew files instead of the concerning files currently in 
place.
+
+*-j, \--jobs *::
+   Assemble multiple packages in parallel.
+
+*-o, \--out *::
+   Write the assembled package(s) to the specified directory.
+
+
+Examples
+
+'bacman' linux-headers
+
+Recreate the package ``linux-headers''.
+
+'bacman' gzip munge binutils -o ~/Downloads
+
+Assemble the packages gzip munge binutils and place the packages at
+``~/Downloads''.
+
+'bacman' --nocolor --pacnew -o ~/backup -j 5 $(pacman -Qsq)
+
+Assemble all currently installed packages using 5 concurrent jobs, use
+``.pacnew'' whenever available, suppress colored output and place the desired
+packages in ``~/backup''.
+
+
+See Also
+
+linkman:makepkg[8], linkman:pacman[8]
+
+include::footer.txt[]
-- 
2.9.3


[pacman-dev] [PATCH v3 4/8] bacman: rewrite usage page and version information

2016-08-31 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 33 +
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index a0bfcf1..ca2945f 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -41,25 +41,33 @@ clean_up() {
echo
exit
 }
-
 # Trap termination signals
 trap clean_up SIGHUP SIGINT SIGTERM
 
 # Print usage information
 usage() {
-   echo "${myname} (pacman) v${myver}"
-   echo
-   echo "Recreate a package using pacman's database and system files"
-   echo
-   echo "Usage: ${myname} [--nocolor] [--pacnew] "
-   echo
-   echo "Example: ${myname} linux-headers"
+   cat <<-EOF
+   $myname (pacman) v$myver
+   This script was design to reassemble installed packages from its 
deliverd files.
+   It comes in handy if you have no access to an up-to-date package cache.
+
+   Usage: $myname [options] <package(s)>
+   -h, --help  display this help message and exit
+   --nocolor   turn off color in output
+   --pacnewpackage .pacnew files
+
+   Examples:   # $myname linux-headers
+   # $myname gzip munge binutils -o ~/Downloads
+   # $myname --nocolor --pacnew gzip munge binutils
+   # $myname \$(pacman -Qsq)
+   EOF
 }
 
 # Print version information
 version() {
printf "%s %s\n" "$myname" "$myver"
    echo 'Copyright (C) 2008 locci '
+   echo 'Copyright (C) 2016 Gordian Edenhofer 
<gordian.edenho...@gmail.com>'
echo 'Copyright (C) 2008-2016 Pacman Development Team 
<pacman-dev@archlinux.org>'
 }
 
@@ -123,7 +131,7 @@ if (( EUID )); then
fi
 fi
 
-# Source environmental variables and specify fallbacks
+# Read in environmental variables
 if [[ ! -r @sysconfdir@/pacman.conf ]]; then
error "unable to read @sysconfdir@/pacman.conf"
exit 1
@@ -139,7 +147,7 @@ if [[ -r ~/.makepkg.conf ]]; then
source ~/.makepkg.conf
 fi
 pkg_dest="${PKGDEST:-$PWD}"
-pkg_pkger=${PACKAGER:-'Unknown Packager'}
+pkg_pkger="${PACKAGER:-'Unknown Packager'}"
 
 # Check for an existing database
 if [[ ! -d $pac_db ]]; then
@@ -339,6 +347,7 @@ fakebuild() {
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
ret=0
 
+   # Move compressed package to destination
# TODO: Maybe this can be set globally for robustness
shopt -s -o pipefail
bsdtar -cf - $comp_files * |
@@ -352,7 +361,7 @@ fakebuild() {
"$PKGEXT"; cat ;;
esac > "${pkg_file}"; ret=$?
 
-   # Move compressed package to destination
+   # Evaluate return code
if (( ret )); then
error "Unable to write package to $pkg_dest"
plain "   Maybe the disk is full or you do not have write 
access"
@@ -362,7 +371,6 @@ fakebuild() {
 
# Clean up working directory
rm -rf "$work_dir"
-   msg "Done."
 }
 
 # Run fakebuild in parralel with at maximum $MAX_JOBS jobs
@@ -391,6 +399,7 @@ else
done
 fi
 
+msg "Done."
 exit 0
 
 # vim: set noet:
-- 
2.9.3


[pacman-dev] [PATCH v3 3/8] bacman: proper option handling

2016-08-31 Thread Gordian Edenhofer
Switch to parseopts instead of merely checking the first argument.

Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 63 ++--
 1 file changed, 41 insertions(+), 22 deletions(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 1241718..a0bfcf1 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -32,6 +32,7 @@ INCLUDE_PACNEW='n'
 ARGS=("$@")
 
 m4_include(../scripts/library/output_format.sh)
+m4_include(../scripts/library/parseopts.sh)
 
 # Lazy recursive clean up of temporary dirs
 work_dir_root="${TMPDIR:-/tmp}/bacman"
@@ -62,35 +63,51 @@ version() {
echo 'Copyright (C) 2008-2016 Pacman Development Team 
<pacman-dev@archlinux.org>'
 }
 
-# Check for specified arguments
-while [[ ! -z $1 ]]; do
-   if [[ $1 == "--nocolor" ]]; then
-   USE_COLOR='n'
-   shift
-   elif [[ $1 == "--pacnew" ]]; then
-   INCLUDE_PACNEW='y'
-   shift
-   else
-   break
-   fi
-done
-
 # Configure colored output
 m4_include(../scripts/library/term_colors.sh)
 
 # Break if no argument was given
-if (( $# < 1 )); then
+if (( $# == 0 )); then
+   usage
+   exit 1
+fi
+
+# Printing the usage information takes precedence over every other parameter
+for option in "$@"; do
+   [[ $option == "-h" || $option == "--help" ]] && usage && exit 0
+done
+
+# Parse arguments
+OPT_SHORT=':v'
+OPT_LONG=('nocolor' 'pacnew' 'version')
+if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
usage
exit 1
 fi
+set -- "${OPTRET[@]}"
+unset OPT_SHORT OPT_LONG OPTRET
+
+while :; do
+   case "$1" in
+   --nocolor)
+   USE_COLOR='n' ;;
+   --pacnew)
+   INCLUDE_PACNEW='y' ;;
+   -v|--version)
+   version
+   exit 0 ;;
+   --)
+   shift
+   break 2 ;;
+   esac
+   shift
+done
 
-# Print usage or version if requested
-if [[ $1 = -@(h|-help) ]]; then
+# Retrieve the list of packages to be assembled and break if none was specified
+pkg_list=($*)
+if [[ ${#pkg_list[@]} == 0 ]]; then
usage
-   exit 0
-elif [[ $1 = -@(V|-version) ]]; then
-   version
-   exit 0
+   exit 1
 fi
 
 # Run with fake root privileges if EUID is not root
@@ -367,9 +384,11 @@ parallelize() {
 
 # Initiate assembly function
 if [[ $MAX_JOBS -gt "1" ]]; then
-   parallelize "$@"
+   parallelize "${pkg_list[@]}"
 else
-   for PKG in $@; do fakebuild $PKG; done
+   for PKG in ${pkg_list[@]}; do
+   fakebuild $PKG
+   done
 fi
 
 exit 0
-- 
2.9.3


[pacman-dev] [PATCH v3 2/8] bacman: parallel packaging

2016-08-31 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer <gordian.edenho...@gmail.com>
---
 contrib/bacman.sh.in | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index a13f074..1241718 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -348,8 +348,29 @@ fakebuild() {
msg "Done."
 }
 
+# Run fakebuild in parralel with at maximum $MAX_JOBS jobs
+# By default only run one job
+MAX_JOBS=${MAX_JOBS:-1}
+# TODO: Use wait -n instead of this hack as soon as it is ok
+# to bump the version of the bash dependency
+parallelize() {
+   while [[ $# -gt 0 ]]; do
+   job_count=($(jobs -p))
+   if [[ ${#job_count[@]} -lt $MAX_JOBS ]] ; then
+   fakebuild "$1" &
+   shift
+   fi
+   sleep 0.1
+   done
+   wait
+}
 
-for PKG in $@; do fakebuild $PKG; done
+# Initiate assembly function
+if [[ $MAX_JOBS -gt "1" ]]; then
+   parallelize "$@"
+else
+   for PKG in $@; do fakebuild $PKG; done
+fi
 
 exit 0
 
-- 
2.9.3


  1   2   >