Blame install-sh

rpm-build 393af8
#!/bin/sh
rpm-build 393af8
# install - install a program, script, or datafile
rpm-build 393af8
rpm-build 393af8
scriptversion=2014-09-12.12; # UTC
rpm-build 393af8
rpm-build 393af8
# This originates from X11R5 (mit/util/scripts/install.sh), which was
rpm-build 393af8
# later released in X11R6 (xc/config/util/install.sh) with the
rpm-build 393af8
# following copyright and license.
rpm-build 393af8
#
rpm-build 393af8
# Copyright (C) 1994 X Consortium
rpm-build 393af8
#
rpm-build 393af8
# Permission is hereby granted, free of charge, to any person obtaining a copy
rpm-build 393af8
# of this software and associated documentation files (the "Software"), to
rpm-build 393af8
# deal in the Software without restriction, including without limitation the
rpm-build 393af8
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
rpm-build 393af8
# sell copies of the Software, and to permit persons to whom the Software is
rpm-build 393af8
# furnished to do so, subject to the following conditions:
rpm-build 393af8
#
rpm-build 393af8
# The above copyright notice and this permission notice shall be included in
rpm-build 393af8
# all copies or substantial portions of the Software.
rpm-build 393af8
#
rpm-build 393af8
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
rpm-build 393af8
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
rpm-build 393af8
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
rpm-build 393af8
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
rpm-build 393af8
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
rpm-build 393af8
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
rpm-build 393af8
#
rpm-build 393af8
# Except as contained in this notice, the name of the X Consortium shall not
rpm-build 393af8
# be used in advertising or otherwise to promote the sale, use or other deal-
rpm-build 393af8
# ings in this Software without prior written authorization from the X Consor-
rpm-build 393af8
# tium.
rpm-build 393af8
#
rpm-build 393af8
#
rpm-build 393af8
# FSF changes to this file are in the public domain.
rpm-build 393af8
#
rpm-build 393af8
# Calling this script install-sh is preferred over install.sh, to prevent
rpm-build 393af8
# 'make' implicit rules from creating a file called install from it
rpm-build 393af8
# when there is no Makefile.
rpm-build 393af8
#
rpm-build 393af8
# This script is compatible with the BSD install script, but was written
rpm-build 393af8
# from scratch.
rpm-build 393af8
rpm-build 393af8
tab='	'
rpm-build 393af8
nl='
rpm-build 393af8
'
rpm-build 393af8
IFS=" $tab$nl"
rpm-build 393af8
rpm-build 393af8
# Set DOITPROG to "echo" to test this script.
rpm-build 393af8
rpm-build 393af8
doit=${DOITPROG-}
rpm-build 393af8
doit_exec=${doit:-exec}
rpm-build 393af8
rpm-build 393af8
# Put in absolute file names if you don't have them in your path;
rpm-build 393af8
# or use environment vars.
rpm-build 393af8
rpm-build 393af8
chgrpprog=${CHGRPPROG-chgrp}
rpm-build 393af8
chmodprog=${CHMODPROG-chmod}
rpm-build 393af8
chownprog=${CHOWNPROG-chown}
rpm-build 393af8
cmpprog=${CMPPROG-cmp}
rpm-build 393af8
cpprog=${CPPROG-cp}
rpm-build 393af8
mkdirprog=${MKDIRPROG-mkdir}
rpm-build 393af8
mvprog=${MVPROG-mv}
rpm-build 393af8
rmprog=${RMPROG-rm}
rpm-build 393af8
stripprog=${STRIPPROG-strip}
rpm-build 393af8
rpm-build 393af8
posix_mkdir=
rpm-build 393af8
rpm-build 393af8
# Desired mode of installed file.
rpm-build 393af8
mode=0755
rpm-build 393af8
rpm-build 393af8
chgrpcmd=
rpm-build 393af8
chmodcmd=$chmodprog
rpm-build 393af8
chowncmd=
rpm-build 393af8
mvcmd=$mvprog
rpm-build 393af8
rmcmd="$rmprog -f"
rpm-build 393af8
stripcmd=
rpm-build 393af8
rpm-build 393af8
src=
rpm-build 393af8
dst=
rpm-build 393af8
dir_arg=
rpm-build 393af8
dst_arg=
rpm-build 393af8
rpm-build 393af8
copy_on_change=false
rpm-build 393af8
is_target_a_directory=possibly
rpm-build 393af8
rpm-build 393af8
usage="\
rpm-build 393af8
Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
rpm-build 393af8
   or: $0 [OPTION]... SRCFILES... DIRECTORY
