Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I need to automate installation of a multitude of Perl modules. Most of them are present in ports. But some modules are located in bundles, for example www/p5-HTML-Tree prvides HTML::Element, HTML::TreeBuilder, etc.

Ideally, it should be a command line utility with the synax like:

install_from_ports CGI CGI::FormBuilder HTML::TreeBuilder ...

Do you have any suggestions?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Here's a lightly-tested solution:


# Build a regex to match all the .pm files
for arg in $*; do
    arg=`echo ${arg} | sed -e 's|::|/|g'`
    if [ "X${regex}X" != "XX" ]; then

# Find the .pm files and derive the port names from them, then install using portinstall.
find /usr/ports -type f -name pkg-plist -path '*/p5-*' -exec egrep -l $regex {} + | sort -u | sed -e 's|/usr/ports/||' -e 's|/pkg-plist||' | xargs portinstall

Now, this won't detect modules installed by ports which don't have a pkg-plist but they're very much in the minority. There's only 58 out of 4188 p5-* ports on my system which don't have pkg-plist files.

share|improve this answer
Thanks for the answer. Just a note: you can use the INDEX file instead of find to find p5-* ports. This is quicker by order of magnitude – eugene y Jan 22 '11 at 23:35
Ah, thanks. I'd totally forgotten about INDEX! – Conor McDermottroe Jan 23 '11 at 12:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.