The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

As an Amazon Associate I earn from qualifying purchases.
Scripts / handy tips
 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Newer Topic  |  Older Topic 
 Searching the ports
Author: William Cooper 
Date:   21-02-02 14:06

We all know rocks for searching for ports online, but what about when we're not online or cannot access it due to whatever.. well I just do..

cd /usr/ports
make search key="keywordhere"

where keywordhere is you type in what your looking for
like 'wget' 'lynx' 'dnetc' 'fxp' and it will bring back
a description/path/name

enjoy ;)


William Cooper

Reply To This Message
 Re: Searching the ports
Author: parv 
Date:   22-02-02 10:34

that works as long as one adjusts the INDEX for $PORTSDIR other than /usr/ports. if one has installed ports tree other than in /usr/ports -- like i have in /source/ports -- then to fix the INDEX (assumming perl is available) there are two ways.

1- brute force (in case you always download the INDEX during cvsup)...

perl -pi -e 's#/usr/ports#/source/ports#go' /source/ports/INDEX

2- the "right way" would be to fix the perl program which generates the INDEX, and afterwords run "make index" in $PORTSDIR (in my case it's /source/ports)...

perl -pi -e 's#/usr/ports#/source/ports#go' /source/ports/Tools/make_index
cd /source/ports && make index

Reply To This Message
 Re: Searching the ports
Author: Benjamin Lutz 
Date:   09-04-02 02:48

Here's a small perl hack I created for doing just that, searching through the INDEX file.

Works like this: if you call it like this "./" it'll just output the whole index in a reformated, more easily readable way, or you do "./ net" to only display stuff in the "net" category.
Now, to actually make use of it I suggest just piping it into grep or something like that. I've saved the output as "index", so to search for lynx I'd do a "grep lynx index".


# Copyright 2001 Benjamin Lutz
# - written on 2001-09-25
# parses /usr/ports/INDEX and prints the name and description of each
# entry in a category. You may specify that category as commandline
# parameter.

use strict;

open FILE, "/usr/ports/INDEX";

my @line;

while ($_ = <FILE>) {
my @thisline = split /\|/, $_;

$thisline[1] =~ s/\/usr\/ports\/(.*)/$1/;
$thisline[0] =~ s/(.*)-(.*)/$1/;

push @line, { name => $thisline[0],
version => $2,
description => $thisline[3],
category => $thisline[6],
path => $thisline[1] };

close FILE;

my $thisline;
my %categories;

foreach $thisline (@line) {
my $category;

foreach $category (split /\s/, $thisline->{category}) {
$categories{$category} = 1;
my $input;

if (@ARGV) {
$input = $ARGV[0];
#} else {
# print "Enter a category: ";
# $input = <STDIN>;
# chomp $input;

my @output;

foreach $thisline (@line) {
next unless (not $input or
$thisline->{category} =~ m/^$input$/i or
$thisline->{category} =~ m/^$input\s/i or
$thisline->{category} =~ m/\s$input$/i or
$thisline->{category} =~ m/\s$input\s/i);

push @output, sprintf "%-15s %-15s %s\n", $thisline->{name}, $thisline->{path}, $thisline->{description};

@output = sort {$a cmp $b} @output;

print @output;

Reply To This Message
 Re: Searching the ports
Author: parv 
Date:   15-04-02 07:00

Benjamin Lutz wrote:
> #!/usr/bin/perl

why not add "-w" there...

#!/usr/bin/perl -w

> open FILE, "/usr/ports/INDEX";

you should check for errors...

open (FILE, "</usr/ports/INDEX") or die "open failed: $!\n";

> while ($_ = <FILE>) {

that's funny, i see "FILE" in angle brackets as i reply, but was omitted from the source code as seen in this forum. below is my try to use the html entities...

while($_ = <FILE>) {

...while at it, remove "$_ = " as that's what $_ is assigned by default anyway...

while(<FILE>) {

> $thisline[1] =~ s/\/usr\/ports\/(.*)/$1/;

instead of escaping "/" when using "/" as the delimiters for s/// or m//, just use different delimiter...

$thisline[1] =~ s#/usr/ports/(.*)#$1#;

> my $input;
> if (@ARGV) {
> $input = $ARGV[0];
> #} else {
> # print "Enter a category: ";
> #
> # $input = <STDIN>;
> # chomp $input;
> }

dead code, enh? if that's going to be removed (eventually), above can be translated to...

my $input = $ARGV[0] if ( scalar(@ARGV) );

- parv

Reply To This Message
 Re: Searching the ports
Author: parv 
Date:   15-04-02 07:05

that didn't work, did it? phorm is butchering the entities, let alone html code. lesson: don't post program/script code involving html code characters; post an url instead.

Reply To This Message
 Re: Searching the ports
Author: el_kab0ng 
Date:   19-09-05 18:09

Any chance there's a simple way to limit the return results other than fancy grepping?

Doing a make search key="openldap" for example, gets you the phone book.

It would be nice to see the make search have options to limit the search down to the /usr/ports/$1 level.

Reply To This Message
 Re: Searching the ports
Author: Dan 
Date:   19-09-05 18:31

What about using

Mind you, the search there may not be directory specific like you want.


Reply To This Message
 Re: Searching the ports
Author: el_kab0ng 
Date:   19-09-05 18:38

When the results are extensive, I usually just wind up hitting the ports search. =/

It'd be nice to have some sort of command line flag to list only results with the term in the title..

Reply To This Message
 Re: Searching the ports
Author: parv 
Date:   19-09-05 23:09

Have you tried textproc/p5-FreeBSD-Ports? From the description ...

FreeBSD::Ports and FreeBSD::Ports::Port are modules for parsing
FreeBSD's Ports INDEX file and selecting ports that match certain

For example, you might want to list ports maintained by
sorted alphabetically:
my $ports = tie my %port, 'FreeBSD::Ports', '/usr/ports/INDEX';
foreach my $p (keys %port) {
print $p->as_ascii,"\n";

...which i promote over my own version ...

... which requires a custom module not available via CPAN ...

- Parv

Reply To This Message
 Forum List  |  Threaded View   Newer Topic  |  Older Topic 

 User Login
 User Name:
 Remember my login:
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.
How to get the most out of the forum