rpm-build 393af8
   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
rpm-build 393af8
   or: $0 [OPTION]... -d DIRECTORIES...
rpm-build 393af8
rpm-build 393af8
In the 1st form, copy SRCFILE to DSTFILE.
rpm-build 393af8
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
rpm-build 393af8
In the 4th, create DIRECTORIES.
rpm-build 393af8
rpm-build 393af8
Options:
rpm-build 393af8
     --help     display this help and exit.
rpm-build 393af8
     --version  display version info and exit.
rpm-build 393af8
rpm-build 393af8
  -c            (ignored)
rpm-build 393af8
  -C            install only if different (preserve the last data modification time)
rpm-build 393af8
  -d            create directories instead of installing files.
rpm-build 393af8
  -g GROUP      $chgrpprog installed files to GROUP.
rpm-build 393af8
  -m MODE       $chmodprog installed files to MODE.
rpm-build 393af8
  -o USER       $chownprog installed files to USER.
rpm-build 393af8
  -s            $stripprog installed files.
rpm-build 393af8
  -t DIRECTORY  install into DIRECTORY.
rpm-build 393af8
  -T            report an error if DSTFILE is a directory.
rpm-build 393af8
rpm-build 393af8
Environment variables override the default commands:
rpm-build 393af8
  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
rpm-build 393af8
  RMPROG STRIPPROG
rpm-build 393af8
"
rpm-build 393af8
rpm-build 393af8
while test $# -ne 0; do
rpm-build 393af8
  case $1 in
rpm-build 393af8
    -c) ;;
rpm-build 393af8
rpm-build 393af8
    -C) copy_on_change=true;;
rpm-build 393af8
rpm-build 393af8
    -d) dir_arg=true;;
rpm-build 393af8
rpm-build 393af8
    -g) chgrpcmd="$chgrpprog $2"
rpm-build 393af8
        shift;;
rpm-build 393af8
rpm-build 393af8
    --help) echo "$usage"; exit $?;;
rpm-build 393af8
rpm-build 393af8
    -m) mode=$2
rpm-build 393af8
        case $mode in
rpm-build 393af8
          *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*)
rpm-build 393af8
            echo "$0: invalid mode: $mode" >&2
rpm-build 393af8
            exit 1;;
rpm-build 393af8
        esac
rpm-build 393af8
        shift;;
rpm-build 393af8
rpm-build 393af8
    -o) chowncmd="$chownprog $2"
rpm-build 393af8
        shift;;
rpm-build 393af8
rpm-build 393af8
    -s) stripcmd=$stripprog;;
rpm-build 393af8
rpm-build 393af8
    -t)
rpm-build 393af8
        is_target_a_directory=always
rpm-build 393af8
        dst_arg=$2
rpm-build 393af8
        # Protect names problematic for 'test' and other utilities.
rpm-build 393af8
        case $dst_arg in
rpm-build 393af8
          -* | [=\(\)!]) dst_arg=./$dst_arg;;
rpm-build 393af8
        esac
rpm-build 393af8
        shift;;
rpm-build 393af8
rpm-build 393af8
    -T) is_target_a_directory=never;;
rpm-build 393af8
rpm-build 393af8
    --version) echo "$0 $scriptversion"; exit $?;;
rpm-build 393af8
rpm-build 393af8
    --) shift
rpm-build 393af8
        break;;
rpm-build 393af8
rpm-build 393af8
    -*) echo "$0: invalid option: $1" >&2
rpm-build 393af8
        exit 1;;
rpm-build 393af8
rpm-build 393af8
    *)  break;;
rpm-build 393af8
  esac
rpm-build 393af8
  shift
rpm-build 393af8
done
rpm-build 393af8
rpm-build 393af8
# We allow the use of options -d and -T together, by making -d
rpm-build 393af8
# take the precedence; this is for compatibility with GNU install.
rpm-build 393af8
rpm-build 393af8
if test -n "$dir_arg"; then
rpm-build 393af8
  if test -n "$dst_arg"; then
rpm-build 393af8
    echo "$0: target directory not allowed when installing a directory." >&2
rpm-build 393af8
    exit 1
rpm-build 393af8
  fi
