perl 4.0 patch 15: patch #11, continued
[p5sagit/p5-mst-13.2.git] / installperl
CommitLineData
c623bd54 1#!./perl
2
3while (@ARGV) {
4 $nonono = 1 if $ARGV[0] eq '-n';
5 $versiononly = 1 if $ARGV[0] eq '-v';
6 shift;
7}
8
45d8adaa 9umask 022;
10
11@scripts = ('cppstdin', 'h2ph', 'c2ph', 'pstruct', 'x2p/s2p', 'x2p/find2perl');
352d5a3a 12@manpages = ('perl.man', 'h2ph.man', 'x2p/a2p.man', 'x2p/s2p.man');
c623bd54 13
fe14fcc3 14$version = sprintf("%5.3f", $]);
15$release = substr($version,0,3);
16$patchlevel = substr($version,3,2);
17
c623bd54 18# Read in the config file.
19
20open(CONFIG, "config.sh") || die "You haven't run Configure yet!\n";
21while (<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
32if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }
33
fe14fcc3 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/#;
c623bd54 38
fe14fcc3 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;
c623bd54 42
fe14fcc3 43-x 't/TEST' || warn "WARNING: You've never run 'make test'!!!",
44 " (Installing anyway.)\n";
c623bd54 45
46# First we install the version-numbered executables.
47
48$ver = sprintf("%5.3f", $]);
49
fe14fcc3 50&unlink("$installbin/perl$ver");
51&cmd("cp perl $installbin/perl$ver");
c623bd54 52
fe14fcc3 53&unlink("$installbin/tperl$ver");
54&cmd("cp taintperl $installbin/tperl$ver");
55&chmod(0755, "$installbin/tperl$ver"); # force non-suid for security
c623bd54 56
fe14fcc3 57&unlink("$installbin/sperl$ver");
c623bd54 58if ($d_dosuid) {
fe14fcc3 59 &cmd("cp suidperl $installbin/sperl$ver");
60 &chmod(04711, "$installbin/sperl$ver");
c623bd54 61}
62
63exit 0 if $versiononly;
64
fe14fcc3 65# Make links to ordinary names if installbin directory isn't current directory.
c623bd54 66
fe14fcc3 67($bdev,$bino) = stat($installbin);
c623bd54 68($ddev,$dino) = stat('.');
69
70if ($bdev != $ddev || $bino != $dino) {
fe14fcc3 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;
c623bd54 75}
76
352d5a3a 77($bdev,$bino) = stat($installbin);
78($ddev,$dino) = stat('x2p');
79
80if ($bdev != $ddev || $bino != $dino) {
81 &unlink("$installbin/a2p");
82 &cmd("cp x2p/a2p $installbin/a2p");
83}
84
c623bd54 85# Make some enemies in the name of standardization. :-)
86
87($udev,$uino) = stat("/usr/bin");
88
fe14fcc3 89if (-w _ && ($udev != $ddev || $uino != $dino) && !$nonono) {
45d8adaa 90 &unlink("/usr/bin/perl");
fe14fcc3 91 eval 'symlink("$installbin/perl", "/usr/bin/perl")' ||
92 eval 'link("$installbin/perl", "/usr/bin/perl")' ||
93 &cmd("cp $installbin/perl /usr/bin");
c623bd54 94}
95
96# Install scripts.
97
352d5a3a 98&makedir($installscr);
c623bd54 99
100for (@scripts) {
352d5a3a 101 &cmd("cp $_ $installscr");
102 s#.*/##; &chmod(0755, "$installscr/$_");
c623bd54 103}
104
c623bd54 105# Install man pages.
106
fe14fcc3 107if ($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/;
352d5a3a 114 $new =~ s#.*/##;
fe14fcc3 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 }
c623bd54 126 }
127}
128
45d8adaa 129# Install library files.
130
131&makedir($installprivlib);
132if (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}
145else {
146 warn "Can't cd to lib to install lib files: $!\n";
147}
148
149&chmod(0755, "usub/mus");
150
c623bd54 151print STDERR " Installation complete\n";
152
153exit 0;
154
155###############################################################################
156
157sub 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
167sub cmd {
168 local($cmd) = @_;
169 print STDERR " $cmd\n";
170 unless ($nonono) {
171 system $cmd;
172 warn "Command failed!!!\n" if $?;
173 }
174}
175
176sub 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
183sub 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
191sub 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}