#!/bin/sh

# NOTE TO MANTAINERS: when you add a string that is displayed to
# the user use $ECHO not echo (that will use gettext if available)

# i18n support
ECHO=`which gettext 2> /dev/null`
[ -z "$ECHO" ] && ECHO="echo" || ECHO="$ECHO -s"
TEXTDOMAIN="urpmi"
export TEXTDOMAIN

dir="/var/lib/urpmi"
options=

while true
do
    case $1 in
	-h|--help)
	    TMPDATA=`$ECHO "urpmf version %s"`
	    printf "$TMPDATA" `rpm -q rpmtools --qf '%{VERSION}'` ; echo
	    $ECHO "Copyright (C) 1999, 2000, 2001, 2002 MandrakeSoft."
	    $ECHO "This is free software and may be redistributed under the terms of the GNU GPL."
	    echo
	    $ECHO "usage: urpmf [options] <file>"
	    $ECHO "  --quiet         - do not print tag name (default if no tag given on command"
	    $ECHO "                    line, incompatible with interactive mode)."
	    $ECHO "  --all           - print all tags."
	    $ECHO "  --name          - print tag name: rpm filename (assumed if no tag given on"
	    $ECHO "                    command line but without package name)."
	    $ECHO "  --group         - print tag group: group."
	    $ECHO "  --size          - print tag size: size."
	    $ECHO "  --serial        - print tag serial: serial."
	    $ECHO "  --summary       - print tag summary: summary."
	    $ECHO "  --description   - print tag description: description."
	    $ECHO "  --provides      - print tag provides: all provides (multiple lines)."
	    $ECHO "  --requires      - print tag requires: all requires (multiple lines)."
	    $ECHO "  --files         - print tag files: all files (multiple lines)."
	    $ECHO "  --conflicts     - print tag conflicts: all conflicts (multiple lines)."
	    $ECHO "  --obsoletes     - print tag obsoletes: all obsoletes (multiple lines)."
	    $ECHO "  --prereqs       - print tag prereqs: all prereqs (multiple lines)."
	    exit 1
	    ;;
	--*)
	    options="$1 $options"
	    shift
	    ;;
	*)
	    if [ $# -gt 1 ]; then
		$ECHO "usage: urpmf [options] <file>"
		$ECHO "try urpmf --help for more options"
		exit 1
	    fi
	    if /bin/ls $dir/hdlist.* >/dev/null 2>/dev/null; then
		parsehdlist ${options:---files --quiet} $dir/hdlist.* | grep -E "$1"
		exit $?
	    else
		$ECHO "no full media list was found"
		exit 1
	    fi
	    ;;
    esac
done