rpm-build 393af8
fi
rpm-build 393af8
rpm-build 393af8
if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
rpm-build 393af8
  # When -d is used, all remaining arguments are directories to create.
rpm-build 393af8
  # When -t is used, the destination is already specified.
rpm-build 393af8
  # Otherwise, the last argument is the destination.  Remove it from $@.
rpm-build 393af8
  for arg
rpm-build 393af8
  do
rpm-build 393af8
    if test -n "$dst_arg"; then
rpm-build 393af8
      # $@ is not empty: it contains at least $arg.
rpm-build 393af8
      set fnord "$@" "$dst_arg"
rpm-build 393af8
      shift # fnord
rpm-build 393af8
    fi
rpm-build 393af8
    shift # arg
rpm-build 393af8
    dst_arg=$arg
rpm-build 393af8
    # Protect names problematic for 'test' and other utilities.
rpm-build 393af8
    case $dst_arg in
rpm-build 393af8
      -* | [=\(\)!]) dst_arg=./$dst_arg;;
rpm-build 393af8
    esac
rpm-build 393af8
  done
rpm-build 393af8
fi
rpm-build 393af8
rpm-build 393af8
if test $# -eq 0; then
rpm-build 393af8
  if test -z "$dir_arg"; then
rpm-build 393af8
    echo "$0: no input file specified." >&2
rpm-build 393af8
    exit 1
rpm-build 393af8
  fi
rpm-build 393af8
  # It's OK to call 'install-sh -d' without argument.
rpm-build 393af8
  # This can happen when creating conditional directories.
rpm-build 393af8
  exit 0
rpm-build 393af8
fi
rpm-build 393af8
rpm-build 393af8
if test -z "$dir_arg"; then
rpm-build 393af8
  if test $# -gt 1 || test "$is_target_a_directory" = always; then
rpm-build 393af8
    if test ! -d "$dst_arg"; then
rpm-build 393af8
      echo "$0: $dst_arg: Is not a directory." >&2
rpm-build 393af8
      exit 1
rpm-build 393af8
    fi
rpm-build 393af8
  fi
rpm-build 393af8
fi
rpm-build 393af8
rpm-build 393af8
if test -z "$dir_arg"; then
rpm-build 393af8
  do_exit='(exit $ret); exit $ret'
rpm-build 393af8
  trap "ret=129; $do_exit" 1
rpm-build 393af8
  trap "ret=130; $do_exit" 2
rpm-build 393af8
  trap "ret=141; $do_exit" 13
rpm-build 393af8
  trap "ret=143; $do_exit" 15
rpm-build 393af8
rpm-build 393af8
  # Set umask so as not to create temps with too-generous modes.
rpm-build 393af8
  # However, 'strip' requires both read and write access to temps.
rpm-build 393af8
  case $mode in
rpm-build 393af8
    # Optimize common cases.
rpm-build 393af8
    *644) cp_umask=133;;
rpm-build 393af8
    *755) cp_umask=22;;
rpm-build 393af8
rpm-build 393af8
    *[0-7])
rpm-build 393af8
      if test -z "$stripcmd"; then
rpm-build 393af8
        u_plus_rw=
rpm-build 393af8
      else
rpm-build 393af8
        u_plus_rw='% 200'
rpm-build 393af8
      fi
rpm-build 393af8
      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
rpm-build 393af8
    *)
rpm-build 393af8
      if test -z "$stripcmd"; then
rpm-build 393af8
        u_plus_rw=
rpm-build 393af8
      else
rpm-build 393af8
        u_plus_rw=,u+rw
rpm-build 393af8
      fi
rpm-build 393af8
      cp_umask=$mode$u_plus_rw;;
rpm-build 393af8
  esac
rpm-build 393af8
fi
rpm-build 393af8
rpm-build 393af8
for src
rpm-build 393af8
do
rpm-build 393af8
  # Protect names problematic for 'test' and other utilities.
rpm-build 393af8
  case $src in
rpm-build 393af8
    -* | [=\(\)!]) src=./$src;;
rpm-build 393af8
  esac
rpm-build 393af8
rpm-build 393af8
  if test -n "$dir_arg"; then
rpm-build 393af8
    dst=$src
rpm-build 393af8
    dstdir=$dst
rpm-build 393af8
    test -d "$dstdir"
rpm-build 393af8
    dstdir_status=$?
