build-scripts/install-sh
author Sylvain Becker <sylvain.becker@gmail.com>
Wed, 30 Jan 2019 16:36:47 +0100
changeset 12584 233b2a61cad1
parent 12336 2f4ebd8f5693
permissions -rwxr-xr-x
Fixed failing SDL_ConvertSurface() when blit has failed.

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