OLD | NEW |
1 #!/bin/sh | 1 #!/bin/sh |
2 # install - install a program, script, or datafile | 2 # install - install a program, script, or datafile |
3 | 3 |
4 scriptversion=2009-04-28.21; # UTC | 4 scriptversion=2011-01-19.21; # UTC |
5 | 5 |
6 # This originates from X11R5 (mit/util/scripts/install.sh), which was | 6 # This originates from X11R5 (mit/util/scripts/install.sh), which was |
7 # later released in X11R6 (xc/config/util/install.sh) with the | 7 # later released in X11R6 (xc/config/util/install.sh) with the |
8 # following copyright and license. | 8 # following copyright and license. |
9 # | 9 # |
10 # Copyright (C) 1994 X Consortium | 10 # Copyright (C) 1994 X Consortium |
11 # | 11 # |
12 # Permission is hereby granted, free of charge, to any person obtaining a copy | 12 # Permission is hereby granted, free of charge, to any person obtaining a copy |
13 # of this software and associated documentation files (the "Software"), to | 13 # of this software and associated documentation files (the "Software"), to |
14 # deal in the Software without restriction, including without limitation the | 14 # deal in the Software without restriction, including without limitation the |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 exit 1;; | 149 exit 1;; |
150 esac | 150 esac |
151 shift;; | 151 shift;; |
152 | 152 |
153 -o) chowncmd="$chownprog $2" | 153 -o) chowncmd="$chownprog $2" |
154 shift;; | 154 shift;; |
155 | 155 |
156 -s) stripcmd=$stripprog;; | 156 -s) stripcmd=$stripprog;; |
157 | 157 |
158 -t) dst_arg=$2 | 158 -t) dst_arg=$2 |
| 159 # Protect names problematic for `test' and other utilities. |
| 160 case $dst_arg in |
| 161 -* | [=\(\)!]) dst_arg=./$dst_arg;; |
| 162 esac |
159 shift;; | 163 shift;; |
160 | 164 |
161 -T) no_target_directory=true;; | 165 -T) no_target_directory=true;; |
162 | 166 |
163 --version) echo "$0 $scriptversion"; exit $?;; | 167 --version) echo "$0 $scriptversion"; exit $?;; |
164 | 168 |
165 --) shift | 169 --) shift |
166 break;; | 170 break;; |
167 | 171 |
168 -*) echo "$0: invalid option: $1" >&2 | 172 -*) echo "$0: invalid option: $1" >&2 |
(...skipping 10 matching lines...) Expand all Loading... |
179 # Otherwise, the last argument is the destination. Remove it from $@. | 183 # Otherwise, the last argument is the destination. Remove it from $@. |
180 for arg | 184 for arg |
181 do | 185 do |
182 if test -n "$dst_arg"; then | 186 if test -n "$dst_arg"; then |
183 # $@ is not empty: it contains at least $arg. | 187 # $@ is not empty: it contains at least $arg. |
184 set fnord "$@" "$dst_arg" | 188 set fnord "$@" "$dst_arg" |
185 shift # fnord | 189 shift # fnord |
186 fi | 190 fi |
187 shift # arg | 191 shift # arg |
188 dst_arg=$arg | 192 dst_arg=$arg |
| 193 # Protect names problematic for `test' and other utilities. |
| 194 case $dst_arg in |
| 195 -* | [=\(\)!]) dst_arg=./$dst_arg;; |
| 196 esac |
189 done | 197 done |
190 fi | 198 fi |
191 | 199 |
192 if test $# -eq 0; then | 200 if test $# -eq 0; then |
193 if test -z "$dir_arg"; then | 201 if test -z "$dir_arg"; then |
194 echo "$0: no input file specified." >&2 | 202 echo "$0: no input file specified." >&2 |
195 exit 1 | 203 exit 1 |
196 fi | 204 fi |
197 # It's OK to call `install-sh -d' without argument. | 205 # It's OK to call `install-sh -d' without argument. |
198 # This can happen when creating conditional directories. | 206 # This can happen when creating conditional directories. |
199 exit 0 | 207 exit 0 |
200 fi | 208 fi |
201 | 209 |
202 if test -z "$dir_arg"; then | 210 if test -z "$dir_arg"; then |
203 trap '(exit $?); exit' 1 2 13 15 | 211 do_exit='(exit $ret); exit $ret' |
| 212 trap "ret=129; $do_exit" 1 |
| 213 trap "ret=130; $do_exit" 2 |
| 214 trap "ret=141; $do_exit" 13 |
| 215 trap "ret=143; $do_exit" 15 |
204 | 216 |
205 # Set umask so as not to create temps with too-generous modes. | 217 # Set umask so as not to create temps with too-generous modes. |
206 # However, 'strip' requires both read and write access to temps. | 218 # However, 'strip' requires both read and write access to temps. |
207 case $mode in | 219 case $mode in |
208 # Optimize common cases. | 220 # Optimize common cases. |
209 *644) cp_umask=133;; | 221 *644) cp_umask=133;; |
210 *755) cp_umask=22;; | 222 *755) cp_umask=22;; |
211 | 223 |
212 *[0-7]) | 224 *[0-7]) |
213 if test -z "$stripcmd"; then | 225 if test -z "$stripcmd"; then |
214 u_plus_rw= | 226 u_plus_rw= |
215 else | 227 else |
216 u_plus_rw='% 200' | 228 u_plus_rw='% 200' |
217 fi | 229 fi |
218 cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; | 230 cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; |
219 *) | 231 *) |
220 if test -z "$stripcmd"; then | 232 if test -z "$stripcmd"; then |
221 u_plus_rw= | 233 u_plus_rw= |
222 else | 234 else |
223 u_plus_rw=,u+rw | 235 u_plus_rw=,u+rw |
224 fi | 236 fi |
225 cp_umask=$mode$u_plus_rw;; | 237 cp_umask=$mode$u_plus_rw;; |
226 esac | 238 esac |
227 fi | 239 fi |
228 | 240 |
229 for src | 241 for src |
230 do | 242 do |
231 # Protect names starting with `-'. | 243 # Protect names problematic for `test' and other utilities. |
232 case $src in | 244 case $src in |
233 -*) src=./$src;; | 245 -* | [=\(\)!]) src=./$src;; |
234 esac | 246 esac |
235 | 247 |
236 if test -n "$dir_arg"; then | 248 if test -n "$dir_arg"; then |
237 dst=$src | 249 dst=$src |
238 dstdir=$dst | 250 dstdir=$dst |
239 test -d "$dstdir" | 251 test -d "$dstdir" |
240 dstdir_status=$? | 252 dstdir_status=$? |
241 else | 253 else |
242 | 254 |
243 # Waiting for this to be detected by the "$cpprog $src $dsttmp" command | 255 # Waiting for this to be detected by the "$cpprog $src $dsttmp" command |
244 # might cause directories to be created, which would be especially bad | 256 # might cause directories to be created, which would be especially bad |
245 # if $src (and thus $dsttmp) contains '*'. | 257 # if $src (and thus $dsttmp) contains '*'. |
246 if test ! -f "$src" && test ! -d "$src"; then | 258 if test ! -f "$src" && test ! -d "$src"; then |
247 echo "$0: $src does not exist." >&2 | 259 echo "$0: $src does not exist." >&2 |
248 exit 1 | 260 exit 1 |
249 fi | 261 fi |
250 | 262 |
251 if test -z "$dst_arg"; then | 263 if test -z "$dst_arg"; then |
252 echo "$0: no destination specified." >&2 | 264 echo "$0: no destination specified." >&2 |
253 exit 1 | 265 exit 1 |
254 fi | 266 fi |
255 | |
256 dst=$dst_arg | 267 dst=$dst_arg |
257 # Protect names starting with `-'. | |
258 case $dst in | |
259 -*) dst=./$dst;; | |
260 esac | |
261 | 268 |
262 # If destination is a directory, append the input filename; won't work | 269 # If destination is a directory, append the input filename; won't work |
263 # if double slashes aren't ignored. | 270 # if double slashes aren't ignored. |
264 if test -d "$dst"; then | 271 if test -d "$dst"; then |
265 if test -n "$no_target_directory"; then | 272 if test -n "$no_target_directory"; then |
266 echo "$0: $dst_arg: Is a directory" >&2 | 273 echo "$0: $dst_arg: Is a directory" >&2 |
267 exit 1 | 274 exit 1 |
268 fi | 275 fi |
269 dstdir=$dst | 276 dstdir=$dst |
270 dst=$dstdir/`basename "$src"` | 277 dst=$dstdir/`basename "$src"` |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 ) | 385 ) |
379 then : | 386 then : |
380 else | 387 else |
381 | 388 |
382 # The umask is ridiculous, or mkdir does not conform to POSIX, | 389 # The umask is ridiculous, or mkdir does not conform to POSIX, |
383 # or it failed possibly due to a race condition. Create the | 390 # or it failed possibly due to a race condition. Create the |
384 # directory the slow way, step by step, checking for races as we go. | 391 # directory the slow way, step by step, checking for races as we go. |
385 | 392 |
386 case $dstdir in | 393 case $dstdir in |
387 /*) prefix='/';; | 394 /*) prefix='/';; |
388 » -*) prefix='./';; | 395 » [-=\(\)!]*) prefix='./';; |
389 *) prefix='';; | 396 *) prefix='';; |
390 esac | 397 esac |
391 | 398 |
392 eval "$initialize_posix_glob" | 399 eval "$initialize_posix_glob" |
393 | 400 |
394 oIFS=$IFS | 401 oIFS=$IFS |
395 IFS=/ | 402 IFS=/ |
396 $posix_glob set -f | 403 $posix_glob set -f |
397 set fnord $dstdir | 404 set fnord $dstdir |
398 shift | 405 shift |
399 $posix_glob set +f | 406 $posix_glob set +f |
400 IFS=$oIFS | 407 IFS=$oIFS |
401 | 408 |
402 prefixes= | 409 prefixes= |
403 | 410 |
404 for d | 411 for d |
405 do | 412 do |
406 » test -z "$d" && continue | 413 » test X"$d" = X && continue |
407 | 414 |
408 prefix=$prefix$d | 415 prefix=$prefix$d |
409 if test -d "$prefix"; then | 416 if test -d "$prefix"; then |
410 prefixes= | 417 prefixes= |
411 else | 418 else |
412 if $posix_mkdir; then | 419 if $posix_mkdir; then |
413 (umask=$mkdir_umask && | 420 (umask=$mkdir_umask && |
414 $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break | 421 $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break |
415 # Don't fail if two instances are running concurrently. | 422 # Don't fail if two instances are running concurrently. |
416 test -d "$prefix" || exit 1 | 423 test -d "$prefix" || exit 1 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 fi | 518 fi |
512 done | 519 done |
513 | 520 |
514 # Local variables: | 521 # Local variables: |
515 # eval: (add-hook 'write-file-hooks 'time-stamp) | 522 # eval: (add-hook 'write-file-hooks 'time-stamp) |
516 # time-stamp-start: "scriptversion=" | 523 # time-stamp-start: "scriptversion=" |
517 # time-stamp-format: "%:y-%02m-%02d.%02H" | 524 # time-stamp-format: "%:y-%02m-%02d.%02H" |
518 # time-stamp-time-zone: "UTC" | 525 # time-stamp-time-zone: "UTC" |
519 # time-stamp-end: "; # UTC" | 526 # time-stamp-end: "; # UTC" |
520 # End: | 527 # End: |
OLD | NEW |