#! /bin/bash # grep-archive - wrapper to run grep-dctrl over a combination of dists, # arches, and components in the Debian archive. # # Copyright (c) 2005, 2006 Adeodato Simó (dato@net.com.org.es) # Licensed under the terms of the MIT license, included below. # Takes a single argument (the rest are passed verbatim to grep-dctrl) # in the form DIST:COMPONENT:ARCH, all three items being optional (but # the colons must be present). Multiple values may be given separated # by commas; the special value 'ALL' will use all the directories present # in the mirror. The default is sid:main:`dpkg --print-architecture`. # Some other examples: # sarge::ALL - main for all arches in sarge # etch:main,contrib:source - main and contrib for sources in etch # ::arm,m68k,hppa - unstable/main for arm, m68k, and hppa MIRROR=${GREP_ARCHIVE_MIRROR:-/org/ftp.debian.org/ftp} if ! command -v grep-dctrl >/dev/null 2>&1; then echo >&2 "E: grep-dctrl could not be found." exit 1 fi # gzip is Essential: yes, bzip2 optional if command -v bzcat >/dev/null 2>&1; then HAVE_BZCAT=yes fi ### cat_for_extension () { case "$1" in '') echo cat ;; .gz) echo zcat ;; .bz2) echo bzcat ;; esac } ### ARGUMENT="$1" shift if ! echo "$ARGUMENT" | egrep -q "^[^: ]*:[^: ]*:[^: ]*$"; then echo >&2 "E: argument '$ARGUMENT' formatted incorectly (should be DIST:COMPONENT:ARCH)." exit 1 fi ### DIST=$( echo "$ARGUMENT" | cut -d: -f1 | tr , "\n" ) COMPONENT=$( echo "$ARGUMENT" | cut -d: -f2 | tr , "\n" ) ARCH=$( echo "$ARGUMENT" | cut -d: -f3 | tr , "\n" ) # If 'ALL' is included, ignore the rest and eval `ALL` in the loop below. # Can't expand it here since the available components may vary from dist # to dist, or the available arches from dist/component to dist/component. # FIXME - re-think this normalization, with it one would not get warnings # for items explicitly mentioned in the command line and not present. for v in DIST COMPONENT ARCH; do if echo "${!v}" | egrep -q 'ALL'; then eval "${v}=ALL" fi done # Defaults : ${DIST:=sid} : ${COMPONENT:=main} : ${ARCH:=`dpkg --print-architecture`} ### the_dists () { if [ "$DIST" != "ALL" ]; then echo $DIST else cd "$MIRROR/dists" || return for d in *; do if [ -d "$d" ] && ! [ -L "$d" ]; then echo $d fi done fi } the_components () { if [ "$COMPONENT" != "ALL" ]; then echo $COMPONENT else cd "$MIRROR/dists/$1" || return for c in *; do # NOTE: nullglob set if [ -d "$c/source" ] || [ $c/binary-* ]; then echo $c fi done fi } the_arches () { if [ "$ARCH" != "ALL" ]; then echo $ARCH else cd "$MIRROR/dists/$1/$2" || return echo binary-* | sed -e 's/binary-//g' fi } ### shopt -s nullglob CAT_FILES="" prev_e="non-empty and not-a-valid-extension" for d in `the_dists`; do for c in `the_components "$d"`; do for a in `the_arches "$d" "$c"`; do found="" # TODO: add support for installer-*? if [ "$a" = source ]; then b= n=Sources else b=binary- n=Packages fi for e in '' .gz ${HAVE_BZCAT:+.bz2} ; do f="$MIRROR/dists/$d/$c/$b$a/$n$e" if [ -e "$f" ]; then # Don't invoke extra processes unless necessary... if [ "$e" = "$prev_e" ]; then CAT_FILES="$CAT_FILES $f" else CAT_FILES="${CAT_FILES:+$CAT_FILES ;} `cat_for_extension $e` $f" fi if [ -n "$DEBUG_GREP_ARCHIVE" ]; then echo >&2 "I: Found: $d/$c/$a ($f)" fi found=1 prev_e="$e" break fi done if [ -z "$found" ]; then echo >&2 "W: Not found: $d/$c/$a (${f%%$e})" fi done done done if [ -z "$DEBUG_GREP_ARCHIVE" ]; then eval $CAT_FILES | grep-dctrl "$@" fi ### # MIT LICENSE (http://www.opensource.org/licenses/mit-license.php) # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.