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