Blame install-sh

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