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