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