rpm-build 393af8
  else
rpm-build 393af8
rpm-build 393af8
    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
rpm-build 393af8
    # might cause directories to be created, which would be especially bad
rpm-build 393af8
    # if $src (and thus $dsttmp) contains '*'.
rpm-build 393af8
    if test ! -f "$src" && test ! -d "$src"; then
rpm-build 393af8
      echo "$0: $src does not exist." >&2
rpm-build 393af8
      exit 1
rpm-build 393af8
    fi
rpm-build 393af8
rpm-build 393af8
    if test -z "$dst_arg"; then
rpm-build 393af8
      echo "$0: no destination specified." >&2
rpm-build 393af8
      exit 1
rpm-build 393af8
    fi
rpm-build 393af8
    dst=$dst_arg
rpm-build 393af8
rpm-build 393af8
    # If destination is a directory, append the input filename; won't work
rpm-build 393af8
    # if double slashes aren't ignored.
rpm-build 393af8
    if test -d "$dst"; then
rpm-build 393af8
      if test "$is_target_a_directory" = never; then
rpm-build 393af8
        echo "$0: $dst_arg: Is a directory" >&2
rpm-build 393af8
        exit 1
rpm-build 393af8
      fi
rpm-build 393af8
      dstdir=$dst
rpm-build 393af8
      dst=$dstdir/`basename "$src"`
rpm-build 393af8
      dstdir_status=0
rpm-build 393af8
    else
rpm-build 393af8
      dstdir=`dirname "$dst"`
rpm-build 393af8
      test -d "$dstdir"
rpm-build 393af8
      dstdir_status=$?
rpm-build 393af8
    fi
rpm-build 393af8
  fi
rpm-build 393af8
rpm-build 393af8
  obsolete_mkdir_used=false
rpm-build 393af8
rpm-build 393af8
  if test $dstdir_status != 0; then
rpm-build 393af8
    case $posix_mkdir in
rpm-build 393af8
      '')
rpm-build 393af8
        # Create intermediate dirs using mode 755 as modified by the umask.
rpm-build 393af8
        # This is like FreeBSD 'install' as of 1997-10-28.
rpm-build 393af8
        umask=`umask`
rpm-build 393af8
        case $stripcmd.$umask in
rpm-build 393af8
          # Optimize common cases.
rpm-build 393af8
          *[2367][2367]) mkdir_umask=$umask;;
rpm-build 393af8
          .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
rpm-build 393af8
rpm-build 393af8
          *[0-7])
rpm-build 393af8
            mkdir_umask=`expr $umask + 22 \
rpm-build 393af8
              - $umask % 100 % 40 + $umask % 20 \
rpm-build 393af8
              - $umask % 10 % 4 + $umask % 2
rpm-build 393af8
            `;;
rpm-build 393af8
          *) mkdir_umask=$umask,go-w;;
rpm-build 393af8
        esac
rpm-build 393af8
rpm-build 393af8
        # With -d, create the new directory with the user-specified mode.
rpm-build 393af8
        # Otherwise, rely on $mkdir_umask.
rpm-build 393af8
        if test -n "$dir_arg"; then
rpm-build 393af8
          mkdir_mode=-m$mode
rpm-build 393af8
        else
rpm-build 393af8
          mkdir_mode=
rpm-build 393af8
        fi
rpm-build 393af8
rpm-build 393af8
        posix_mkdir=false
rpm-build 393af8
        case $umask in
rpm-build 393af8
          *[123567][0-7][0-7])
rpm-build 393af8
            # POSIX mkdir -p sets u+wx bits regardless of umask, which
rpm-build 393af8
            # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
rpm-build 393af8
            ;;
rpm-build 393af8
          *)
rpm-build 393af8
            # $RANDOM is not portable (e.g. dash);  use it when possible to
rpm-build 393af8
            # lower collision chance
rpm-build 393af8
            tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
rpm-build 393af8
            trap 'ret=$?; rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null; exit $ret' 0
rpm-build 393af8
rpm-build 393af8
            # As "mkdir -p" follows symlinks and we work in /tmp possibly;  so
rpm-build 393af8
            # create the $tmpdir first (and fail if unsuccessful) to make sure
rpm-build 393af8
            # that nobody tries to guess the $tmpdir name.
