index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | contrib/.gitignore | 1 | ||||
-rw-r--r-- | contrib/Makefile.am | 51 | ||||
-rwxr-xr-x | contrib/bacman.sh.in (renamed from contrib/bacman.in) | 1 | ||||
-rwxr-xr-x | contrib/paccache.sh.in (renamed from contrib/paccache.in) | 119 | ||||
-rwxr-xr-x | contrib/pacdiff.sh.in (renamed from contrib/pacdiff.in) | 0 | ||||
-rwxr-xr-x | contrib/paclist.sh.in (renamed from contrib/paclist.in) | 0 | ||||
-rwxr-xr-x | contrib/paclog-pkglist.sh.in (renamed from contrib/paclog-pkglist.in) | 0 | ||||
-rwxr-xr-x | contrib/pacscripts.sh.in (renamed from contrib/pacscripts.in) | 0 | ||||
-rwxr-xr-x | contrib/pacsysclean.sh.in (renamed from contrib/pacsysclean.in) | 0 | ||||
-rw-r--r-- | contrib/rankmirrors.sh.in | 212 |
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 a3d2d42b..a325d62a 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -4,15 +4,22 @@ AUTOMAKE_OPTIONS = std-options bin_SCRIPTS = \ $(OURSCRIPTS) -OURSCRIPTS = \ +BASHSCRIPTS = \ bacman \ paccache \ pacdiff \ paclist \ paclog-pkglist \ pacscripts \ - pacsearch \ - pacsysclean + pacsysclean \ + rankmirrors + +OTHERSCRIPTS = \ + pacsearch + +OURSCRIPTS = \ + $(BASHSCRIPTS) \ + $(OTHERSCRIPTS) OURFILES = \ bash_completion \ @@ -20,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 @@ -50,12 +58,18 @@ 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)/$@.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 $(AM_V_GEN)$(edit) $(srcdir)/$@.in >$@.tmp @@ -74,15 +88,16 @@ 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 $(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 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 index da65f476..e8116721 100755 --- a/contrib/paccache.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 <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 } @@ -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=("$@") diff --git a/contrib/pacdiff.in b/contrib/pacdiff.sh.in index bfafda26..bfafda26 100755 --- a/contrib/pacdiff.in +++ b/contrib/pacdiff.sh.in diff --git a/contrib/paclist.in b/contrib/paclist.sh.in index 7883e21b..7883e21b 100755 --- a/contrib/paclist.in +++ b/contrib/paclist.sh.in diff --git a/contrib/paclog-pkglist.in b/contrib/paclog-pkglist.sh.in index 222bbc4c..222bbc4c 100755 --- a/contrib/paclog-pkglist.in +++ b/contrib/paclog-pkglist.sh.in diff --git a/contrib/pacscripts.in b/contrib/pacscripts.sh.in index 84687145..84687145 100755 --- a/contrib/pacscripts.in +++ b/contrib/pacscripts.sh.in diff --git a/contrib/pacsysclean.in b/contrib/pacsysclean.sh.in index 162530ef..162530ef 100755 --- a/contrib/pacsysclean.in +++ b/contrib/pacsysclean.sh.in 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: |