The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]

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 freshports.org 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 ;)

regards

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 "./makesubindexes.pl" it'll just output the whole index in a reformated, more easily readable way, or you do "./makesubindexes.pl 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".

#!/usr/bin/perl

#
# Copyright 2001 Benjamin Lutz
#
# makesubindex.pl - 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 http://www.freshports.org?

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

--
Webmaster

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 FreeBSD.org 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 ...

<quote>
FreeBSD::Ports and FreeBSD::Ports::Port are modules for parsing
FreeBSD's Ports INDEX file and selecting ports that match certain
criteria.

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

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

http://www103.pair.com/parv/comp/src/perl/parse-index
http://www103.pair.com/parv/comp/src/perl/pod/parse-index.pod

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

http://www103.pair.com/parv/comp/src/perl/dist/Parv-Util-1.10.tar.gz

- Parv

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


 Forum List  |  Need a Login? Register Here 
 User Login
 User Name:
 Password:
 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

phorum.org