rpm-build 393af8
            if (umask $mkdir_umask &&
rpm-build 393af8
                $mkdirprog $mkdir_mode "$tmpdir" &&
rpm-build 393af8
                exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
rpm-build 393af8
            then
rpm-build 393af8
              if test -z "$dir_arg" || {
rpm-build 393af8
                   # Check for POSIX incompatibilities with -m.
rpm-build 393af8
                   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
rpm-build 393af8
                   # other-writable bit of parent directory when it shouldn't.
rpm-build 393af8
                   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
rpm-build 393af8
                   test_tmpdir="$tmpdir/a"
rpm-build 393af8
                   ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
rpm-build 393af8
                   case $ls_ld_tmpdir in
rpm-build 393af8
                     d????-?r-*) different_mode=700;;
rpm-build 393af8
                     d????-?--*) different_mode=755;;
rpm-build 393af8
                     *) false;;
rpm-build 393af8
                   esac &&
rpm-build 393af8
                   $mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
rpm-build 393af8
                     ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
rpm-build 393af8
                     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
rpm-build 393af8
                   }
rpm-build 393af8
                 }
rpm-build 393af8
              then posix_mkdir=:
rpm-build 393af8
              fi
rpm-build 393af8
              rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
rpm-build 393af8
            else
rpm-build 393af8
              # Remove any dirs left behind by ancient mkdir implementations.
rpm-build 393af8
              rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
rpm-build 393af8
            fi
rpm-build 393af8
            trap '' 0;;
rpm-build 393af8
        esac;;
rpm-build 393af8
    esac
rpm-build 393af8
rpm-build 393af8
    if
rpm-build 393af8
      $posix_mkdir && (
rpm-build 393af8
        umask $mkdir_umask &&
rpm-build 393af8
        $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
rpm-build 393af8
      )
rpm-build 393af8
    then :
rpm-build 393af8
    else
rpm-build 393af8
rpm-build 393af8
      # The umask is ridiculous, or mkdir does not conform to POSIX,
rpm-build 393af8
      # or it failed possibly due to a race condition.  Create the
rpm-build 393af8
      # directory the slow way, step by step, checking for races as we go.
rpm-build 393af8
rpm-build 393af8
      case $dstdir in
