#!/bin/sh -f # -f is used to stop file name globbing ## author: parv(at)pair(dot)com ## date: jun 21 2002 ## ## license: free to use as you please w/ proper credit given. ## use at your own risk. all responsibility for potential damage, loss, ## etc. is disclaimed. ## ## name: listpkg ## ## purpose: print port/package name & location, mainly, for maintenance ## purposes; like pkg_delete, or to parse '+CONTENTS', etc. ## ## usage: ## to list all the ports beginning w/ any characters from [a-z0-9]... ## listpkg ## ## to list ports beginning w/ particular string... ## listpkg *font ## listpkg fvwm ## listpkg x ## # external programs needed: # awk -- to create list for find # echo -- to create list for find (could be built in shell command) # find -- to search for installed ports # perl5 -- to rearrange find output; could be substituted w/ sed; # regex to parse version strings will always be in need of update # # optional external programs used: # sort -- to sort case insenstively; find could be used # w/ '-s' option to achieve case sensitive sorting # xargs, # printf -- to format find/perl output # # search is case insensitive as allowed by find via '-iname' option. # set $Pkg_Dir to directory where installed package/port information # is stored Pkg_Dir=/var/db/pkg # create a list like '-iname p5* -o iname fvwm*' # ---- # to be used on rhs of a pipeline # ---- name_list() { awk 'BEGIN { list = "" } { if (1 == NF) # special case, only one pattern given { list = " -iname "$1"\*" } else # more than 1 pattern given { for (i = 1; i <= NF; i++) { list = list" -iname "$i"\*" if (i < NF) { list = list" -o" } } } } END { print list }' } case $# in # no argument given 0) # either exit w/ error message... #printf "%s\n" " no package name given" 1>&2 #exit 1 # ...or create list for (almost) all the ports list=$( echo 'a b c d e f g h i j k l m n o p q r s t u v w x y z \ 0 1 2 3 4 5 6 7 8 9' | \ name_list ) ;; # something passed to the program *) # create list from input given list=$( echo "$*" | name_list ) # exit if list creation failed [ $? -ne 0 ] \ && printf "%s\n" " an error occurred while creating '-name' expression" 1>&2 \ && exit 1 ;; esac # to see what is passed to find #cat << _LIST_ #${list} # #_LIST_ # find: find a port directory in $Pkg_Dir # sort: sort # perl: massage list to display: # port name, e.g. fvwm # port name-version, fvwm-2.5 # complete port location, ${Pkg_Dir}/fvwm-2.5 # printf: format listing; very long port name so far are... # [ 0 5 0 5 0 5 0 5 0 ] # ruby-shim-ruby18-1.7.2.2002.05.21 # XFree86-fontDefaultBitmaps-4.2.0 find -L ${Pkg_Dir} \( ${list} \) -type d -maxdepth 1 -mindepth 1 -print \ | sort -bf \ | perl -p -l -e ' # turn a $Pkg_Dir/port-version like string into... # port port-version $Pkg_Dir/port-version s{ ^('${Pkg_Dir}'/) # capture $Pkg_Dir (.+) # capture port name # capture port version, assuming version does not contain # hyphen; otherwise use /(-(?:\d+[-_.,\w]*|pl.+))$/ (-(?:[^-]+))$ } {$2 $2$3 $1$2$3}x; # remove /-(without-|no)blah/ like strings from port name s{ ^(.+?) # capture everything upto the... -(?:without-|no)[0-9a-zA-Z]+ # first /-(without-|no)blah/ (.+)$ # start capturing again } {$1$2}x; ' \ | xargs printf "%-26s %-34s %s\n"