[pacman-dev] [PATCH 2/2] Add ALPM_ERR_OK = 0 to _alpm_err_t

2016-09-02 Thread ivy . foster
From: Ivy Foster 

Functions that expect an _alpm_err_t can now get a true one, even on
success. Since previous practice was to return 0 (not included in the
_alpm_err_t enum type), anything that just checks !err or (err == 0)
should work as is.

Signed-off-by: Ivy Foster 
---
 lib/libalpm/alpm.h   |  3 +-
 lib/libalpm/be_package.c |  2 +-
 lib/libalpm/be_sync.c|  4 +--
 lib/libalpm/db.c | 18 +--
 lib/libalpm/dload.c  |  2 +-
 lib/libalpm/package.c| 78 
 lib/libalpm/signing.c|  6 ++--
 lib/libalpm/sync.c   |  8 ++---
 lib/libalpm/util.h   |  2 +-
 9 files changed, 62 insertions(+), 61 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 7955585..0f8274b 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -53,7 +53,8 @@ typedef struct __alpm_trans_t alpm_trans_t;
  * @{
  */
 typedef enum _alpm_errno_t {
-   ALPM_ERR_MEMORY = 1,
+   ALPM_ERR_OK = 0,
+   ALPM_ERR_MEMORY,
ALPM_ERR_SYSTEM,
ALPM_ERR_BADPERMS,
ALPM_ERR_NOT_A_FILE,
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 430d2ae..befcba3 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -274,7 +274,7 @@ int _alpm_pkg_validate_internal(alpm_handle_t *handle,
alpm_siglist_t **sigdata, alpm_pkgvalidation_t *validation)
 {
int has_sig;
-   handle->pm_errno = 0;
+   handle->pm_errno = ALPM_ERR_OK;
 
if(pkgfile == NULL || strlen(pkgfile) == 0) {
RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1);
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 32a669d..2cd722e 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -186,7 +186,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
/* Sanity checks */
ASSERT(db != NULL, return -1);
handle = db->handle;
-   handle->pm_errno = 0;
+   handle->pm_errno = ALPM_ERR_OK;
ASSERT(db != handle->db_local, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, 
-1));
ASSERT(db->servers != NULL, RET_ERR(handle, ALPM_ERR_SERVER_NONE, -1));
 
@@ -320,7 +320,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
_alpm_log(handle, ALPM_LOG_DEBUG, "failed to sync db: %s\n",
alpm_strerror(handle->pm_errno));
} else {
-   handle->pm_errno = 0;
+   handle->pm_errno = ALPM_ERR_OK;
}
 
_alpm_handle_unlock(handle);
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index f70f83c..6e04adb 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -112,7 +112,7 @@ int SYMEXPORT alpm_db_unregister(alpm_db_t *db)
ASSERT(db != NULL, return -1);
/* Do not unregister a database if a transaction is on-going */
handle = db->handle;
-   handle->pm_errno = 0;
+   handle->pm_errno = ALPM_ERR_OK;
ASSERT(handle->trans == NULL, RET_ERR(handle, ALPM_ERR_TRANS_NOT_NULL, 
-1));
 
if(db == handle->db_local) {
@@ -179,7 +179,7 @@ int SYMEXPORT alpm_db_add_server(alpm_db_t *db, const char 
*url)
 
/* Sanity checks */
ASSERT(db != NULL, return -1);
-   db->handle->pm_errno = 0;
+   db->handle->pm_errno = ALPM_ERR_OK;
ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, 
ALPM_ERR_WRONG_ARGS, -1));
 
newurl = sanitize_url(url);
@@ -206,7 +206,7 @@ int SYMEXPORT alpm_db_remove_server(alpm_db_t *db, const 
char *url)
 
/* Sanity checks */
ASSERT(db != NULL, return -1);
-   db->handle->pm_errno = 0;
+   db->handle->pm_errno = ALPM_ERR_OK;
ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, 
ALPM_ERR_WRONG_ARGS, -1));
 
newurl = sanitize_url(url);
@@ -249,7 +249,7 @@ alpm_siglevel_t SYMEXPORT alpm_db_get_siglevel(alpm_db_t 
*db)
 int SYMEXPORT alpm_db_get_valid(alpm_db_t *db)
 {
ASSERT(db != NULL, return -1);
-   db->handle->pm_errno = 0;
+   db->handle->pm_errno = ALPM_ERR_OK;
return db->ops->validate(db);
 }
 
