diff options
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/.gitignore | 1 | ||||
-rw-r--r-- | contrib/Makefile.am | 94 | ||||
-rw-r--r--[-rwxr-xr-x] | contrib/bacman.sh.in (renamed from contrib/bacman.in) | 29 | ||||
-rw-r--r-- | contrib/bash_completion.in | 60 | ||||
-rw-r--r--[-rwxr-xr-x] | contrib/paccache.sh.in (renamed from contrib/paccache.in) | 123 | ||||
-rw-r--r--[-rwxr-xr-x] | contrib/pacdiff.sh.in (renamed from contrib/pacdiff.in) | 22 | ||||
-rw-r--r--[-rwxr-xr-x] | contrib/paclist.sh.in (renamed from contrib/paclist.in) | 29 | ||||
-rw-r--r--[-rwxr-xr-x] | contrib/paclog-pkglist.sh.in (renamed from contrib/paclog-pkglist.in) | 21 | ||||
-rw-r--r--[-rwxr-xr-x] | contrib/pacscripts.sh.in (renamed from contrib/pacscripts.in) | 18 | ||||
-rw-r--r--[-rwxr-xr-x] | contrib/pacsearch.in | 26 | ||||
-rw-r--r--[-rwxr-xr-x] | contrib/pacsysclean.sh.in (renamed from contrib/pacsysclean.in) | 13 | ||||
-rw-r--r-- | contrib/rankmirrors.sh.in | 212 | ||||
-rw-r--r-- | contrib/zsh_completion.in | 211 |
13 files changed, 721 insertions, 138 deletions
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 a7dee54f..a325d62a 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -1,12 +1,25 @@ -OURSCRIPTS = \ +# enforce that all scripts have a --help and --version option +AUTOMAKE_OPTIONS = std-options + +bin_SCRIPTS = \ + $(OURSCRIPTS) + +BASHSCRIPTS = \ bacman \ paccache \ pacdiff \ paclist \ paclog-pkglist \ pacscripts \ - pacsearch \ - pacsysclean + pacsysclean \ + rankmirrors + +OTHERSCRIPTS = \ + pacsearch + +OURSCRIPTS = \ + $(BASHSCRIPTS) \ + $(OTHERSCRIPTS) OURFILES = \ bash_completion \ @@ -14,15 +27,16 @@ 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 \ + rankmirrors.sh.in vimprojects \ zsh_completion.in \ README @@ -30,38 +44,60 @@ EXTRA_DIST = \ # Files that should be removed, but which Automake does not know. MOSTLYCLEANFILES = $(OURSCRIPTS) $(OURFILES) *.tmp +if USE_GIT_VERSION +GIT_VERSION := $(shell sh -c 'git describe --abbrev=4 --dirty | sed s/^v//') +REAL_PACKAGE_VERSION = $(GIT_VERSION) +else +REAL_PACKAGE_VERSION = $(PACKAGE_VERSION) +endif + edit = sed \ -e 's|@sysconfdir[@]|$(sysconfdir)|g' \ -e 's|@localstatedir[@]|$(localstatedir)|g' \ + -e 's|@PACKAGE_VERSION[@]|$(REAL_PACKAGE_VERSION)|g' \ -e 's|@SIZECMD[@]|$(SIZECMD)|g' \ -e '1s|!/bin/bash|!$(BASH_SHELL)|g' -$(OURSCRIPTS): Makefile - @echo ' ' GEN $@; - @$(RM) $@ $@.tmp - @$(edit) $(srcdir)/$@.in >$@.tmp - @chmod +x $@.tmp - @chmod a-w $@.tmp - @mv $@.tmp $@ +$(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)/$@.sh.in && m4 -P -I $(srcdir) $(srcdir)/$@.sh.in | $(edit) >$@ + $(AM_V_at)chmod +x,a-w $@ + @$(BASH_SHELL) -O extglob -n $@ $(OURFILES): Makefile - @echo ' ' GEN $@; - @$(RM) $@ $@.tmp - @$(edit) $(srcdir)/$@.in >$@.tmp - @chmod a-w $@.tmp - @mv $@.tmp $@ + $(AM_V_at)$(RM) $@ $@.tmp + $(AM_V_GEN)$(edit) $(srcdir)/$@.in >$@.tmp + $(AM_V_at)chmod a-w $@.tmp + $(AM_V_at)mv $@.tmp $@ all-am: $(OURSCRIPTS) $(OURFILES) -bacman: $(srcdir)/bacman.in +install-data-local: + $(MKDIR_P) $(DESTDIR)$(sysconfdir)/bash_completion.d/ + $(INSTALL_DATA) bash_completion $(DESTDIR)$(sysconfdir)/bash_completion.d/pacman + $(MKDIR_P) $(DESTDIR)$(datarootdir)/zsh/site-functions/ + $(INSTALL_DATA) zsh_completion $(DESTDIR)$(datarootdir)/zsh/site-functions/_pacman + +uninstall-local: + $(RM) $(DESTDIR)$(sysconfdir)/bash_completion.d/pacman + $(RM) $(DESTDIR)$(datarootdir)/zsh/site-functions/_pacman + +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 $(top_srcdir)/scripts/library/parseopts.sh +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 +rankmirrors: $(srcdir)/rankmirrors.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 index c55d7161..ffb9d6d3 100755..100644 --- a/contrib/bacman.in +++ b/contrib/bacman.sh.in @@ -23,16 +23,21 @@ shopt -s extglob shopt -s nullglob -readonly progname="bacman" -readonly progver="0.2.1" +declare -r myname='bacman' +declare -r myver='@PACKAGE_VERSION@' # # User Friendliness # usage() { echo "This program recreates a package using pacman's db and system files" - echo "Usage: $progname <installed package name>" - echo "Example: $progname kernel26" + echo "Usage: $myname <installed package name>" + echo "Example: $myname kernel26" +} + +version() { + printf "%s %s\n" "$myname" "$myver" + echo 'Copyright (C) 2008 locci <carlocci_at_gmail_dot_com>' } if (( $# != 1 )); then @@ -40,14 +45,11 @@ if (( $# != 1 )); then exit 1 fi -if [[ $1 == "--help" || $1 == "-h" ]]; then +if [[ $1 = -@(h|-help) ]]; then usage exit 0 -fi - -if [[ $1 == "--version" || $1 == "-v" ]]; then - echo "$progname version $progver" - echo "Copyright (C) 2008 locci" +elif [[ $1 = -@(V|-version) ]]; then + version exit 0 fi @@ -61,7 +63,7 @@ if (( EUID )); then /usr/bin/fakeroot -u -- "$0" "$@" exit $? else - echo "WARNING: installing fakeroot or running ${progname} as root is required to" + echo "WARNING: installing fakeroot or running $myname as root is required to" echo " preserve the ownership permissions of files in some packages" echo "" fi @@ -151,7 +153,7 @@ while read i; do echo "" echo "ERROR: unable to add /$i to the package" echo " If your user does not have permssion to read this file then" - echo " you will need to run $progname as root" + echo " you will need to run $myname as root" rm -rf "$work_dir" exit 1 fi @@ -177,7 +179,7 @@ pkg_size=$(du -sk | awk '{print $1 * 1024}') # TODO adopt makepkg's write_pkginfo() into this or scripts/library # echo Generating .PKGINFO metadata... -echo "# Generated by $progname $progver" > .PKGINFO +echo "# Generated by $myname $myver" > .PKGINFO if [[ $INFAKEROOT == "1" ]]; then echo "# Using $(fakeroot -v)" >> .PKGINFO fi @@ -303,4 +305,3 @@ echo Done exit 0 # vim: set ts=2 sw=2 noet: - diff --git a/contrib/bash_completion.in b/contrib/bash_completion.in index 8983c92b..1b265e0c 100644 --- a/contrib/bash_completion.in +++ b/contrib/bash_completion.in @@ -27,17 +27,44 @@ _arch_incomp() { local r="\s-(-${1#* }\s|\w*${1% *})"; [[ $COMP_LINE =~ $r ]] } +_pacman_keyids() { + \pacman-key --list-keys 2>/dev/null | awk ' + $1 == "pub" { + # key id + split($2, a, "/"); print a[2] + } + $1 == "uid" { + # email + if (match($NF, /<[^>]+>/)) + print substr($NF, RSTART + 1, RLENGTH - 2) + }' +} + _pacman_key() { - local cur opts prev + local o cur opts prev wantfiles COMPREPLY=() _get_comp_words_by_ref cur prev - if [[ $cur = -* && - $prev != -@(a|-add|c|-config|g|-gpgdir|h|-help|import?(-trustdb)) ]]; then - opts=('add delete export finger help list-keys recv-keys updatedb verify version - config edit-key gpgdir import import-trustdb init keyserver list-sigs - lsign-key populate refresh-keys' - 'a d e f h l r u v V') + opts=('add delete export finger help list-keys recv-keys updatedb verify + version config edit-key gpgdir import import-trustdb init keyserver + list-sigs lsign-key populate refresh-keys' + 'a d e f h l r u v V') + + # operations for which we want to complete keyids + for o in 'd delete' 'e export' 'f finger' 'l list-keys' 'r recv-keys' \ + 'edit-key' 'list-sigs' 'refresh-keys'; do + _arch_incomp "$o" && break + unset o + done + + # options for which we want file completion + wantfiles='-@(c|-config|g|-gpgdir)' + + if [[ $prev = 'pacman-key' || ( $cur = -* && $prev != $wantfiles ) ]]; then _arch_ptr2comp opts + elif [[ $prev = @(-k|--keyserver) ]]; then + return + elif [[ $prev != $wantfiles && $o ]]; then + COMPREPLY=($(compgen -W '$(_pacman_keyids)' -- "$cur")) fi true } @@ -76,8 +103,8 @@ _pacman() { remove=('cascade dbonly nodeps nosave print recursive unneeded' 'c n p s u') sync=('asdeps asexplicit clean dbonly downloadonly force groups ignore ignoregroup info list needed nodeps print refresh recursive search sysupgrade' - 'c f g i l p s u w y') - upgrade=('asdeps asexplicit force needed nodeps print recursive' 'f p') + 'c g i l p s u w y') + upgrade=('asdeps asexplicit force needed nodeps print recursive' 'p') common=('arch cachedir config dbpath debug help logfile noconfirm noprogressbar noscriptlet quiet root verbose' 'b d h q r v') core=('database help query remove sync upgrade version' 'D Q R S U V h') @@ -111,18 +138,11 @@ _pacman() { true } -if [[ $(type -t compopt) = "builtin" ]]; then - _pacman_file() { - compopt -o filenames; _filedir 'pkg.tar*' - } - complete -F _pacman -o default pacman -else - _pacman_file() { - _filedir 'pkg.tar*' - } - complete -F _pacman -o filenames -o default pacman -fi +_pacman_file() { + compopt -o filenames; _filedir 'pkg.tar*' +} +complete -F _pacman -o default pacman complete -F _makepkg -o default makepkg complete -F _pacman_key -o default pacman-key diff --git a/contrib/paccache.in b/contrib/paccache.sh.in index a9e5bfbc..e8116721 100755..100644 --- a/contrib/paccache.in +++ b/contrib/paccache.sh.in @@ -20,6 +20,9 @@ shopt -s extglob +declare -r myname='paccache' +declare -r myver='@PACKAGE_VERSION@' + declare -a candidates=() cmdopts=() whitelist=() blacklist=() declare -i delete=0 dryrun=0 filecount=0 move=0 needsroot=0 totalsaved=0 verbose=0 declare cachedir=@localstatedir@/cache/pacman/pkg delim=$'\n' keep=3 movedir= scanarch= @@ -39,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 @@ -174,70 +179,106 @@ summarize() { usage() { cat <<EOF -usage: ${0##*/} <operation> [options] [targets...] +usage: $myname <operation> [options] [targets...] -${0##*/} is a flexible pacman cache cleaning utility, which has numerous +$myname is a flexible pacman cache cleaning utility, which has numerous 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 <movedir> move candidate packages to 'movedir'. - -r remove candidate packages. + -d, --dryrun perform a dry run, only finding candidate packages. + -m, --move <dir> move candidate packages to 'movedir'. + -r, --remove remove candidate packages. Options: - -a <arch> scan for 'arch' (default: all architectures). - -c <cachedir> 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 <pkgs> ignore 'pkgs', which is a comma separated. Alternatively, - specify '-' to read package names from stdin, newline delimited. - -k <num> 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 <arch> scan for 'arch' (default: all architectures). + -c, --cachedir <dir> 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 <pkgs> ignore 'pkgs', comma separated. Alternatively, specify '-' to + read package names from stdin, newline delimited. + -k, --keep <num> 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 } +version() { + printf "%s %s\n" "$myname" "$myver" + echo 'Copyright (C) 2011 Dave Reisner <dreisner@archlinux.org>' +} + if (( ! UID )); then error "Do not run this script as root. You will be prompted for privilege escalation." exit 42 fi -while getopts ':a:c:dfhi:k:m:rsuvz' opt; do - case $opt in - a) scanarch=$OPTARG ;; - c) cachedir=$OPTARG ;; - d) dryrun=1 ;; - f) cmdopts=(-f) ;; - h) usage +OPT_SHORT=':a:c:dfhi:k:m:rsuVvz' +OPT_LONG=('arch:' 'cachedir:' 'dryrun' 'force' 'help' 'ignore:' 'keep:' 'move' + 'remove' 'uninstalled' 'version' 'verbose' 'null') + +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) 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 + -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=("$@") diff --git a/contrib/pacdiff.in b/contrib/pacdiff.sh.in index 3f26f381..bfafda26 100755..100644 --- a/contrib/pacdiff.in +++ b/contrib/pacdiff.sh.in @@ -17,17 +17,25 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # +declare -r myname='pacdiff' +declare -r myver='@PACKAGE_VERSION@' + diffprog=${DIFFPROG:-vimdiff} diffsearchpath=${DIFFSEARCHPATH:-/etc} locate=0 usage() { - echo "pacdiff : a simple pacnew/pacorig/pacsave updater" - echo "Usage : pacdiff [-l]" - echo " -l/--locate makes pacdiff use locate rather than find" + echo "$myname : a simple pacnew/pacorig/pacsave updater" + echo "Usage : $myname [-l]" + echo " -l/--locate makes $myname use locate rather than find" echo " DIFFPROG variable allows to override the default vimdiff" echo " DIFFSEARCHPATH allows to override the default /etc path" - echo "Example : DIFFPROG=meld DIFFSEARCHPATH=\"/boot /etc /usr\" pacdiff" + echo "Example : DIFFPROG=meld DIFFSEARCHPATH=\"/boot /etc /usr\" $myname" +} + +version() { + printf "%s %s\n" "$myname" "$myver" + echo 'Copyright (C) 2007 Aaron Griffin <aaronmgriffin@gmail.com>' } cmd() { @@ -42,8 +50,12 @@ if [ $# -gt 0 ]; then case $1 in -l|--locate) locate=1;; - *) + -V|--version) + version; exit 0;; + -h|--help) usage; exit 0;; + *) + usage; exit 1;; esac fi diff --git a/contrib/paclist.in b/contrib/paclist.sh.in index 06b06f2c..7883e21b 100755..100644 --- a/contrib/paclist.in +++ b/contrib/paclist.sh.in @@ -17,6 +17,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +declare -r myname='paclist' +declare -r myver='@PACKAGE_VERSION@' + export TEXTDOMAIN='pacman' export TEXTDOMAINDIR='/usr/share/locale' @@ -27,13 +30,31 @@ if ! type gettext &>/dev/null; then } fi -if [[ -z $1 || $1 = -@(h|-help) ]]; then - printf '%s - List all packages installed from a given repo\n' "${0##*/}" - printf 'Usage: %s <repo>\n' "${0##*/}" - printf 'Example: %s testing\n' "${0##*/}" +usage() { + printf '%s - List all packages installed from a given repo\n' "$myname" + printf 'Usage: %s <repo>\n' "$myname" + printf 'Example: %s testing\n' "$myname" +} + +version() { + printf "%s %s\n" "$myname" "$myver" + echo 'Copyright (C) 2008 Dan McGee <dpmcgee@gmail.com>' + echo 'Copyright (C) 2011 Dave Reisner <dreisner@archlinux.org>' +} + +if [[ -z $1 ]]; then + usage exit 1 fi +if [[ $1 = -@(h|-help) ]]; then + usage + exit 0 +elif [[ $1 = -@(V|-version) ]]; then + version + exit 0 +fi + printf -v installed '[%s]' "$(gettext installed)" pacman -Sl $1 | awk -v i="$installed" '$NF == i { print $2,$3 }' diff --git a/contrib/paclog-pkglist.in b/contrib/paclog-pkglist.sh.in index 27dfd302..222bbc4c 100755..100644 --- a/contrib/paclog-pkglist.in +++ b/contrib/paclog-pkglist.sh.in @@ -17,15 +17,30 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +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} +usage() { + printf 'usage: %s [pacman log]\n' "$myname" + printf 'example: %s @localstatedir@/log/pacman.log\n' "$myname" + printf '\ndefaults to: @localstatedir@/log/pacman.log\n' +} + +version() { + printf "%s %s\n" "$myname" "$myver" + echo 'Copyright (C) 2011 Dave Reisner <dave@archlinux.org>' +} + if [[ $1 ]]; then if [[ $1 = -@(h|-help) ]]; then - printf 'usage: %s [pacman log]\n' "${0##*/}" - printf 'example: %s @localstatedir@/log/pacman.log\n' "${0##*/}" - printf '\ndefaults to: @localstatedir@/log/pacman.log\n' + usage + exit 0 + elif [[ $1 = -@(V|-version) ]]; then + version exit 0 elif [[ ! -e $logfile ]]; then printf $"target not found: %s\n" "$1" diff --git a/contrib/pacscripts.in b/contrib/pacscripts.sh.in index 37d3feae..84687145 100755..100644 --- a/contrib/pacscripts.in +++ b/contrib/pacscripts.sh.in @@ -24,8 +24,8 @@ set -o nounset set -o errexit -progname=$(basename $0) -progver="0.4" +declare -r myname='pacscripts' +declare -r myver='@PACKAGE_VERSION@' conf="@sysconfdir@/pacman.conf" @@ -47,14 +47,20 @@ error() { usage() { echo "This program prints out the {pre,post}_{install,remove,upgrade} scripts" echo "of a given package." - echo "Usage: $progname pkgname|pkgfile" + echo "Usage: $myname pkgname|pkgfile" echo echo " OPTIONS:" echo " -h, --help Print this help message" echo " -v, --version Print program name and version" echo - echo "Example: $progname gconf-editor" - echo "Example: $progname gconf-editor-2.24.1-1-x86_64.pkg.tar.gz" + echo "Example: $myname gconf-editor" + echo "Example: $myname gconf-editor-2.24.1-1-x86_64.pkg.tar.gz" +} + +version() { + printf "%s %s\n" "$myname" "$myver" + echo 'Copyright (c) 2009 Giulio "giulivo" Fidente <giulivo.navigante@gmail.com>' + echo 'Copyright (c) 2009 Xavier Chantry <shiningxc@gmail.com>' } spacman() { @@ -127,6 +133,6 @@ fi case "$1" in --help|-h) usage; exit 0 ;; - --version|-v) echo "$progname version $progver"; exit 0 ;; + --version|-V) version; exit 0 ;; *) print_scriptlet $1 ;; esac diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index db9d6ad1..b1db8abe 100755..100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -24,22 +24,32 @@ use strict; use warnings; -my $progname = "pacsearch"; -my $version = "2.0"; +my $myname = 'pacsearch'; +my $myver = '@PACKAGE_VERSION@'; + +sub usage { + print "$myname - Add color and install information to a pacman -Ss search\n"; + print "Usage: $myname <pattern>\n"; + print "Example: $myname ^gnome\n"; +} + +sub version { + printf "%s %s\n", $myname, $myver; + print "Copyright (C) 2008-2011 Dan McGee <dan\@archlinux.org>\n\n"; + print "Based off original shell script version:\n"; + print "Copyright (C) 2006-2007 Dan McGee <dan\@archlinux.org>\n"; +} if ($#ARGV lt 0 || $ARGV[0] eq "--help" || $ARGV[0] eq "-h") { - print "$progname - Add color and install information to a pacman -Ss search\n"; - print "Usage: $progname <pattern>\n"; - print "Example: $progname ^gnome\n"; + usage; if ($#ARGV lt 0) { exit 1; } exit 0; } -if ($ARGV[0] eq "--version" || $ARGV[0] eq "-v") { - print "$progname version $version\n"; - print "Copyright (C) 2006-2011 Dan McGee\n"; +if ($ARGV[0] eq "--version" || $ARGV[0] eq "-V") { + version; exit 0; } diff --git a/contrib/pacsysclean.in b/contrib/pacsysclean.sh.in index 9e25d39e..f80c816d 100755..100644 --- a/contrib/pacsysclean.in +++ b/contrib/pacsysclean.sh.in @@ -2,23 +2,32 @@ # pacsysclean - Sort installed packages by increasing installed size. Useful for system clean-up. +declare -r myname='pacsysclean' +declare -r myver='@PACKAGE_VERSION@' + PACMAN_OPTS= usage() { - echo "pacsysclean - Sort installed packages by increasing installed size." + echo "$myname - Sort installed packages by increasing installed size." echo - echo "Usage: pacsysclean [options]" + echo "Usage: $myname [options]" echo echo "Options:" echo " -o <options> Specify custom pacman query options (e.g., dt)" echo " -h, --help Show this help message and exit" } +version() { + printf "%s %s\n" "$myname" "$myver" + echo 'Copyright (C) 2011 Eric BĂ©langer <snowmaniscool@gmail.com>' +} + if [ -n "$1" ]; then case "$1" in -o) PACMAN_OPTS="${2}" ;; -h|--help) usage; exit 0 ;; + -V|--version) version; exit 0 ;; *) usage; exit 1 ;; esac fi diff --git a/contrib/rankmirrors.sh.in b/contrib/rankmirrors.sh.in new file mode 100644 index 00000000..875a1439 --- /dev/null +++ b/contrib/rankmirrors.sh.in @@ -0,0 +1,212 @@ +#!/bin/bash +# +# rankmirrors - read a list of mirrors from a file and rank them by speed +# @configure_input@ +# +# Copyright (c) 2009 Matthew Bruenig <matthewbruenig@gmail.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# traps interrupt key to spit out pre-interrupt info +trap finaloutput INT + +usage() { + echo "Usage: rankmirrors [options] MIRRORFILE | URL" + 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." + 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, --times only 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 specific repo name instead of guessing" + exit 0 +} + +version() { + echo "rankmirrors (pacman) @PACKAGE_VERSION@" + echo "Copyright (c) 2009 Matthew Bruenig <matthewbruenig@gmail.com>." + echo + echo "This is free software; see the source for copying conditions." + echo "There is NO WARRANTY, to the extent permitted by law." + exit 0 +} + +err() { + echo "$1" >&2 + exit 1 +} + +# gettime fetchurl (e.g gettime http://foo.com/core/os/i686/core.db.tar.gz) +# returns the fetching time, or timeout, or unreachable +gettime() { + IFS=' ' output=( $(curl -s -m 10 -w "%{time_total} %{http_code}" "$1" -o/dev/null) ) + (( $? == 28 )) && echo timeout && return + (( ${output[1]} >= 400 || ! ${output[1]} )) && echo unreachable && return + echo "${output[0]}" +} + +# getfetchurl serverurl (e.g. getturl http://foo.com/core/os/i686) +# if $repo is in the line, then assumes core +# if $arch is in the line, then assumes $(uname -m) +# returns a fetchurl (e.g. http://foo.com/core/os/i686/core.db.tar.gz) +ARCH="$(uname -m)" +getfetchurl() { + local strippedurl="${1%/}" + + local replacedurl="${strippedurl//'$arch'/$ARCH}" + if [[ ! $TARGETREPO ]]; then + replacedurl="${replacedurl//'$repo'/core}" + local tmp="${replacedurl%/*}" + tmp="${tmp%/*}" + + local reponame="${tmp##*/}" + else + replacedurl="${replacedurl//'$repo'/$TARGETREPO}" + local reponame="$TARGETREPO" + fi + + if [[ -z $reponame || $reponame = $replacedurl ]]; then + echo "fail" + else + local fetchurl="${replacedurl}/$reponame.db" + echo "$fetchurl" + fi +} + +# This exists to remove the need for a separate interrupt function +finaloutput() { + IFS=$'\n' read -r -d '' -a sortedarray < \ + <(printf '%s\n' "${timesarray[@]}" | LC_COLLATE=C sort) + + # Final output for mirrorfile + numiterator="0" + if [[ $TIMESONLY ]]; then + echo + echo " Servers sorted by time (seconds):" + for line in "${sortedarray[@]}"; do + echo "${line#* } : ${line% *}" + ((numiterator++)) + (( NUM && numiterator >= NUM )) && break + done + else + for line in "${sortedarray[@]}"; do + echo "Server = ${line#* }" + ((numiterator++)) + (( NUM && numiterator >= NUM )) && break + done + fi + 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 repo 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=( $(</dev/stdin) ) + STDIN=1 + shift + else + snum=1 + for ((i=1 ; i<${#1}; i++)); do + case ${1:$i:1} in + h) usage ;; + t) TIMESONLY=1 ;; + v) VERBOSE=1 ;; + u) CHECKURL=1; [[ $2 ]] || err "Must specify url."; URL="$2"; snum=2;; + r) [[ $2 ]] || err "Must specify repo name."; TARGETREPO="$2"; snum=2;; + n) [[ $2 ]] || err "Must specify number." ; NUM="$2" ; snum=2;; + *) err "\`-$1' is an invald argument." ;; + esac + done + shift $snum + fi + elif [[ -f $1 ]]; then + FILE="1" + IFS=$'\n' linearray=( $(<$1) ) + [[ $linearray ]] || err "File is empty." + shift + else + err "\`$1' does not exist." + fi +done + +# Some sanity checks +[[ $NUM ]] || NUM=0 +[[ $FILE && $CHECKURL ]] && err "Cannot specify a url and mirrorfile." +[[ $FILE || $CHECKURL || $STDIN ]] || err "Must specify url, mirrorfile, or stdin." + +# Single url handling +if [[ $CHECKURL ]]; then + url="$(getfetchurl "$URL")" + [[ $url = fail ]] && err "url \`$URL' is malformed." + [[ $VERBOSE ]] && echo "Testing $url..." + time=$(gettime "$url") + echo "$URL : $time" + exit 0 +fi + +# Get url results from mirrorfile, fill up the array, and so on +if [[ $TIMESONLY ]]; then + echo "Querying servers, this may take some time..." +elif [[ $FILE ]]; then + echo "# Server list generated by rankmirrors on $(date +%Y-%m-%d)" +fi + +timesarray=() +for line in "${linearray[@]}"; do + if [[ $line =~ ^[[:space:]]*# ]]; then + [[ $TIMESONLY ]] || echo $line + elif [[ $line =~ ^[[:space:]]*Server ]]; then + + # Getting values and times and such + server="${line#*= }" + server="${server%%#*}" + url="$(getfetchurl "$server")" + [[ $url = fail ]] && err "url \`$URL' is malformed." + time=$(gettime "$url") + timesarray+=("$time $server") + + # Output + if [[ $VERBOSE && $TIMESONLY ]]; then + echo "$server ... $time" + elif [[ $VERBOSE ]]; then + echo "# $server ... $time" + elif [[ $TIMESONLY ]]; then + echo -n " *" + fi + fi +done +finaloutput + +# vim: set ts=2 sw=2 noet: diff --git a/contrib/zsh_completion.in b/contrib/zsh_completion.in index 2cfc946c..2de47cd8 100644 --- a/contrib/zsh_completion.in +++ b/contrib/zsh_completion.in @@ -1,4 +1,4 @@ -#compdef pacman pacman.static=pacman +#compdef pacman pacman.static=pacman pacman-key makepkg # copy this file to /usr/share/zsh/site-functions/_pacman @@ -32,8 +32,8 @@ _pacman_opts_common=( # options for passing to _arguments: options for --upgrade commands _pacman_opts_pkgfile=( '-d[Skip dependency checks]' - '-f[Overwrite conflicting files]' '--dbonly[Only remove database entry, do not remove files]' + '--force[Overwrite conflicting files]' '--needed[Do not reinstall up to date packages]' '--recursive[Reinstall all dependencies of target packages]' '*:package file:_files -g "*.pkg.tar*(.)"' @@ -85,7 +85,6 @@ _pacman_opts_sync_actions=( # options for passing to _arguments: options for --sync command _pacman_opts_sync_modifiers=( '-d[Skip dependency checks]' - '-f[Overwrite conflicting files]' '-i[View package information]' '-l[List all packages in a repository]' '-p[Print download URIs for each package to be installed]' @@ -98,6 +97,7 @@ _pacman_opts_sync_modifiers=( _pacman_completions_all_groups' '--asdeps[Install packages as non-explicitly installed]' '--asexplicit[Install packages as explicitly installed]' + '--force[Overwrite conflicting files]' ) # handles --help subcommand @@ -286,7 +286,7 @@ _pacman_get_command() { } # main dispatcher -_pacman() { +_pacman_zsh_comp() { case $words[2] in -Q*g*) # ipkg groups _arguments -s : \ @@ -332,5 +332,204 @@ _pacman() { esac } -# run the main dispatcher -_pacman "$@" +_key_shortopts=( + '-h[show help]' \ + '-a[Add the specified keys (empty for stdin)]: :_files' + '-d[Remove the Specified keyids]:*: :_keys' + '-e[Export the specified or all keyids]:*: :_keys' + '-f[List fingreprint for specidied or all keyids]:*: :_keys' + '-l[List the specified or all keys]:*: :_keys' + '-r[Fetch the specified keyids]:*: :_keys' + '-u[Update the trustdb of pacman]' + '-v[Verify the file specified by the signature]: :_files -g "*.sig"' + '-V[Show program version]' + ) + +_key_longopts=( + '--help[show help]' + '--add[Add the specified keys (empty for stdin)]: :_files' + '--delete[Remove the Specified keyids]:*: :_keys' + '--export[Export the specified or all keyids]:*: :_keys' + '--finger[List fingreprint for specidied or all keyids]:*: :_keys' + '--list-keys[List the specified or all keys]:*: :_keys' + '--recv-keys[Fetch the specified keyids]:*: :_keys' + '--updatedb[Update the trustdb of pacman]' + '--verify[Verify the file specified by the signature]: :_files -g "*.sig"' + '--version[Show program version]' + '--edit-key[Present a menu for key management task on keyids]:*: :_keys' + '--import[Imports pubring.gpg from dir(s)]: :_files -g "*.gpg"' + '--import-tb[Imports ownertrust values from trustdb.gpg in dir(s)]: :_files -g "*.gpg"' + '--init[Ensure the keyring is properly initialized]' + '--list-sigs[List keys and their signatures]:*: :_keys' + '--lsign-key[Locally sign the specified keyid]:*: :_keys' + '--populate[Reload the default keys from the (given) keyrings in '/usr/share/pacman/keyrings']: :_path_files -W /usr/share/pacman/keyrings' + '--refresh-keys[Update specified or all keys from a keyserver]:*: :_keys' + ) + +_pacman_key_options=( + '--config[Use an alternate config file (instead of /etc/pacman.con)]: :_files' + '--gpgdir[Set an alternate directory for GnuPG (instead of /etc/pacman.d/gnupg)]: :_files -/' + '--keyserver[Specify a keyserver to use if necessary]' + ) + +_pacman_key() { + case $words[CURRENT] in + --*) + _arguments -s : \ + "$_pacman_key_options[@]" \ + "$_key_longopts[@]" + ;; + -*) + _arguments -s : \ + "$_pacman_key_options[@]" \ + "$_key_shortopts[@]" \ + "$_key_longopts[@]" + ;; + *) + i=$#; + while [[ $words[$i] != -* ]] && [[ $words[$i] != "pacman-key" ]];do + i=$(($i-1)) + done + case $i in + --*) + _arguments -s : \ + "$_pacman_key_options[@]" \ + "$_key_longopts[@]" + ;; + -*) + _arguments -s : \ + "$_pacman_key_options[@]" \ + "$_key_shortopts[@]" \ + "$_key_longopts[@]" + ;; + *) return 1;; + esac + ;; + esac +} + +_keys() { + local keylist keys + keylist=$(pacman-key --list-keys 2>/dev/null | awk ' + $1 == "pub" { + # key id + split($2, a, "/"); print a[2] + } + $1 == "uid" { + # email + if (match($NF, /<[^>]+>/)) + print substr($NF, RSTART + 1, RLENGTH - 2) + #this adds support for names as well if that is ever added + # } + #$1 == "uid" { + #for (i=2;i<NF;i++) {printf "%s%s",sep, $i;sep=" "}; printf "\n" + }' #|sed -e 's/(.*)//g' -e 's/^\ //g' -e 's/\ *$//g' |uniq + ) + #keys=(${keylist//$'\n'/\/}) + keys=(${(s:/:)${keylist//$'\n'/\/}}) + _describe -t modules 'keys in keyring' keys && return 0 +} + +_makepkg_shortopts=( + '*-s[Install missing dependencies with pacman]' + '*-i[Install package after successful build]' + '*-A[Ignore incomplete arch field in PKGBUILD]' + '*-c[Clean up work files after build]' + '*-d[Skip all dependency checks]' + '*-e[Do not extract source files (use existing src/ dir)]' + '*-f[Overwrite existing package]' + '*-g[Generate integrity checks for source files]' + '*-h[Show help message and exit]' + '*-L[Log package build process]' + '*-m[Disable colorized output messages]' + '*-o[Download and extract files only]' + '-p[Use an alternate build script (instead of 'PKGBUILD')]: :_files' + '*-r[Remove installed dependencies after a successful build]' + '*-R[Repackage contents of the package without rebuilding]' + '*-S[Generate a source-only tarball without downloading sources]' + ) + +_makepkg_action_none(){ + _arguments \ + "$_makepkg_shortopts[@]"\ + "$_makepkg_longopts[@]" +} +_makepkg_longopts=( + '--ignorearch[Ignore incomplete arch field in PKGBUILD]' + '--clean[Clean up work files after build]' + '--nodeps[Skip all dependency checks]' + '--noextract[Do not extract source files (use existing src/ dir)]' + '--force[Overwrite existing package]' + '--geninteg[Generate integrity checks for source files]' + '--help[Show help message and exit]' + '--install[Install package after successful build]' + '--log[Log package build process]' + '--nocolor[Disable colorized output messages]' + '--nobuild[Download and extract files only]' + '--rmdeps[Remove installed dependencies after a successful build]' + '--repackage[Repackage contents of the package without rebuilding]' + '--syncdeps[Install missing dependencies with pacman]' + '--source[Generate a source-only tarball without downloading sources]' + '--allsource[Generate a source-only tarball including downloaded source]' + '--asroot[Allow makepkg to run as root user]' + '--check[Run check() function in the PKGBUILD]' + '--config[Use an alternate config file instead of '/etc/makepkg.conf']: :_files' + '--holdver[Prevent automatic version bumping for development PKGBUILDs]' + '--key[Specify key to use for gpg signing instead of the default]: :_keys' + '--nocheck[Do not run the check() function in the PKGBUILD]' + '--nosign[Do not create a signature for the package]' + '--pkg[Only build listed packages from a split package]' + '--sign[Sign the resulting package with gpg]' + '--skipchecksums[Do not verify checksums of the source files]' + '--skipinteg[do not perform any verification checks on source files]' + '--skippgpcheck[Do not verify source files with PGP signatures]' + '--noconfirm[do not ask for confirmation when resolving dependencies]' + '--noprogressbar[Do not show a progress bar when downloading files]' + ) +_makepkg(){ + case $words[CURRENT] in + -*) + _arguments -s -w : \ + "$_makepkg_shortopts[@]" \ + "$_makepkg_longopts[@]" + ;; + --* ) + _arguments -s \ + "$_makepkg_longopts[@]" + ;; + - )_makepkg_action_none ;; + * ) + i=$# + while [[ $words[i] != -* ]] && [[ $words[$i] != "makepkg" ]];do + i=$((i-1)); + done + case $words[$i] in + -*) + _arguments -s -w : \ + "$_makepkg_shortopts[@]" \ + "$_makepkg_longopts[@]" + ;; + --* ) + _arguments -s \ + "$_makepkg_longopts[@]" + ;; + - )_makepkg_action_none ;; + * ) return 1 ;; + esac + ;; + esac +} +_pacman_comp() { + case "$service" in + makepkg) + _makepkg "$@";; + pacman-key) + _pacman_key "$@";; + pacman) + _pacman_zsh_comp "$@";; + *) + _message "Error";; + esac +} + +_pacman_comp "$@" |