toolkit/crashreporter/google-breakpad/src/third_party/glog/install-sh

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/bin/sh
michael@0 2 # install - install a program, script, or datafile
michael@0 3
michael@0 4 scriptversion=2006-12-25.00
michael@0 5
michael@0 6 # This originates from X11R5 (mit/util/scripts/install.sh), which was
michael@0 7 # later released in X11R6 (xc/config/util/install.sh) with the
michael@0 8 # following copyright and license.
michael@0 9 #
michael@0 10 # Copyright (C) 1994 X Consortium
michael@0 11 #
michael@0 12 # Permission is hereby granted, free of charge, to any person obtaining a copy
michael@0 13 # of this software and associated documentation files (the "Software"), to
michael@0 14 # deal in the Software without restriction, including without limitation the
michael@0 15 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
michael@0 16 # sell copies of the Software, and to permit persons to whom the Software is
michael@0 17 # furnished to do so, subject to the following conditions:
michael@0 18 #
michael@0 19 # The above copyright notice and this permission notice shall be included in
michael@0 20 # all copies or substantial portions of the Software.
michael@0 21 #
michael@0 22 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
michael@0 23 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
michael@0 24 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
michael@0 25 # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
michael@0 26 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
michael@0 27 # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
michael@0 28 #
michael@0 29 # Except as contained in this notice, the name of the X Consortium shall not
michael@0 30 # be used in advertising or otherwise to promote the sale, use or other deal-
michael@0 31 # ings in this Software without prior written authorization from the X Consor-
michael@0 32 # tium.
michael@0 33 #
michael@0 34 #
michael@0 35 # FSF changes to this file are in the public domain.
michael@0 36 #
michael@0 37 # Calling this script install-sh is preferred over install.sh, to prevent
michael@0 38 # `make' implicit rules from creating a file called install from it
michael@0 39 # when there is no Makefile.
michael@0 40 #
michael@0 41 # This script is compatible with the BSD install script, but was written
michael@0 42 # from scratch.
michael@0 43
michael@0 44 nl='
michael@0 45 '
michael@0 46 IFS=" "" $nl"
michael@0 47
michael@0 48 # set DOITPROG to echo to test this script
michael@0 49
michael@0 50 # Don't use :- since 4.3BSD and earlier shells don't like it.
michael@0 51 doit=${DOITPROG-}
michael@0 52 if test -z "$doit"; then
michael@0 53 doit_exec=exec
michael@0 54 else
michael@0 55 doit_exec=$doit
michael@0 56 fi
michael@0 57
michael@0 58 # Put in absolute file names if you don't have them in your path;
michael@0 59 # or use environment vars.
michael@0 60
michael@0 61 chgrpprog=${CHGRPPROG-chgrp}
michael@0 62 chmodprog=${CHMODPROG-chmod}
michael@0 63 chownprog=${CHOWNPROG-chown}
michael@0 64 cmpprog=${CMPPROG-cmp}
michael@0 65 cpprog=${CPPROG-cp}
michael@0 66 mkdirprog=${MKDIRPROG-mkdir}
michael@0 67 mvprog=${MVPROG-mv}
michael@0 68 rmprog=${RMPROG-rm}
michael@0 69 stripprog=${STRIPPROG-strip}
michael@0 70
michael@0 71 posix_glob='?'
michael@0 72 initialize_posix_glob='
michael@0 73 test "$posix_glob" != "?" || {
michael@0 74 if (set -f) 2>/dev/null; then
michael@0 75 posix_glob=
michael@0 76 else
michael@0 77 posix_glob=:
michael@0 78 fi
michael@0 79 }
michael@0 80 '
michael@0 81
michael@0 82 posix_mkdir=
michael@0 83
michael@0 84 # Desired mode of installed file.
michael@0 85 mode=0755
michael@0 86
michael@0 87 chgrpcmd=
michael@0 88 chmodcmd=$chmodprog
michael@0 89 chowncmd=
michael@0 90 mvcmd=$mvprog
michael@0 91 rmcmd="$rmprog -f"
michael@0 92 stripcmd=
michael@0 93
michael@0 94 src=
michael@0 95 dst=
michael@0 96 dir_arg=
michael@0 97 dst_arg=
michael@0 98
michael@0 99 copy_on_change=false
michael@0 100 no_target_directory=
michael@0 101
michael@0 102 usage="\
michael@0 103 Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
michael@0 104 or: $0 [OPTION]... SRCFILES... DIRECTORY
michael@0 105 or: $0 [OPTION]... -t DIRECTORY SRCFILES...
michael@0 106 or: $0 [OPTION]... -d DIRECTORIES...
michael@0 107
michael@0 108 In the 1st form, copy SRCFILE to DSTFILE.
michael@0 109 In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
michael@0 110 In the 4th, create DIRECTORIES.
michael@0 111
michael@0 112 Options:
michael@0 113 --help display this help and exit.
michael@0 114 --version display version info and exit.
michael@0 115
michael@0 116 -c (ignored)
michael@0 117 -C install only if different (preserve the last data modification time)
michael@0 118 -d create directories instead of installing files.
michael@0 119 -g GROUP $chgrpprog installed files to GROUP.
michael@0 120 -m MODE $chmodprog installed files to MODE.
michael@0 121 -o USER $chownprog installed files to USER.
michael@0 122 -s $stripprog installed files.
michael@0 123 -t DIRECTORY install into DIRECTORY.
michael@0 124 -T report an error if DSTFILE is a directory.
michael@0 125
michael@0 126 Environment variables override the default commands:
michael@0 127 CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
michael@0 128 RMPROG STRIPPROG
michael@0 129 "
michael@0 130
michael@0 131 while test $# -ne 0; do
michael@0 132 case $1 in
michael@0 133 -c) ;;
michael@0 134
michael@0 135 -C) copy_on_change=true;;
michael@0 136
michael@0 137 -d) dir_arg=true;;
michael@0 138
michael@0 139 -g) chgrpcmd="$chgrpprog $2"
michael@0 140 shift;;
michael@0 141
michael@0 142 --help) echo "$usage"; exit $?;;
michael@0 143
michael@0 144 -m) mode=$2
michael@0 145 case $mode in
michael@0 146 *' '* | *' '* | *'
michael@0 147 '* | *'*'* | *'?'* | *'['*)
michael@0 148 echo "$0: invalid mode: $mode" >&2
michael@0 149 exit 1;;
michael@0 150 esac
michael@0 151 shift;;
michael@0 152
michael@0 153 -o) chowncmd="$chownprog $2"
michael@0 154 shift;;
michael@0 155
michael@0 156 -s) stripcmd=$stripprog;;
michael@0 157
michael@0 158 -t) dst_arg=$2
michael@0 159 shift;;
michael@0 160
michael@0 161 -T) no_target_directory=true;;
michael@0 162
michael@0 163 --version) echo "$0 $scriptversion"; exit $?;;
michael@0 164
michael@0 165 --) shift
michael@0 166 break;;
michael@0 167
michael@0 168 -*) echo "$0: invalid option: $1" >&2
michael@0 169 exit 1;;
michael@0 170
michael@0 171 *) break;;
michael@0 172 esac
michael@0 173 shift
michael@0 174 done
michael@0 175
michael@0 176 if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
michael@0 177 # When -d is used, all remaining arguments are directories to create.
michael@0 178 # When -t is used, the destination is already specified.
michael@0 179 # Otherwise, the last argument is the destination. Remove it from $@.
michael@0 180 for arg
michael@0 181 do
michael@0 182 if test -n "$dst_arg"; then
michael@0 183 # $@ is not empty: it contains at least $arg.
michael@0 184 set fnord "$@" "$dst_arg"
michael@0 185 shift # fnord
michael@0 186 fi
michael@0 187 shift # arg
michael@0 188 dst_arg=$arg
michael@0 189 done
michael@0 190 fi
michael@0 191
michael@0 192 if test $# -eq 0; then
michael@0 193 if test -z "$dir_arg"; then
michael@0 194 echo "$0: no input file specified." >&2
michael@0 195 exit 1
michael@0 196 fi
michael@0 197 # It's OK to call `install-sh -d' without argument.
michael@0 198 # This can happen when creating conditional directories.
michael@0 199 exit 0
michael@0 200 fi
michael@0 201
michael@0 202 if test -z "$dir_arg"; then
michael@0 203 trap '(exit $?); exit' 1 2 13 15
michael@0 204
michael@0 205 # Set umask so as not to create temps with too-generous modes.
michael@0 206 # However, 'strip' requires both read and write access to temps.
michael@0 207 case $mode in
michael@0 208 # Optimize common cases.
michael@0 209 *644) cp_umask=133;;
michael@0 210 *755) cp_umask=22;;
michael@0 211
michael@0 212 *[0-7])
michael@0 213 if test -z "$stripcmd"; then
michael@0 214 u_plus_rw=
michael@0 215 else
michael@0 216 u_plus_rw='% 200'
michael@0 217 fi
michael@0 218 cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
michael@0 219 *)
michael@0 220 if test -z "$stripcmd"; then
michael@0 221 u_plus_rw=
michael@0 222 else
michael@0 223 u_plus_rw=,u+rw
michael@0 224 fi
michael@0 225 cp_umask=$mode$u_plus_rw;;
michael@0 226 esac
michael@0 227 fi
michael@0 228
michael@0 229 for src
michael@0 230 do
michael@0 231 # Protect names starting with `-'.
michael@0 232 case $src in
michael@0 233 -*) src=./$src;;
michael@0 234 esac
michael@0 235
michael@0 236 if test -n "$dir_arg"; then
michael@0 237 dst=$src
michael@0 238 dstdir=$dst
michael@0 239 test -d "$dstdir"
michael@0 240 dstdir_status=$?
michael@0 241 else
michael@0 242
michael@0 243 # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
michael@0 244 # might cause directories to be created, which would be especially bad
michael@0 245 # if $src (and thus $dsttmp) contains '*'.
michael@0 246 if test ! -f "$src" && test ! -d "$src"; then
michael@0 247 echo "$0: $src does not exist." >&2
michael@0 248 exit 1
michael@0 249 fi
michael@0 250
michael@0 251 if test -z "$dst_arg"; then
michael@0 252 echo "$0: no destination specified." >&2
michael@0 253 exit 1
michael@0 254 fi
michael@0 255
michael@0 256 dst=$dst_arg
michael@0 257 # Protect names starting with `-'.
michael@0 258 case $dst in
michael@0 259 -*) dst=./$dst;;
michael@0 260 esac
michael@0 261
michael@0 262 # If destination is a directory, append the input filename; won't work
michael@0 263 # if double slashes aren't ignored.
michael@0 264 if test -d "$dst"; then
michael@0 265 if test -n "$no_target_directory"; then
michael@0 266 echo "$0: $dst_arg: Is a directory" >&2
michael@0 267 exit 1
michael@0 268 fi
michael@0 269 dstdir=$dst
michael@0 270 dst=$dstdir/`basename "$src"`
michael@0 271 dstdir_status=0
michael@0 272 else
michael@0 273 # Prefer dirname, but fall back on a substitute if dirname fails.
michael@0 274 dstdir=`
michael@0 275 (dirname "$dst") 2>/dev/null ||
michael@0 276 expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
michael@0 277 X"$dst" : 'X\(//\)[^/]' \| \
michael@0 278 X"$dst" : 'X\(//\)$' \| \
michael@0 279 X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
michael@0 280 echo X"$dst" |
michael@0 281 sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
michael@0 282 s//\1/
michael@0 283 q
michael@0 284 }
michael@0 285 /^X\(\/\/\)[^/].*/{
michael@0 286 s//\1/
michael@0 287 q
michael@0 288 }
michael@0 289 /^X\(\/\/\)$/{
michael@0 290 s//\1/
michael@0 291 q
michael@0 292 }
michael@0 293 /^X\(\/\).*/{
michael@0 294 s//\1/
michael@0 295 q
michael@0 296 }
michael@0 297 s/.*/./; q'
michael@0 298 `
michael@0 299
michael@0 300 test -d "$dstdir"
michael@0 301 dstdir_status=$?
michael@0 302 fi
michael@0 303 fi
michael@0 304
michael@0 305 obsolete_mkdir_used=false
michael@0 306
michael@0 307 if test $dstdir_status != 0; then
michael@0 308 case $posix_mkdir in
michael@0 309 '')
michael@0 310 # Create intermediate dirs using mode 755 as modified by the umask.
michael@0 311 # This is like FreeBSD 'install' as of 1997-10-28.
michael@0 312 umask=`umask`
michael@0 313 case $stripcmd.$umask in
michael@0 314 # Optimize common cases.
michael@0 315 *[2367][2367]) mkdir_umask=$umask;;
michael@0 316 .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
michael@0 317
michael@0 318 *[0-7])
michael@0 319 mkdir_umask=`expr $umask + 22 \
michael@0 320 - $umask % 100 % 40 + $umask % 20 \
michael@0 321 - $umask % 10 % 4 + $umask % 2
michael@0 322 `;;
michael@0 323 *) mkdir_umask=$umask,go-w;;
michael@0 324 esac
michael@0 325
michael@0 326 # With -d, create the new directory with the user-specified mode.
michael@0 327 # Otherwise, rely on $mkdir_umask.
michael@0 328 if test -n "$dir_arg"; then
michael@0 329 mkdir_mode=-m$mode
michael@0 330 else
michael@0 331 mkdir_mode=
michael@0 332 fi
michael@0 333
michael@0 334 posix_mkdir=false
michael@0 335 case $umask in
michael@0 336 *[123567][0-7][0-7])
michael@0 337 # POSIX mkdir -p sets u+wx bits regardless of umask, which
michael@0 338 # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
michael@0 339 ;;
michael@0 340 *)
michael@0 341 tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
michael@0 342 trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
michael@0 343
michael@0 344 if (umask $mkdir_umask &&
michael@0 345 exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
michael@0 346 then
michael@0 347 if test -z "$dir_arg" || {
michael@0 348 # Check for POSIX incompatibilities with -m.
michael@0 349 # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
michael@0 350 # other-writeable bit of parent directory when it shouldn't.
michael@0 351 # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
michael@0 352 ls_ld_tmpdir=`ls -ld "$tmpdir"`
michael@0 353 case $ls_ld_tmpdir in
michael@0 354 d????-?r-*) different_mode=700;;
michael@0 355 d????-?--*) different_mode=755;;
michael@0 356 *) false;;
michael@0 357 esac &&
michael@0 358 $mkdirprog -m$different_mode -p -- "$tmpdir" && {
michael@0 359 ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
michael@0 360 test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
michael@0 361 }
michael@0 362 }
michael@0 363 then posix_mkdir=:
michael@0 364 fi
michael@0 365 rmdir "$tmpdir/d" "$tmpdir"
michael@0 366 else
michael@0 367 # Remove any dirs left behind by ancient mkdir implementations.
michael@0 368 rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
michael@0 369 fi
michael@0 370 trap '' 0;;
michael@0 371 esac;;
michael@0 372 esac
michael@0 373
michael@0 374 if
michael@0 375 $posix_mkdir && (
michael@0 376 umask $mkdir_umask &&
michael@0 377 $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
michael@0 378 )
michael@0 379 then :
michael@0 380 else
michael@0 381
michael@0 382 # The umask is ridiculous, or mkdir does not conform to POSIX,
michael@0 383 # or it failed possibly due to a race condition. Create the
michael@0 384 # directory the slow way, step by step, checking for races as we go.
michael@0 385
michael@0 386 case $dstdir in
michael@0 387 /*) prefix='/';;
michael@0 388 -*) prefix='./';;
michael@0 389 *) prefix='';;
michael@0 390 esac
michael@0 391
michael@0 392 eval "$initialize_posix_glob"
michael@0 393
michael@0 394 oIFS=$IFS
michael@0 395 IFS=/
michael@0 396 $posix_glob set -f
michael@0 397 set fnord $dstdir
michael@0 398 shift
michael@0 399 $posix_glob set +f
michael@0 400 IFS=$oIFS
michael@0 401
michael@0 402 prefixes=
michael@0 403
michael@0 404 for d
michael@0 405 do
michael@0 406 test -z "$d" && continue
michael@0 407
michael@0 408 prefix=$prefix$d
michael@0 409 if test -d "$prefix"; then
michael@0 410 prefixes=
michael@0 411 else
michael@0 412 if $posix_mkdir; then
michael@0 413 (umask=$mkdir_umask &&
michael@0 414 $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
michael@0 415 # Don't fail if two instances are running concurrently.
michael@0 416 test -d "$prefix" || exit 1
michael@0 417 else
michael@0 418 case $prefix in
michael@0 419 *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
michael@0 420 *) qprefix=$prefix;;
michael@0 421 esac
michael@0 422 prefixes="$prefixes '$qprefix'"
michael@0 423 fi
michael@0 424 fi
michael@0 425 prefix=$prefix/
michael@0 426 done
michael@0 427
michael@0 428 if test -n "$prefixes"; then
michael@0 429 # Don't fail if two instances are running concurrently.
michael@0 430 (umask $mkdir_umask &&
michael@0 431 eval "\$doit_exec \$mkdirprog $prefixes") ||
michael@0 432 test -d "$dstdir" || exit 1
michael@0 433 obsolete_mkdir_used=true
michael@0 434 fi
michael@0 435 fi
michael@0 436 fi
michael@0 437
michael@0 438 if test -n "$dir_arg"; then
michael@0 439 { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
michael@0 440 { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
michael@0 441 { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
michael@0 442 test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
michael@0 443 else
michael@0 444
michael@0 445 # Make a couple of temp file names in the proper directory.
michael@0 446 dsttmp=$dstdir/_inst.$$_
michael@0 447 rmtmp=$dstdir/_rm.$$_
michael@0 448
michael@0 449 # Trap to clean up those temp files at exit.
michael@0 450 trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
michael@0 451
michael@0 452 # Copy the file name to the temp name.
michael@0 453 (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
michael@0 454
michael@0 455 # and set any options; do chmod last to preserve setuid bits.
michael@0 456 #
michael@0 457 # If any of these fail, we abort the whole thing. If we want to
michael@0 458 # ignore errors from any of these, just make sure not to ignore
michael@0 459 # errors from the above "$doit $cpprog $src $dsttmp" command.
michael@0 460 #
michael@0 461 { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
michael@0 462 { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
michael@0 463 { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
michael@0 464 { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
michael@0 465
michael@0 466 # If -C, don't bother to copy if it wouldn't change the file.
michael@0 467 if $copy_on_change &&
michael@0 468 old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` &&
michael@0 469 new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
michael@0 470
michael@0 471 eval "$initialize_posix_glob" &&
michael@0 472 $posix_glob set -f &&
michael@0 473 set X $old && old=:$2:$4:$5:$6 &&
michael@0 474 set X $new && new=:$2:$4:$5:$6 &&
michael@0 475 $posix_glob set +f &&
michael@0 476
michael@0 477 test "$old" = "$new" &&
michael@0 478 $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
michael@0 479 then
michael@0 480 rm -f "$dsttmp"
michael@0 481 else
michael@0 482 # Rename the file to the real destination.
michael@0 483 $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
michael@0 484
michael@0 485 # The rename failed, perhaps because mv can't rename something else
michael@0 486 # to itself, or perhaps because mv is so ancient that it does not
michael@0 487 # support -f.
michael@0 488 {
michael@0 489 # Now remove or move aside any old file at destination location.
michael@0 490 # We try this two ways since rm can't unlink itself on some
michael@0 491 # systems and the destination file might be busy for other
michael@0 492 # reasons. In this case, the final cleanup might fail but the new
michael@0 493 # file should still install successfully.
michael@0 494 {
michael@0 495 test ! -f "$dst" ||
michael@0 496 $doit $rmcmd -f "$dst" 2>/dev/null ||
michael@0 497 { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
michael@0 498 { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
michael@0 499 } ||
michael@0 500 { echo "$0: cannot unlink or rename $dst" >&2
michael@0 501 (exit 1); exit 1
michael@0 502 }
michael@0 503 } &&
michael@0 504
michael@0 505 # Now rename the file to the real destination.
michael@0 506 $doit $mvcmd "$dsttmp" "$dst"
michael@0 507 }
michael@0 508 fi || exit 1
michael@0 509
michael@0 510 trap '' 0
michael@0 511 fi
michael@0 512 done
michael@0 513
michael@0 514 # Local variables:
michael@0 515 # eval: (add-hook 'write-file-hooks 'time-stamp)
michael@0 516 # time-stamp-start: "scriptversion="
michael@0 517 # time-stamp-format: "%:y-%02m-%02d.%02H"
michael@0 518 # time-stamp-end: "$"
michael@0 519 # End:

mercurial