@@ -258,7 +258,7 @@ alpm_pkg_t SYMEXPORT *alpm_db_get_pkg(alpm_db_t *db, const 
char *name)
 {
alpm_pkg_t *pkg;
ASSERT(db != NULL, return NULL);
-   db->handle->pm_errno = 0;
+   db->handle->pm_errno = ALPM_ERR_OK;
ASSERT(name != NULL && strlen(name) != 0,
RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, NULL));
 
@@ -273,7 +273,7 @@ alpm_pkg_t SYMEXPORT *alpm_db_get_pkg(alpm_db_t *db, const 
char *name)
 alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(alpm_db_t *db)
 {
ASSERT(db != NULL, return NULL);
-   db->handle->pm_errno = 0;
+   db->handle->pm_errno = ALPM_ERR_OK;
return _alpm_db_get_pkgcache(db);
 }
 
@@ -281,7 +281,7 @@ alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(alpm_db_t *db)
 alpm_group_t SYMEXPORT *alpm_db_get_group(alpm_db_t *db, const char *name)
 {
ASSERT(db != 

[pacman-dev] [PATCH 1/2] Do not #define _RESERVED_IDENTIFIERS

2016-09-02 Thread ivy . foster
From: Ivy Foster 

Signed-off-by: Ivy Foster 
---
 lib/libalpm/add.h   | 6 +++---
 lib/libalpm/alpm.h  | 6 +++---
 lib/libalpm/alpm_list.h | 6 +++---
 lib/libalpm/backup.h| 6 +++---
 lib/libalpm/base64.h| 4 ++--
 lib/libalpm/conflict.h  | 6 +++---
 lib/libalpm/db.h| 6 +++---
 lib/libalpm/delta.h | 6 +++---
 lib/libalpm/deps.h  | 6 +++---
 lib/libalpm/diskspace.h | 6 +++---
 lib/libalpm/dload.h | 6 +++---
 lib/libalpm/filelist.h  | 6 +++---
 lib/libalpm/graph.h | 6 +++---
 lib/libalpm/group.h | 6 +++---
 lib/libalpm/handle.h| 6 +++---
 lib/libalpm/hook.h  | 6 +++---
 lib/libalpm/libarchive-compat.h | 6 +++---
 lib/libalpm/log.h   | 6 +++---
 lib/libalpm/md5.h   | 4 ++--
 lib/libalpm/package.h   | 6 +++---
 lib/libalpm/pkghash.h   | 6 +++---
 lib/libalpm/remove.h| 6 +++---
 lib/libalpm/sha2.h  | 4 ++--
 lib/libalpm/signing.h   | 6 +++---
 lib/libalpm/sync.h  | 6 +++---
 lib/libalpm/trans.h | 6 +++---
 lib/libalpm/util.h  | 6 +++---
 src/common/ini.h| 6 +++---
 src/common/util-common.h| 6 +++---
 src/pacman/callback.h   | 6 +++---
 src/pacman/check.h  | 6 +++---
 src/pacman/conf.h   | 6 +++---
 src/pacman/package.h| 6 +++---
 src/pacman/pacman.h | 6 +++---
 src/pacman/sighandler.h | 6 +++---
 src/pacman/util.h   | 6 +++---
 36 files changed, 105 insertions(+), 105 deletions(-)

diff --git a/lib/libalpm/add.h b/lib/libalpm/add.h
index aa707fa..c1ab62a 100644
--- a/lib/libalpm/add.h
+++ b/lib/libalpm/add.h
@@ -17,8 +17,8 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see .
  */
-#ifndef _ALPM_ADD_H
-#define _ALPM_ADD_H
+#ifndef ALPM_ADD_H
+#define ALPM_ADD_H
 
 #include "db.h"
 #include "alpm_list.h"
@@ -26,6 +26,6 @@
 
 int _alpm_upgrade_packages(alpm_handle_t *handle);
 
-#endif /* _ALPM_ADD_H */
+#endif /* ALPM_ADD_H */
 
 /* vim: set noet: */
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 168d71b..7955585 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -20,8 +20,8 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see .
  */
-#ifndef _ALPM_H
-#define _ALPM_H
+#ifndef ALPM_H
+#define ALPM_H
 
 #ifdef __cplusplus
 extern "C" {
@@ -1624,6 +1624,6 @@ void alpm_conflict_free(alpm_conflict_t *conflict);
 #ifdef __cplusplus
 }
 #endif
-#endif /* _ALPM_H */
+#endif /* ALPM_H */
 
 /* vim: set noet: */
diff --git a/lib/libalpm/alpm_list.h b/lib/libalpm/alpm_list.h
index 5af84e1..cf7d463 100644
--- a/lib/libalpm/alpm_list.h
+++ b/lib/libalpm/alpm_list.h
@@ -17,8 +17,8 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see .
  */
-#ifndef _ALPM_LIST_H
-#define _ALPM_LIST_H
+#ifndef ALPM_LIST_H
+#define ALPM_LIST_H
 
 #include  /* size_t */
 
@@ -90,6 +90,6 @@ void *alpm_list_to_array(const alpm_list_t *list, size_t n, 
size_t size);
 #ifdef __cplusplus
 }
 #endif
-#endif /* _ALPM_LIST_H */
+#endif /* ALPM_LIST_H */
 
 /* vim: set noet: */
diff --git a/lib/libalpm/backup.h b/lib/libalpm/backup.h
index 2e11dbc..5cf3f90 100644
--- a/lib/libalpm/backup.h
+++ b/lib/libalpm/backup.h
@@ -17,8 +17,8 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see .
  */
-#ifndef _ALPM_BACKUP_H
-#define _ALPM_BACKUP_H
+#ifndef ALPM_BACKUP_H
+#define ALPM_BACKUP_H
 
 #include "alpm_list.h"
 #include "alpm.h"
@@ -28,6 +28,6 @@ alpm_backup_t *_alpm_needbackup(const char *file, alpm_pkg_t 
*pkg);
 void _alpm_backup_free(alpm_backup_t *backup);
 alpm_backup_t *_alpm_backup_dup(const alpm_backup_t *backup);
 
-#endif /* _ALPM_BACKUP_H */
+#endif /* ALPM_BACKUP_H */
 
 /* vim: set noet: */
diff --git a/lib/libalpm/base64.h b/lib/libalpm/base64.h
index df684ab..9edb864 100644
--- a/lib/libalpm/base64.h
+++ b/lib/libalpm/base64.h
@@ -22,8 +22,8 @@
  *  along with this program.  If not, see .
  */
 
-#ifndef _BASE64_H
-#define _BASE64_H
+#ifndef BASE64_H
+#define BASE64_H
 
 #include 
 
diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h
index e17d552..801c201 100644
--- a/lib/libalpm/conflict.h
+++ b/lib/libalpm/conflict.h
@@ -17,8 +17,8 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see .
  */
-#ifndef _ALPM_CONFLICT_H
-#define _ALPM_CONFLICT_H
+#ifndef ALPM_CONFLICT_H
+#define ALPM_CONFLICT_H
 
 

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 
---
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] 
+
+
+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 
---
 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] ")\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 
