8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / install.d / install.sh
blobc5ed81349d1b1ad5b22bbbb0f4c84d7cb70f6d57
1 #!/sbin/sh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License, Version 1.0 only
7 # (the "License"). You may not use this file except in compliance
8 # with the License.
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
21 # CDDL HEADER END
23 # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
24 # All Rights Reserved
27 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.12.1.1 */
29 # INSTALL COMMAND
31 FLIST=$ROOT/etc/syslist
32 DEFAULT="$ROOT/bin $ROOT/usr/bin $ROOT/etc $ROOT/lib $ROOT/usr/lib" FOUND="" MOVOLD=""
33 ECHO=echo PATH=/usr/bin FLAG=off
34 USAGE="eval echo 'usage: install [options] file [dir1 ...]'; exit 2"
36 if [ $# -lt 2 ] ; then
37 $USAGE
40 MFLAG=off
41 UFLAG=off
42 GFLAG=off
44 MODE=755
45 GRP=`expr "\`id\`" : ".*gid=[0-9]*(\(..*\)) .*"`
46 GROUP=`echo $GRP | sed -e 's/) fsid.*//p'`
47 OWN=`expr "\`id\`" : ".*uid=[0-9]*(\(..*\)) .*"`
48 OWNER=`echo $OWN | sed -e 's/) .*//p'`
49 if [ -z "$GROUP" ]
50 then
51 GROUP=`expr "\`id\`" : ".*gid=\([0-9]*\).*"`
53 if [ -z "$OWNER" ]
54 then
55 OWNER=`expr "\`id\`" : ".*uid=\([0-9]*\).*"`
57 if [ "$OWNER" = root ]
58 then
59 ROOTFLAG=on
60 OWNER=bin
61 GROUP=bin
62 else
63 ROOTFLAG=off
67 for i in $*
69 if [ $FLAG = on ]
70 then
71 case $i in
72 -*) echo "install: The -c, -f, -n options each require a directory following!"
73 exit 2;;
74 *) FLAG=off
75 continue;;
76 esac
78 case $i in
79 -c) if [ x$ARG = x-d -o x$ARG = x-f ]
80 then
81 echo "install: -c dir: illegal option with $ARG option!"
82 exit 2
83 elif [ x$arg = x-i -o x$arg = x-o -o x$arg = x-n ]
84 then
85 echo "install: -c dir: illegal option with $arg option!"
86 exit 2
87 elif test $# -lt 3
88 then
89 echo "install: -c option must have at least 3 args!"
90 exit 2
91 else
92 direct=$2
93 FLAG=on
94 ARG=-c
95 shift; shift
96 fi;;
97 -f) if [ x$ARG = x-d -o x$ARG = x-c ]
98 then
99 echo "install: -f dir: illegal option with $ARG option!"
100 exit 2
101 elif [ x$arg = x-i -o x$arg = x-n ]
102 then
103 echo "install: -f dir: illegal option with $arg option!"
104 exit 2
105 elif test $# -lt 3
106 then
107 echo "install: -f option must have at least 3 args!"
108 exit 2
109 else
110 direct=$2
111 FLAG=on
112 ARG=-f
113 shift; shift
114 fi;;
115 -i) if [ x$ARG = x-d -o x$ARG = x-c -o x$ARG = x-f ]
116 then
117 echo "install: -i: illegal option with $ARG option!"
118 exit 2
119 elif test $# -lt 3
120 then
121 echo "install: -i option requires at least 3 args!"
122 exit 2
123 else
124 DEFAULT=""
125 arg=-i
126 shift
127 fi;;
128 -o) if [ x$ARG = x-d -o x$ARG = x-c ]
129 then
130 echo "install: -o: illegal option with $ARG option!"
131 exit 2
132 elif test $# -lt 2
133 then
134 $USAGE
135 else
136 MOVOLD=yes
137 arg=-o
138 shift
139 fi;;
140 -n) if [ x$ARG = x-d -o x$ARG = x-c -o x$ARG = x-f ]
141 then
142 echo "install: -n dir: illegal option with $ARG option!"
143 exit 2
144 elif test $# -lt 3
145 then
146 echo "install: -n option requires at least 3 args!"
147 exit 2
148 else
149 LASTRES=$2
150 FLAG=on
151 FOUND=n
152 arg=-n
153 shift; shift
154 fi;;
155 -d) if [ x$ARG = x-c -o x$ARG = x-f ]
156 then
157 echo "install: -d: illegal option with $ARG option!"
158 exit 2
159 elif [ x$arg = x-i -o x$arg = x-o -o x$arg = x-n ]
160 then
161 echo "install: -d: illegal option with $arg option!"
162 exit 2
163 else
164 ARG=-d
165 shift
166 fi;;
167 -s) if test $# -lt 2
168 then
169 $USAGE
170 else
171 ECHO=:
172 shift
173 fi;;
174 -u) if [ $ROOTFLAG = off ]
175 then
176 echo "install: -u option available only to root -- ignored"
177 else
178 OWNER=$2
179 UFLAG=on
180 $ECHO new owner is $OWNER
182 FLAG=on
183 shift; shift;;
184 -g) if [ $ROOTFLAG = off ]
185 then
186 echo "install: -g option available only to root -- ignored"
187 else
188 GROUP=$2
189 GFLAG=on
191 FLAG=on
192 shift; shift;;
193 -m) MODE=$2
194 MFLAG=on
195 FLAG=on
196 shift; shift;;
197 *) break;;
198 esac
199 done
202 if [ x$ARG = x-d ]
203 then
204 if [ ! -d $i ]
205 then
206 mkdir -p $i
207 if [ $? = 0 ]
208 then
209 $ECHO "directory $i created"
210 chgrp $GROUP $i
211 chown $OWNER $i
212 chmod $MODE $i
213 else
214 echo "install: mkdir $i failed "
216 else
217 chgrp $GROUP $i
218 chown $OWNER $i
219 chmod $MODE $i
221 exit
224 FILEP=$i FILE=`echo $i | sed -e "s/.*\///"`
225 if [ x$ARG = x-c -o x$ARG = x-f ]
226 then
227 case $2 in
228 -*) $USAGE ;;
229 "") : ;;
230 esac
231 if test -f $direct/$FILE -o -f $direct/$FILE/$FILE
232 then
233 case $ARG in
234 -c) echo "install: $FILE already exists in $direct"
235 exit 2;;
236 -f) GRP=`ls -l $direct/$FILE | awk '{print $4}'`
237 OWN=`ls -l $direct/$FILE | awk '{print $3}'`
238 if [ "$MOVOLD" = yes ]
239 then
240 mv -f $direct/$FILE $direct/OLD$FILE
241 cp $direct/OLD$FILE $direct/$FILE
242 if [ $? = 0 ]
243 then
244 $ECHO "$FILE moved to $direct/OLD$FILE"
245 else
246 echo "install: mv $direct/OLD$FILE $direct/$FILE failed"
247 exit 2
250 if cp $FILEP $direct/$FILE
251 then
252 chgrp $GRP $direct/$FILE
253 chown $OWN $direct/$FILE
255 if [ "$GFLAG" = on ]
256 then
257 chgrp $GROUP $direct/$FILE
259 if [ "$MFLAG" = on ]
260 then
261 chmod $MODE $direct/$FILE
263 if [ "$UFLAG" = on ]
264 then
265 chown $OWNER $direct/$FILE
268 $ECHO "$FILEP installed as $direct/$FILE"
269 else
270 echo "install: cp $FILEP $direct/$FILE failed "
271 exit 2
273 exit;;
274 esac
275 else
276 cp $FILEP $direct/$FILE
277 if [ $? = 0 ]
278 then
279 $ECHO "$FILEP installed as $direct/$FILE"
280 chgrp $GROUP $direct/$FILE
281 chown $OWNER $direct/$FILE
282 chmod $MODE $direct/$FILE
283 else
284 echo "install: cp $FILEP $direct/$FILE failed "
285 exit 2
288 exit
291 shift
293 PUTHERE=""
294 for i in $*
296 case $i in
297 -*) $USAGE ;;
298 esac
299 PUTHOLD=`find $i -follow -name $FILE -type f -print`
300 PUTHERE=`expr "\`echo $PUTHOLD\`" : '\([^ ]*\)'`
301 if [ "$PUTHERE" != "" ]
302 then break
304 done
305 if [ -r $FLIST -a "$PUTHERE" = "" ]
306 then
307 PUTHERE=`grep "/${FILE}$" $FLIST | sed -n -e '1p'`
308 if [ "$PUTHERE" != "" -a "$ROOT" != "" ]
309 then
310 PUTHERE=${ROOT}${PUTHERE}
313 if [ "$PUTHERE" = "" ]
314 then
315 for i in $DEFAULT
317 PUTHOLD=`find $i -follow -name $FILE -type f -print`
318 PUTHERE=`expr "\`echo $PUTHOLD\`" : '\([^ ]*\)'`
319 if [ "$PUTHERE" != "" ]
320 then break
322 done
324 if [ "$PUTHERE" != "" ]
325 then
326 GRP=`ls -l $PUTHERE | awk '{print $4}'`
327 OWN=`ls -l $PUTHERE | awk '{print $3}'`
328 if [ "$MOVOLD" = yes ]
329 then
330 old=`echo $PUTHERE | sed -e "s/\/[^\/]*$//"`
331 mv -f $PUTHERE $old/OLD$FILE
332 cp $old/OLD$FILE $PUTHERE
333 if [ $? = 0 ]
334 then
335 $ECHO "old $FILE moved to $old/OLD$FILE"
336 else
337 echo "install: cp $direct/OLD$FILE $direct/$FILE failed"
338 exit 2
341 FOUND=y
342 if cp $FILEP $PUTHERE
343 then
344 chgrp $GRP $PUTHERE
345 chown $OWN $PUTHERE
347 if [ "$GFLAG" = on ]
348 then
349 chgrp $GROUP $PUTHERE
351 if [ "$MFLAG" = on ]
352 then
353 chmod $MODE $PUTHERE
355 if [ "$UFLAG" = on ]
356 then
357 chown $OWNER $PUTHERE
360 $ECHO "$FILEP installed as $PUTHERE"
361 break
362 else
363 exit 2
367 case $FOUND in
368 "") echo "install: $FILE was not found anywhere!"
369 exit 2;;
370 y) : ;;
371 n) cp $FILEP $LASTRES/$FILE
372 if [ $? = 0 ]
373 then
374 $ECHO "$FILEP installed as $LASTRES/$FILE by default!"
375 cd $LASTRES
376 chgrp $GROUP $FILE
377 chown $OWNER $FILE
378 chmod $MODE $FILE
379 else
380 echo "install: cp $FILEP $LASTRES/$FILE failed"
381 exit 2
382 fi;;
383 esac