summaryrefslogtreecommitdiff
path: root/installperl
blob: 12c314d4dd1bc21b6dd3f82605b6330e15fde765 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!./perl

while (@ARGV) {
    $nonono = 1 if $ARGV[0] eq '-n';
    $versiononly = 1 if $ARGV[0] eq '-v';
    shift;
}

@scripts = 'h2ph';
@manpages = ('perl.man', 'h2ph.man');

# Read in the config file.

open(CONFIG, "config.sh") || die "You haven't run Configure yet!\n";
while (<CONFIG>) {
    if (s/^(\w+=)/\$$1/) {
	$accum =~ s/'undef'/undef/g;
	eval $accum;
	$accum = '';
    }
    $accum .= $_;
}

# Do some quick sanity checks.

if ($d_dosuid && $>) { die "You must run as root to install suidperl\n"; }

   $bin		|| die "No bin directory in config.sh\n";
-d $bin		|| die "$bin is not a directory\n";
-w $bin		|| die "$bin is not writable by you\n";

-x 'perl'	|| die "perl isn't executable!\n";
-x 'taintperl'	|| die "taintperl isn't executable!\n";
-x 'suidperl'	|| die "suidperl isn't executable!\n" if $d_dosuid;

-x 't/TEST'	|| die "You've never run 'make test'!\n";

# First we install the version-numbered executables.

$ver = sprintf("%5.3f", $]);

&unlink("$bin/perl$ver");
&cmd("cp perl $bin/perl$ver");

&unlink("$bin/tperl$ver");
&cmd("cp taintperl $bin/tperl$ver");
&chmod(0755, "$bin/tperl$ver");		# force non-suid for security

&unlink("$bin/sperl$ver");
if ($d_dosuid) {
    &cmd("cp suidperl $bin/sperl$ver");
    &chmod(04711, "$bin/sperl$ver");
}

exit 0 if $versiononly;

# Make links to ordinary names if bin directory isn't current directory.

($bdev,$bino) = stat($bin);
($ddev,$dino) = stat('.');

if ($bdev != $ddev || $bino != $dino) {
    &unlink("$bin/perl", "$bin/taintperl", "$bin/suidperl");
    &link("$bin/perl$ver", "$bin/perl");
    &link("$bin/tperl$ver", "$bin/taintperl");
    &link("$bin/sperl$ver", "$bin/suidperl") if $d_dosuid;
}

# Make some enemies in the name of standardization.   :-)

($udev,$uino) = stat("/usr/bin");

if (($udev != $ddev || $uino != $dino) && !$nonono) {
    unlink "/usr/bin/perl";
    eval 'symlink("$bin/perl", "/usr/bin/perl")' ||
    eval 'link("$bin/perl", "/usr/bin/perl")' ||
    &cmd("cp $bin/perl /usr/bin");
}

# Install scripts.

&makedir($scriptdir);

for (@scripts) {
    &chmod(0755, $_);
    &cmd("cp $_ $scriptdir");
}

# Install library files.

&makedir($privlib);

($pdev,$pino) = stat($privlib);

if ($pdev != $ddev || $pino != $dino) {
    &cmd("cd lib && cp *.pl $privlib");
}

# Install man pages.

&makedir($mansrc);

($mdev,$mino) = stat($mansrc);
if ($mdev != $ddev || $mino != $dino) {
    for (@manpages) {
	($new = $_) =~ s/man$/$manext/;
	&cmd("cp $_ $mansrc/$new");
    }
}

print STDERR "  Installation complete\n";

exit 0;

###############################################################################

sub unlink {
    local(@names) = @_;

    foreach $name (@names) {
	next unless -e $name;
	print STDERR "  unlink $name\n";
	unlink($name) || warn "Couldn't unlink $name: $!\n" unless $nonono;
    }
}

sub cmd {
    local($cmd) = @_;
    print STDERR "  $cmd\n";
    unless ($nonono) {
	system $cmd;
	warn "Command failed!!!\n" if $?;
    }
}

sub link {
    local($from,$to) = @_;

    print STDERR "  ln $from $to\n";
    link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $nonono;
}

sub chmod {
    local($mode,$name) = @_;

    printf STDERR "  chmod %o %s\n", $mode, $name;
    chmod($mode,$name) || warn "Couldn't chmod $mode $name: $!\n"
	unless $nonono;
}

sub makedir {
    local($dir) = @_;
    unless (-d $dir) {
	local($shortdir) = $dir;

	$shortdir =~ s#(.*)/.*#$1#;
	&makedir($shortdir);

	print STDERR "  mkdir $dir\n";
	mkdir($dir, 0777) || warn "Couldn't create $dir: $!\n" unless $nonono;
    }
}