add disclaimer about perl 4 libraries (modified version of
[p5sagit/p5-mst-13.2.git] / eg / g / gcp
CommitLineData
378cc40b 1#!/usr/bin/perl
2
79072805 3# $RCSfile: gcp,v $$Revision: 4.1 $$Date: 92/08/07 17:20:15 $
378cc40b 4
5# Here is a script to do global rcps. See man page.
6
7$#ARGV >= 1 || die "Not enough arguments.\n";
8
9if ($ARGV[0] eq '-r') {
10 $rcp = 'rcp -r';
11 shift;
12} else {
13 $rcp = 'rcp';
14}
15$args = $rcp;
16$dest = $ARGV[$#ARGV];
17
18$SIG{'QUIT'} = 'CLEANUP';
19$SIG{'INT'} = 'CONT';
20
21while ($arg = shift) {
22 if ($arg =~ /^([-a-zA-Z0-9_+]+):/) {
23 if ($systype && $systype ne $1) {
24 die "Can't mix system type specifers ($systype vs $1).\n";
25 }
26 $#ARGV < 0 || $arg !~ /:$/ || die "No source file specified.\n";
27 $systype = $1;
28 $args .= " $arg";
29 } else {
30 if ($#ARGV >= 0) {
31 if ($arg =~ /^[\/~]/) {
32 $arg =~ /^(.*)\// && ($dir = $1);
33 } else {
34 if (!$pwd) {
35 chop($pwd = `pwd`);
36 }
37 $dir = $pwd;
38 }
39 }
40 if ($olddir && $dir ne $olddir && $dest =~ /:$/) {
41 $args .= " $dest$olddir; $rcp";
42 }
43 $olddir = $dir;
44 $args .= " $arg";
45 }
46}
47
48die "No system type specified.\n" unless $systype;
49
50$args =~ s/:$/:$olddir/;
51
52chop($thishost = `hostname`);
53
54$one_of_these = ":$systype:";
55if ($systype =~ s/\+/[+]/g) {
56 $one_of_these =~ s/\+/:/g;
57}
58$one_of_these =~ s/-/:-/g;
59
60@ARGV = ();
61push(@ARGV,'.grem') if -f '.grem';
62push(@ARGV,'.ghosts') if -f '.ghosts';
63push(@ARGV,'/etc/ghosts');
64
65$remainder = '';
66
67line: while (<>) {
68 s/[ \t]*\n//;
69 if (!$_ || /^#/) {
70 next line;
71 }
72 if (/^([a-zA-Z_0-9]+)=(.+)/) {
73 $name = $1; $repl = $2;
74 $repl =~ s/\+/:/g;
75 $repl =~ s/-/:-/g;
76 $one_of_these =~ s/:$name:/:$repl:/;
77 $repl =~ s/:/:-/g;
78 $one_of_these =~ s/:-$name:/:-$repl:/g;
79 next line;
80 }
81 @gh = split(' ');
82 $host = $gh[0];
83 next line if $host eq $thishost; # should handle aliases too
84 $wanted = 0;
85 foreach $class (@gh) {
86 $wanted++ if index($one_of_these,":$class:") >= 0;
87 $wanted = -9999 if index($one_of_these,":-$class:") >= 0;
88 }
89 if ($wanted > 0) {
90 ($cmd = $args) =~ s/[ \t]$systype:/ $host:/g;
91 print "$cmd\n";
92 $result = `$cmd 2>&1`;
93 $remainder .= "$host+" if
94 $result =~ /Connection timed out|Permission denied/;
95 print $result;
96 }
97}
98
99if ($remainder) {
100 chop($remainder);
a687059c 101 open(grem,">.grem") || (printf stderr "Can't create .grem: $!\n");
378cc40b 102 print grem 'rem=', $remainder, "\n";
103 close(grem);
104 print 'rem=', $remainder, "\n";
105}
106
107sub CLEANUP {
108 exit;
109}
110
111sub CONT {
112 print "Continuing...\n"; # Just ignore the signal that kills rcp
113 $remainder .= "$host+";
114}