Blame install-sh

Packit Service 102f81
#!/bin/sh
Packit Service 102f81
# install - install a program, script, or datafile
Packit Service 102f81
Packit Service 102f81
scriptversion=2005-05-14.22
Packit Service 102f81
Packit Service 102f81
# This originates from X11R5 (mit/util/scripts/install.sh), which was
Packit Service 102f81
# later released in X11R6 (xc/config/util/install.sh) with the
Packit Service 102f81
# following copyright and license.
Packit Service 102f81
#
Packit Service 102f81
# Copyright (C) 1994 X Consortium
Packit Service 102f81
#
Packit Service 102f81
# Permission is hereby granted, free of charge, to any person obtaining a copy
Packit Service 102f81
# of this software and associated documentation files (the "Software"), to
Packit Service 102f81
# deal in the Software without restriction, including without limitation the
Packit Service 102f81
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
Packit Service 102f81
# sell copies of the Software, and to permit persons to whom the Software is
Packit Service 102f81
# furnished to do so, subject to the following conditions:
Packit Service 102f81
#
Packit Service 102f81
# The above copyright notice and this permission notice shall be included in
Packit Service 102f81
# all copies or substantial portions of the Software.
Packit Service 102f81
#
Packit Service 102f81
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit Service 102f81
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit Service 102f81
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
Packit Service 102f81
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
Packit Service 102f81
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
Packit Service 102f81
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Packit Service 102f81
#
Packit Service 102f81
# Except as contained in this notice, the name of the X Consortium shall not
Packit Service 102f81
# be used in advertising or otherwise to promote the sale, use or other deal-
Packit Service 102f81
# ings in this Software without prior written authorization from the X Consor-
Packit Service 102f81
# tium.
Packit Service 102f81
#
Packit Service 102f81
#
Packit Service 102f81
# FSF changes to this file are in the public domain.
Packit Service 102f81
#
Packit Service 102f81
# Calling this script install-sh is preferred over install.sh, to prevent
Packit Service 102f81
# `make' implicit rules from creating a file called install from it
Packit Service 102f81
# when there is no Makefile.
Packit Service 102f81
#
Packit Service 102f81
# This script is compatible with the BSD install script, but was written
Packit Service 102f81
# from scratch.  It can only install one file at a time, a restriction
Packit Service 102f81
# shared with many OS's install programs.
Packit Service 102f81
Packit Service 102f81
# set DOITPROG to echo to test this script
Packit Service 102f81
Packit Service 102f81
# Don't use :- since 4.3BSD and earlier shells don't like it.
Packit Service 102f81
doit="${DOITPROG-}"
Packit Service 102f81
Packit Service 102f81
# put in absolute paths if you don't have them in your path; or use env. vars.
Packit Service 102f81
Packit Service 102f81
mvprog="${MVPROG-mv}"
Packit Service 102f81
cpprog="${CPPROG-cp}"
Packit Service 102f81
chmodprog="${CHMODPROG-chmod}"
Packit Service 102f81
chownprog="${CHOWNPROG-chown}"
Packit Service 102f81
chgrpprog="${CHGRPPROG-chgrp}"
Packit Service 102f81
stripprog="${STRIPPROG-strip}"
Packit Service 102f81
rmprog="${RMPROG-rm}"
Packit Service 102f81
mkdirprog="${MKDIRPROG-mkdir}"
Packit Service 102f81
Packit Service 102f81
chmodcmd="$chmodprog 0755"
Packit Service 102f81
chowncmd=
Packit Service 102f81
chgrpcmd=
Packit Service 102f81
stripcmd=
Packit Service 102f81
rmcmd="$rmprog -f"
Packit Service 102f81
mvcmd="$mvprog"
Packit Service 102f81
src=
Packit Service 102f81
dst=
Packit Service 102f81
dir_arg=
Packit Service 102f81
dstarg=
Packit Service 102f81
no_target_directory=
Packit Service 102f81
Packit Service 102f81
usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
Packit Service 102f81
   or: $0 [OPTION]... SRCFILES... DIRECTORY
Packit Service 102f81
   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
