Blame install-sh

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