#!/usr/bin/env bash # Daniel Pecos Martínez (contact@netpecos.org) # November, 2001 # http://www.netpecos.org # Use: debfind [-r release] [-s section] [-x] [-desc] [-nd] [-nc] packages # if any option is omited, release will be "all" and section "all" web="http://packages.debian.org/cgi-bin/search_packages.pl" key="?keywords=" search="&searchon=" sub="&subword=" ver="&version=" rel="&release=" release="all" section="all" names="names" description=1 subword=1 continue=1 white="" normal="" while [ $continue -gt 0 ] do case $1 in "-r") release="" while [ "$2" == "stable" -o "$2" == "testing" \ -o "$2" == "unstable" -o "$2" == "all" -o "$2" == "|" ] do case $2 in "all") release="all";; "|") ;; *) if [ "$release"!="all" ]; then release=$release" "$2; fi ;; esac shift done if [ "$1" == "-d" ] || [ "$release" == "" ] then echo "You didn't specified any release!" echo " release -> [ stable | testing | unstable | all ]" exit fi ;; "-s") section="" while [ "$2" == "main" -o "$2" == "contrib" -o "$2" == "non-free" \ -o "$2" == "non-us" -o "$2" == "all" -o "$2" == "|" ] do case $2 in "all") section="all" ;; "|") ;; *) if [ "section"!="all" ]; then section=$section" "$2; fi ;; esac shift done if [ "$1" == "-s" ] || [ "$section" == "" ] then echo "You didn't specified any section!" echo " section -> [ main | contrib | non-free | non-us | all ]" exit fi ;; "-desc") names="all" ;; "-x") subword=0 ;; "-nd") description=0 ;; "-nc") white="" normal="" ;; "-h"|"--help") echo "Use: debfind [-r release] [-s section] [-x] [-nd] packages" echo " -r: Release of the Debian target to look for" echo " (\"all\" by default)" echo " -s: Section of" echo " (\"all\" by default)" echo " -desc: Search in packages descriptions" echo " -x: Look for exact match" echo " -nd: Don't show descriptions of the results" echo " -nc: Don't use colour in output" exit ;; *) while [ $# -gt 0 ] do packages=$packages" "$1 shift done if [ "$packages" == "" ] then echo "You didn't specified any package to look for!" echo "Use: debfind [-r release] [-s section] [-x] [-nd] packages" exit fi continue=0 ;; esac shift done for dist in $release do for sect in $section do for pack in $packages do for res in $( lynx -source $web$key$pack$search$names$sub$subword$ver$dist$rel$sect | sed 's/ /#/g') do tmp=$( echo $res | sed 's/#/ /g' | grep "" \ | sed s/""//) if [ "$tmp" ] then echo -n " Release: "$tmp else tmp=$( echo $res | sed 's/#/ /g' | grep "  " \ | sed s/"  "// | cut -f 1 -d "<" ) if [ "$tmp" ]; then echo " -> "$tmp; echo; fi fi fi done done done done