Packit Service 102f81
   or: $0 [OPTION]... -d DIRECTORIES...
Packit Service 102f81
Packit Service 102f81
In the 1st form, copy SRCFILE to DSTFILE.
Packit Service 102f81
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
Packit Service 102f81
In the 4th, create DIRECTORIES.
Packit Service 102f81
Packit Service 102f81
Options:
Packit Service 102f81
-c         (ignored)
Packit Service 102f81
-d         create directories instead of installing files.
Packit Service 102f81
-g GROUP   $chgrpprog installed files to GROUP.
Packit Service 102f81
-m MODE    $chmodprog installed files to MODE.
Packit Service 102f81
-o USER    $chownprog installed files to USER.
Packit Service 102f81
-s         $stripprog installed files.
Packit Service 102f81
-t DIRECTORY  install into DIRECTORY.
Packit Service 102f81
-T         report an error if DSTFILE is a directory.
Packit Service 102f81
--help     display this help and exit.
Packit Service 102f81
--version  display version info and exit.
Packit Service 102f81
Packit Service 102f81
Environment variables override the default commands:
Packit Service 102f81
  CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
Packit Service 102f81
"
Packit Service 102f81
Packit Service 102f81
while test -n "$1"; do
Packit Service 102f81
  case $1 in
Packit Service 102f81
    -c) shift
Packit Service 102f81
        continue;;
Packit Service 102f81
Packit Service 102f81
    -d) dir_arg=true
Packit Service 102f81
        shift
Packit Service 102f81
        continue;;
Packit Service 102f81
Packit Service 102f81
    -g) chgrpcmd="$chgrpprog $2"
Packit Service 102f81
        shift
Packit Service 102f81
        shift
Packit Service 102f81
        continue;;
Packit Service 102f81
Packit Service 102f81
    --help) echo "$usage"; exit $?;;
Packit Service 102f81
Packit Service 102f81
    -m) chmodcmd="$chmodprog $2"
Packit Service 102f81
        shift
Packit Service 102f81
        shift
Packit Service 102f81
        continue;;
Packit Service 102f81
Packit Service 102f81
    -o) chowncmd="$chownprog $2"
Packit Service 102f81
        shift
Packit Service 102f81
        shift
Packit Service 102f81
        continue;;
Packit Service 102f81
Packit Service 102f81
    -s) stripcmd=$stripprog
Packit Service 102f81
        shift
Packit Service 102f81
        continue;;
Packit Service 102f81
Packit Service 102f81
    -t) dstarg=$2
Packit Service 102f81
	shift
Packit Service 102f81
	shift
Packit Service 102f81
	continue;;
Packit Service 102f81
Packit Service 102f81
    -T) no_target_directory=true
Packit Service 102f81
	shift
Packit Service 102f81
	continue;;
Packit Service 102f81
Packit Service 102f81
    --version) echo "$0 $scriptversion"; exit $?;;
Packit Service 102f81
Packit Service 102f81
    *)  # When -d is used, all remaining arguments are directories to create.
Packit Service 102f81
	# When -t is used, the destination is already specified.
Packit Service 102f81
	test -n "$dir_arg$dstarg" && break
Packit Service 102f81
        # Otherwise, the last argument is the destination.  Remove it from $@.
Packit Service 102f81
	for arg
Packit Service 102f81
	do
Packit Service 102f81
          if test -n "$dstarg"; then
Packit Service 102f81
	    # $@ is not empty: it contains at least $arg.
Packit Service 102f81
	    set fnord "$@" "$dstarg"
Packit Service 102f81
	    shift # fnord
Packit Service 102f81
	  fi
Packit Service 102f81
	  shift # arg
Packit Service 102f81
	  dstarg=$arg
Packit Service 102f81
	done
Packit Service 102f81
	break;;
Packit Service 102f81
  esac
Packit Service 102f81
done
Packit Service 102f81
Packit Service 102f81
if test -z "$1"; then
Packit Service 102f81
  if test -z "$dir_arg"; then
Packit Service 102f81
    echo "$0: no input file specified." >&2
