]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | #!/bin/sh |
2 | # | |
e07d4801 | 3 | # "$Id$" |
ef416fc2 | 4 | # |
e07d4801 MS |
5 | # Install a program, script, or datafile. |
6 | # | |
7 | # Copyright 2008-2009 by Apple Inc. | |
8 | # | |
9 | # This script is not compatible with BSD (or any other) install program, as it | |
10 | # allows owner and group changes to fail with a warning and makes sure that the | |
11 | # destination directory permissions are as specified - BSD install and the | |
12 | # original X11 install script did not change permissions of existing | |
13 | # directories. It also does not support the transform options since CUPS does | |
14 | # not use them... | |
15 | # | |
16 | # Original script from X11R5 (mit/util/scripts/install.sh) | |
ef416fc2 | 17 | # Copyright 1991 by the Massachusetts Institute of Technology |
18 | # | |
19 | # Permission to use, copy, modify, distribute, and sell this software and its | |
20 | # documentation for any purpose is hereby granted without fee, provided that | |
21 | # the above copyright notice appear in all copies and that both that | |
22 | # copyright notice and this permission notice appear in supporting | |
23 | # documentation, and that the name of M.I.T. not be used in advertising or | |
24 | # publicity pertaining to distribution of the software without specific, | |
25 | # written prior permission. M.I.T. makes no representations about the | |
26 | # suitability of this software for any purpose. It is provided "as is" | |
27 | # without express or implied warranty. | |
28 | # | |
29 | # Calling this script install-sh is preferred over install.sh, to prevent | |
30 | # `make' implicit rules from creating a file called install from it | |
31 | # when there is no Makefile. | |
ef416fc2 | 32 | |
33 | # set DOITPROG to echo to test this script | |
ef416fc2 | 34 | # Don't use :- since 4.3BSD and earlier shells don't like it. |
35 | doit="${DOITPROG-}" | |
36 | ||
e07d4801 MS |
37 | # Force umask to 022... |
38 | umask 022 | |
ef416fc2 | 39 | |
40 | # put in absolute paths if you don't have them in your path; or use env. vars. | |
ef416fc2 | 41 | mvprog="${MVPROG-mv}" |
42 | cpprog="${CPPROG-cp}" | |
43 | chmodprog="${CHMODPROG-chmod}" | |
44 | chownprog="${CHOWNPROG-chown}" | |
45 | chgrpprog="${CHGRPPROG-chgrp}" | |
46 | stripprog="${STRIPPROG-strip}" | |
47 | rmprog="${RMPROG-rm}" | |
48 | mkdirprog="${MKDIRPROG-mkdir}" | |
49 | ||
50 | transformbasename="" | |
51 | transform_arg="" | |
52 | instcmd="$mvprog" | |
53 | chmodcmd="$chmodprog 0755" | |
54 | chowncmd="" | |
55 | chgrpcmd="" | |
56 | stripcmd="" | |
57 | rmcmd="$rmprog -f" | |
58 | mvcmd="$mvprog" | |
59 | src="" | |
60 | dst="" | |
61 | dir_arg="" | |
62 | ||
63 | while [ x"$1" != x ]; do | |
e07d4801 MS |
64 | case $1 in |
65 | -c) | |
66 | instcmd="$cpprog" | |
67 | shift | |
68 | continue | |
69 | ;; | |
70 | ||
71 | -d) | |
72 | dir_arg=true | |
73 | shift | |
74 | continue | |
75 | ;; | |
76 | ||
77 | -m) | |
78 | chmodcmd="$chmodprog $2" | |
79 | shift | |
80 | shift | |
81 | continue | |
82 | ;; | |
83 | ||
84 | -o) | |
85 | chowncmd="$chownprog $2" | |
86 | shift | |
87 | shift | |
88 | continue | |
89 | ;; | |
90 | ||
91 | -g) | |
92 | chgrpcmd="$chgrpprog $2" | |
93 | shift | |
94 | shift | |
95 | continue | |
96 | ;; | |
97 | ||
98 | -s) | |
99 | stripcmd="$stripprog" | |
100 | shift | |
101 | continue | |
102 | ;; | |
ef416fc2 | 103 | |
e07d4801 MS |
104 | *) |
105 | if [ x"$src" = x ]; then | |
106 | src="$1" | |
107 | else | |
108 | dst="$1" | |
109 | fi | |
110 | shift | |
111 | continue | |
112 | ;; | |
113 | esac | |
ef416fc2 | 114 | done |
115 | ||
e07d4801 MS |
116 | if [ x"$src" = x ]; then |
117 | echo "install-sh: No input file specified" | |
ef416fc2 | 118 | exit 1 |
ef416fc2 | 119 | fi |
120 | ||
121 | if [ x"$dir_arg" != x ]; then | |
e07d4801 | 122 | dst="$src" |
ef416fc2 | 123 | src="" |
124 | ||
e07d4801 | 125 | if [ -d "$dst" ]; then |
ef416fc2 | 126 | instcmd=: |
ef416fc2 | 127 | else |
128 | instcmd=$mkdirprog | |
129 | fi | |
130 | else | |
e07d4801 MS |
131 | # Waiting for this to be detected by the "$instcmd $src $dsttmp" command |
132 | # might cause directories to be created, which would be especially bad | |
133 | # if $src (and thus $dsttmp) contains '*'. | |
134 | if [ ! -f "$src" -a ! -d "$src" ]; then | |
135 | echo "install: $src does not exist" | |
ef416fc2 | 136 | exit 1 |
137 | fi | |
138 | ||
e07d4801 MS |
139 | if [ x"$dst" = x ]; then |
140 | echo "install: No destination specified" | |
ef416fc2 | 141 | exit 1 |
ef416fc2 | 142 | fi |
143 | ||
e07d4801 MS |
144 | # If destination is a directory, append the input filename. |
145 | if [ -d "$dst" ]; then | |
146 | dst="$dst/`basename $src`" | |
ef416fc2 | 147 | fi |
148 | fi | |
149 | ||
150 | ## this sed command emulates the dirname command | |
e07d4801 | 151 | dstdir="`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`" |
ef416fc2 | 152 | |
153 | # Make sure that the destination directory exists. | |
e07d4801 | 154 | # This part is taken from Noah Friedman's mkinstalldirs script |
ef416fc2 | 155 | |
156 | # Skip lots of stat calls in the usual case. | |
157 | if [ ! -d "$dstdir" ]; then | |
e07d4801 | 158 | defaultIFS=' |
ef416fc2 | 159 | ' |
e07d4801 | 160 | IFS="${IFS-${defaultIFS}}" |
ef416fc2 | 161 | |
e07d4801 MS |
162 | oIFS="${IFS}" |
163 | # Some sh's can't handle IFS=/ for some reason. | |
164 | IFS='%' | |
165 | set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` | |
166 | IFS="${oIFS}" | |
ef416fc2 | 167 | |
e07d4801 | 168 | pathcomp='' |
ef416fc2 | 169 | |
e07d4801 MS |
170 | while [ $# -ne 0 ] ; do |
171 | pathcomp="${pathcomp}${1}" | |
172 | shift | |
ef416fc2 | 173 | |
e07d4801 | 174 | if [ ! -d "${pathcomp}" ]; then $doit $mkdirprog "${pathcomp}"; fi |
ef416fc2 | 175 | |
e07d4801 MS |
176 | pathcomp="${pathcomp}/" |
177 | done | |
ef416fc2 | 178 | fi |
179 | ||
e07d4801 MS |
180 | if [ x"$dir_arg" != x ]; then |
181 | # Make a directory... | |
182 | $doit $instcmd $dst || exit 1 | |
ef416fc2 | 183 | |
e07d4801 MS |
184 | # Allow chown/chgrp to fail, but log a warning |
185 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst || echo "warning: Unable to change owner of $dst!"; fi | |
186 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst || echo "warning: Unable to change group of $dst!"; fi | |
187 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst || exit 1; fi | |
ef416fc2 | 188 | else |
e07d4801 MS |
189 | # Install a file... |
190 | dstfile="`basename $dst`" | |
ef416fc2 | 191 | |
e07d4801 MS |
192 | # Check the destination file - for libraries just use the "-x" option |
193 | # to strip... | |
839a51c8 MS |
194 | case "$dstfile" in |
195 | *.a | *.dylib | *.sl | *.sl.* | *.so | *.so.*) | |
196 | stripopt="-x" | |
197 | ;; | |
198 | *) | |
199 | stripopt="" | |
200 | ;; | |
201 | esac | |
202 | ||
e07d4801 MS |
203 | # Make a temp file name in the proper directory. |
204 | dsttmp="$dstdir/#inst.$$#" | |
ef416fc2 | 205 | |
e07d4801 MS |
206 | # Move or copy the file name to the temp name |
207 | $doit $instcmd $src $dsttmp || exit 1 | |
ef416fc2 | 208 | |
e07d4801 MS |
209 | # Update permissions and strip as needed, then move to the final name. |
210 | # If the chmod, strip, rm, or mv commands fail, remove the installed | |
211 | # file... | |
97c9a8d7 | 212 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $stripopt "$dsttmp" || echo "warning: Unable to strip $dst!"; fi |
e07d4801 MS |
213 | if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp" || echo "warning: Unable to change owner of $dst!"; fi |
214 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp" || echo "warning: Unable to change group of $dst!"; fi | |
ef416fc2 | 215 | |
216 | trap "rm -f ${dsttmp}" 0 && | |
e07d4801 MS |
217 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; fi && |
218 | $doit $rmcmd -f "$dstdir/$dstfile" && | |
219 | $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" | |
220 | fi | |
ef416fc2 | 221 | |
222 | exit 0 |