1 | #!/bin/sh |
---|
2 | # |
---|
3 | # $Revision: 1.1.1.2 $ |
---|
4 | # |
---|
5 | # This script implements a subset of the normal BSD install(1) program. |
---|
6 | # It's certainly not complete. |
---|
7 | # |
---|
8 | |
---|
9 | Copy=1 # Copy src to target |
---|
10 | Strip=0 # Strip installed target |
---|
11 | Group=staff # Default group |
---|
12 | Mode=0755 # Default file mode |
---|
13 | dst="" |
---|
14 | src="" |
---|
15 | Prog=$0 |
---|
16 | |
---|
17 | # |
---|
18 | # Find the locations of various commands we'll need |
---|
19 | # |
---|
20 | if [ -x /usr/bin/cp ]; then |
---|
21 | cp=/usr/bin/cp |
---|
22 | elif [ -x /bin/cp ]; then |
---|
23 | cp=/bin/cp |
---|
24 | else |
---|
25 | echo "${Prog}: Cannot locate the cp program." |
---|
26 | exit 1 |
---|
27 | fi |
---|
28 | |
---|
29 | if [ -x /usr/bin/mv ]; then |
---|
30 | mv=/usr/bin/mv |
---|
31 | elif [ -x /bin/mv ]; then |
---|
32 | mv=/bin/mv |
---|
33 | else |
---|
34 | echo "${Prog}: Cannot locate the mv program." |
---|
35 | exit 1 |
---|
36 | fi |
---|
37 | |
---|
38 | if [ -x /usr/bin/rm ]; then |
---|
39 | rm=/usr/bin/rm |
---|
40 | elif [ -x /bin/rm ]; then |
---|
41 | rm=/bin/rm |
---|
42 | else |
---|
43 | echo "${Prog}: Cannot locate the rm program." |
---|
44 | exit 1 |
---|
45 | fi |
---|
46 | |
---|
47 | if [ -x /usr/bin/chmod ]; then |
---|
48 | chmod=/usr/bin/chmod |
---|
49 | elif [ -x /bin/chmod ]; then |
---|
50 | chmod=/bin/chmod |
---|
51 | else |
---|
52 | echo "${Prog}: Cannot locate the chmod program." |
---|
53 | exit 1 |
---|
54 | fi |
---|
55 | |
---|
56 | if [ -x /usr/bin/strip ]; then |
---|
57 | strip=/usr/bin/strip |
---|
58 | elif [ -x /bin/strip ]; then |
---|
59 | strip=/bin/strip |
---|
60 | elif [ -x /usr/ccs/bin/strip ]; then |
---|
61 | strip=/usr/ccs/bin/strip |
---|
62 | else |
---|
63 | echo "${Prog}: Cannot locate the strip program." |
---|
64 | exit 1 |
---|
65 | fi |
---|
66 | |
---|
67 | if [ -x /usr/bin/chgrp ]; then |
---|
68 | chgrp=/usr/bin/chgrp |
---|
69 | elif [ -x /bin/chgrp ]; then |
---|
70 | chgrp=/bin/chgrp |
---|
71 | elif [ -x /etc/chgrp ]; then |
---|
72 | chgrp=/etc/chgrp |
---|
73 | else |
---|
74 | echo "${Prog}: Cannot locate the chgrp program." |
---|
75 | exit 1 |
---|
76 | fi |
---|
77 | |
---|
78 | if [ -x /usr/etc/chown ]; then |
---|
79 | chown=/usr/etc/chown |
---|
80 | elif [ -x /usr/sbin/chown ]; then |
---|
81 | chown=/usr/sbin/chown |
---|
82 | elif [ -x /usr/ucb/chown ]; then |
---|
83 | chown=/usr/ucb/chown |
---|
84 | elif [ -x /bin/chown ]; then |
---|
85 | chown=/bin/chown |
---|
86 | elif [ -x /usr/bin/chown ]; then |
---|
87 | chown=/usr/bin/chown |
---|
88 | elif [ -x /etc/chown ]; then |
---|
89 | chown=/etc/chown |
---|
90 | else |
---|
91 | echo "${Prog}: Cannot locate the chown program." |
---|
92 | exit 1 |
---|
93 | fi |
---|
94 | |
---|
95 | # |
---|
96 | # Parse command line options |
---|
97 | # |
---|
98 | while [ x$1 != x ]; do |
---|
99 | case $1 in |
---|
100 | -c) # Option for backwards compatibility |
---|
101 | shift |
---|
102 | continue;; |
---|
103 | |
---|
104 | -m) |
---|
105 | Mode=$2 |
---|
106 | shift |
---|
107 | shift |
---|
108 | continue;; |
---|
109 | |
---|
110 | -g) |
---|
111 | Group=$2 |
---|
112 | shift |
---|
113 | shift |
---|
114 | continue;; |
---|
115 | |
---|
116 | -o) |
---|
117 | Owner=$2 |
---|
118 | shift |
---|
119 | shift |
---|
120 | continue;; |
---|
121 | |
---|
122 | -s) |
---|
123 | Strip=1 |
---|
124 | shift |
---|
125 | continue;; |
---|
126 | |
---|
127 | -*) |
---|
128 | echo "${Prog}: Unknown option $2." |
---|
129 | exit 1 |
---|
130 | ;; |
---|
131 | |
---|
132 | *) |
---|
133 | if [ x$src = x ]; then |
---|
134 | src=$1 |
---|
135 | else |
---|
136 | dst=$1 |
---|
137 | fi |
---|
138 | shift |
---|
139 | continue;; |
---|
140 | |
---|
141 | esac |
---|
142 | done |
---|
143 | |
---|
144 | if [ x$src = x ]; then |
---|
145 | echo "${Prog}: No source file was specified." |
---|
146 | exit 1 |
---|
147 | fi |
---|
148 | if [ x$dst = x ]; then |
---|
149 | echo "${Prog}: No destination file was specified." |
---|
150 | exit 1 |
---|
151 | fi |
---|
152 | |
---|
153 | if [ -d $dst ]; then |
---|
154 | base=`basename $src` |
---|
155 | Target=$dst/$base |
---|
156 | else |
---|
157 | Target=$dst |
---|
158 | fi |
---|
159 | |
---|
160 | if [ -f $Target ]; then |
---|
161 | $rm -f $Target |
---|
162 | fi |
---|
163 | |
---|
164 | if [ $Copy -eq 1 ]; then |
---|
165 | InstallProg=$cp |
---|
166 | else |
---|
167 | InstallProg=$mv |
---|
168 | fi |
---|
169 | |
---|
170 | $InstallProg $src $Target && { |
---|
171 | if [ x$Owner != x ]; then |
---|
172 | $chown $Owner $Target |
---|
173 | fi |
---|
174 | } && { |
---|
175 | $chgrp $Group $Target |
---|
176 | } && { |
---|
177 | $chmod $Mode $Target |
---|
178 | } && { |
---|
179 | if [ $Strip -gt 0 ]; then |
---|
180 | $strip $Target |
---|
181 | fi |
---|
182 | } |
---|
183 | |
---|