Packit Service 102f81
    exit 1
Packit Service 102f81
  fi
Packit Service 102f81
  # It's OK to call `install-sh -d' without argument.
Packit Service 102f81
  # This can happen when creating conditional directories.
Packit Service 102f81
  exit 0
Packit Service 102f81
fi
Packit Service 102f81
Packit Service 102f81
for src
Packit Service 102f81
do
Packit Service 102f81
  # Protect names starting with `-'.
Packit Service 102f81
  case $src in
Packit Service 102f81
    -*) src=./$src ;;
Packit Service 102f81
  esac
Packit Service 102f81
Packit Service 102f81
  if test -n "$dir_arg"; then
Packit Service 102f81
    dst=$src
Packit Service 102f81
    src=
Packit Service 102f81
Packit Service 102f81
    if test -d "$dst"; then
Packit Service 102f81
      mkdircmd=:
Packit Service 102f81
      chmodcmd=
Packit Service 102f81
    else
Packit Service 102f81
      mkdircmd=$mkdirprog
Packit Service 102f81
    fi
Packit Service 102f81
  else
Packit Service 102f81
    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
Packit Service 102f81
    # might cause directories to be created, which would be especially bad
Packit Service 102f81
    # if $src (and thus $dsttmp) contains '*'.
Packit Service 102f81
    if test ! -f "$src" && test ! -d "$src"; then
Packit Service 102f81
      echo "$0: $src does not exist." >&2
Packit Service 102f81
      exit 1
Packit Service 102f81
    fi
Packit Service 102f81
Packit Service 102f81
    if test -z "$dstarg"; then
Packit Service 102f81
      echo "$0: no destination specified." >&2
Packit Service 102f81
      exit 1
Packit Service 102f81
    fi
Packit Service 102f81
Packit Service 102f81
    dst=$dstarg
Packit Service 102f81
    # Protect names starting with `-'.
Packit Service 102f81
    case $dst in
Packit Service 102f81
      -*) dst=./$dst ;;
Packit Service 102f81
    esac
Packit Service 102f81
Packit Service 102f81
    # If destination is a directory, append the input filename; won't work
Packit Service 102f81
    # if double slashes aren't ignored.
Packit Service 102f81
    if test -d "$dst"; then
Packit Service 102f81
      if test -n "$no_target_directory"; then
Packit Service 102f81
	echo "$0: $dstarg: Is a directory" >&2
Packit Service 102f81
	exit 1
Packit Service 102f81
      fi
Packit Service 102f81
      dst=$dst/`basename "$src"`
Packit Service 102f81
    fi
Packit Service 102f81
  fi
Packit Service 102f81
Packit Service 102f81
  # This sed command emulates the dirname command.
Packit Service 102f81
  dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`
Packit Service 102f81
Packit Service 102f81
  # Make sure that the destination directory exists.
Packit Service 102f81
Packit Service 102f81
  # Skip lots of stat calls in the usual case.
Packit Service 102f81
  if test ! -d "$dstdir"; then
Packit Service 102f81
    defaultIFS='
Packit Service 102f81
	 '
Packit Service 102f81
    IFS="${IFS-$defaultIFS}"
Packit Service 102f81
Packit Service 102f81
    oIFS=$IFS
Packit Service 102f81
    # Some sh's can't handle IFS=/ for some reason.
Packit Service 102f81
    IFS='%'
Packit Service 102f81
    set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
Packit Service 102f81
    shift
Packit Service 102f81
    IFS=$oIFS
Packit Service 102f81
Packit Service 102f81
    pathcomp=
Packit Service 102f81
Packit Service 102f81
    while test $# -ne 0 ; do
Packit Service 102f81
      pathcomp=$pathcomp$1
Packit Service 102f81
      shift
Packit Service 102f81
      if test ! -d "$pathcomp"; then
Packit Service 102f81
        $mkdirprog "$pathcomp"
Packit Service 102f81
	# mkdir can fail with a `File exist' error in case several
Packit Service 102f81
	# install-sh are creating the directory concurrently.  This
Packit Service 102f81
	# is OK.
