scripts/install-sh
changeset 2834 0a0410dd0cb0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/scripts/install-sh	Mon Nov 07 22:28:40 2011 +0100
     1.3 @@ -0,0 +1,520 @@
     1.4 +#!/bin/sh
     1.5 +# install - install a program, script, or datafile
     1.6 +
     1.7 +scriptversion=2009-04-28.21; # UTC
     1.8 +
     1.9 +# This originates from X11R5 (mit/util/scripts/install.sh), which was
    1.10 +# later released in X11R6 (xc/config/util/install.sh) with the
    1.11 +# following copyright and license.
    1.12 +#
    1.13 +# Copyright (C) 1994 X Consortium
    1.14 +#
    1.15 +# Permission is hereby granted, free of charge, to any person obtaining a copy
    1.16 +# of this software and associated documentation files (the "Software"), to
    1.17 +# deal in the Software without restriction, including without limitation the
    1.18 +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    1.19 +# sell copies of the Software, and to permit persons to whom the Software is
    1.20 +# furnished to do so, subject to the following conditions:
    1.21 +#
    1.22 +# The above copyright notice and this permission notice shall be included in
    1.23 +# all copies or substantial portions of the Software.
    1.24 +#
    1.25 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    1.26 +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    1.27 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    1.28 +# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    1.29 +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
    1.30 +# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    1.31 +#
    1.32 +# Except as contained in this notice, the name of the X Consortium shall not
    1.33 +# be used in advertising or otherwise to promote the sale, use or other deal-
    1.34 +# ings in this Software without prior written authorization from the X Consor-
    1.35 +# tium.
    1.36 +#
    1.37 +#
    1.38 +# FSF changes to this file are in the public domain.
    1.39 +#
    1.40 +# Calling this script install-sh is preferred over install.sh, to prevent
    1.41 +# `make' implicit rules from creating a file called install from it
    1.42 +# when there is no Makefile.
    1.43 +#
    1.44 +# This script is compatible with the BSD install script, but was written
    1.45 +# from scratch.
    1.46 +
    1.47 +nl='
    1.48 +'
    1.49 +IFS=" ""	$nl"
    1.50 +
    1.51 +# set DOITPROG to echo to test this script
    1.52 +
    1.53 +# Don't use :- since 4.3BSD and earlier shells don't like it.
    1.54 +doit=${DOITPROG-}
    1.55 +if test -z "$doit"; then
    1.56 +  doit_exec=exec
    1.57 +else
    1.58 +  doit_exec=$doit
    1.59 +fi
    1.60 +
    1.61 +# Put in absolute file names if you don't have them in your path;
    1.62 +# or use environment vars.
    1.63 +
    1.64 +chgrpprog=${CHGRPPROG-chgrp}
    1.65 +chmodprog=${CHMODPROG-chmod}
    1.66 +chownprog=${CHOWNPROG-chown}
    1.67 +cmpprog=${CMPPROG-cmp}
    1.68 +cpprog=${CPPROG-cp}
    1.69 +mkdirprog=${MKDIRPROG-mkdir}
    1.70 +mvprog=${MVPROG-mv}
    1.71 +rmprog=${RMPROG-rm}
    1.72 +stripprog=${STRIPPROG-strip}
    1.73 +
    1.74 +posix_glob='?'
    1.75 +initialize_posix_glob='
    1.76 +  test "$posix_glob" != "?" || {
    1.77 +    if (set -f) 2>/dev/null; then
    1.78 +      posix_glob=
    1.79 +    else
    1.80 +      posix_glob=:
    1.81 +    fi
    1.82 +  }
    1.83 +'
    1.84 +
    1.85 +posix_mkdir=
    1.86 +
    1.87 +# Desired mode of installed file.
    1.88 +mode=0755
    1.89 +
    1.90 +chgrpcmd=
    1.91 +chmodcmd=$chmodprog
    1.92 +chowncmd=
    1.93 +mvcmd=$mvprog
    1.94 +rmcmd="$rmprog -f"
    1.95 +stripcmd=
    1.96 +
    1.97 +src=
    1.98 +dst=
    1.99 +dir_arg=
   1.100 +dst_arg=
   1.101 +
   1.102 +copy_on_change=false
   1.103 +no_target_directory=
   1.104 +
   1.105 +usage="\
   1.106 +Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
   1.107 +   or: $0 [OPTION]... SRCFILES... DIRECTORY
   1.108 +   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
   1.109 +   or: $0 [OPTION]... -d DIRECTORIES...
   1.110 +
   1.111 +In the 1st form, copy SRCFILE to DSTFILE.
   1.112 +In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
   1.113 +In the 4th, create DIRECTORIES.
   1.114 +
   1.115 +Options:
   1.116 +     --help     display this help and exit.
   1.117 +     --version  display version info and exit.
   1.118 +
   1.119 +  -c            (ignored)
   1.120 +  -C            install only if different (preserve the last data modification time)
   1.121 +  -d            create directories instead of installing files.
   1.122 +  -g GROUP      $chgrpprog installed files to GROUP.
   1.123 +  -m MODE       $chmodprog installed files to MODE.
   1.124 +  -o USER       $chownprog installed files to USER.
   1.125 +  -s            $stripprog installed files.
   1.126 +  -t DIRECTORY  install into DIRECTORY.
   1.127 +  -T            report an error if DSTFILE is a directory.
   1.128 +
   1.129 +Environment variables override the default commands:
   1.130 +  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
   1.131 +  RMPROG STRIPPROG
   1.132 +"
   1.133 +
   1.134 +while test $# -ne 0; do
   1.135 +  case $1 in
   1.136 +    -c) ;;
   1.137 +
   1.138 +    -C) copy_on_change=true;;
   1.139 +
   1.140 +    -d) dir_arg=true;;
   1.141 +
   1.142 +    -g) chgrpcmd="$chgrpprog $2"
   1.143 +	shift;;
   1.144 +
   1.145 +    --help) echo "$usage"; exit $?;;
   1.146 +
   1.147 +    -m) mode=$2
   1.148 +	case $mode in
   1.149 +	  *' '* | *'	'* | *'
   1.150 +'*	  | *'*'* | *'?'* | *'['*)
   1.151 +	    echo "$0: invalid mode: $mode" >&2
   1.152 +	    exit 1;;
   1.153 +	esac
   1.154 +	shift;;
   1.155 +
   1.156 +    -o) chowncmd="$chownprog $2"
   1.157 +	shift;;
   1.158 +
   1.159 +    -s) stripcmd=$stripprog;;
   1.160 +
   1.161 +    -t) dst_arg=$2
   1.162 +	shift;;
   1.163 +
   1.164 +    -T) no_target_directory=true;;
   1.165 +
   1.166 +    --version) echo "$0 $scriptversion"; exit $?;;
   1.167 +
   1.168 +    --)	shift
   1.169 +	break;;
   1.170 +
   1.171 +    -*)	echo "$0: invalid option: $1" >&2
   1.172 +	exit 1;;
   1.173 +
   1.174 +    *)  break;;
   1.175 +  esac
   1.176 +  shift
   1.177 +done
   1.178 +
   1.179 +if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
   1.180 +  # When -d is used, all remaining arguments are directories to create.
   1.181 +  # When -t is used, the destination is already specified.
   1.182 +  # Otherwise, the last argument is the destination.  Remove it from $@.
   1.183 +  for arg
   1.184 +  do
   1.185 +    if test -n "$dst_arg"; then
   1.186 +      # $@ is not empty: it contains at least $arg.
   1.187 +      set fnord "$@" "$dst_arg"
   1.188 +      shift # fnord
   1.189 +    fi
   1.190 +    shift # arg
   1.191 +    dst_arg=$arg
   1.192 +  done
   1.193 +fi
   1.194 +
   1.195 +if test $# -eq 0; then
   1.196 +  if test -z "$dir_arg"; then
   1.197 +    echo "$0: no input file specified." >&2
   1.198 +    exit 1
   1.199 +  fi
   1.200 +  # It's OK to call `install-sh -d' without argument.
   1.201 +  # This can happen when creating conditional directories.
   1.202 +  exit 0
   1.203 +fi
   1.204 +
   1.205 +if test -z "$dir_arg"; then
   1.206 +  trap '(exit $?); exit' 1 2 13 15
   1.207 +
   1.208 +  # Set umask so as not to create temps with too-generous modes.
   1.209 +  # However, 'strip' requires both read and write access to temps.
   1.210 +  case $mode in
   1.211 +    # Optimize common cases.
   1.212 +    *644) cp_umask=133;;
   1.213 +    *755) cp_umask=22;;
   1.214 +
   1.215 +    *[0-7])
   1.216 +      if test -z "$stripcmd"; then
   1.217 +	u_plus_rw=
   1.218 +      else
   1.219 +	u_plus_rw='% 200'
   1.220 +      fi
   1.221 +      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
   1.222 +    *)
   1.223 +      if test -z "$stripcmd"; then
   1.224 +	u_plus_rw=
   1.225 +      else
   1.226 +	u_plus_rw=,u+rw
   1.227 +      fi
   1.228 +      cp_umask=$mode$u_plus_rw;;
   1.229 +  esac
   1.230 +fi
   1.231 +
   1.232 +for src
   1.233 +do
   1.234 +  # Protect names starting with `-'.
   1.235 +  case $src in
   1.236 +    -*) src=./$src;;
   1.237 +  esac
   1.238 +
   1.239 +  if test -n "$dir_arg"; then
   1.240 +    dst=$src
   1.241 +    dstdir=$dst
   1.242 +    test -d "$dstdir"
   1.243 +    dstdir_status=$?
   1.244 +  else
   1.245 +
   1.246 +    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
   1.247 +    # might cause directories to be created, which would be especially bad
   1.248 +    # if $src (and thus $dsttmp) contains '*'.
   1.249 +    if test ! -f "$src" && test ! -d "$src"; then
   1.250 +      echo "$0: $src does not exist." >&2
   1.251 +      exit 1
   1.252 +    fi
   1.253 +
   1.254 +    if test -z "$dst_arg"; then
   1.255 +      echo "$0: no destination specified." >&2
   1.256 +      exit 1
   1.257 +    fi
   1.258 +
   1.259 +    dst=$dst_arg
   1.260 +    # Protect names starting with `-'.
   1.261 +    case $dst in
   1.262 +      -*) dst=./$dst;;
   1.263 +    esac
   1.264 +
   1.265 +    # If destination is a directory, append the input filename; won't work
   1.266 +    # if double slashes aren't ignored.
   1.267 +    if test -d "$dst"; then
   1.268 +      if test -n "$no_target_directory"; then
   1.269 +	echo "$0: $dst_arg: Is a directory" >&2
   1.270 +	exit 1
   1.271 +      fi
   1.272 +      dstdir=$dst
   1.273 +      dst=$dstdir/`basename "$src"`
   1.274 +      dstdir_status=0
   1.275 +    else
   1.276 +      # Prefer dirname, but fall back on a substitute if dirname fails.
   1.277 +      dstdir=`
   1.278 +	(dirname "$dst") 2>/dev/null ||
   1.279 +	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
   1.280 +	     X"$dst" : 'X\(//\)[^/]' \| \
   1.281 +	     X"$dst" : 'X\(//\)$' \| \
   1.282 +	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
   1.283 +	echo X"$dst" |
   1.284 +	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
   1.285 +		   s//\1/
   1.286 +		   q
   1.287 +		 }
   1.288 +		 /^X\(\/\/\)[^/].*/{
   1.289 +		   s//\1/
   1.290 +		   q
   1.291 +		 }
   1.292 +		 /^X\(\/\/\)$/{
   1.293 +		   s//\1/
   1.294 +		   q
   1.295 +		 }
   1.296 +		 /^X\(\/\).*/{
   1.297 +		   s//\1/
   1.298 +		   q
   1.299 +		 }
   1.300 +		 s/.*/./; q'
   1.301 +      `
   1.302 +
   1.303 +      test -d "$dstdir"
   1.304 +      dstdir_status=$?
   1.305 +    fi
   1.306 +  fi
   1.307 +
   1.308 +  obsolete_mkdir_used=false
   1.309 +
   1.310 +  if test $dstdir_status != 0; then
   1.311 +    case $posix_mkdir in
   1.312 +      '')
   1.313 +	# Create intermediate dirs using mode 755 as modified by the umask.
   1.314 +	# This is like FreeBSD 'install' as of 1997-10-28.
   1.315 +	umask=`umask`
   1.316 +	case $stripcmd.$umask in
   1.317 +	  # Optimize common cases.
   1.318 +	  *[2367][2367]) mkdir_umask=$umask;;
   1.319 +	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
   1.320 +
   1.321 +	  *[0-7])
   1.322 +	    mkdir_umask=`expr $umask + 22 \
   1.323 +	      - $umask % 100 % 40 + $umask % 20 \
   1.324 +	      - $umask % 10 % 4 + $umask % 2
   1.325 +	    `;;
   1.326 +	  *) mkdir_umask=$umask,go-w;;
   1.327 +	esac
   1.328 +
   1.329 +	# With -d, create the new directory with the user-specified mode.
   1.330 +	# Otherwise, rely on $mkdir_umask.
   1.331 +	if test -n "$dir_arg"; then
   1.332 +	  mkdir_mode=-m$mode
   1.333 +	else
   1.334 +	  mkdir_mode=
   1.335 +	fi
   1.336 +
   1.337 +	posix_mkdir=false
   1.338 +	case $umask in
   1.339 +	  *[123567][0-7][0-7])
   1.340 +	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
   1.341 +	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
   1.342 +	    ;;
   1.343 +	  *)
   1.344 +	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
   1.345 +	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
   1.346 +
   1.347 +	    if (umask $mkdir_umask &&
   1.348 +		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
   1.349 +	    then
   1.350 +	      if test -z "$dir_arg" || {
   1.351 +		   # Check for POSIX incompatibilities with -m.
   1.352 +		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
   1.353 +		   # other-writeable bit of parent directory when it shouldn't.
   1.354 +		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
   1.355 +		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
   1.356 +		   case $ls_ld_tmpdir in
   1.357 +		     d????-?r-*) different_mode=700;;
   1.358 +		     d????-?--*) different_mode=755;;
   1.359 +		     *) false;;
   1.360 +		   esac &&
   1.361 +		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
   1.362 +		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
   1.363 +		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
   1.364 +		   }
   1.365 +		 }
   1.366 +	      then posix_mkdir=:
   1.367 +	      fi
   1.368 +	      rmdir "$tmpdir/d" "$tmpdir"
   1.369 +	    else
   1.370 +	      # Remove any dirs left behind by ancient mkdir implementations.
   1.371 +	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
   1.372 +	    fi
   1.373 +	    trap '' 0;;
   1.374 +	esac;;
   1.375 +    esac
   1.376 +
   1.377 +    if
   1.378 +      $posix_mkdir && (
   1.379 +	umask $mkdir_umask &&
   1.380 +	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
   1.381 +      )
   1.382 +    then :
   1.383 +    else
   1.384 +
   1.385 +      # The umask is ridiculous, or mkdir does not conform to POSIX,
   1.386 +      # or it failed possibly due to a race condition.  Create the
   1.387 +      # directory the slow way, step by step, checking for races as we go.
   1.388 +
   1.389 +      case $dstdir in
   1.390 +	/*) prefix='/';;
   1.391 +	-*) prefix='./';;
   1.392 +	*)  prefix='';;
   1.393 +      esac
   1.394 +
   1.395 +      eval "$initialize_posix_glob"
   1.396 +
   1.397 +      oIFS=$IFS
   1.398 +      IFS=/
   1.399 +      $posix_glob set -f
   1.400 +      set fnord $dstdir
   1.401 +      shift
   1.402 +      $posix_glob set +f
   1.403 +      IFS=$oIFS
   1.404 +
   1.405 +      prefixes=
   1.406 +
   1.407 +      for d
   1.408 +      do
   1.409 +	test -z "$d" && continue
   1.410 +
   1.411 +	prefix=$prefix$d
   1.412 +	if test -d "$prefix"; then
   1.413 +	  prefixes=
   1.414 +	else
   1.415 +	  if $posix_mkdir; then
   1.416 +	    (umask=$mkdir_umask &&
   1.417 +	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
   1.418 +	    # Don't fail if two instances are running concurrently.
   1.419 +	    test -d "$prefix" || exit 1
   1.420 +	  else
   1.421 +	    case $prefix in
   1.422 +	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
   1.423 +	      *) qprefix=$prefix;;
   1.424 +	    esac
   1.425 +	    prefixes="$prefixes '$qprefix'"
   1.426 +	  fi
   1.427 +	fi
   1.428 +	prefix=$prefix/
   1.429 +      done
   1.430 +
   1.431 +      if test -n "$prefixes"; then
   1.432 +	# Don't fail if two instances are running concurrently.
   1.433 +	(umask $mkdir_umask &&
   1.434 +	 eval "\$doit_exec \$mkdirprog $prefixes") ||
   1.435 +	  test -d "$dstdir" || exit 1
   1.436 +	obsolete_mkdir_used=true
   1.437 +      fi
   1.438 +    fi
   1.439 +  fi
   1.440 +
   1.441 +  if test -n "$dir_arg"; then
   1.442 +    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
   1.443 +    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
   1.444 +    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
   1.445 +      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
   1.446 +  else
   1.447 +
   1.448 +    # Make a couple of temp file names in the proper directory.
   1.449 +    dsttmp=$dstdir/_inst.$$_
   1.450 +    rmtmp=$dstdir/_rm.$$_
   1.451 +
   1.452 +    # Trap to clean up those temp files at exit.
   1.453 +    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
   1.454 +
   1.455 +    # Copy the file name to the temp name.
   1.456 +    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
   1.457 +
   1.458 +    # and set any options; do chmod last to preserve setuid bits.
   1.459 +    #
   1.460 +    # If any of these fail, we abort the whole thing.  If we want to
   1.461 +    # ignore errors from any of these, just make sure not to ignore
   1.462 +    # errors from the above "$doit $cpprog $src $dsttmp" command.
   1.463 +    #
   1.464 +    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
   1.465 +    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
   1.466 +    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
   1.467 +    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
   1.468 +
   1.469 +    # If -C, don't bother to copy if it wouldn't change the file.
   1.470 +    if $copy_on_change &&
   1.471 +       old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` &&
   1.472 +       new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` &&
   1.473 +
   1.474 +       eval "$initialize_posix_glob" &&
   1.475 +       $posix_glob set -f &&
   1.476 +       set X $old && old=:$2:$4:$5:$6 &&
   1.477 +       set X $new && new=:$2:$4:$5:$6 &&
   1.478 +       $posix_glob set +f &&
   1.479 +
   1.480 +       test "$old" = "$new" &&
   1.481 +       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
   1.482 +    then
   1.483 +      rm -f "$dsttmp"
   1.484 +    else
   1.485 +      # Rename the file to the real destination.
   1.486 +      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
   1.487 +
   1.488 +      # The rename failed, perhaps because mv can't rename something else
   1.489 +      # to itself, or perhaps because mv is so ancient that it does not
   1.490 +      # support -f.
   1.491 +      {
   1.492 +	# Now remove or move aside any old file at destination location.
   1.493 +	# We try this two ways since rm can't unlink itself on some
   1.494 +	# systems and the destination file might be busy for other
   1.495 +	# reasons.  In this case, the final cleanup might fail but the new
   1.496 +	# file should still install successfully.
   1.497 +	{
   1.498 +	  test ! -f "$dst" ||
   1.499 +	  $doit $rmcmd -f "$dst" 2>/dev/null ||
   1.500 +	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
   1.501 +	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
   1.502 +	  } ||
   1.503 +	  { echo "$0: cannot unlink or rename $dst" >&2
   1.504 +	    (exit 1); exit 1
   1.505 +	  }
   1.506 +	} &&
   1.507 +
   1.508 +	# Now rename the file to the real destination.
   1.509 +	$doit $mvcmd "$dsttmp" "$dst"
   1.510 +      }
   1.511 +    fi || exit 1
   1.512 +
   1.513 +    trap '' 0
   1.514 +  fi
   1.515 +done
   1.516 +
   1.517 +# Local variables:
   1.518 +# eval: (add-hook 'write-file-hooks 'time-stamp)
   1.519 +# time-stamp-start: "scriptversion="
   1.520 +# time-stamp-format: "%:y-%02m-%02d.%02H"
   1.521 +# time-stamp-time-zone: "UTC"
   1.522 +# time-stamp-end: "; # UTC"
   1.523 +# End: