xref: /third_party/node/deps/cares/install-sh (revision 1cb0ef41)
11cb0ef41Sopenharmony_ci#!/bin/sh
21cb0ef41Sopenharmony_ci# install - install a program, script, or datafile
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciscriptversion=2020-11-14.01; # UTC
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci# This originates from X11R5 (mit/util/scripts/install.sh), which was
71cb0ef41Sopenharmony_ci# later released in X11R6 (xc/config/util/install.sh) with the
81cb0ef41Sopenharmony_ci# following copyright and license.
91cb0ef41Sopenharmony_ci#
101cb0ef41Sopenharmony_ci# Copyright (C) 1994 X Consortium
111cb0ef41Sopenharmony_ci#
121cb0ef41Sopenharmony_ci# Permission is hereby granted, free of charge, to any person obtaining a copy
131cb0ef41Sopenharmony_ci# of this software and associated documentation files (the "Software"), to
141cb0ef41Sopenharmony_ci# deal in the Software without restriction, including without limitation the
151cb0ef41Sopenharmony_ci# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
161cb0ef41Sopenharmony_ci# sell copies of the Software, and to permit persons to whom the Software is
171cb0ef41Sopenharmony_ci# furnished to do so, subject to the following conditions:
181cb0ef41Sopenharmony_ci#
191cb0ef41Sopenharmony_ci# The above copyright notice and this permission notice shall be included in
201cb0ef41Sopenharmony_ci# all copies or substantial portions of the Software.
211cb0ef41Sopenharmony_ci#
221cb0ef41Sopenharmony_ci# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
231cb0ef41Sopenharmony_ci# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
241cb0ef41Sopenharmony_ci# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
251cb0ef41Sopenharmony_ci# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
261cb0ef41Sopenharmony_ci# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
271cb0ef41Sopenharmony_ci# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
281cb0ef41Sopenharmony_ci#
291cb0ef41Sopenharmony_ci# Except as contained in this notice, the name of the X Consortium shall not
301cb0ef41Sopenharmony_ci# be used in advertising or otherwise to promote the sale, use or other deal-
311cb0ef41Sopenharmony_ci# ings in this Software without prior written authorization from the X Consor-
321cb0ef41Sopenharmony_ci# tium.
331cb0ef41Sopenharmony_ci#
341cb0ef41Sopenharmony_ci#
351cb0ef41Sopenharmony_ci# FSF changes to this file are in the public domain.
361cb0ef41Sopenharmony_ci#
371cb0ef41Sopenharmony_ci# Calling this script install-sh is preferred over install.sh, to prevent
381cb0ef41Sopenharmony_ci# 'make' implicit rules from creating a file called install from it
391cb0ef41Sopenharmony_ci# when there is no Makefile.
401cb0ef41Sopenharmony_ci#
411cb0ef41Sopenharmony_ci# This script is compatible with the BSD install script, but was written
421cb0ef41Sopenharmony_ci# from scratch.
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_citab='	'
451cb0ef41Sopenharmony_cinl='
461cb0ef41Sopenharmony_ci'
471cb0ef41Sopenharmony_ciIFS=" $tab$nl"
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci# Set DOITPROG to "echo" to test this script.
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_cidoit=${DOITPROG-}
521cb0ef41Sopenharmony_cidoit_exec=${doit:-exec}
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci# Put in absolute file names if you don't have them in your path;
551cb0ef41Sopenharmony_ci# or use environment vars.
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_cichgrpprog=${CHGRPPROG-chgrp}
581cb0ef41Sopenharmony_cichmodprog=${CHMODPROG-chmod}
591cb0ef41Sopenharmony_cichownprog=${CHOWNPROG-chown}
601cb0ef41Sopenharmony_cicmpprog=${CMPPROG-cmp}
611cb0ef41Sopenharmony_cicpprog=${CPPROG-cp}
621cb0ef41Sopenharmony_cimkdirprog=${MKDIRPROG-mkdir}
631cb0ef41Sopenharmony_cimvprog=${MVPROG-mv}
641cb0ef41Sopenharmony_cirmprog=${RMPROG-rm}
651cb0ef41Sopenharmony_cistripprog=${STRIPPROG-strip}
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ciposix_mkdir=
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ci# Desired mode of installed file.
701cb0ef41Sopenharmony_cimode=0755
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci# Create dirs (including intermediate dirs) using mode 755.
731cb0ef41Sopenharmony_ci# This is like GNU 'install' as of coreutils 8.32 (2020).
741cb0ef41Sopenharmony_cimkdir_umask=22
751cb0ef41Sopenharmony_ci
761cb0ef41Sopenharmony_cibackupsuffix=
771cb0ef41Sopenharmony_cichgrpcmd=
781cb0ef41Sopenharmony_cichmodcmd=$chmodprog
791cb0ef41Sopenharmony_cichowncmd=
801cb0ef41Sopenharmony_cimvcmd=$mvprog
811cb0ef41Sopenharmony_cirmcmd="$rmprog -f"
821cb0ef41Sopenharmony_cistripcmd=
831cb0ef41Sopenharmony_ci
841cb0ef41Sopenharmony_cisrc=
851cb0ef41Sopenharmony_cidst=
861cb0ef41Sopenharmony_cidir_arg=
871cb0ef41Sopenharmony_cidst_arg=
881cb0ef41Sopenharmony_ci
891cb0ef41Sopenharmony_cicopy_on_change=false
901cb0ef41Sopenharmony_ciis_target_a_directory=possibly
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ciusage="\
931cb0ef41Sopenharmony_ciUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE
941cb0ef41Sopenharmony_ci   or: $0 [OPTION]... SRCFILES... DIRECTORY
951cb0ef41Sopenharmony_ci   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
961cb0ef41Sopenharmony_ci   or: $0 [OPTION]... -d DIRECTORIES...
971cb0ef41Sopenharmony_ci
981cb0ef41Sopenharmony_ciIn the 1st form, copy SRCFILE to DSTFILE.
991cb0ef41Sopenharmony_ciIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
1001cb0ef41Sopenharmony_ciIn the 4th, create DIRECTORIES.
1011cb0ef41Sopenharmony_ci
1021cb0ef41Sopenharmony_ciOptions:
1031cb0ef41Sopenharmony_ci     --help     display this help and exit.
1041cb0ef41Sopenharmony_ci     --version  display version info and exit.
1051cb0ef41Sopenharmony_ci
1061cb0ef41Sopenharmony_ci  -c            (ignored)
1071cb0ef41Sopenharmony_ci  -C            install only if different (preserve data modification time)
1081cb0ef41Sopenharmony_ci  -d            create directories instead of installing files.
1091cb0ef41Sopenharmony_ci  -g GROUP      $chgrpprog installed files to GROUP.
1101cb0ef41Sopenharmony_ci  -m MODE       $chmodprog installed files to MODE.
1111cb0ef41Sopenharmony_ci  -o USER       $chownprog installed files to USER.
1121cb0ef41Sopenharmony_ci  -p            pass -p to $cpprog.
1131cb0ef41Sopenharmony_ci  -s            $stripprog installed files.
1141cb0ef41Sopenharmony_ci  -S SUFFIX     attempt to back up existing files, with suffix SUFFIX.
1151cb0ef41Sopenharmony_ci  -t DIRECTORY  install into DIRECTORY.
1161cb0ef41Sopenharmony_ci  -T            report an error if DSTFILE is a directory.
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ciEnvironment variables override the default commands:
1191cb0ef41Sopenharmony_ci  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
1201cb0ef41Sopenharmony_ci  RMPROG STRIPPROG
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ciBy default, rm is invoked with -f; when overridden with RMPROG,
1231cb0ef41Sopenharmony_ciit's up to you to specify -f if you want it.
1241cb0ef41Sopenharmony_ci
1251cb0ef41Sopenharmony_ciIf -S is not specified, no backups are attempted.
1261cb0ef41Sopenharmony_ci
1271cb0ef41Sopenharmony_ciEmail bug reports to bug-automake@gnu.org.
1281cb0ef41Sopenharmony_ciAutomake home page: https://www.gnu.org/software/automake/
1291cb0ef41Sopenharmony_ci"
1301cb0ef41Sopenharmony_ci
1311cb0ef41Sopenharmony_ciwhile test $# -ne 0; do
1321cb0ef41Sopenharmony_ci  case $1 in
1331cb0ef41Sopenharmony_ci    -c) ;;
1341cb0ef41Sopenharmony_ci
1351cb0ef41Sopenharmony_ci    -C) copy_on_change=true;;
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ci    -d) dir_arg=true;;
1381cb0ef41Sopenharmony_ci
1391cb0ef41Sopenharmony_ci    -g) chgrpcmd="$chgrpprog $2"
1401cb0ef41Sopenharmony_ci        shift;;
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_ci    --help) echo "$usage"; exit $?;;
1431cb0ef41Sopenharmony_ci
1441cb0ef41Sopenharmony_ci    -m) mode=$2
1451cb0ef41Sopenharmony_ci        case $mode in
1461cb0ef41Sopenharmony_ci          *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*)
1471cb0ef41Sopenharmony_ci            echo "$0: invalid mode: $mode" >&2
1481cb0ef41Sopenharmony_ci            exit 1;;
1491cb0ef41Sopenharmony_ci        esac
1501cb0ef41Sopenharmony_ci        shift;;
1511cb0ef41Sopenharmony_ci
1521cb0ef41Sopenharmony_ci    -o) chowncmd="$chownprog $2"
1531cb0ef41Sopenharmony_ci        shift;;
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ci    -p) cpprog="$cpprog -p";;
1561cb0ef41Sopenharmony_ci
1571cb0ef41Sopenharmony_ci    -s) stripcmd=$stripprog;;
1581cb0ef41Sopenharmony_ci
1591cb0ef41Sopenharmony_ci    -S) backupsuffix="$2"
1601cb0ef41Sopenharmony_ci        shift;;
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_ci    -t)
1631cb0ef41Sopenharmony_ci        is_target_a_directory=always
1641cb0ef41Sopenharmony_ci        dst_arg=$2
1651cb0ef41Sopenharmony_ci        # Protect names problematic for 'test' and other utilities.
1661cb0ef41Sopenharmony_ci        case $dst_arg in
1671cb0ef41Sopenharmony_ci          -* | [=\(\)!]) dst_arg=./$dst_arg;;
1681cb0ef41Sopenharmony_ci        esac
1691cb0ef41Sopenharmony_ci        shift;;
1701cb0ef41Sopenharmony_ci
1711cb0ef41Sopenharmony_ci    -T) is_target_a_directory=never;;
1721cb0ef41Sopenharmony_ci
1731cb0ef41Sopenharmony_ci    --version) echo "$0 $scriptversion"; exit $?;;
1741cb0ef41Sopenharmony_ci
1751cb0ef41Sopenharmony_ci    --) shift
1761cb0ef41Sopenharmony_ci        break;;
1771cb0ef41Sopenharmony_ci
1781cb0ef41Sopenharmony_ci    -*) echo "$0: invalid option: $1" >&2
1791cb0ef41Sopenharmony_ci        exit 1;;
1801cb0ef41Sopenharmony_ci
1811cb0ef41Sopenharmony_ci    *)  break;;
1821cb0ef41Sopenharmony_ci  esac
1831cb0ef41Sopenharmony_ci  shift
1841cb0ef41Sopenharmony_cidone
1851cb0ef41Sopenharmony_ci
1861cb0ef41Sopenharmony_ci# We allow the use of options -d and -T together, by making -d
1871cb0ef41Sopenharmony_ci# take the precedence; this is for compatibility with GNU install.
1881cb0ef41Sopenharmony_ci
1891cb0ef41Sopenharmony_ciif test -n "$dir_arg"; then
1901cb0ef41Sopenharmony_ci  if test -n "$dst_arg"; then
1911cb0ef41Sopenharmony_ci    echo "$0: target directory not allowed when installing a directory." >&2
1921cb0ef41Sopenharmony_ci    exit 1
1931cb0ef41Sopenharmony_ci  fi
1941cb0ef41Sopenharmony_cifi
1951cb0ef41Sopenharmony_ci
1961cb0ef41Sopenharmony_ciif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
1971cb0ef41Sopenharmony_ci  # When -d is used, all remaining arguments are directories to create.
1981cb0ef41Sopenharmony_ci  # When -t is used, the destination is already specified.
1991cb0ef41Sopenharmony_ci  # Otherwise, the last argument is the destination.  Remove it from $@.
2001cb0ef41Sopenharmony_ci  for arg
2011cb0ef41Sopenharmony_ci  do
2021cb0ef41Sopenharmony_ci    if test -n "$dst_arg"; then
2031cb0ef41Sopenharmony_ci      # $@ is not empty: it contains at least $arg.
2041cb0ef41Sopenharmony_ci      set fnord "$@" "$dst_arg"
2051cb0ef41Sopenharmony_ci      shift # fnord
2061cb0ef41Sopenharmony_ci    fi
2071cb0ef41Sopenharmony_ci    shift # arg
2081cb0ef41Sopenharmony_ci    dst_arg=$arg
2091cb0ef41Sopenharmony_ci    # Protect names problematic for 'test' and other utilities.
2101cb0ef41Sopenharmony_ci    case $dst_arg in
2111cb0ef41Sopenharmony_ci      -* | [=\(\)!]) dst_arg=./$dst_arg;;
2121cb0ef41Sopenharmony_ci    esac
2131cb0ef41Sopenharmony_ci  done
2141cb0ef41Sopenharmony_cifi
2151cb0ef41Sopenharmony_ci
2161cb0ef41Sopenharmony_ciif test $# -eq 0; then
2171cb0ef41Sopenharmony_ci  if test -z "$dir_arg"; then
2181cb0ef41Sopenharmony_ci    echo "$0: no input file specified." >&2
2191cb0ef41Sopenharmony_ci    exit 1
2201cb0ef41Sopenharmony_ci  fi
2211cb0ef41Sopenharmony_ci  # It's OK to call 'install-sh -d' without argument.
2221cb0ef41Sopenharmony_ci  # This can happen when creating conditional directories.
2231cb0ef41Sopenharmony_ci  exit 0
2241cb0ef41Sopenharmony_cifi
2251cb0ef41Sopenharmony_ci
2261cb0ef41Sopenharmony_ciif test -z "$dir_arg"; then
2271cb0ef41Sopenharmony_ci  if test $# -gt 1 || test "$is_target_a_directory" = always; then
2281cb0ef41Sopenharmony_ci    if test ! -d "$dst_arg"; then
2291cb0ef41Sopenharmony_ci      echo "$0: $dst_arg: Is not a directory." >&2
2301cb0ef41Sopenharmony_ci      exit 1
2311cb0ef41Sopenharmony_ci    fi
2321cb0ef41Sopenharmony_ci  fi
2331cb0ef41Sopenharmony_cifi
2341cb0ef41Sopenharmony_ci
2351cb0ef41Sopenharmony_ciif test -z "$dir_arg"; then
2361cb0ef41Sopenharmony_ci  do_exit='(exit $ret); exit $ret'
2371cb0ef41Sopenharmony_ci  trap "ret=129; $do_exit" 1
2381cb0ef41Sopenharmony_ci  trap "ret=130; $do_exit" 2
2391cb0ef41Sopenharmony_ci  trap "ret=141; $do_exit" 13
2401cb0ef41Sopenharmony_ci  trap "ret=143; $do_exit" 15
2411cb0ef41Sopenharmony_ci
2421cb0ef41Sopenharmony_ci  # Set umask so as not to create temps with too-generous modes.
2431cb0ef41Sopenharmony_ci  # However, 'strip' requires both read and write access to temps.
2441cb0ef41Sopenharmony_ci  case $mode in
2451cb0ef41Sopenharmony_ci    # Optimize common cases.
2461cb0ef41Sopenharmony_ci    *644) cp_umask=133;;
2471cb0ef41Sopenharmony_ci    *755) cp_umask=22;;
2481cb0ef41Sopenharmony_ci
2491cb0ef41Sopenharmony_ci    *[0-7])
2501cb0ef41Sopenharmony_ci      if test -z "$stripcmd"; then
2511cb0ef41Sopenharmony_ci        u_plus_rw=
2521cb0ef41Sopenharmony_ci      else
2531cb0ef41Sopenharmony_ci        u_plus_rw='% 200'
2541cb0ef41Sopenharmony_ci      fi
2551cb0ef41Sopenharmony_ci      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
2561cb0ef41Sopenharmony_ci    *)
2571cb0ef41Sopenharmony_ci      if test -z "$stripcmd"; then
2581cb0ef41Sopenharmony_ci        u_plus_rw=
2591cb0ef41Sopenharmony_ci      else
2601cb0ef41Sopenharmony_ci        u_plus_rw=,u+rw
2611cb0ef41Sopenharmony_ci      fi
2621cb0ef41Sopenharmony_ci      cp_umask=$mode$u_plus_rw;;
2631cb0ef41Sopenharmony_ci  esac
2641cb0ef41Sopenharmony_cifi
2651cb0ef41Sopenharmony_ci
2661cb0ef41Sopenharmony_cifor src
2671cb0ef41Sopenharmony_cido
2681cb0ef41Sopenharmony_ci  # Protect names problematic for 'test' and other utilities.
2691cb0ef41Sopenharmony_ci  case $src in
2701cb0ef41Sopenharmony_ci    -* | [=\(\)!]) src=./$src;;
2711cb0ef41Sopenharmony_ci  esac
2721cb0ef41Sopenharmony_ci
2731cb0ef41Sopenharmony_ci  if test -n "$dir_arg"; then
2741cb0ef41Sopenharmony_ci    dst=$src
2751cb0ef41Sopenharmony_ci    dstdir=$dst
2761cb0ef41Sopenharmony_ci    test -d "$dstdir"
2771cb0ef41Sopenharmony_ci    dstdir_status=$?
2781cb0ef41Sopenharmony_ci    # Don't chown directories that already exist.
2791cb0ef41Sopenharmony_ci    if test $dstdir_status = 0; then
2801cb0ef41Sopenharmony_ci      chowncmd=""
2811cb0ef41Sopenharmony_ci    fi
2821cb0ef41Sopenharmony_ci  else
2831cb0ef41Sopenharmony_ci
2841cb0ef41Sopenharmony_ci    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
2851cb0ef41Sopenharmony_ci    # might cause directories to be created, which would be especially bad
2861cb0ef41Sopenharmony_ci    # if $src (and thus $dsttmp) contains '*'.
2871cb0ef41Sopenharmony_ci    if test ! -f "$src" && test ! -d "$src"; then
2881cb0ef41Sopenharmony_ci      echo "$0: $src does not exist." >&2
2891cb0ef41Sopenharmony_ci      exit 1
2901cb0ef41Sopenharmony_ci    fi
2911cb0ef41Sopenharmony_ci
2921cb0ef41Sopenharmony_ci    if test -z "$dst_arg"; then
2931cb0ef41Sopenharmony_ci      echo "$0: no destination specified." >&2
2941cb0ef41Sopenharmony_ci      exit 1
2951cb0ef41Sopenharmony_ci    fi
2961cb0ef41Sopenharmony_ci    dst=$dst_arg
2971cb0ef41Sopenharmony_ci
2981cb0ef41Sopenharmony_ci    # If destination is a directory, append the input filename.
2991cb0ef41Sopenharmony_ci    if test -d "$dst"; then
3001cb0ef41Sopenharmony_ci      if test "$is_target_a_directory" = never; then
3011cb0ef41Sopenharmony_ci        echo "$0: $dst_arg: Is a directory" >&2
3021cb0ef41Sopenharmony_ci        exit 1
3031cb0ef41Sopenharmony_ci      fi
3041cb0ef41Sopenharmony_ci      dstdir=$dst
3051cb0ef41Sopenharmony_ci      dstbase=`basename "$src"`
3061cb0ef41Sopenharmony_ci      case $dst in
3071cb0ef41Sopenharmony_ci	*/) dst=$dst$dstbase;;
3081cb0ef41Sopenharmony_ci	*)  dst=$dst/$dstbase;;
3091cb0ef41Sopenharmony_ci      esac
3101cb0ef41Sopenharmony_ci      dstdir_status=0
3111cb0ef41Sopenharmony_ci    else
3121cb0ef41Sopenharmony_ci      dstdir=`dirname "$dst"`
3131cb0ef41Sopenharmony_ci      test -d "$dstdir"
3141cb0ef41Sopenharmony_ci      dstdir_status=$?
3151cb0ef41Sopenharmony_ci    fi
3161cb0ef41Sopenharmony_ci  fi
3171cb0ef41Sopenharmony_ci
3181cb0ef41Sopenharmony_ci  case $dstdir in
3191cb0ef41Sopenharmony_ci    */) dstdirslash=$dstdir;;
3201cb0ef41Sopenharmony_ci    *)  dstdirslash=$dstdir/;;
3211cb0ef41Sopenharmony_ci  esac
3221cb0ef41Sopenharmony_ci
3231cb0ef41Sopenharmony_ci  obsolete_mkdir_used=false
3241cb0ef41Sopenharmony_ci
3251cb0ef41Sopenharmony_ci  if test $dstdir_status != 0; then
3261cb0ef41Sopenharmony_ci    case $posix_mkdir in
3271cb0ef41Sopenharmony_ci      '')
3281cb0ef41Sopenharmony_ci        # With -d, create the new directory with the user-specified mode.
3291cb0ef41Sopenharmony_ci        # Otherwise, rely on $mkdir_umask.
3301cb0ef41Sopenharmony_ci        if test -n "$dir_arg"; then
3311cb0ef41Sopenharmony_ci          mkdir_mode=-m$mode
3321cb0ef41Sopenharmony_ci        else
3331cb0ef41Sopenharmony_ci          mkdir_mode=
3341cb0ef41Sopenharmony_ci        fi
3351cb0ef41Sopenharmony_ci
3361cb0ef41Sopenharmony_ci        posix_mkdir=false
3371cb0ef41Sopenharmony_ci	# The $RANDOM variable is not portable (e.g., dash).  Use it
3381cb0ef41Sopenharmony_ci	# here however when possible just to lower collision chance.
3391cb0ef41Sopenharmony_ci	tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
3401cb0ef41Sopenharmony_ci
3411cb0ef41Sopenharmony_ci	trap '
3421cb0ef41Sopenharmony_ci	  ret=$?
3431cb0ef41Sopenharmony_ci	  rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null
3441cb0ef41Sopenharmony_ci	  exit $ret
3451cb0ef41Sopenharmony_ci	' 0
3461cb0ef41Sopenharmony_ci
3471cb0ef41Sopenharmony_ci	# Because "mkdir -p" follows existing symlinks and we likely work
3481cb0ef41Sopenharmony_ci	# directly in world-writeable /tmp, make sure that the '$tmpdir'
3491cb0ef41Sopenharmony_ci	# directory is successfully created first before we actually test
3501cb0ef41Sopenharmony_ci	# 'mkdir -p'.
3511cb0ef41Sopenharmony_ci	if (umask $mkdir_umask &&
3521cb0ef41Sopenharmony_ci	    $mkdirprog $mkdir_mode "$tmpdir" &&
3531cb0ef41Sopenharmony_ci	    exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
3541cb0ef41Sopenharmony_ci	then
3551cb0ef41Sopenharmony_ci	  if test -z "$dir_arg" || {
3561cb0ef41Sopenharmony_ci	       # Check for POSIX incompatibilities with -m.
3571cb0ef41Sopenharmony_ci	       # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
3581cb0ef41Sopenharmony_ci	       # other-writable bit of parent directory when it shouldn't.
3591cb0ef41Sopenharmony_ci	       # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
3601cb0ef41Sopenharmony_ci	       test_tmpdir="$tmpdir/a"
3611cb0ef41Sopenharmony_ci	       ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
3621cb0ef41Sopenharmony_ci	       case $ls_ld_tmpdir in
3631cb0ef41Sopenharmony_ci		 d????-?r-*) different_mode=700;;
3641cb0ef41Sopenharmony_ci		 d????-?--*) different_mode=755;;
3651cb0ef41Sopenharmony_ci		 *) false;;
3661cb0ef41Sopenharmony_ci	       esac &&
3671cb0ef41Sopenharmony_ci	       $mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
3681cb0ef41Sopenharmony_ci		 ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
3691cb0ef41Sopenharmony_ci		 test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
3701cb0ef41Sopenharmony_ci	       }
3711cb0ef41Sopenharmony_ci	     }
3721cb0ef41Sopenharmony_ci	  then posix_mkdir=:
3731cb0ef41Sopenharmony_ci	  fi
3741cb0ef41Sopenharmony_ci	  rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
3751cb0ef41Sopenharmony_ci	else
3761cb0ef41Sopenharmony_ci	  # Remove any dirs left behind by ancient mkdir implementations.
3771cb0ef41Sopenharmony_ci	  rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
3781cb0ef41Sopenharmony_ci	fi
3791cb0ef41Sopenharmony_ci	trap '' 0;;
3801cb0ef41Sopenharmony_ci    esac
3811cb0ef41Sopenharmony_ci
3821cb0ef41Sopenharmony_ci    if
3831cb0ef41Sopenharmony_ci      $posix_mkdir && (
3841cb0ef41Sopenharmony_ci        umask $mkdir_umask &&
3851cb0ef41Sopenharmony_ci        $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
3861cb0ef41Sopenharmony_ci      )
3871cb0ef41Sopenharmony_ci    then :
3881cb0ef41Sopenharmony_ci    else
3891cb0ef41Sopenharmony_ci
3901cb0ef41Sopenharmony_ci      # mkdir does not conform to POSIX,
3911cb0ef41Sopenharmony_ci      # or it failed possibly due to a race condition.  Create the
3921cb0ef41Sopenharmony_ci      # directory the slow way, step by step, checking for races as we go.
3931cb0ef41Sopenharmony_ci
3941cb0ef41Sopenharmony_ci      case $dstdir in
3951cb0ef41Sopenharmony_ci        /*) prefix='/';;
3961cb0ef41Sopenharmony_ci        [-=\(\)!]*) prefix='./';;
3971cb0ef41Sopenharmony_ci        *)  prefix='';;
3981cb0ef41Sopenharmony_ci      esac
3991cb0ef41Sopenharmony_ci
4001cb0ef41Sopenharmony_ci      oIFS=$IFS
4011cb0ef41Sopenharmony_ci      IFS=/
4021cb0ef41Sopenharmony_ci      set -f
4031cb0ef41Sopenharmony_ci      set fnord $dstdir
4041cb0ef41Sopenharmony_ci      shift
4051cb0ef41Sopenharmony_ci      set +f
4061cb0ef41Sopenharmony_ci      IFS=$oIFS
4071cb0ef41Sopenharmony_ci
4081cb0ef41Sopenharmony_ci      prefixes=
4091cb0ef41Sopenharmony_ci
4101cb0ef41Sopenharmony_ci      for d
4111cb0ef41Sopenharmony_ci      do
4121cb0ef41Sopenharmony_ci        test X"$d" = X && continue
4131cb0ef41Sopenharmony_ci
4141cb0ef41Sopenharmony_ci        prefix=$prefix$d
4151cb0ef41Sopenharmony_ci        if test -d "$prefix"; then
4161cb0ef41Sopenharmony_ci          prefixes=
4171cb0ef41Sopenharmony_ci        else
4181cb0ef41Sopenharmony_ci          if $posix_mkdir; then
4191cb0ef41Sopenharmony_ci            (umask $mkdir_umask &&
4201cb0ef41Sopenharmony_ci             $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
4211cb0ef41Sopenharmony_ci            # Don't fail if two instances are running concurrently.
4221cb0ef41Sopenharmony_ci            test -d "$prefix" || exit 1
4231cb0ef41Sopenharmony_ci          else
4241cb0ef41Sopenharmony_ci            case $prefix in
4251cb0ef41Sopenharmony_ci              *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
4261cb0ef41Sopenharmony_ci              *) qprefix=$prefix;;
4271cb0ef41Sopenharmony_ci            esac
4281cb0ef41Sopenharmony_ci            prefixes="$prefixes '$qprefix'"
4291cb0ef41Sopenharmony_ci          fi
4301cb0ef41Sopenharmony_ci        fi
4311cb0ef41Sopenharmony_ci        prefix=$prefix/
4321cb0ef41Sopenharmony_ci      done
4331cb0ef41Sopenharmony_ci
4341cb0ef41Sopenharmony_ci      if test -n "$prefixes"; then
4351cb0ef41Sopenharmony_ci        # Don't fail if two instances are running concurrently.
4361cb0ef41Sopenharmony_ci        (umask $mkdir_umask &&
4371cb0ef41Sopenharmony_ci         eval "\$doit_exec \$mkdirprog $prefixes") ||
4381cb0ef41Sopenharmony_ci          test -d "$dstdir" || exit 1
4391cb0ef41Sopenharmony_ci        obsolete_mkdir_used=true
4401cb0ef41Sopenharmony_ci      fi
4411cb0ef41Sopenharmony_ci    fi
4421cb0ef41Sopenharmony_ci  fi
4431cb0ef41Sopenharmony_ci
4441cb0ef41Sopenharmony_ci  if test -n "$dir_arg"; then
4451cb0ef41Sopenharmony_ci    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
4461cb0ef41Sopenharmony_ci    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
4471cb0ef41Sopenharmony_ci    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
4481cb0ef41Sopenharmony_ci      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
4491cb0ef41Sopenharmony_ci  else
4501cb0ef41Sopenharmony_ci
4511cb0ef41Sopenharmony_ci    # Make a couple of temp file names in the proper directory.
4521cb0ef41Sopenharmony_ci    dsttmp=${dstdirslash}_inst.$$_
4531cb0ef41Sopenharmony_ci    rmtmp=${dstdirslash}_rm.$$_
4541cb0ef41Sopenharmony_ci
4551cb0ef41Sopenharmony_ci    # Trap to clean up those temp files at exit.
4561cb0ef41Sopenharmony_ci    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
4571cb0ef41Sopenharmony_ci
4581cb0ef41Sopenharmony_ci    # Copy the file name to the temp name.
4591cb0ef41Sopenharmony_ci    (umask $cp_umask &&
4601cb0ef41Sopenharmony_ci     { test -z "$stripcmd" || {
4611cb0ef41Sopenharmony_ci	 # Create $dsttmp read-write so that cp doesn't create it read-only,
4621cb0ef41Sopenharmony_ci	 # which would cause strip to fail.
4631cb0ef41Sopenharmony_ci	 if test -z "$doit"; then
4641cb0ef41Sopenharmony_ci	   : >"$dsttmp" # No need to fork-exec 'touch'.
4651cb0ef41Sopenharmony_ci	 else
4661cb0ef41Sopenharmony_ci	   $doit touch "$dsttmp"
4671cb0ef41Sopenharmony_ci	 fi
4681cb0ef41Sopenharmony_ci       }
4691cb0ef41Sopenharmony_ci     } &&
4701cb0ef41Sopenharmony_ci     $doit_exec $cpprog "$src" "$dsttmp") &&
4711cb0ef41Sopenharmony_ci
4721cb0ef41Sopenharmony_ci    # and set any options; do chmod last to preserve setuid bits.
4731cb0ef41Sopenharmony_ci    #
4741cb0ef41Sopenharmony_ci    # If any of these fail, we abort the whole thing.  If we want to
4751cb0ef41Sopenharmony_ci    # ignore errors from any of these, just make sure not to ignore
4761cb0ef41Sopenharmony_ci    # errors from the above "$doit $cpprog $src $dsttmp" command.
4771cb0ef41Sopenharmony_ci    #
4781cb0ef41Sopenharmony_ci    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
4791cb0ef41Sopenharmony_ci    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
4801cb0ef41Sopenharmony_ci    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
4811cb0ef41Sopenharmony_ci    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
4821cb0ef41Sopenharmony_ci
4831cb0ef41Sopenharmony_ci    # If -C, don't bother to copy if it wouldn't change the file.
4841cb0ef41Sopenharmony_ci    if $copy_on_change &&
4851cb0ef41Sopenharmony_ci       old=`LC_ALL=C ls -dlL "$dst"     2>/dev/null` &&
4861cb0ef41Sopenharmony_ci       new=`LC_ALL=C ls -dlL "$dsttmp"  2>/dev/null` &&
4871cb0ef41Sopenharmony_ci       set -f &&
4881cb0ef41Sopenharmony_ci       set X $old && old=:$2:$4:$5:$6 &&
4891cb0ef41Sopenharmony_ci       set X $new && new=:$2:$4:$5:$6 &&
4901cb0ef41Sopenharmony_ci       set +f &&
4911cb0ef41Sopenharmony_ci       test "$old" = "$new" &&
4921cb0ef41Sopenharmony_ci       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
4931cb0ef41Sopenharmony_ci    then
4941cb0ef41Sopenharmony_ci      rm -f "$dsttmp"
4951cb0ef41Sopenharmony_ci    else
4961cb0ef41Sopenharmony_ci      # If $backupsuffix is set, and the file being installed
4971cb0ef41Sopenharmony_ci      # already exists, attempt a backup.  Don't worry if it fails,
4981cb0ef41Sopenharmony_ci      # e.g., if mv doesn't support -f.
4991cb0ef41Sopenharmony_ci      if test -n "$backupsuffix" && test -f "$dst"; then
5001cb0ef41Sopenharmony_ci        $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null
5011cb0ef41Sopenharmony_ci      fi
5021cb0ef41Sopenharmony_ci
5031cb0ef41Sopenharmony_ci      # Rename the file to the real destination.
5041cb0ef41Sopenharmony_ci      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
5051cb0ef41Sopenharmony_ci
5061cb0ef41Sopenharmony_ci      # The rename failed, perhaps because mv can't rename something else
5071cb0ef41Sopenharmony_ci      # to itself, or perhaps because mv is so ancient that it does not
5081cb0ef41Sopenharmony_ci      # support -f.
5091cb0ef41Sopenharmony_ci      {
5101cb0ef41Sopenharmony_ci        # Now remove or move aside any old file at destination location.
5111cb0ef41Sopenharmony_ci        # We try this two ways since rm can't unlink itself on some
5121cb0ef41Sopenharmony_ci        # systems and the destination file might be busy for other
5131cb0ef41Sopenharmony_ci        # reasons.  In this case, the final cleanup might fail but the new
5141cb0ef41Sopenharmony_ci        # file should still install successfully.
5151cb0ef41Sopenharmony_ci        {
5161cb0ef41Sopenharmony_ci          test ! -f "$dst" ||
5171cb0ef41Sopenharmony_ci          $doit $rmcmd "$dst" 2>/dev/null ||
5181cb0ef41Sopenharmony_ci          { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
5191cb0ef41Sopenharmony_ci            { $doit $rmcmd "$rmtmp" 2>/dev/null; :; }
5201cb0ef41Sopenharmony_ci          } ||
5211cb0ef41Sopenharmony_ci          { echo "$0: cannot unlink or rename $dst" >&2
5221cb0ef41Sopenharmony_ci            (exit 1); exit 1
5231cb0ef41Sopenharmony_ci          }
5241cb0ef41Sopenharmony_ci        } &&
5251cb0ef41Sopenharmony_ci
5261cb0ef41Sopenharmony_ci        # Now rename the file to the real destination.
5271cb0ef41Sopenharmony_ci        $doit $mvcmd "$dsttmp" "$dst"
5281cb0ef41Sopenharmony_ci      }
5291cb0ef41Sopenharmony_ci    fi || exit 1
5301cb0ef41Sopenharmony_ci
5311cb0ef41Sopenharmony_ci    trap '' 0
5321cb0ef41Sopenharmony_ci  fi
5331cb0ef41Sopenharmony_cidone
5341cb0ef41Sopenharmony_ci
5351cb0ef41Sopenharmony_ci# Local variables:
5361cb0ef41Sopenharmony_ci# eval: (add-hook 'before-save-hook 'time-stamp)
5371cb0ef41Sopenharmony_ci# time-stamp-start: "scriptversion="
5381cb0ef41Sopenharmony_ci# time-stamp-format: "%:y-%02m-%02d.%02H"
5391cb0ef41Sopenharmony_ci# time-stamp-time-zone: "UTC0"
5401cb0ef41Sopenharmony_ci# time-stamp-end: "; # UTC"
5411cb0ef41Sopenharmony_ci# End:
542