Packit Service 102f81
	test -d "$pathcomp" || exit
Packit Service 102f81
      fi
Packit Service 102f81
      pathcomp=$pathcomp/
Packit Service 102f81
    done
Packit Service 102f81
  fi
Packit Service 102f81
Packit Service 102f81
  if test -n "$dir_arg"; then
Packit Service 102f81
    $doit $mkdircmd "$dst" \
Packit Service 102f81
      && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
Packit Service 102f81
      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
Packit Service 102f81
      && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
Packit Service 102f81
      && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
Packit Service 102f81
Packit Service 102f81
  else
Packit Service 102f81
    dstfile=`basename "$dst"`
Packit Service 102f81
Packit Service 102f81
    # Make a couple of temp file names in the proper directory.
Packit Service 102f81
    dsttmp=$dstdir/_inst.$$_
Packit Service 102f81
    rmtmp=$dstdir/_rm.$$_
Packit Service 102f81
Packit Service 102f81
    # Trap to clean up those temp files at exit.
Packit Service 102f81
    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
Packit Service 102f81
    trap '(exit $?); exit' 1 2 13 15
Packit Service 102f81
Packit Service 102f81
    # Copy the file name to the temp name.
Packit Service 102f81
    $doit $cpprog "$src" "$dsttmp" &&
Packit Service 102f81
Packit Service 102f81
    # and set any options; do chmod last to preserve setuid bits.
Packit Service 102f81
    #
Packit Service 102f81
    # If any of these fail, we abort the whole thing.  If we want to
Packit Service 102f81
    # ignore errors from any of these, just make sure not to ignore
Packit Service 102f81
    # errors from the above "$doit $cpprog $src $dsttmp" command.
Packit Service 102f81
    #
Packit Service 102f81
    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
Packit Service 102f81
      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
Packit Service 102f81
      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
Packit Service 102f81
      && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
Packit Service 102f81
Packit Service 102f81
    # Now rename the file to the real destination.
Packit Service 102f81
    { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
Packit Service 102f81
      || {
Packit Service 102f81
	   # The rename failed, perhaps because mv can't rename something else
Packit Service 102f81
	   # to itself, or perhaps because mv is so ancient that it does not
Packit Service 102f81
	   # support -f.
Packit Service 102f81
Packit Service 102f81
	   # Now remove or move aside any old file at destination location.
Packit Service 102f81
	   # We try this two ways since rm can't unlink itself on some
Packit Service 102f81
	   # systems and the destination file might be busy for other
Packit Service 102f81
	   # reasons.  In this case, the final cleanup might fail but the new
Packit Service 102f81
	   # file should still install successfully.
Packit Service 102f81
	   {
Packit Service 102f81
	     if test -f "$dstdir/$dstfile"; then
Packit Service 102f81
	       $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
Packit Service 102f81
	       || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
Packit Service 102f81
	       || {
Packit Service 102f81
		 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
Packit Service 102f81
		 (exit 1); exit 1
Packit Service 102f81
	       }
Packit Service 102f81
	     else
Packit Service 102f81
	       :
Packit Service 102f81
	     fi
Packit Service 102f81
	   } &&
Packit Service 102f81
Packit Service 102f81
	   # Now rename the file to the real destination.
Packit Service 102f81
	   $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
Packit Service 102f81
	 }
Packit Service 102f81
    }
Packit Service 102f81
  fi || { (exit 1); exit 1; }
Packit Service 102f81
done
Packit Service 102f81
Packit Service 102f81
# The final little trick to "correctly" pass the exit status to the exit trap.
Packit Service 102f81
{
Packit Service 102f81
  (exit 0); exit 0
Packit Service 102f81
}
Packit Service 102f81
Packit Service 102f81
# Local variables:
Packit Service 102f81
# eval: (add-hook 'write-file-hooks 'time-stamp)
Packit Service 102f81
# time-stamp-start: "scriptversion="
Packit Service 102f81
# time-stamp-format: "%:y-%02m-%02d.%02H"
Packit Service 102f81
# time-stamp-end: "$"
Packit Service 102f81
# End: