Add install.sh copyright terms from X11R5.
[deliverable/binutils-gdb.git] / install.sh
1 #!/bin/sh
2 #
3 # Copyright 1991 by the Massachusetts Institute of Technology
4 #
5 # Permission to use, copy, modify, distribute, and sell this software and its
6 # documentation for any purpose is hereby granted without fee, provided that
7 # the above copyright notice appear in all copies and that both that
8 # copyright notice and this permission notice appear in supporting
9 # documentation, and that the name of M.I.T. not be used in advertising or
10 # publicity pertaining to distribution of the software without specific,
11 # written prior permission. M.I.T. makes no representations about the
12 # suitability of this software for any purpose. It is provided "as is"
13 # without express or implied warranty.
14 #
15 # install - install a program, script, or datafile
16 # The original version of this script came from X11R5
17 # (mit/util/scripts/install.sh); it is not part of GNU.
18 #
19 # $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
20 #
21 # This script is compatible with the BSD install script, but was written
22 # from scratch.
23 #
24 # At Cygnus this script is duplicated as:
25 #
26 # install.sh
27 # apache/install-sh
28 # dejagnu/install-sh
29 # expect/install-sh
30 # inet/install-sh
31 #
32 # if you change one of these, you will probably want to change them
33 # all. Variants of it also appear in:
34 #
35 # tcl/unix/install-sh
36 # tk/unix/install-sh
37 #
38 # however these versions are the versions of this script from the
39 # original Tcl/Tk distribution, and are somewhat different, and so
40 # changing these will result in divergences from the Tcl/Tk
41 # distribution.
42 #
43
44
45 # set DOITPROG to echo to test this script
46
47 # Don't use :- since 4.3BSD and earlier shells don't like it.
48 doit="${DOITPROG-}"
49
50
51 # put in absolute paths if you don't have them in your path; or use env. vars.
52
53 mvprog="${MVPROG-mv}"
54 cpprog="${CPPROG-cp}"
55 chmodprog="${CHMODPROG-chmod}"
56 chownprog="${CHOWNPROG-chown}"
57 chgrpprog="${CHGRPPROG-chgrp}"
58 stripprog="${STRIPPROG-strip}"
59 rmprog="${RMPROG-rm}"
60 mkdirprog="${MKDIRPROG-mkdir}"
61
62 transformbasename=""
63 transform_arg=""
64 instcmd="$mvprog"
65 chmodcmd="$chmodprog 0755"
66 chowncmd=""
67 chgrpcmd=""
68 stripcmd=""
69 rmcmd="$rmprog -f"
70 mvcmd="$mvprog"
71 src=""
72 dst=""
73 dir_arg=""
74
75 while [ x"$1" != x ]; do
76 case $1 in
77 -c) instcmd="$cpprog"
78 shift
79 continue;;
80
81 -d) dir_arg=true
82 shift
83 continue;;
84
85 -m) chmodcmd="$chmodprog $2"
86 shift
87 shift
88 continue;;
89
90 -o) chowncmd="$chownprog $2"
91 shift
92 shift
93 continue;;
94
95 -g) chgrpcmd="$chgrpprog $2"
96 shift
97 shift
98 continue;;
99
100 -s) stripcmd="$stripprog"
101 shift
102 continue;;
103
104 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
105 shift
106 continue;;
107
108 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
109 shift
110 continue;;
111
112 *) if [ x"$src" = x ]
113 then
114 src=$1
115 else
116 # this colon is to work around a 386BSD /bin/sh bug
117 :
118 dst=$1
119 fi
120 shift
121 continue;;
122 esac
123 done
124
125 if [ x"$src" = x ]
126 then
127 echo "install: no input file specified"
128 exit 1
129 else
130 true
131 fi
132
133 if [ x"$dir_arg" != x ]; then
134 dst=$src
135 src=""
136
137 if [ -d $dst ]; then
138 instcmd=:
139 else
140 instcmd=mkdir
141 fi
142 else
143
144 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
145 # might cause directories to be created, which would be especially bad
146 # if $src (and thus $dsttmp) contains '*'.
147
148 if [ -f $src -o -d $src ]
149 then
150 true
151 else
152 echo "install: $src does not exist"
153 exit 1
154 fi
155
156 if [ x"$dst" = x ]
157 then
158 echo "install: no destination specified"
159 exit 1
160 else
161 true
162 fi
163
164 # If destination is a directory, append the input filename; if your system
165 # does not like double slashes in filenames, you may need to add some logic
166
167 if [ -d $dst ]
168 then
169 dst="$dst"/`basename $src`
170 else
171 true
172 fi
173 fi
174
175 ## this sed command emulates the dirname command
176 dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
177
178 # Make sure that the destination directory exists.
179 # this part is taken from Noah Friedman's mkinstalldirs script
180
181 # Skip lots of stat calls in the usual case.
182 if [ ! -d "$dstdir" ]; then
183 defaultIFS='
184 '
185 IFS="${IFS-${defaultIFS}}"
186
187 oIFS="${IFS}"
188 # Some sh's can't handle IFS=/ for some reason.
189 IFS='%'
190 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
191 IFS="${oIFS}"
192
193 pathcomp=''
194
195 while [ $# -ne 0 ] ; do
196 pathcomp="${pathcomp}${1}"
197 shift
198
199 if [ ! -d "${pathcomp}" ] ;
200 then
201 $mkdirprog "${pathcomp}"
202 else
203 true
204 fi
205
206 pathcomp="${pathcomp}/"
207 done
208 fi
209
210 if [ x"$dir_arg" != x ]
211 then
212 $doit $instcmd $dst &&
213
214 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
215 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
216 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
217 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
218 else
219
220 # If we're going to rename the final executable, determine the name now.
221
222 if [ x"$transformarg" = x ]
223 then
224 dstfile=`basename $dst`
225 else
226 dstfile=`basename $dst $transformbasename |
227 sed $transformarg`$transformbasename
228 fi
229
230 # don't allow the sed command to completely eliminate the filename
231
232 if [ x"$dstfile" = x ]
233 then
234 dstfile=`basename $dst`
235 else
236 true
237 fi
238
239 # Make a temp file name in the proper directory.
240
241 dsttmp=$dstdir/#inst.$$#
242
243 # Move or copy the file name to the temp name
244
245 $doit $instcmd $src $dsttmp &&
246
247 trap "rm -f ${dsttmp}" 0 &&
248
249 # and set any options; do chmod last to preserve setuid bits
250
251 # If any of these fail, we abort the whole thing. If we want to
252 # ignore errors from any of these, just make sure not to ignore
253 # errors from the above "$doit $instcmd $src $dsttmp" command.
254
255 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
256 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
257 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
258 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
259
260 # Now rename the file to the real destination.
261
262 $doit $rmcmd -f $dstdir/$dstfile &&
263 $doit $mvcmd $dsttmp $dstdir/$dstfile
264
265 fi &&
266
267
268 exit 0
This page took 0.037894 seconds and 5 git commands to generate.