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