Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Sep 1998 23:46:11 +0200 (MET DST)
From:      Wolfram Schneider <wosch@panke.de.freebsd.org>
To:        ports@FreeBSD.ORG
Subject:   Portcheckout script
Message-ID:  <199809102146.XAA01398@campa.panke.de>

next in thread | raw e-mail | index | archive | help

I wrote a script to check out a FreeBSD port *and* all runtime and
buildtime depending ports into the current working directory. The
output is written to stdout as an executable shell-script.

Here is the manpage and the script.


NAME
        portcheckout - checkout ports and all depending ports

SYNOPSIS
        portcheckout ports [...]

DESCRIPTION
    Portcheckout(1) checks out a FreeBSD port and all runtime and buildtime
    depending ports into the current working directory. The output is
    written to stdout as an executable shell-script.

    Compiling a FreeBSD usually require a full tree of ports in /usr/port. A
    cvs checkout or a cvs update command takes a very long time and need
    much free space.

    With portcheckout, you checkout only the parts of the port tree which
    you really need. This is a magnitude faster!

FILES
    Portcheckout depend on a an up to date INDEX file in /usr/ports/INDEX.

EXAMPLE
      $cd /tmp || exit 1
      PORTSDIR="/tmp/ports"; export PORTSDIR
       
      # checkout ports
      # gnuplot-340
      cvs co ports/math/gnuplot
       
      # checkout depencies
      # png-1.0.2
      cvs co ports/graphics/png
      # gd-1.3
      cvs co ports/graphics/gd
       
      # Compile and install gnuplot-340
      (cd ports/math/gnuplot && make all install clean)

AUTHOR
    Wolfram Schneider <wosch@FreeBSD.org>, Berlin, September 1998.


#!/usr/local/bin/perl
# Copyright (c) Sep 1998 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $Id: ruplot.pl,v 1.2 1998/09/06 13:58:41 wosch Exp $
#
# portcheckout - do a `cvs checkout' for given ports and
#                all depending ports.

=pod

=head1 NAME

    portcheckout - checkout ports and all depending ports

=head1 SYNOPSIS

    portcheckout ports [...]

=head1 DESCRIPTION


Portcheckout(1) checks out a FreeBSD port and all runtime and
buildtime depending ports into the current working directory.
The output is written to stdout as an executable shell-script.

Compiling a FreeBSD usually require a full tree of ports
in /usr/port. A cvs checkout or a cvs update command 
takes a very long time and need much free space.

With portcheckout, you checkout only the parts of the port 
tree which you really need. This is a magnitude faster! 

=head1 FILES

Portcheckout depend on a an up to date INDEX file in /usr/ports/INDEX.

=head1 EXAMPLE

  $cd /tmp || exit 1
  PORTSDIR="/tmp/ports"; export PORTSDIR
   
  # checkout ports
  # gnuplot-340
  cvs co ports/math/gnuplot
   
  # checkout depencies
  # png-1.0.2
  cvs co ports/graphics/png
  # gd-1.3
  cvs co ports/graphics/gd
   
  # Compile and install gnuplot-340
  (cd ports/math/gnuplot && make all install clean)

=head1 AUTHOR

Wolfram Schneider <wosch@FreeBSD.org>, Berlin, September 1998.

=cut


$dir = `pwd`; chomp($dir);
$index = '/usr/ports/INDEX';

sub usage {
    warn "usage portcheckout ports ... \n\n";
    sleep 1;

    $ENV{'PAGER'} = 'cat';
    exec pod2text, $0;
    exit 2;
}

&usage if $#ARGV < 0;

sub read_index {
    local($index, *port, @ports) = @_;

    my $string;
    for($i = 0; $i <= $#ports; $i++) {
	$string .= '^' . $ports[$i];
	$string .= '|' if $i < $#ports;
    }

    die "Cannot open INDEX file: $index: $!\n" if (! -r $index);

    # egrep is fast than perl reg expr
    open(INDEX, "-|") || exec ('egrep', '--', $string, $index) ||
        die "open $index: $!\n";


    my $dep;
    my ($distributionname, $portpath, $installationprefix, 
	 $comment, $descriptionfile, $maintainer, $categories,
	$builddeps, $rundeps);

    while(<INDEX>) {

	($distributionname, $portpath, $installationprefix, 
	 $comment, $descriptionfile, $maintainer, $categories,
	 $builddeps, $rundeps) = split('\|');

	$portpath =~ s%/usr/%%;
	
	$port{"$distributionname"} = $portpath;
	    
	# save depencies
	$depends_no{"$distributionname"}++;

	foreach $dep (split(' ', $builddeps)) {
	    $depends{"$dep"}++;
	}

	foreach $dep (split(' ', $rundeps)) {
	    $depends{"$dep"}++;
	}
    }
    close INDEX;
}    

&read_index($index, *port, @ARGV);
{
    my @data = keys %port;
    die "No matching ports found for: @ARGV\n" 
	if $#data < 0;
}

# shell header
print "cd $dir || exit 1\n";
print qq{PORTSDIR="$dir/ports"; export PORTSDIR\n};
# uncomment next line if you have write permission to /usr/ports/distfiles
#print qq{DISTDIR="/usr/ports/distfiles"; export DISTDIR\n};
print "\n# checkout ports\n";

# checkout main ports
foreach (keys %port) {
    print "# $_\n";
    print qq|cvs co $port{$_}\n|;
}

# avoid cycles of ports 
# Port B depend on A, C depend on B and A
foreach (keys %depends_no) {
    undef $depends{"$_"};
}

# checkout depending ports
my @list = keys %depends;
if ($#list >= 0) {
    &read_index($index, *portdepends, @list);

    print "\n# checkout depencies\n";
    foreach (keys %portdepends) {
	# already checked out as master port
	next if $port{"$_"};

	print "# $_\n";
	print qq|cvs co $portdepends{$_}\n|;
    }
}

# Compile and install
foreach (keys %port) {
    print "\n# Compile and install $_\n";
    print qq|(cd $port{$_} && make all install clean)\n|;
}

-- 
Wolfram Schneider <wosch@freebsd.org> http://www.freebsd.org/~w/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199809102146.XAA01398>