]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/install-sh
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / libantlr3c-3.2 / install-sh
1 #!/bin/sh\r
2 # install - install a program, script, or datafile\r
3 \r
4 scriptversion=2005-05-14.22\r
5 \r
6 # This originates from X11R5 (mit/util/scripts/install.sh), which was\r
7 # later released in X11R6 (xc/config/util/install.sh) with the\r
8 # following copyright and license.\r
9 #\r
10 # Copyright (C) 1994 X Consortium\r
11 #\r
12 # Permission is hereby granted, free of charge, to any person obtaining a copy\r
13 # of this software and associated documentation files (the "Software"), to\r
14 # deal in the Software without restriction, including without limitation the\r
15 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\r
16 # sell copies of the Software, and to permit persons to whom the Software is\r
17 # furnished to do so, subject to the following conditions:\r
18 #\r
19 # The above copyright notice and this permission notice shall be included in\r
20 # all copies or substantial portions of the Software.\r
21 #\r
22 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
23 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
24 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
25 # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
26 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-\r
27 # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
28 #\r
29 # Except as contained in this notice, the name of the X Consortium shall not\r
30 # be used in advertising or otherwise to promote the sale, use or other deal-\r
31 # ings in this Software without prior written authorization from the X Consor-\r
32 # tium.\r
33 #\r
34 #\r
35 # FSF changes to this file are in the public domain.\r
36 #\r
37 # Calling this script install-sh is preferred over install.sh, to prevent\r
38 # `make' implicit rules from creating a file called install from it\r
39 # when there is no Makefile.\r
40 #\r
41 # This script is compatible with the BSD install script, but was written\r
42 # from scratch.  It can only install one file at a time, a restriction\r
43 # shared with many OS's install programs.\r
44 \r
45 # set DOITPROG to echo to test this script\r
46 \r
47 # Don't use :- since 4.3BSD and earlier shells don't like it.\r
48 doit="${DOITPROG-}"\r
49 \r
50 # put in absolute paths if you don't have them in your path; or use env. vars.\r
51 \r
52 mvprog="${MVPROG-mv}"\r
53 cpprog="${CPPROG-cp}"\r
54 chmodprog="${CHMODPROG-chmod}"\r
55 chownprog="${CHOWNPROG-chown}"\r
56 chgrpprog="${CHGRPPROG-chgrp}"\r
57 stripprog="${STRIPPROG-strip}"\r
58 rmprog="${RMPROG-rm}"\r
59 mkdirprog="${MKDIRPROG-mkdir}"\r
60 \r
61 chmodcmd="$chmodprog 0755"\r
62 chowncmd=\r
63 chgrpcmd=\r
64 stripcmd=\r
65 rmcmd="$rmprog -f"\r
66 mvcmd="$mvprog"\r
67 src=\r
68 dst=\r
69 dir_arg=\r
70 dstarg=\r
71 no_target_directory=\r
72 \r
73 usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE\r
74    or: $0 [OPTION]... SRCFILES... DIRECTORY\r
75    or: $0 [OPTION]... -t DIRECTORY SRCFILES...\r
76    or: $0 [OPTION]... -d DIRECTORIES...\r
77 \r
78 In the 1st form, copy SRCFILE to DSTFILE.\r
79 In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.\r
80 In the 4th, create DIRECTORIES.\r
81 \r
82 Options:\r
83 -c         (ignored)\r
84 -d         create directories instead of installing files.\r
85 -g GROUP   $chgrpprog installed files to GROUP.\r
86 -m MODE    $chmodprog installed files to MODE.\r
87 -o USER    $chownprog installed files to USER.\r
88 -s         $stripprog installed files.\r
89 -t DIRECTORY  install into DIRECTORY.\r
90 -T         report an error if DSTFILE is a directory.\r
91 --help     display this help and exit.\r
92 --version  display version info and exit.\r
93 \r
94 Environment variables override the default commands:\r
95   CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG\r
96 "\r
97 \r
98 while test -n "$1"; do\r
99   case $1 in\r
100     -c) shift\r
101         continue;;\r
102 \r
103     -d) dir_arg=true\r
104         shift\r
105         continue;;\r
106 \r
107     -g) chgrpcmd="$chgrpprog $2"\r
108         shift\r
109         shift\r
110         continue;;\r
111 \r
112     --help) echo "$usage"; exit $?;;\r
113 \r
114     -m) chmodcmd="$chmodprog $2"\r
115         shift\r
116         shift\r
117         continue;;\r
118 \r
119     -o) chowncmd="$chownprog $2"\r
120         shift\r
121         shift\r
122         continue;;\r
123 \r
124     -s) stripcmd=$stripprog\r
125         shift\r
126         continue;;\r
127 \r
128     -t) dstarg=$2\r
129         shift\r
130         shift\r
131         continue;;\r
132 \r
133     -T) no_target_directory=true\r
134         shift\r
135         continue;;\r
136 \r
137     --version) echo "$0 $scriptversion"; exit $?;;\r
138 \r
139     *)  # When -d is used, all remaining arguments are directories to create.\r
140         # When -t is used, the destination is already specified.\r
141         test -n "$dir_arg$dstarg" && break\r
142         # Otherwise, the last argument is the destination.  Remove it from $@.\r
143         for arg\r
144         do\r
145           if test -n "$dstarg"; then\r
146             # $@ is not empty: it contains at least $arg.\r
147             set fnord "$@" "$dstarg"\r
148             shift # fnord\r
149           fi\r
150           shift # arg\r
151           dstarg=$arg\r
152         done\r
153         break;;\r
154   esac\r
155 done\r
156 \r
157 if test -z "$1"; then\r
158   if test -z "$dir_arg"; then\r
159     echo "$0: no input file specified." >&2\r
160     exit 1\r
161   fi\r
162   # It's OK to call `install-sh -d' without argument.\r
163   # This can happen when creating conditional directories.\r
164   exit 0\r
165 fi\r
166 \r
167 for src\r
168 do\r
169   # Protect names starting with `-'.\r
170   case $src in\r
171     -*) src=./$src ;;\r
172   esac\r
173 \r
174   if test -n "$dir_arg"; then\r
175     dst=$src\r
176     src=\r
177 \r
178     if test -d "$dst"; then\r
179       mkdircmd=:\r
180       chmodcmd=\r
181     else\r
182       mkdircmd=$mkdirprog\r
183     fi\r
184   else\r
185     # Waiting for this to be detected by the "$cpprog $src $dsttmp" command\r
186     # might cause directories to be created, which would be especially bad\r
187     # if $src (and thus $dsttmp) contains '*'.\r
188     if test ! -f "$src" && test ! -d "$src"; then\r
189       echo "$0: $src does not exist." >&2\r
190       exit 1\r
191     fi\r
192 \r
193     if test -z "$dstarg"; then\r
194       echo "$0: no destination specified." >&2\r
195       exit 1\r
196     fi\r
197 \r
198     dst=$dstarg\r
199     # Protect names starting with `-'.\r
200     case $dst in\r
201       -*) dst=./$dst ;;\r
202     esac\r
203 \r
204     # If destination is a directory, append the input filename; won't work\r
205     # if double slashes aren't ignored.\r
206     if test -d "$dst"; then\r
207       if test -n "$no_target_directory"; then\r
208         echo "$0: $dstarg: Is a directory" >&2\r
209         exit 1\r
210       fi\r
211       dst=$dst/`basename "$src"`\r
212     fi\r
213   fi\r
214 \r
215   # This sed command emulates the dirname command.\r
216   dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`\r
217 \r
218   # Make sure that the destination directory exists.\r
219 \r
220   # Skip lots of stat calls in the usual case.\r
221   if test ! -d "$dstdir"; then\r
222     defaultIFS='\r
223          '\r
224     IFS="${IFS-$defaultIFS}"\r
225 \r
226     oIFS=$IFS\r
227     # Some sh's can't handle IFS=/ for some reason.\r
228     IFS='%'\r
229     set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`\r
230     shift\r
231     IFS=$oIFS\r
232 \r
233     pathcomp=\r
234 \r
235     while test $# -ne 0 ; do\r
236       pathcomp=$pathcomp$1\r
237       shift\r
238       if test ! -d "$pathcomp"; then\r
239         $mkdirprog "$pathcomp"\r
240         # mkdir can fail with a `File exist' error in case several\r
241         # install-sh are creating the directory concurrently.  This\r
242         # is OK.\r
243         test -d "$pathcomp" || exit\r
244       fi\r
245       pathcomp=$pathcomp/\r
246     done\r
247   fi\r
248 \r
249   if test -n "$dir_arg"; then\r
250     $doit $mkdircmd "$dst" \\r
251       && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \\r
252       && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \\r
253       && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \\r
254       && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }\r
255 \r
256   else\r
257     dstfile=`basename "$dst"`\r
258 \r
259     # Make a couple of temp file names in the proper directory.\r
260     dsttmp=$dstdir/_inst.$$_\r
261     rmtmp=$dstdir/_rm.$$_\r
262 \r
263     # Trap to clean up those temp files at exit.\r
264     trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0\r
265     trap '(exit $?); exit' 1 2 13 15\r
266 \r
267     # Copy the file name to the temp name.\r
268     $doit $cpprog "$src" "$dsttmp" &&\r
269 \r
270     # and set any options; do chmod last to preserve setuid bits.\r
271     #\r
272     # If any of these fail, we abort the whole thing.  If we want to\r
273     # ignore errors from any of these, just make sure not to ignore\r
274     # errors from the above "$doit $cpprog $src $dsttmp" command.\r
275     #\r
276     { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \\r
277       && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \\r
278       && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \\r
279       && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&\r
280 \r
281     # Now rename the file to the real destination.\r
282     { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \\r
283       || {\r
284            # The rename failed, perhaps because mv can't rename something else\r
285            # to itself, or perhaps because mv is so ancient that it does not\r
286            # support -f.\r
287 \r
288            # Now remove or move aside any old file at destination location.\r
289            # We try this two ways since rm can't unlink itself on some\r
290            # systems and the destination file might be busy for other\r
291            # reasons.  In this case, the final cleanup might fail but the new\r
292            # file should still install successfully.\r
293            {\r
294              if test -f "$dstdir/$dstfile"; then\r
295                $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \\r
296                || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \\r
297                || {\r
298                  echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2\r
299                  (exit 1); exit 1\r
300                }\r
301              else\r
302                :\r
303              fi\r
304            } &&\r
305 \r
306            # Now rename the file to the real destination.\r
307            $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"\r
308          }\r
309     }\r
310   fi || { (exit 1); exit 1; }\r
311 done\r
312 \r
313 # The final little trick to "correctly" pass the exit status to the exit trap.\r
314 {\r
315   (exit 0); exit 0\r
316 }\r
317 \r
318 # Local variables:\r
319 # eval: (add-hook 'write-file-hooks 'time-stamp)\r
320 # time-stamp-start: "scriptversion="\r
321 # time-stamp-format: "%:y-%02m-%02d.%02H"\r
322 # time-stamp-end: "$"\r
323 # End:\r