#!perl5 -- # -*- Perl -*- # $Id: pinstall,v 1.2 2000/02/01 20:07:32 eray Exp $ require 5.000; # Force the user to have Perl 5.000 while (@ARGV) { $_ = shift @ARGV; die "Unexpected argument: $_\n" if !/^([A-Z0-9]+)\=(.*)$/; eval "\$$1 = \"\$2\""; } %REPL = ('%%PRODROOT%%' => $PRODROOT, '%%BINDIR%%' => $BINDIR, '%%DEFPRN%%' => $DEFPRN, '%%SGMLSOPT%%' => $SGMLSOPT, '%%TMPDIR%%' => $TMPDIR, '%%GTROFFPATHNAME%%' => $GTROFFPATHNAME, '%%SOELIMPATHNAME%%' => $SOELIMPATHNAME, '%%PERL5%%' => $PERL5); foreach $_ (keys %REPL) { die "Undefined replacement: $_\n" if $REPL{$_} =~ /^\s*$/; } @INSTALL_DIRS = ('bin', 'lib', 'macros', 'sgml', 'sed'); select(STDERR); $| = 1; select(STDOUT); ######################################################################## @PATH = split(/[:;]/, $ENV{'PATH'}); push(@PATH, $REPL{'%%BINDIR%%'}); push(@PATH, $REPL{'%%PRODROOT%%'}); %FILES = ('nsgmls' => 1, 'tar' => 1, 'lockfile' => 1, 'crlf' => 1, 'troff' => 0); foreach $_ (@PATH) { foreach $exec (keys %FILES) { $FILES{$exec} = $_ if -f "$_/$exec" && -x "$_/$exec"; } } $errcount = 0; foreach $exec (keys %FILES) { if ($FILES{$exec} eq '1') { print STDERR "Error: cannot find $exec.\n"; $errcount++; } elsif ($FILES{$exec} eq '0') { print STDERR "Warning: cannot find $exec.\n"; } else { print STDERR "Found: $FILES{$exec}/$exec.\n"; } } exit 1 if $errcount > 0; ######################################################################## print STDERR "Creating install root: $PRODROOT\n"; &mkdirhier($PRODROOT); print STDERR "Copying files with tar\n"; $rc = system ("tar cf - @INSTALL_DIRS | (cd $PRODROOT; tar xfBp -)"); die "Warning: install with tar failed: $rc\n" if $rc; @DIRS = ($PRODROOT); while (@DIRS) { $dir = shift (@DIRS); opendir (DIR, $dir); while (defined($file = readdir(DIR))) { next if $file =~ /^\.+$/; $file = "$dir/$file"; if (-d $file) { push (@DIRS, $file); next; } next if -l $file; $prfile = $file; $prfile = $1 if ($file =~ /\/([^\/]+)$/); printf STDERR "Configuring %-64s\r", $prfile; @LINES = (); open (F, "$file"); @LINES = (); close (F); open (F, ">$file"); foreach $_ (@LINES) { foreach $repl (keys %REPL) { s/$repl/$REPL{$repl}/g; } print F $_; } close (F); } } printf STDERR "%-72s\n", "done."; exit 0; sub mkdirhier { my($dir) = @_; my(@paths) = split(/\//, $dir); local($_) = ""; while (@paths) { $dir = shift @paths; $_ .= "/$dir"; next if -d $_; mkdir($_, 0755) || die "Cannot make $_\n"; } }