]>
git.ipfire.org Git - thirdparty/cups.git/blob - install-sh
5 # Install a program, script, or datafile.
7 # Copyright 2008-2009 by Apple Inc.
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
16 # Original script from X11R5 (mit/util/scripts/install.sh)
17 # Copyright 1991 by the Massachusetts Institute of Technology
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.
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.
33 # set DOITPROG to echo to test this script
34 # Don't use :- since 4.3BSD and earlier shells don't like it.
37 # Force umask to 022...
40 # put in absolute paths if you don't have them in your path; or use env. vars.
43 chmodprog
="${CHMODPROG-chmod}"
44 chownprog
="${CHOWNPROG-chown}"
45 chgrpprog
="${CHGRPPROG-chgrp}"
46 stripprog
="${STRIPPROG-strip}"
48 mkdirprog
="${MKDIRPROG-mkdir}"
53 chmodcmd
="$chmodprog 0755"
63 while [ x
"$1" != x
]; do
78 chmodcmd
="$chmodprog $2"
85 chowncmd
="$chownprog $2"
92 chgrpcmd
="$chgrpprog $2"
105 if [ x
"$src" = x
]; then
116 if [ x
"$src" = x
]; then
117 echo "install-sh: No input file specified"
121 if [ x
"$dir_arg" != x
]; then
125 if [ -d "$dst" ]; then
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"
139 if [ x
"$dst" = x
]; then
140 echo "install: No destination specified"
144 # If destination is a directory, append the input filename.
145 if [ -d "$dst" ]; then
146 dst
="$dst/`basename $src`"
150 ## this sed command emulates the dirname command
151 dstdir
="`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`"
153 # Make sure that the destination directory exists.
154 # This part is taken from Noah Friedman's mkinstalldirs script
156 # Skip lots of stat calls in the usual case.
157 if [ ! -d "$dstdir" ]; then
160 IFS
="${IFS-${defaultIFS}}"
163 # Some sh's can't handle IFS=/ for some reason.
165 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
170 while [ $# -ne 0 ] ; do
171 pathcomp
="${pathcomp}${1}"
174 if [ ! -d "${pathcomp}" ]; then $doit $mkdirprog "${pathcomp}"; fi
176 pathcomp
="${pathcomp}/"
180 if [ x
"$dir_arg" != x
]; then
181 # Make a directory...
182 $doit $instcmd $dst ||
exit 1
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
190 dstfile
="`basename $dst`"
192 # Check the destination file - for libraries just use the "-x" option
195 *.a |
*.dylib |
*.sl |
*.sl.
* |
*.so |
*.so.
*)
203 # Make a temp file name in the proper directory.
204 dsttmp
="$dstdir/#inst.$$#"
206 # Move or copy the file name to the temp name
207 $doit $instcmd $src $dsttmp ||
exit 1
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
212 if [ x
"$chowncmd" != x
]; then $doit $chowncmd "$dsttmp" ||
echo "warning: Unable to change owner of $dst!"; fi
213 if [ x
"$chgrpcmd" != x
]; then $doit $chgrpcmd "$dsttmp" ||
echo "warning: Unable to change group of $dst!"; fi
215 trap "rm -f ${dsttmp}" 0 &&
216 if [ x
"$stripcmd" != x
]; then $doit $stripcmd $stripopt "$dsttmp"; fi &&
217 if [ x
"$chmodcmd" != x
]; then $doit $chmodcmd "$dsttmp"; fi &&
218 $doit $rmcmd -f "$dstdir/$dstfile" &&
219 $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"