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