perl 4.0 patch 15: patch #11, continued
[p5sagit/p5-mst-13.2.git] / installperl
1 #!./perl
2
3 while (@ARGV) {
4     $nonono = 1 if $ARGV[0] eq '-n';
5     $versiononly = 1 if $ARGV[0] eq '-v';
6     shift;
7 }
8
9 umask 022;
10
11 @scripts = ('cppstdin', 'h2ph', 'c2ph', 'pstruct', 'x2p/s2p', 'x2p/find2perl');
12 @manpages = ('perl.man', 'h2ph.man', 'x2p/a2p.man', 'x2p/s2p.man');
13
14 $version = sprintf("%5.3f", $]);
15 $release = substr($version,0,3);
16 $patchlevel = substr($version,3,2);
17
18 # Read in the config file.
19
20 open(CONFIG, "config.sh") || die "You haven't run Configure yet!\n";
21 while (<CONFIG>) {
22     if (s/^(\w+=)/\$$1/) {
23         $accum =~ s/'undef'/undef/g;
24         eval $accum;
25         $accum = '';
26     }
27     $accum .= $_;
28 }
29
30 # Do some quick sanity checks.
31
32 if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
33
34    $installbin          || die "No installbin directory in config.sh\n";
35 -d $installbin          || die "$installbin is not a directory\n";
36 -w $installbin          || die "$installbin is not writable by you\n"
37         unless $installbin =~ m#^/afs/#;
38
39 -x 'perl'               || die "perl isn't executable!\n";
40 -x 'taintperl'          || die "taintperl isn't executable!\n";
41 -x 'suidperl'           || die "suidperl isn't executable!\n" if $d_dosuid;
42
43 -x 't/TEST'             || warn "WARNING: You've never run 'make test'!!!",
44         "  (Installing anyway.)\n";
45
46 # First we install the version-numbered executables.
47
48 $ver = sprintf("%5.3f", $]);
49
50 &unlink("$installbin/perl$ver");
51 &cmd("cp perl $installbin/perl$ver");
52
53 &unlink("$installbin/tperl$ver");
54 &cmd("cp taintperl $installbin/tperl$ver");
55 &chmod(0755, "$installbin/tperl$ver");          # force non-suid for security
56
57 &unlink("$installbin/sperl$ver");
58 if ($d_dosuid) {
59     &cmd("cp suidperl $installbin/sperl$ver");
60     &chmod(04711, "$installbin/sperl$ver");
61 }
62
63 exit 0 if $versiononly;
64
65 # Make links to ordinary names if installbin directory isn't current directory.
66
67 ($bdev,$bino) = stat($installbin);
68 ($ddev,$dino) = stat('.');
69
70 if ($bdev != $ddev || $bino != $dino) {
71     &unlink("$installbin/perl", "$installbin/taintperl", "$installbin/suidperl");
72     &link("$installbin/perl$ver", "$installbin/perl");
73     &link("$installbin/tperl$ver", "$installbin/taintperl");
74     &link("$installbin/sperl$ver", "$installbin/suidperl") if $d_dosuid;
75 }
76
77 ($bdev,$bino) = stat($installbin);
78 ($ddev,$dino) = stat('x2p');
79
80 if ($bdev != $ddev || $bino != $dino) {
81     &unlink("$installbin/a2p");
82     &cmd("cp x2p/a2p $installbin/a2p");
83 }
84
85 # Make some enemies in the name of standardization.   :-)
86
87 ($udev,$uino) = stat("/usr/bin");
88
89 if (-w _ && ($udev != $ddev || $uino != $dino) && !$nonono) {
90     &unlink("/usr/bin/perl");
91     eval 'symlink("$installbin/perl", "/usr/bin/perl")' ||
92     eval 'link("$installbin/perl", "/usr/bin/perl")' ||
93     &cmd("cp $installbin/perl /usr/bin");
94 }
95
96 # Install scripts.
97
98 &makedir($installscr);
99
100 for (@scripts) {
101     &cmd("cp $_ $installscr");
102     s#.*/##; &chmod(0755, "$installscr/$_");
103 }
104
105 # Install man pages.
106
107 if ($mansrc ne '') {
108     &makedir($mansrc);
109
110     ($mdev,$mino) = stat($mansrc);
111     if ($mdev != $ddev || $mino != $dino) {
112         for (@manpages) {
113             ($new = $_) =~ s/man$/$manext/;
114             $new =~ s#.*/##;
115             print STDERR "  Installing $mansrc/$new\n";
116             next if $nonono;
117             open(MI,$_);
118             open(MO,">$mansrc/$new");
119             print MO ".ds RP Release $release Patchlevel $patchlevel\n";
120             while (<MI>) {
121                 print MO;
122             }
123             close MI;
124             close MO;
125         }
126     }
127 }
128
129 # Install library files.
130
131 &makedir($installprivlib);
132 if (chdir "lib") {
133
134     ($pdev,$pino) = stat($installprivlib);
135     ($ldev,$lino) = stat('.');
136
137     if ($pdev != $ldev || $pino != $lino) {
138         foreach $file (<*.pl>) {
139             &unlink("$installprivlib/$file");
140             &cmd("cp $file $installprivlib");
141         }
142     }
143     chdir ".." || die "Can't cd back to source directory: $!\n";
144 }
145 else {
146     warn "Can't cd to lib to install lib files: $!\n";
147 }
148
149 &chmod(0755, "usub/mus");
150
151 print STDERR "  Installation complete\n";
152
153 exit 0;
154
155 ###############################################################################
156
157 sub unlink {
158     local(@names) = @_;
159
160     foreach $name (@names) {
161         next unless -e $name;
162         print STDERR "  unlink $name\n";
163         unlink($name) || warn "Couldn't unlink $name: $!\n" unless $nonono;
164     }
165 }
166
167 sub cmd {
168     local($cmd) = @_;
169     print STDERR "  $cmd\n";
170     unless ($nonono) {
171         system $cmd;
172         warn "Command failed!!!\n" if $?;
173     }
174 }
175
176 sub link {
177     local($from,$to) = @_;
178
179     print STDERR "  ln $from $to\n";
180     link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $nonono;
181 }
182
183 sub chmod {
184     local($mode,$name) = @_;
185
186     printf STDERR "  chmod %o %s\n", $mode, $name;
187     chmod($mode,$name) || warn "Couldn't chmod $mode $name: $!\n"
188         unless $nonono;
189 }
190
191 sub makedir {
192     local($dir) = @_;
193     unless (-d $dir) {
194         local($shortdir) = $dir;
195
196         $shortdir =~ s#(.*)/.*#$1#;
197         &makedir($shortdir);
198
199         print STDERR "  mkdir $dir\n";
200         mkdir($dir, 0777) || warn "Couldn't create $dir: $!\n" unless $nonono;
201     }
202 }