3 # Install a program, script, or datafile.
5 # Copyright 2008-2012 by Apple Inc.
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
14 # Original script from X11R5 (mit/util/scripts/install.sh)
15 # Copyright 1991 by the Massachusetts Institute of Technology
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.
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.
31 # set DOITPROG to echo to test this script
32 # Don't use :- since 4.3BSD and earlier shells don't like it.
35 # Force umask to 022...
38 # put in absolute paths if you don't have them in your path; or use env. vars.
41 chmodprog="${CHMODPROG-chmod}"
42 chownprog="${CHOWNPROG-chown}"
43 chgrpprog="${CHGRPPROG-chgrp}"
44 stripprog="${STRIPPROG-strip}"
46 mkdirprog="${MKDIRPROG-mkdir}"
47 gzipprog="${GZIPPROG-gzip}"
52 chmodcmd="$chmodprog 0755"
64 $gzipprog -9 <"$1" >"$2"
67 while [ x"$1" != x ]; do
82 chmodcmd="$chmodprog $2"
89 chowncmd="$chownprog $2"
96 chgrpcmd="$chgrpprog $2"
103 stripcmd="$stripprog"
115 if [ x"$src" = x ]; then
126 if [ x"$src" = x ]; then
127 echo "install-sh: No input file specified"
131 if [ x"$dir_arg" != x ]; then
135 if [ -d "$dst" ]; then
141 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
142 # might cause directories to be created, which would be especially bad
143 # if $src (and thus $dsttmp) contains '*'.
144 if [ ! -f "$src" -a ! -d "$src" ]; then
145 echo "install: $src does not exist"
149 if [ x"$dst" = x ]; then
150 echo "install: No destination specified"
154 # If destination is a directory, append the input filename.
155 if [ -d "$dst" ]; then
156 dst="$dst/`basename $src`"
160 ## this sed command emulates the dirname command
161 dstdir="`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`"
163 # Make sure that the destination directory exists.
164 # This part is taken from Noah Friedman's mkinstalldirs script
166 # Skip lots of stat calls in the usual case.
167 if [ ! -d "$dstdir" ]; then
170 IFS="${IFS-${defaultIFS}}"
173 # Some sh's can't handle IFS=/ for some reason.
175 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
180 while [ $# -ne 0 ] ; do
181 pathcomp="${pathcomp}${1}"
184 if [ ! -d "${pathcomp}" ]; then $doit $mkdirprog "${pathcomp}"; fi
186 pathcomp="${pathcomp}/"
190 if [ x"$dir_arg" != x ]; then
191 # Make a directory...
192 $doit $instcmd $dst || exit 1
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
200 dstfile="`basename $dst`"
202 # Check the destination file - for libraries just use the "-x" option
205 *.a | *.dylib | *.sl | *.sl.* | *.so | *.so.*)
213 # Make a temp file name in the proper directory.
214 dsttmp="$dstdir/#inst.$$#"
216 # Move or copy the file name to the temp name
217 $doit $instcmd $src $dsttmp || exit 1
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
222 if [ x"$stripcmd" != x ]; then $doit $stripcmd $stripopt "$dsttmp" || echo "warning: Unable to strip $dst!"; fi
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
226 trap "rm -f ${dsttmp}" 0 &&
227 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; fi &&
228 $doit $rmcmd -f "$dstdir/$dstfile" &&
229 $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"