#! /usr/bin/perl -w # ---------------------------------------------------------------------------- # "THE BEER-WARE LICENSE" (Revision 42) # wrote this file. As long as you retain this notice you # can do whatever you want with this stuff. If we meet some day, and you think # this stuff is worth it, you can buy me a beer in return. Anton Berezin # ---------------------------------------------------------------------------- # # Version 0.1 # use strict; use Cwd; use File::Find; use constant DEBUG => 1; use constant MAXAGE => 0.2; usage() if @ARGV > 2; my $PORTSDIR = "/home/tobez/jail/usr/ports"; $PORTSDIR = "/data/ad2-tax/jail/usr/ports"; $PORTSDIR = $ARGV[0] if @ARGV; my ($category,$name) = get_port_category_and_name(); find sub { debug("cp $File::Find::name .\n") if -f && -M _ < MAXAGE; }, "$PORTSDIR/$category/$name"; sub usage { print "$_[0]\n" if $_[0]; print "Usage:\n"; print " cpport /path/to/ports/tree\n"; print "The script should be invoked from within the port skeleton directory.\n"; exit; } sub debug { warn(@_) if DEBUG; } sub get_cur_dir { my $dir = cwd; $dir =~ s|^.*?([^/]*)$|$1|; debug("get_cur_dir: $dir\n"); $dir; } sub get_port_category_and_name { open MF, "< Makefile" or usage("get_port_category_and_name: open: $!"); my ($pn,$pc,$pp,$ll); while () { /^PORTNAME=\s*(\S+)\s*$/ && do { $pn = $1 }; /^CATEGORIES\??=\s*(\S+)\s*/ && do { $pc = $1 }; /^PKGNAMEPREFIX=\s*(\S+)\s*$/ && do { $pp = $1 }; /^LATEST_LINK=\s*(\S+)\s*$/ && do { $ll = $1 }; } close MF; $pn ||= ''; $pc ||= ''; $pp ||= ''; $ll ||= ''; usage("cannot find PORTNAME in Makefile") unless $pn; usage("cannot find CATEGORIES in Makefile") unless $pc; debug("port name: $pn\n"); debug("port category: $pc\n"); debug("port prefix: $pp\n") if $pp; my $n = $ll ? $ll : "$pp$pn"; return ($pc,$n); }