Debian Codegraph @

install-sh

raw
1 #!/bin/sh
2 #
3 # Install a program, script, or datafile.
4 #
5 # Copyright 2008-2009 by Apple Inc.
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)
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.
30
31 # set DOITPROG to echo to test this script
32 # Don't use :- since 4.3BSD and earlier shells don't like it.
33 doit="${DOITPROG-}"
34
35 # Force umask to 022...
36 umask 022
37
38 # put in absolute paths if you don't have them in your path; or use env. vars.
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}"
47
48 transformbasename=""
49 transform_arg=""
50 instcmd="$mvprog"
51 chmodcmd="$chmodprog 0755"
52 chowncmd=""
53 chgrpcmd=""
54 stripcmd=""
55 rmcmd="$rmprog -f"
56 mvcmd="$mvprog"
57 src=""
58 dst=""
59 dir_arg=""
60
61 while [ x"$1" != x ]; do
62 case $1 in
63 -c)
64 instcmd="$cpprog"
65 shift
66 continue
67 ;;
68
69 -d)
70 dir_arg=true
71 shift
72 continue
73 ;;
74
75 -m)
76 chmodcmd="$chmodprog $2"
77 shift
78 shift
79 continue
80 ;;
81
82 -o)
83 chowncmd="$chownprog $2"
84 shift
85 shift
86 continue
87 ;;
88
89 -g)
90 chgrpcmd="$chgrpprog $2"
91 shift
92 shift
93 continue
94 ;;
95
96 -s)
97 stripcmd="$stripprog"
98 shift
99 continue
100 ;;
101
102 *)
103 if [ x"$src" = x ]; then
104 src="$1"
105 else
106 dst="$1"
107 fi
108 shift
109 continue
110 ;;
111 esac
112 done
113
114 if [ x"$src" = x ]; then
115 echo "install-sh: No input file specified"
116 exit 1
117 fi
118
119 if [ x"$dir_arg" != x ]; then
120 dst="$src"
121 src=""
122
123 if [ -d "$dst" ]; then
124 instcmd=:
125 else
126 instcmd=$mkdirprog
127 fi
128 else
129 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
130 # might cause directories to be created, which would be especially bad
131 # if $src (and thus $dsttmp) contains '*'.
132 if [ ! -f "$src" -a ! -d "$src" ]; then
133 echo "install: $src does not exist"
134 exit 1
135 fi
136
137 if [ x"$dst" = x ]; then
138 echo "install: No destination specified"
139 exit 1
140 fi
141
142 # If destination is a directory, append the input filename.
143 if [ -d "$dst" ]; then
144 dst="$dst/`basename $src`"
145 fi
146 fi
147
148 ## this sed command emulates the dirname command
149 dstdir="`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`"
150
151 # Make sure that the destination directory exists.
152 # This part is taken from Noah Friedman's mkinstalldirs script
153
154 # Skip lots of stat calls in the usual case.
155 if [ ! -d "$dstdir" ]; then
156 defaultIFS='
157 '
158 IFS="${IFS-${defaultIFS}}"
159
160 oIFS="${IFS}"
161 # Some sh's can't handle IFS=/ for some reason.
162 IFS='%'
163 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
164 IFS="${oIFS}"
165
166 pathcomp=''
167
168 while [ $# -ne 0 ] ; do
169 pathcomp="${pathcomp}${1}"
170 shift
171
172 if [ ! -d "${pathcomp}" ]; then $doit $mkdirprog "${pathcomp}"; fi
173
174 pathcomp="${pathcomp}/"
175 done
176 fi
177
178 if [ x"$dir_arg" != x ]; then
179 # Make a directory...
180 $doit $instcmd $dst || exit 1
181
182 # Allow chown/chgrp to fail, but log a warning
183 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst || echo "warning: Unable to change owner of $dst!"; fi
184 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst || echo "warning: Unable to change group of $dst!"; fi
185 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst || exit 1; fi
186 else
187 # Install a file...
188 dstfile="`basename $dst`"
189
190 # Check the destination file - for libraries just use the "-x" option
191 # to strip...
192 case "$dstfile" in
193 *.a | *.dylib | *.sl | *.sl.* | *.so | *.so.*)
194 stripopt="-x"
195 ;;
196 *)
197 stripopt=""
198 ;;
199 esac
200
201 # Make a temp file name in the proper directory.
202 dsttmp="$dstdir/#inst.$$#"
203
204 # Move or copy the file name to the temp name
205 $doit $instcmd $src $dsttmp || exit 1
206
207 # Update permissions and strip as needed, then move to the final name.
208 # If the chmod, strip, rm, or mv commands fail, remove the installed
209 # file...
210 if [ x"$stripcmd" != x ]; then $doit $stripcmd $stripopt "$dsttmp" || echo "warning: Unable to strip $dst!"; fi
211 if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp" || echo "warning: Unable to change owner of $dst!"; fi
212 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp" || echo "warning: Unable to change group of $dst!"; fi
213
214 trap "rm -f ${dsttmp}" 0 &&
215 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; fi &&
216 $doit $rmcmd -f "$dstdir/$dstfile" &&
217 $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
218 fi
219
220 exit 0