rpm-build 393af8
        /*) prefix='/';;
rpm-build 393af8
        [-=\(\)!]*) prefix='./';;
rpm-build 393af8
        *)  prefix='';;
rpm-build 393af8
      esac
rpm-build 393af8
rpm-build 393af8
      oIFS=$IFS
rpm-build 393af8
      IFS=/
rpm-build 393af8
      set -f
rpm-build 393af8
      set fnord $dstdir
rpm-build 393af8
      shift
rpm-build 393af8
      set +f
rpm-build 393af8
      IFS=$oIFS
rpm-build 393af8
rpm-build 393af8
      prefixes=
rpm-build 393af8
rpm-build 393af8
      for d
rpm-build 393af8
      do
rpm-build 393af8
        test X"$d" = X && continue
rpm-build 393af8
rpm-build 393af8
        prefix=$prefix$d
rpm-build 393af8
        if test -d "$prefix"; then
rpm-build 393af8
          prefixes=
rpm-build 393af8
        else
rpm-build 393af8
          if $posix_mkdir; then
rpm-build 393af8
            (umask=$mkdir_umask &&
rpm-build 393af8
             $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
rpm-build 393af8
            # Don't fail if two instances are running concurrently.
rpm-build 393af8
            test -d "$prefix" || exit 1
rpm-build 393af8
          else
rpm-build 393af8
            case $prefix in
rpm-build 393af8
              *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
rpm-build 393af8
              *) qprefix=$prefix;;
rpm-build 393af8
            esac
rpm-build 393af8
            prefixes="$prefixes '$qprefix'"
rpm-build 393af8
          fi
rpm-build 393af8
        fi
rpm-build 393af8
        prefix=$prefix/
rpm-build 393af8
      done
rpm-build 393af8
rpm-build 393af8
      if test -n "$prefixes"; then
rpm-build 393af8
        # Don't fail if two instances are running concurrently.
rpm-build 393af8
        (umask $mkdir_umask &&
rpm-build 393af8
         eval "\$doit_exec \$mkdirprog $prefixes") ||
rpm-build 393af8
          test -d "$dstdir" || exit 1
rpm-build 393af8
        obsolete_mkdir_used=true
rpm-build 393af8
      fi
rpm-build 393af8
    fi
rpm-build 393af8
  fi
rpm-build 393af8
rpm-build 393af8
  if test -n "$dir_arg"; then
rpm-build 393af8
    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
rpm-build 393af8
    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
rpm-build 393af8
    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
rpm-build 393af8
      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
rpm-build 393af8
  else
rpm-build 393af8
rpm-build 393af8
    # Make a couple of temp file names in the proper directory.
rpm-build 393af8
    dsttmp=$dstdir/_inst.$$_
rpm-build 393af8
    rmtmp=$dstdir/_rm.$$_
rpm-build 393af8
rpm-build 393af8
    # Trap to clean up those temp files at exit.
rpm-build 393af8
    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
rpm-build 393af8
rpm-build 393af8
    # Copy the file name to the temp name.
rpm-build 393af8
    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
rpm-build 393af8
rpm-build 393af8
    # and set any options; do chmod last to preserve setuid bits.
rpm-build 393af8
    #
rpm-build 393af8
    # If any of these fail, we abort the whole thing.  If we want to
rpm-build 393af8
    # ignore errors from any of these, just make sure not to ignore
rpm-build 393af8
    # errors from the above "$doit $cpprog $src $dsttmp" command.
rpm-build 393af8
    #
rpm-build 393af8
    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
rpm-build 393af8
    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
rpm-build 393af8
    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
rpm-build 393af8
    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
rpm-build 393af8
rpm-build 393af8
    # If -C, don't bother to copy if it wouldn't change the file.
rpm-build 393af8
    if $copy_on_change &&
rpm-build 393af8
       old=`LC_ALL=C ls -dlL "$dst"     2>/dev/null` &&
rpm-build 393af8
       new=`LC_ALL=C ls -dlL "$dsttmp"  2>/dev/null` &&
rpm-build 393af8
       set -f &&
rpm-build 393af8
       set X $old && old=:$2:$4:$5:$6 &&
rpm-build 393af8
       set X $new && new=:$2:$4:$5:$6 &&
rpm-build 393af8
       set +f &&
rpm-build 393af8
       test "$old" = "$new" &&
rpm-build 393af8
       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
rpm-build 393af8
    then
rpm-build 393af8
      rm -f "$dsttmp"
rpm-build 393af8
    else
rpm-build 393af8
      # Rename the file to the real destination.
rpm-build 393af8
      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
rpm-build 393af8
rpm-build 393af8
      # The rename failed, perhaps because mv can't rename something else
rpm-build 393af8
      # to itself, or perhaps because mv is so ancient that it does not
rpm-build 393af8
      # support -f.
rpm-build 393af8
      {
rpm-build 393af8
        # Now remove or move aside any old file at destination location.
rpm-build 393af8
        # We try this two ways since rm can't unlink itself on some
rpm-build 393af8
        # systems and the destination file might be busy for other
rpm-build 393af8
        # reasons.  In this case, the final cleanup might fail but the new
rpm-build 393af8
        # file should still install successfully.
rpm-build 393af8
        {
rpm-build 393af8
          test ! -f "$dst" ||
rpm-build 393af8
          $doit $rmcmd -f "$dst" 2>/dev/null ||
rpm-build 393af8
          { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
rpm-build 393af8
            { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
rpm-build 393af8
          } ||
rpm-build 393af8
          { echo "$0: cannot unlink or rename $dst" >&2
rpm-build 393af8
            (exit 1); exit 1
rpm-build 393af8
          }
rpm-build 393af8
        } &&
rpm-build 393af8
rpm-build 393af8
        # Now rename the file to the real destination.
rpm-build 393af8
        $doit $mvcmd "$dsttmp" "$dst"
rpm-build 393af8
      }
rpm-build 393af8
    fi || exit 1
rpm-build 393af8
rpm-build 393af8
    trap '' 0
rpm-build 393af8
  fi
rpm-build 393af8
done
rpm-build 393af8
rpm-build 393af8
# Local variables:
rpm-build 393af8
# eval: (add-hook 'write-file-hooks 'time-stamp)
rpm-build 393af8
# time-stamp-start: "scriptversion="
rpm-build 393af8
# time-stamp-format: "%:y-%02m-%02d.%02H"
rpm-build 393af8
# time-stamp-time-zone: "UTC"
rpm-build 393af8
# time-stamp-end: "; # UTC"
rpm-build 393af8
# End: