From 71fcb69028d6e02bc7f24459918e504d261f86cd Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Thu, 19 Apr 2012 12:46:48 -0400 Subject: [PATCH 1/7] contrib: use a separate build rule for bash scripts Treat bash scripts separately from the others to allow for a different build rule, which is reused from the scripts/ subdir. Signed-off-by: Dave Reisner --- contrib/Makefile.am | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/contrib/Makefile.am b/contrib/Makefile.am index a3d2d42b..3936e23d 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -4,16 +4,22 @@ AUTOMAKE_OPTIONS = std-options bin_SCRIPTS = \ $(OURSCRIPTS) -OURSCRIPTS = \ +BASHSCRIPTS = \ bacman \ paccache \ pacdiff \ paclist \ paclog-pkglist \ pacscripts \ - pacsearch \ pacsysclean +OTHERSCRIPTS = \ + pacsearch + +OURSCRIPTS = \ + $(BASHSCRIPTS) \ + $(OTHERSCRIPTS) + OURFILES = \ bash_completion \ zsh_completion @@ -50,12 +56,17 @@ edit = sed \ -e 's|@SIZECMD[@]|$(SIZECMD)|g' \ -e '1s|!/bin/bash|!$(BASH_SHELL)|g' -$(OURSCRIPTS): Makefile +$(OTHERSCRIPTS): Makefile $(AM_V_at)$(RM) $@ $@.tmp $(AM_V_GEN)$(edit) $(srcdir)/$@.in >$@.tmp $(AM_V_at)chmod +x,a-w $@.tmp $(AM_V_at)mv $@.tmp $@ +$(BASHSCRIPTS): Makefile + $(AM_V_at)$(RM) $@ + $(AM_V_GEN)test -f $(srcdir)/$@.in && m4 -P -I $(srcdir) $(srcdir)/$@.in | $(edit) >$@ + $(AM_V_at)chmod +x,a-w $@ + $(OURFILES): Makefile $(AM_V_at)$(RM) $@ $@.tmp $(AM_V_GEN)$(edit) $(srcdir)/$@.in >$@.tmp From 1b494ab77198a6cbb9c06a13435159641e2dc0c5 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Thu, 19 Apr 2012 12:55:20 -0400 Subject: [PATCH 2/7] contrib: rename bash scripts: .in -> .sh.in For consistency with the scripts/ directory, ensure that all bash scripts use the same pre-build suffix. Signed-off-by: Dave Reisner --- contrib/Makefile.am | 30 +++++++++---------- contrib/{bacman.in => bacman.sh.in} | 1 - contrib/{paccache.in => paccache.sh.in} | 0 contrib/{pacdiff.in => pacdiff.sh.in} | 0 contrib/{paclist.in => paclist.sh.in} | 0 ...paclog-pkglist.in => paclog-pkglist.sh.in} | 0 contrib/{pacscripts.in => pacscripts.sh.in} | 0 contrib/{pacsysclean.in => pacsysclean.sh.in} | 0 8 files changed, 15 insertions(+), 16 deletions(-) rename contrib/{bacman.in => bacman.sh.in} (99%) rename contrib/{paccache.in => paccache.sh.in} (100%) rename contrib/{pacdiff.in => pacdiff.sh.in} (100%) rename contrib/{paclist.in => paclist.sh.in} (100%) rename contrib/{paclog-pkglist.in => paclog-pkglist.sh.in} (100%) rename contrib/{pacscripts.in => pacscripts.sh.in} (100%) rename contrib/{pacsysclean.in => pacsysclean.sh.in} (100%) diff --git a/contrib/Makefile.am b/contrib/Makefile.am index 3936e23d..5139b54d 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -26,15 +26,15 @@ OURFILES = \ EXTRA_DIST = \ PKGBUILD.vim \ - bacman.in \ + bacman.sh.in \ bash_completion.in \ - paccache.in \ - paclog-pkglist.in \ - pacdiff.in \ - paclist.in \ - pacscripts.in \ + paccache.sh.in \ + paclog-pkglist.sh.in \ + pacdiff.sh.in \ + paclist.sh.in \ + pacscripts.sh.in \ pacsearch.in \ - pacsysclean.in \ + pacsysclean.sh.in \ vimprojects \ zsh_completion.in \ README @@ -64,7 +64,7 @@ $(OTHERSCRIPTS): Makefile $(BASHSCRIPTS): Makefile $(AM_V_at)$(RM) $@ - $(AM_V_GEN)test -f $(srcdir)/$@.in && m4 -P -I $(srcdir) $(srcdir)/$@.in | $(edit) >$@ + $(AM_V_GEN)test -f $(srcdir)/$@.sh.in && m4 -P -I $(srcdir) $(srcdir)/$@.sh.in | $(edit) >$@ $(AM_V_at)chmod +x,a-w $@ $(OURFILES): Makefile @@ -85,15 +85,15 @@ uninstall-local: $(RM) $(DESTDIR)$(sysconfdir)/bash_completion.d/pacman $(RM) $(DESTDIR)$(datarootdir)/zsh/site-functions/_pacman -bacman: $(srcdir)/bacman.in +bacman: $(srcdir)/bacman.sh.in bash_completion: $(srcdir)/bash_completion.in -paccache: $(srcdir)/paccache.in -pacdiff: $(srcdir)/pacdiff.in -paclist: $(srcdir)/paclist.in -paclog-pkglist: $(srcdir)/paclog-pkglist.in -pacscripts: $(srcdir)/pacscripts.in +paccache: $(srcdir)/paccache.sh.in +pacdiff: $(srcdir)/pacdiff.sh.in +paclist: $(srcdir)/paclist.sh.in +paclog-pkglist: $(srcdir)/paclog-pkglist.sh.in +pacscripts: $(srcdir)/pacscripts.sh.in pacsearch: $(srcdir)/pacsearch.in -pacsysclean: $(srcdir)/pacsysclean.in +pacsysclean: $(srcdir)/pacsysclean.sh.in zsh_completion: $(srcdir)/zsh_completion.in # vim:set ts=2 sw=2 noet: diff --git a/contrib/bacman.in b/contrib/bacman.sh.in similarity index 99% rename from contrib/bacman.in rename to contrib/bacman.sh.in index 93623565..ffb9d6d3 100755 --- a/contrib/bacman.in +++ b/contrib/bacman.sh.in @@ -305,4 +305,3 @@ echo Done exit 0 # vim: set ts=2 sw=2 noet: - diff --git a/contrib/paccache.in b/contrib/paccache.sh.in similarity index 100% rename from contrib/paccache.in rename to contrib/paccache.sh.in diff --git a/contrib/pacdiff.in b/contrib/pacdiff.sh.in similarity index 100% rename from contrib/pacdiff.in rename to contrib/pacdiff.sh.in diff --git a/contrib/paclist.in b/contrib/paclist.sh.in similarity index 100% rename from contrib/paclist.in rename to contrib/paclist.sh.in diff --git a/contrib/paclog-pkglist.in b/contrib/paclog-pkglist.sh.in similarity index 100% rename from contrib/paclog-pkglist.in rename to contrib/paclog-pkglist.sh.in diff --git a/contrib/pacscripts.in b/contrib/pacscripts.sh.in similarity index 100% rename from contrib/pacscripts.in rename to contrib/pacscripts.sh.in diff --git a/contrib/pacsysclean.in b/contrib/pacsysclean.sh.in similarity index 100% rename from contrib/pacsysclean.in rename to contrib/pacsysclean.sh.in From 03acea832ad39fa371781f045c39677a02d1156a Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Tue, 17 Apr 2012 21:34:30 -0400 Subject: [PATCH 3/7] validate bash scripts with 'bash -n' during build. Use the no-exec mode of $(BASH_SHELL) to check for syntax errors in shell scripts. Since we use the extglob feature in various places, this requires that we pass -O extglob to the shell as well, to ensure that the parser is armed to handle this syntax. Signed-off-by: Dave Reisner --- contrib/Makefile.am | 1 + scripts/Makefile.am | 1 + 2 files changed, 2 insertions(+) diff --git a/contrib/Makefile.am b/contrib/Makefile.am index 5139b54d..3cc1e578 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -66,6 +66,7 @@ $(BASHSCRIPTS): Makefile $(AM_V_at)$(RM) $@ $(AM_V_GEN)test -f $(srcdir)/$@.sh.in && m4 -P -I $(srcdir) $(srcdir)/$@.sh.in | $(edit) >$@ $(AM_V_at)chmod +x,a-w $@ + @$(BASH_SHELL) -O extglob -n $@ $(OURFILES): Makefile $(AM_V_at)$(RM) $@ $@.tmp diff --git a/scripts/Makefile.am b/scripts/Makefile.am index b8a19900..06e9095e 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -64,6 +64,7 @@ $(OURSCRIPTS): Makefile $(AM_V_at)$(RM) $@ $(AM_V_GEN)test -f $(srcdir)/$@.sh.in && m4 -P -I $(srcdir) $(srcdir)/$@.sh.in | $(edit) >$@ $(AM_V_at)chmod +x,a-w $@ + @$(BASH_SHELL) -O extglob -n $@ makepkg: \ $(srcdir)/makepkg.sh.in \ From ea4aa6f184909db38bacbbf60f22f1674f2853a6 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Wed, 11 Apr 2012 09:29:07 -0400 Subject: [PATCH 4/7] configure: require bash >= 4.1 at compile time We've unofficially agreed to raise our minimum supported bash version to 4.1, and since added features that require it. Additionally, an earlier commit adds a syntax check to the builds of scripts/ and contrib/ which could conceivably fail with an earlier shell. Therefore, make this a hard requirement of the build process. Signed-off-by: Dave Reisner --- configure.ac | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index d488bfaf..0e78c238 100644 --- a/configure.ac +++ b/configure.ac @@ -148,7 +148,23 @@ AC_PROG_AWK AC_PROG_CC_C99 AC_PROG_INSTALL AC_CHECK_PROGS([PYTHON], [python2.7 python2.6 python2.5 python2 python], [false]) -AC_PATH_PROGS([BASH_SHELL], [bash bash4 bash3], [false]) +AC_PATH_PROGS([BASH_SHELL], [bash bash4], [false]) + +AS_IF([test "x$BASH_SHELL" = "xfalse"], + AC_MSG_WARN([*** bash >= 4.1.0 is required for pacman scripts]), + [bash_version_major=`$BASH_SHELL -c 'echo "${BASH_VERSINFO[[0]]}"'` + bash_version_minor=`$BASH_SHELL -c 'echo "${BASH_VERSINFO[[1]]}"'` + ok=yes + if test "$bash_version_major" -lt 4; then + ok=no + fi + if test "$bash_version_major" -eq 4 && test "$bash_version_minor" -lt 1; then + ok=no + fi + if test "$ok" = "no"; then + AC_MSG_ERROR([*** bash >= 4.1.0 is required for pacman scripts]) + fi + unset bash_version_major bash_version_minor ok]) # find installed gettext AM_GNU_GETTEXT([external], [need-ngettext]) From 6d10de881e0ca38d8f20384e20139784589ea2c7 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Thu, 19 Apr 2012 13:33:57 -0400 Subject: [PATCH 5/7] paccache: adopt parseopts for options parsing Add longopts and update usage. This removes the TODO item and incorporates --help/--version into the standard option set. Signed-off-by: Dave Reisner --- contrib/Makefile.am | 2 +- contrib/paccache.sh.in | 119 +++++++++++++++++++++++++---------------- 2 files changed, 73 insertions(+), 48 deletions(-) diff --git a/contrib/Makefile.am b/contrib/Makefile.am index 3cc1e578..fe2fa550 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -88,7 +88,7 @@ uninstall-local: bacman: $(srcdir)/bacman.sh.in bash_completion: $(srcdir)/bash_completion.in -paccache: $(srcdir)/paccache.sh.in +paccache: $(srcdir)/paccache.sh.in $(top_srcdir)/scripts/library/parseopts.sh pacdiff: $(srcdir)/pacdiff.sh.in paclist: $(srcdir)/paclist.sh.in paclog-pkglist: $(srcdir)/paclog-pkglist.sh.in diff --git a/contrib/paccache.sh.in b/contrib/paccache.sh.in index da65f476..e8116721 100755 --- a/contrib/paccache.sh.in +++ b/contrib/paccache.sh.in @@ -42,6 +42,8 @@ die() { exit 1 } +m4_include(../scripts/library/parseopts.sh) + # reads a list of files on stdin and prints out deletion candidates pkgfilter() { # there's whitelist and blacklist parameters passed to this @@ -184,21 +186,21 @@ options to help control how much, and what, is deleted from any directory containing pacman package tarballs. Operations: - -d perform a dry run, only finding candidate packages. - -m move candidate packages to 'movedir'. - -r remove candidate packages. + -d, --dryrun perform a dry run, only finding candidate packages. + -m, --move move candidate packages to 'movedir'. + -r, --remove remove candidate packages. Options: - -a scan for 'arch' (default: all architectures). - -c scan 'cachedir' for packages (default: @localstatedir@/cache/pacman/pkg). - -f apply force to mv(1) and rm(1) operations. - -h display this help message. - -i ignore 'pkgs', which is a comma separated. Alternatively, - specify '-' to read package names from stdin, newline delimited. - -k keep 'num' of each package in 'cachedir' (default: 3). - -u target uninstalled packages. - -v increase verbosity. specify up to 3 times. - -z use null delimiters for candidate names (only with -v and -vv) + -a, --arch scan for 'arch' (default: all architectures). + -c, --cachedir scan 'cachedir' for packages (default: @localstatedir@/cache/pacman/pkg). + -f, --force apply force to mv(1) and rm(1) operations. + -h, --help display 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 'cachedir' (default: 3). + -u, --uninstalled target uninstalled packages. + -v, --verbose increase verbosity. specify up to 3 times. + -z, --null use null delimiters for candidate names (only with -v and -vv) EOF } @@ -213,47 +215,70 @@ if (( ! UID )); then exit 42 fi -# TODO: remove this workaround and use a sane command line parser (like the -# parse_options library from scripts/) here -if [[ $1 = -@(h|-help) ]]; then - usage - exit 0 -elif [[ $1 = -@(V|-version) ]]; then - version - exit 0 -fi +OPT_SHORT=':a:c:dfhi:k:m:rsuVvz' +OPT_LONG=('arch:' 'cachedir:' 'dryrun' 'force' 'help' 'ignore:' 'keep:' 'move' + 'remove' 'uninstalled' 'version' 'verbose' 'null') -while getopts ':a:c:dfi:k:m:rsuvz' opt; do - case $opt in - a) scanarch=$OPTARG ;; - c) cachedir=$OPTARG ;; - d) dryrun=1 ;; - f) cmdopts=(-f) ;; - i) if [[ $OPTARG = '-' ]]; then - [[ ! -t 0 ]] && IFS=$'\n' read -r -d '' -a ign - else - IFS=',' read -r -a ign <<< "$OPTARG" - fi - blacklist+=("${ign[@]}") - unset i ign ;; - k) keep=$OPTARG +if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then + exit 1 +fi +set -- "${OPTRET[@]}" +unset OPT_SHORT OPT_LONG OPTRET + +while :; do + case $1 in + -a|--arch) + scanarch=$2 + shift ;; + -c|--cachedir) + cachedir=$2 + shift ;; + -d|--dryrun) + dryrun=1 ;; + -f|--force) + cmdopts=(-f) ;; + -h|--help) + usage + exit 0 ;; + -i|--ignore) + if [[ $2 = '-' ]]; then + [[ ! -t 0 ]] && IFS=$'\n' read -r -d '' -a ign + else + IFS=',' read -r -a ign <<< "$2" + fi + blacklist+=("${ign[@]}") + unset i ign + shift ;; + -k|--keep) + keep=$2 if [[ -z $keep || -n ${keep//[0-9]/} ]]; then die 'argument to option -k must be a non-negative integer' else keep=$(( 10#$keep )) - fi ;; - m) move=1 movedir=$OPTARG ;; - r) delete=1 ;; - u) IFS=$'\n' read -r -d '' -a ign < <(pacman -Qq) - blacklist+=("${ign[@]}") - unset ign ;; - v) (( ++verbose )) ;; - z) delim='\0' ;; - :) die "option '--%s' requires an argument" "$OPTARG" ;; - ?) die "invalid option -- '%s'" "$OPTARG" ;; + fi + shift ;; + -m|--move) + move=1 movedir=$2 + shift ;; + -r|--remove) + delete=1 ;; + -u|--uninstalled) + IFS=$'\n' read -r -d '' -a ign < <(pacman -Qq) + blacklist+=("${ign[@]}") + unset ign ;; + -V|--version) + version + exit 0 ;; + -v|--verbose) + (( ++verbose )) ;; + -z|--null) + delim='\0' ;; + --) + shift + break 2 ;; esac + shift done -shift $(( OPTIND - 1 )) # remaining args are a whitelist whitelist=("$@") From 953415c86a17c1db8bebbbaca89e6fd5783386b6 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 22 Apr 2012 17:38:48 -0400 Subject: [PATCH 6/7] rankmirrors: move to contrib/ This script is of questionable value, as it ranks mirrors by an uninteresting attribute: ping. While the script itself is interesting, people should be encouraged to rank mirrors by more useful measures, such as actual speed, locality, or up to date-ness. Signed-off-by: Dave Reisner --- contrib/.gitignore | 1 + contrib/Makefile.am | 5 ++++- {scripts => contrib}/rankmirrors.sh.in | 0 scripts/.gitignore | 1 - scripts/Makefile.am | 4 ---- 5 files changed, 5 insertions(+), 6 deletions(-) rename {scripts => contrib}/rankmirrors.sh.in (100%) diff --git a/contrib/.gitignore b/contrib/.gitignore index 70d19093..01bc22bd 100644 --- a/contrib/.gitignore +++ b/contrib/.gitignore @@ -7,4 +7,5 @@ paclog-pkglist pacscripts pacsearch pacsysclean +rankmirrors zsh_completion diff --git a/contrib/Makefile.am b/contrib/Makefile.am index fe2fa550..a325d62a 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -11,7 +11,8 @@ BASHSCRIPTS = \ paclist \ paclog-pkglist \ pacscripts \ - pacsysclean + pacsysclean \ + rankmirrors OTHERSCRIPTS = \ pacsearch @@ -35,6 +36,7 @@ EXTRA_DIST = \ pacscripts.sh.in \ pacsearch.in \ pacsysclean.sh.in \ + rankmirrors.sh.in vimprojects \ zsh_completion.in \ README @@ -95,6 +97,7 @@ paclog-pkglist: $(srcdir)/paclog-pkglist.sh.in pacscripts: $(srcdir)/pacscripts.sh.in pacsearch: $(srcdir)/pacsearch.in pacsysclean: $(srcdir)/pacsysclean.sh.in +rankmirrors: $(srcdir)/rankmirrors.sh.in zsh_completion: $(srcdir)/zsh_completion.in # vim:set ts=2 sw=2 noet: diff --git a/scripts/rankmirrors.sh.in b/contrib/rankmirrors.sh.in similarity index 100% rename from scripts/rankmirrors.sh.in rename to contrib/rankmirrors.sh.in diff --git a/scripts/.gitignore b/scripts/.gitignore index 21b671c0..9e403bfb 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -3,7 +3,6 @@ pacman-db-upgrade pacman-key pacman-optimize pkgdelta -rankmirrors repo-add repo-elephant repo-remove diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 06e9095e..a1a4f366 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -12,7 +12,6 @@ OURSCRIPTS = \ pacman-key \ pacman-optimize \ pkgdelta \ - rankmirrors \ repo-add EXTRA_DIST = \ @@ -21,7 +20,6 @@ EXTRA_DIST = \ pacman-key.sh.in \ pacman-optimize.sh.in \ pkgdelta.sh.in \ - rankmirrors.sh.in \ repo-add.sh.in \ $(LIBRARY) @@ -87,8 +85,6 @@ pkgdelta: \ $(srcdir)/pkgdelta.sh.in \ $(srcdir)/library/output_format.sh -rankmirrors: $(srcdir)/rankmirrors.sh.in - repo-add: \ $(srcdir)/repo-add.sh.in \ $(srcdir)/library/output_format.sh From 82b7122542e16354b560bae9c7f6f3608873a8e1 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 19 Mar 2012 23:56:59 -0400 Subject: [PATCH 7/7] libalpm: add pkg-config file No one seems to do this "correctly", but for the sake of having an easy method of detecting the presence and version of libalpm on a given system, we provide a straightforward .pc file. Signed-off-by: Dave Reisner --- configure.ac | 1 + lib/libalpm/.gitignore | 1 + lib/libalpm/Makefile.am | 3 +++ lib/libalpm/libalpm.pc.in | 12 ++++++++++++ 4 files changed, 17 insertions(+) create mode 100644 lib/libalpm/libalpm.pc.in diff --git a/configure.ac b/configure.ac index 0e78c238..15e93e71 100644 --- a/configure.ac +++ b/configure.ac @@ -449,6 +449,7 @@ AC_DEFINE_UNQUOTED([SCRIPTLET_SHELL], "$SCRIPTLET_SHELL", [The full path of the AC_CONFIG_FILES([ lib/libalpm/Makefile lib/libalpm/po/Makefile.in +lib/libalpm/libalpm.pc src/pacman/Makefile src/pacman/po/Makefile.in src/util/Makefile diff --git a/lib/libalpm/.gitignore b/lib/libalpm/.gitignore index 36d41441..82318d3f 100644 --- a/lib/libalpm/.gitignore +++ b/lib/libalpm/.gitignore @@ -2,3 +2,4 @@ .libs *.lo *.la +libalpm.pc diff --git a/lib/libalpm/Makefile.am b/lib/libalpm/Makefile.am index 0781d5d8..ef448417 100644 --- a/lib/libalpm/Makefile.am +++ b/lib/libalpm/Makefile.am @@ -23,6 +23,9 @@ if ENABLE_GNU89_INLINE_CC AM_CFLAGS += -fgnu89-inline endif +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = libalpm.pc + libalpm_la_SOURCES = \ add.h add.c \ alpm.h alpm.c \ diff --git a/lib/libalpm/libalpm.pc.in b/lib/libalpm/libalpm.pc.in new file mode 100644 index 00000000..fe4e2583 --- /dev/null +++ b/lib/libalpm/libalpm.pc.in @@ -0,0 +1,12 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libalpm +Description: Arch Linux package management library +URL: http://www.archlinux.org/pacman/ +Version: @VERSION@ +Cflags: -I${includedir} +Libs: -L${libdir} -lalpm +Libs.private: @LIBS@ @LIBARCHIVE_LIBS@ @LIBSSL_LIBS@ @LIBCURL_LIBS@ @GPGME_LIBS@