Blame SOURCES/libsodium-1.0.18/build-aux/install-sh

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