---
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 
---
 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 
---
 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 
---
 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 
---
 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 
'
 }
 
-# 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 
---
 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 
'
 }
 
+# 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%)
-   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
-   

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

2016-09-02 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer 
---
 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 v5 4/8] bacman: rewrite usage page and version information

2016-09-02 Thread Allan McRae
On 02/09/16 22:51, Gordian Edenhofer wrote:
>   echo 'Copyright (C) 2008 locci '
> + echo 'Copyright (C) 2016 Gordian Edenhofer 
> '
>   echo 'Copyright (C) 2008-2016 Pacman Development Team 
> '


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).

A


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

2016-09-02 Thread Allan McRae
On 02/09/16 22:51, Gordian Edenhofer wrote:
> Signed-off-by: Gordian Edenhofer 
> ---
>  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] 
> +
> +
> +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.
> +

pacman is not Arch Linux specific.  Remove any references.


> +'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''.
> +

Parallel patch is not being accepted (as stated multiple times).  Remove
references to it.

> +
> +See Also
> +
> +linkman:makepkg[8], linkman:pacman[8]
> +
> +include::footer.txt[]
> 


[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 
---
 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 
'
 }
 
+# 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%)
-   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
-   

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

2016-09-02 Thread Gordian Edenhofer
Signed-off-by: Gordian Edenhofer 
---
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] ")\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 
'
echo 'Copyright (C) 2008-2016 Pacman Development Team 
'
 }
 
@@ -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 
---
 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 
---
 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] 
+
+
+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 
---
 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 
'
 }
 
-# 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 
---
 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 
---
 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