0
|
1 |
#!/usr/perl5/bin/perl
|
|
2 |
#
|
|
3 |
# CDDL HEADER START
|
|
4 |
#
|
|
5 |
# The contents of this file are subject to the terms of the
|
|
6 |
# Common Development and Distribution License (the "License").
|
|
7 |
# You may not use this file except in compliance with the License.
|
|
8 |
#
|
|
9 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
10 |
# or http://www.opensolaris.org/os/licensing.
|
|
11 |
# See the License for the specific language governing permissions
|
|
12 |
# and limitations under the License.
|
|
13 |
#
|
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each
|
|
15 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
16 |
# If applicable, add the following below this CDDL HEADER, with the
|
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying
|
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner]
|
|
19 |
#
|
|
20 |
# CDDL HEADER END
|
|
21 |
#
|
66
|
22 |
# Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
|
0
|
23 |
#
|
66
|
24 |
#ident "@(#)install-proto.pl 1.6 11/01/11 SMI"
|
0
|
25 |
#
|
|
26 |
# BSD compatible install(1b) that honors DESTDIR and performs SFW post
|
|
27 |
# processing on various file types
|
|
28 |
#
|
|
29 |
|
|
30 |
use Getopt::Std;
|
|
31 |
use File::Basename;
|
|
32 |
use File::Copy;
|
|
33 |
|
6
|
34 |
my ($PERL, $DESTDIR, $SRC, $MANSCRIPT, $PYTHON, %opts, @paths) =
|
|
35 |
($ENV{'PERL'}, $ENV{'DESTDIR'}, $ENV{'SRC'}, $ENV{'MANSCRIPT'}, $ENV{'PYTHON'});
|
0
|
36 |
my ($post_process, $post_process_so, $strip) = (
|
|
37 |
$SRC.'/tools/post_process',
|
|
38 |
$SRC.'/tools/post_process_so',
|
|
39 |
'/usr/ccs/bin/strip');
|
|
40 |
my $progname = basename($0);
|
|
41 |
|
|
42 |
defined($PERL) || ($PERL = $); # fallback to this version of perl
|
66
|
43 |
defined($PYTHON) || ($PYTHON = '/usr/bin/python2.4'); # fallback to this version of python
|
0
|
44 |
|
|
45 |
(defined($DESTDIR)) || ($DESTDIR = $ENV{'ROOT'});
|
|
46 |
|
|
47 |
sub usage {
|
|
48 |
print "$progname [-cs] [-g group] [-o owner] [-m mode] file1 file2\n";
|
|
49 |
print "$progname [-cs] [-g group] [-o owner] [-m mode] file... dir\n";
|
|
50 |
print "$progname -d [-g group] [-o owner] [-m mode] dir\n";
|
|
51 |
exit (1);
|
|
52 |
}
|
|
53 |
|
|
54 |
sub file_type {
|
|
55 |
local ($path) = @_;
|
|
56 |
|
|
57 |
open(FH, "/bin/file $path|");
|
|
58 |
my $line = <FH>;
|
|
59 |
close(FH);
|
|
60 |
|
|
61 |
# if the path matches the pattern, it's a man page.
|
|
62 |
($path =~ /.*\/man\/man.+\/.*\.[1-9].*/) && ($line = 'roff');
|
|
63 |
|
|
64 |
return($line);
|
|
65 |
}
|
|
66 |
|
|
67 |
sub copyfile {
|
|
68 |
local ($src, $dst) = @_;
|
|
69 |
|
|
70 |
if (! -f $src) { # if there is no src, skip it
|
|
71 |
warn("$src: no such file\n");
|
|
72 |
return;
|
|
73 |
}
|
|
74 |
|
|
75 |
unlink($dst); # remove the original
|
|
76 |
|
|
77 |
my $type = file_type($src);
|
|
78 |
if ((defined($MANSCRIPT)) && ($type =~ /roff,/)) {
|
|
79 |
(-f $MANSCRIPT) ||
|
|
80 |
die "$progname: error: $MANSCRIPT does not exist\n";
|
|
81 |
system("sed -f $MANSCRIPT <$src >$dst");
|
6
|
82 |
} elsif ($type =~ / .*script/) {
|
0
|
83 |
my $IFH, $OFH;
|
|
84 |
|
|
85 |
open($IFH, "<$src") || die("$progname: open(<$src): $!\n");
|
|
86 |
open($OFH, ">$dst") || die("$progname: open(>$dst): $!\n");
|
|
87 |
|
|
88 |
while (<$IFH>) {
|
6
|
89 |
if ($. == 1) {
|
|
90 |
(s|^#!.*perl|#!${PERL}|g);
|
|
91 |
(s|^#!.*python[\d\.]*|#!${PYTHON}|g);
|
|
92 |
}
|
0
|
93 |
print($OFH "$_");
|
|
94 |
}
|
|
95 |
|
|
96 |
close($IFH);
|
|
97 |
close($OFH);
|
|
98 |
} elsif (-T $src) {
|
|
99 |
my $IFH, $OFH;
|
|
100 |
|
|
101 |
open($IFH, "<$src") || die("$progname: open(<$src): $!\n");
|
|
102 |
open($OFH, ">$dst") || die("$progname: open(>$dst): $!\n");
|
|
103 |
|
|
104 |
while (<$IFH>) {
|
|
105 |
defined($DESTDIR) && (s|${DESTDIR}||g);
|
|
106 |
print($OFH "$_");
|
|
107 |
}
|
|
108 |
|
|
109 |
close($IFH);
|
|
110 |
close($OFH);
|
|
111 |
} else {
|
|
112 |
copy($src, $dst);
|
|
113 |
}
|
|
114 |
|
|
115 |
# ELF files get post processing
|
|
116 |
if (($type =~ /ELF .*dynamic lib/) && (-x $post_process_so)) {
|
|
117 |
system("$post_process_so $dst");
|
|
118 |
chmod(0555, $dst); # default to ugo rx
|
|
119 |
} elsif (($type =~ /ELF .*executable/) && (-x $post_process) &&
|
|
120 |
(-x $strip)) {
|
|
121 |
system("$post_process $dst ; $strip $dst");
|
|
122 |
chmod(0555, $dst); # default to ugo rx
|
|
123 |
} elsif ($type =~ /executable/) {
|
|
124 |
chmod(0555, $dst); # default to ugo rx
|
|
125 |
}
|
|
126 |
}
|
|
127 |
|
|
128 |
sub mkdir_p {
|
|
129 |
local($path, $mode) = @_;
|
|
130 |
|
|
131 |
(-d $path) && return; # found it, return
|
|
132 |
|
|
133 |
mkdir_p(dirname($path), $mode); # make the parent first
|
|
134 |
mkdir($path, $mode);
|
|
135 |
}
|
|
136 |
|
|
137 |
#
|
|
138 |
# Execution begins here
|
|
139 |
#
|
|
140 |
getopts('cdg:G:m:o:O:s', \%opts);
|
|
141 |
|
|
142 |
# the last argument is the destination (file or dir)
|
|
143 |
my $dst = $ARGV[$#ARGV];
|
|
144 |
$#ARGV--;
|
|
145 |
|
|
146 |
(defined($opts{'d'})) && ($#ARGV != -1) && usage();
|
|
147 |
($#ARGV > 0) && (! -d $dst) && usage();
|
|
148 |
|
|
149 |
# dst should include the DESTDIR
|
|
150 |
($DESTDIR ne substr($dst, 0, length($DESTDIR))) &&
|
|
151 |
($dst = $DESTDIR.'/'.$dst);
|
|
152 |
|
|
153 |
if (defined($opts{'d'})) { # ... -d dir
|
|
154 |
mkdir_p($dst, 0755);
|
|
155 |
push(@paths, $dst);
|
|
156 |
} elsif (-d $dst) { # ... file... dir
|
|
157 |
foreach $path (@ARGV) {
|
|
158 |
my $file = $dst.'/'.basename($path);
|
|
159 |
copyfile($path, $file);
|
|
160 |
push(@paths, $file);
|
|
161 |
}
|
|
162 |
} else { # ... file1 file2
|
|
163 |
copyfile($ARGV[0], $dst);
|
|
164 |
push(@paths, $dst);
|
|
165 |
}
|
|
166 |
|
|
167 |
# fix the file attributes
|
|
168 |
foreach $path (@paths) {
|
|
169 |
# fix the mode
|
|
170 |
if (defined($opts{'m'})) {
|
|
171 |
chmod(oct($opts{'m'}), $path);
|
|
172 |
}
|
|
173 |
|
|
174 |
# fix the owner/group information
|
|
175 |
if (defined($opts{'o'}) || defined($opts{'g'})) {
|
|
176 |
my ($uid, $gid) = (-1, -1);
|
|
177 |
|
|
178 |
(defined($opts{'o'})) && (($x,$x,$uid) = getpwnam($opts{'o'}));
|
|
179 |
(defined($opts{'g'})) && (($x,$x,$gid) = getgrnam($opts{'g'}));
|
|
180 |
chown($uid, $gid, $path);
|
|
181 |
}
|
|
182 |
}
|
|
183 |
|
|
184 |
exit 0;
|