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