1159b3361Sopenharmony_ci#!/bin/sh
2159b3361Sopenharmony_ci# install - install a program, script, or datafile
3159b3361Sopenharmony_ci
4159b3361Sopenharmony_ciscriptversion=2018-03-11.20; # UTC
5159b3361Sopenharmony_ci
6159b3361Sopenharmony_ci# This originates from X11R5 (mit/util/scripts/install.sh), which was
7159b3361Sopenharmony_ci# later released in X11R6 (xc/config/util/install.sh) with the
8159b3361Sopenharmony_ci# following copyright and license.
9159b3361Sopenharmony_ci#
10159b3361Sopenharmony_ci# Copyright (C) 1994 X Consortium
11159b3361Sopenharmony_ci#
12159b3361Sopenharmony_ci# Permission is hereby granted, free of charge, to any person obtaining a copy
13159b3361Sopenharmony_ci# of this software and associated documentation files (the "Software"), to
14159b3361Sopenharmony_ci# deal in the Software without restriction, including without limitation the
15159b3361Sopenharmony_ci# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16159b3361Sopenharmony_ci# sell copies of the Software, and to permit persons to whom the Software is
17159b3361Sopenharmony_ci# furnished to do so, subject to the following conditions:
18159b3361Sopenharmony_ci#
19159b3361Sopenharmony_ci# The above copyright notice and this permission notice shall be included in
20159b3361Sopenharmony_ci# all copies or substantial portions of the Software.
21159b3361Sopenharmony_ci#
22159b3361Sopenharmony_ci# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23159b3361Sopenharmony_ci# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24159b3361Sopenharmony_ci# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
25159b3361Sopenharmony_ci# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26159b3361Sopenharmony_ci# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
27159b3361Sopenharmony_ci# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28159b3361Sopenharmony_ci#
29159b3361Sopenharmony_ci# Except as contained in this notice, the name of the X Consortium shall not
30159b3361Sopenharmony_ci# be used in advertising or otherwise to promote the sale, use or other deal-
31159b3361Sopenharmony_ci# ings in this Software without prior written authorization from the X Consor-
32159b3361Sopenharmony_ci# tium.
33159b3361Sopenharmony_ci#
34159b3361Sopenharmony_ci#
35159b3361Sopenharmony_ci# FSF changes to this file are in the public domain.
36159b3361Sopenharmony_ci#
37159b3361Sopenharmony_ci# Calling this script install-sh is preferred over install.sh, to prevent
38159b3361Sopenharmony_ci# 'make' implicit rules from creating a file called install from it
39159b3361Sopenharmony_ci# when there is no Makefile.
40159b3361Sopenharmony_ci#
41159b3361Sopenharmony_ci# This script is compatible with the BSD install script, but was written
42159b3361Sopenharmony_ci# from scratch.
43159b3361Sopenharmony_ci
44159b3361Sopenharmony_citab='	'
45159b3361Sopenharmony_cinl='
46159b3361Sopenharmony_ci'
47159b3361Sopenharmony_ciIFS=" $tab$nl"
48159b3361Sopenharmony_ci
49159b3361Sopenharmony_ci# Set DOITPROG to "echo" to test this script.
50159b3361Sopenharmony_ci
51159b3361Sopenharmony_cidoit=${DOITPROG-}
52159b3361Sopenharmony_cidoit_exec=${doit:-exec}
53159b3361Sopenharmony_ci
54159b3361Sopenharmony_ci# Put in absolute file names if you don't have them in your path;
55159b3361Sopenharmony_ci# or use environment vars.
56159b3361Sopenharmony_ci
57159b3361Sopenharmony_cichgrpprog=${CHGRPPROG-chgrp}
58159b3361Sopenharmony_cichmodprog=${CHMODPROG-chmod}
59159b3361Sopenharmony_cichownprog=${CHOWNPROG-chown}
60159b3361Sopenharmony_cicmpprog=${CMPPROG-cmp}
61159b3361Sopenharmony_cicpprog=${CPPROG-cp}
62159b3361Sopenharmony_cimkdirprog=${MKDIRPROG-mkdir}
63159b3361Sopenharmony_cimvprog=${MVPROG-mv}
64159b3361Sopenharmony_cirmprog=${RMPROG-rm}
65159b3361Sopenharmony_cistripprog=${STRIPPROG-strip}
66159b3361Sopenharmony_ci
67159b3361Sopenharmony_ciposix_mkdir=
68159b3361Sopenharmony_ci
69159b3361Sopenharmony_ci# Desired mode of installed file.
70159b3361Sopenharmony_cimode=0755
71159b3361Sopenharmony_ci
72159b3361Sopenharmony_cichgrpcmd=
73159b3361Sopenharmony_cichmodcmd=$chmodprog
74159b3361Sopenharmony_cichowncmd=
75159b3361Sopenharmony_cimvcmd=$mvprog
76159b3361Sopenharmony_cirmcmd="$rmprog -f"
77159b3361Sopenharmony_cistripcmd=
78159b3361Sopenharmony_ci
79159b3361Sopenharmony_cisrc=
80159b3361Sopenharmony_cidst=
81159b3361Sopenharmony_cidir_arg=
82159b3361Sopenharmony_cidst_arg=
83159b3361Sopenharmony_ci
84159b3361Sopenharmony_cicopy_on_change=false
85159b3361Sopenharmony_ciis_target_a_directory=possibly
86159b3361Sopenharmony_ci
87159b3361Sopenharmony_ciusage="\
88159b3361Sopenharmony_ciUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE
89159b3361Sopenharmony_ci   or: $0 [OPTION]... SRCFILES... DIRECTORY
90159b3361Sopenharmony_ci   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
91159b3361Sopenharmony_ci   or: $0 [OPTION]... -d DIRECTORIES...
92159b3361Sopenharmony_ci
93159b3361Sopenharmony_ciIn the 1st form, copy SRCFILE to DSTFILE.
94159b3361Sopenharmony_ciIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
95159b3361Sopenharmony_ciIn the 4th, create DIRECTORIES.
96159b3361Sopenharmony_ci
97159b3361Sopenharmony_ciOptions:
98159b3361Sopenharmony_ci     --help     display this help and exit.
99159b3361Sopenharmony_ci     --version  display version info and exit.
100159b3361Sopenharmony_ci
101159b3361Sopenharmony_ci  -c            (ignored)
102159b3361Sopenharmony_ci  -C            install only if different (preserve the last data modification time)
103159b3361Sopenharmony_ci  -d            create directories instead of installing files.
104159b3361Sopenharmony_ci  -g GROUP      $chgrpprog installed files to GROUP.
105159b3361Sopenharmony_ci  -m MODE       $chmodprog installed files to MODE.
106159b3361Sopenharmony_ci  -o USER       $chownprog installed files to USER.
107159b3361Sopenharmony_ci  -s            $stripprog installed files.
108159b3361Sopenharmony_ci  -t DIRECTORY  install into DIRECTORY.
109159b3361Sopenharmony_ci  -T            report an error if DSTFILE is a directory.
110159b3361Sopenharmony_ci
111159b3361Sopenharmony_ciEnvironment variables override the default commands:
112159b3361Sopenharmony_ci  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
113159b3361Sopenharmony_ci  RMPROG STRIPPROG
114159b3361Sopenharmony_ci"
115159b3361Sopenharmony_ci
116159b3361Sopenharmony_ciwhile test $# -ne 0; do
117159b3361Sopenharmony_ci  case $1 in
118159b3361Sopenharmony_ci    -c) ;;
119159b3361Sopenharmony_ci
120159b3361Sopenharmony_ci    -C) copy_on_change=true;;
121159b3361Sopenharmony_ci
122159b3361Sopenharmony_ci    -d) dir_arg=true;;
123159b3361Sopenharmony_ci
124159b3361Sopenharmony_ci    -g) chgrpcmd="$chgrpprog $2"
125159b3361Sopenharmony_ci        shift;;
126159b3361Sopenharmony_ci
127159b3361Sopenharmony_ci    --help) echo "$usage"; exit $?;;
128159b3361Sopenharmony_ci
129159b3361Sopenharmony_ci    -m) mode=$2
130159b3361Sopenharmony_ci        case $mode in
131159b3361Sopenharmony_ci          *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*)
132159b3361Sopenharmony_ci            echo "$0: invalid mode: $mode" >&2
133159b3361Sopenharmony_ci            exit 1;;
134159b3361Sopenharmony_ci        esac
135159b3361Sopenharmony_ci        shift;;
136159b3361Sopenharmony_ci
137159b3361Sopenharmony_ci    -o) chowncmd="$chownprog $2"
138159b3361Sopenharmony_ci        shift;;
139159b3361Sopenharmony_ci
140159b3361Sopenharmony_ci    -s) stripcmd=$stripprog;;
141159b3361Sopenharmony_ci
142159b3361Sopenharmony_ci    -t)
143159b3361Sopenharmony_ci        is_target_a_directory=always
144159b3361Sopenharmony_ci        dst_arg=$2
145159b3361Sopenharmony_ci        # Protect names problematic for 'test' and other utilities.
146159b3361Sopenharmony_ci        case $dst_arg in
147159b3361Sopenharmony_ci          -* | [=\(\)!]) dst_arg=./$dst_arg;;
148159b3361Sopenharmony_ci        esac
149159b3361Sopenharmony_ci        shift;;
150159b3361Sopenharmony_ci
151159b3361Sopenharmony_ci    -T) is_target_a_directory=never;;
152159b3361Sopenharmony_ci
153159b3361Sopenharmony_ci    --version) echo "$0 $scriptversion"; exit $?;;
154159b3361Sopenharmony_ci
155159b3361Sopenharmony_ci    --) shift
156159b3361Sopenharmony_ci        break;;
157159b3361Sopenharmony_ci
158159b3361Sopenharmony_ci    -*) echo "$0: invalid option: $1" >&2
159159b3361Sopenharmony_ci        exit 1;;
160159b3361Sopenharmony_ci
161159b3361Sopenharmony_ci    *)  break;;
162159b3361Sopenharmony_ci  esac
163159b3361Sopenharmony_ci  shift
164159b3361Sopenharmony_cidone
165159b3361Sopenharmony_ci
166159b3361Sopenharmony_ci# We allow the use of options -d and -T together, by making -d
167159b3361Sopenharmony_ci# take the precedence; this is for compatibility with GNU install.
168159b3361Sopenharmony_ci
169159b3361Sopenharmony_ciif test -n "$dir_arg"; then
170159b3361Sopenharmony_ci  if test -n "$dst_arg"; then
171159b3361Sopenharmony_ci    echo "$0: target directory not allowed when installing a directory." >&2
172159b3361Sopenharmony_ci    exit 1
173159b3361Sopenharmony_ci  fi
174159b3361Sopenharmony_cifi
175159b3361Sopenharmony_ci
176159b3361Sopenharmony_ciif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
177159b3361Sopenharmony_ci  # When -d is used, all remaining arguments are directories to create.
178159b3361Sopenharmony_ci  # When -t is used, the destination is already specified.
179159b3361Sopenharmony_ci  # Otherwise, the last argument is the destination.  Remove it from $@.
180159b3361Sopenharmony_ci  for arg
181159b3361Sopenharmony_ci  do
182159b3361Sopenharmony_ci    if test -n "$dst_arg"; then
183159b3361Sopenharmony_ci      # $@ is not empty: it contains at least $arg.
184159b3361Sopenharmony_ci      set fnord "$@" "$dst_arg"
185159b3361Sopenharmony_ci      shift # fnord
186159b3361Sopenharmony_ci    fi
187159b3361Sopenharmony_ci    shift # arg
188159b3361Sopenharmony_ci    dst_arg=$arg
189159b3361Sopenharmony_ci    # Protect names problematic for 'test' and other utilities.
190159b3361Sopenharmony_ci    case $dst_arg in
191159b3361Sopenharmony_ci      -* | [=\(\)!]) dst_arg=./$dst_arg;;
192159b3361Sopenharmony_ci    esac
193159b3361Sopenharmony_ci  done
194159b3361Sopenharmony_cifi
195159b3361Sopenharmony_ci
196159b3361Sopenharmony_ciif test $# -eq 0; then
197159b3361Sopenharmony_ci  if test -z "$dir_arg"; then
198159b3361Sopenharmony_ci    echo "$0: no input file specified." >&2
199159b3361Sopenharmony_ci    exit 1
200159b3361Sopenharmony_ci  fi
201159b3361Sopenharmony_ci  # It's OK to call 'install-sh -d' without argument.
202159b3361Sopenharmony_ci  # This can happen when creating conditional directories.
203159b3361Sopenharmony_ci  exit 0
204159b3361Sopenharmony_cifi
205159b3361Sopenharmony_ci
206159b3361Sopenharmony_ciif test -z "$dir_arg"; then
207159b3361Sopenharmony_ci  if test $# -gt 1 || test "$is_target_a_directory" = always; then
208159b3361Sopenharmony_ci    if test ! -d "$dst_arg"; then
209159b3361Sopenharmony_ci      echo "$0: $dst_arg: Is not a directory." >&2
210159b3361Sopenharmony_ci      exit 1
211159b3361Sopenharmony_ci    fi
212159b3361Sopenharmony_ci  fi
213159b3361Sopenharmony_cifi
214159b3361Sopenharmony_ci
215159b3361Sopenharmony_ciif test -z "$dir_arg"; then
216159b3361Sopenharmony_ci  do_exit='(exit $ret); exit $ret'
217159b3361Sopenharmony_ci  trap "ret=129; $do_exit" 1
218159b3361Sopenharmony_ci  trap "ret=130; $do_exit" 2
219159b3361Sopenharmony_ci  trap "ret=141; $do_exit" 13
220159b3361Sopenharmony_ci  trap "ret=143; $do_exit" 15
221159b3361Sopenharmony_ci
222159b3361Sopenharmony_ci  # Set umask so as not to create temps with too-generous modes.
223159b3361Sopenharmony_ci  # However, 'strip' requires both read and write access to temps.
224159b3361Sopenharmony_ci  case $mode in
225159b3361Sopenharmony_ci    # Optimize common cases.
226159b3361Sopenharmony_ci    *644) cp_umask=133;;
227159b3361Sopenharmony_ci    *755) cp_umask=22;;
228159b3361Sopenharmony_ci
229159b3361Sopenharmony_ci    *[0-7])
230159b3361Sopenharmony_ci      if test -z "$stripcmd"; then
231159b3361Sopenharmony_ci        u_plus_rw=
232159b3361Sopenharmony_ci      else
233159b3361Sopenharmony_ci        u_plus_rw='% 200'
234159b3361Sopenharmony_ci      fi
235159b3361Sopenharmony_ci      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
236159b3361Sopenharmony_ci    *)
237159b3361Sopenharmony_ci      if test -z "$stripcmd"; then
238159b3361Sopenharmony_ci        u_plus_rw=
239159b3361Sopenharmony_ci      else
240159b3361Sopenharmony_ci        u_plus_rw=,u+rw
241159b3361Sopenharmony_ci      fi
242159b3361Sopenharmony_ci      cp_umask=$mode$u_plus_rw;;
243159b3361Sopenharmony_ci  esac
244159b3361Sopenharmony_cifi
245159b3361Sopenharmony_ci
246159b3361Sopenharmony_cifor src
247159b3361Sopenharmony_cido
248159b3361Sopenharmony_ci  # Protect names problematic for 'test' and other utilities.
249159b3361Sopenharmony_ci  case $src in
250159b3361Sopenharmony_ci    -* | [=\(\)!]) src=./$src;;
251159b3361Sopenharmony_ci  esac
252159b3361Sopenharmony_ci
253159b3361Sopenharmony_ci  if test -n "$dir_arg"; then
254159b3361Sopenharmony_ci    dst=$src
255159b3361Sopenharmony_ci    dstdir=$dst
256159b3361Sopenharmony_ci    test -d "$dstdir"
257159b3361Sopenharmony_ci    dstdir_status=$?
258159b3361Sopenharmony_ci  else
259159b3361Sopenharmony_ci
260159b3361Sopenharmony_ci    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
261159b3361Sopenharmony_ci    # might cause directories to be created, which would be especially bad
262159b3361Sopenharmony_ci    # if $src (and thus $dsttmp) contains '*'.
263159b3361Sopenharmony_ci    if test ! -f "$src" && test ! -d "$src"; then
264159b3361Sopenharmony_ci      echo "$0: $src does not exist." >&2
265159b3361Sopenharmony_ci      exit 1
266159b3361Sopenharmony_ci    fi
267159b3361Sopenharmony_ci
268159b3361Sopenharmony_ci    if test -z "$dst_arg"; then
269159b3361Sopenharmony_ci      echo "$0: no destination specified." >&2
270159b3361Sopenharmony_ci      exit 1
271159b3361Sopenharmony_ci    fi
272159b3361Sopenharmony_ci    dst=$dst_arg
273159b3361Sopenharmony_ci
274159b3361Sopenharmony_ci    # If destination is a directory, append the input filename.
275159b3361Sopenharmony_ci    if test -d "$dst"; then
276159b3361Sopenharmony_ci      if test "$is_target_a_directory" = never; then
277159b3361Sopenharmony_ci        echo "$0: $dst_arg: Is a directory" >&2
278159b3361Sopenharmony_ci        exit 1
279159b3361Sopenharmony_ci      fi
280159b3361Sopenharmony_ci      dstdir=$dst
281159b3361Sopenharmony_ci      dstbase=`basename "$src"`
282159b3361Sopenharmony_ci      case $dst in
283159b3361Sopenharmony_ci	*/) dst=$dst$dstbase;;
284159b3361Sopenharmony_ci	*)  dst=$dst/$dstbase;;
285159b3361Sopenharmony_ci      esac
286159b3361Sopenharmony_ci      dstdir_status=0
287159b3361Sopenharmony_ci    else
288159b3361Sopenharmony_ci      dstdir=`dirname "$dst"`
289159b3361Sopenharmony_ci      test -d "$dstdir"
290159b3361Sopenharmony_ci      dstdir_status=$?
291159b3361Sopenharmony_ci    fi
292159b3361Sopenharmony_ci  fi
293159b3361Sopenharmony_ci
294159b3361Sopenharmony_ci  case $dstdir in
295159b3361Sopenharmony_ci    */) dstdirslash=$dstdir;;
296159b3361Sopenharmony_ci    *)  dstdirslash=$dstdir/;;
297159b3361Sopenharmony_ci  esac
298159b3361Sopenharmony_ci
299159b3361Sopenharmony_ci  obsolete_mkdir_used=false
300159b3361Sopenharmony_ci
301159b3361Sopenharmony_ci  if test $dstdir_status != 0; then
302159b3361Sopenharmony_ci    case $posix_mkdir in
303159b3361Sopenharmony_ci      '')
304159b3361Sopenharmony_ci        # Create intermediate dirs using mode 755 as modified by the umask.
305159b3361Sopenharmony_ci        # This is like FreeBSD 'install' as of 1997-10-28.
306159b3361Sopenharmony_ci        umask=`umask`
307159b3361Sopenharmony_ci        case $stripcmd.$umask in
308159b3361Sopenharmony_ci          # Optimize common cases.
309159b3361Sopenharmony_ci          *[2367][2367]) mkdir_umask=$umask;;
310159b3361Sopenharmony_ci          .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
311159b3361Sopenharmony_ci
312159b3361Sopenharmony_ci          *[0-7])
313159b3361Sopenharmony_ci            mkdir_umask=`expr $umask + 22 \
314159b3361Sopenharmony_ci              - $umask % 100 % 40 + $umask % 20 \
315159b3361Sopenharmony_ci              - $umask % 10 % 4 + $umask % 2
316159b3361Sopenharmony_ci            `;;
317159b3361Sopenharmony_ci          *) mkdir_umask=$umask,go-w;;
318159b3361Sopenharmony_ci        esac
319159b3361Sopenharmony_ci
320159b3361Sopenharmony_ci        # With -d, create the new directory with the user-specified mode.
321159b3361Sopenharmony_ci        # Otherwise, rely on $mkdir_umask.
322159b3361Sopenharmony_ci        if test -n "$dir_arg"; then
323159b3361Sopenharmony_ci          mkdir_mode=-m$mode
324159b3361Sopenharmony_ci        else
325159b3361Sopenharmony_ci          mkdir_mode=
326159b3361Sopenharmony_ci        fi
327159b3361Sopenharmony_ci
328159b3361Sopenharmony_ci        posix_mkdir=false
329159b3361Sopenharmony_ci        case $umask in
330159b3361Sopenharmony_ci          *[123567][0-7][0-7])
331159b3361Sopenharmony_ci            # POSIX mkdir -p sets u+wx bits regardless of umask, which
332159b3361Sopenharmony_ci            # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
333159b3361Sopenharmony_ci            ;;
334159b3361Sopenharmony_ci          *)
335159b3361Sopenharmony_ci            # Note that $RANDOM variable is not portable (e.g. dash);  Use it
336159b3361Sopenharmony_ci            # here however when possible just to lower collision chance.
337159b3361Sopenharmony_ci            tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
338159b3361Sopenharmony_ci
339159b3361Sopenharmony_ci            trap 'ret=$?; rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null; exit $ret' 0
340159b3361Sopenharmony_ci
341159b3361Sopenharmony_ci            # Because "mkdir -p" follows existing symlinks and we likely work
342159b3361Sopenharmony_ci            # directly in world-writeable /tmp, make sure that the '$tmpdir'
343159b3361Sopenharmony_ci            # directory is successfully created first before we actually test
344159b3361Sopenharmony_ci            # 'mkdir -p' feature.
345159b3361Sopenharmony_ci            if (umask $mkdir_umask &&
346159b3361Sopenharmony_ci                $mkdirprog $mkdir_mode "$tmpdir" &&
347159b3361Sopenharmony_ci                exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
348159b3361Sopenharmony_ci            then
349159b3361Sopenharmony_ci              if test -z "$dir_arg" || {
350159b3361Sopenharmony_ci                   # Check for POSIX incompatibilities with -m.
351159b3361Sopenharmony_ci                   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
352159b3361Sopenharmony_ci                   # other-writable bit of parent directory when it shouldn't.
353159b3361Sopenharmony_ci                   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
354159b3361Sopenharmony_ci                   test_tmpdir="$tmpdir/a"
355159b3361Sopenharmony_ci                   ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
356159b3361Sopenharmony_ci                   case $ls_ld_tmpdir in
357159b3361Sopenharmony_ci                     d????-?r-*) different_mode=700;;
358159b3361Sopenharmony_ci                     d????-?--*) different_mode=755;;
359159b3361Sopenharmony_ci                     *) false;;
360159b3361Sopenharmony_ci                   esac &&
361159b3361Sopenharmony_ci                   $mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
362159b3361Sopenharmony_ci                     ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
363159b3361Sopenharmony_ci                     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
364159b3361Sopenharmony_ci                   }
365159b3361Sopenharmony_ci                 }
366159b3361Sopenharmony_ci              then posix_mkdir=:
367159b3361Sopenharmony_ci              fi
368159b3361Sopenharmony_ci              rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
369159b3361Sopenharmony_ci            else
370159b3361Sopenharmony_ci              # Remove any dirs left behind by ancient mkdir implementations.
371159b3361Sopenharmony_ci              rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
372159b3361Sopenharmony_ci            fi
373159b3361Sopenharmony_ci            trap '' 0;;
374159b3361Sopenharmony_ci        esac;;
375159b3361Sopenharmony_ci    esac
376159b3361Sopenharmony_ci
377159b3361Sopenharmony_ci    if
378159b3361Sopenharmony_ci      $posix_mkdir && (
379159b3361Sopenharmony_ci        umask $mkdir_umask &&
380159b3361Sopenharmony_ci        $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
381159b3361Sopenharmony_ci      )
382159b3361Sopenharmony_ci    then :
383159b3361Sopenharmony_ci    else
384159b3361Sopenharmony_ci
385159b3361Sopenharmony_ci      # The umask is ridiculous, or mkdir does not conform to POSIX,
386159b3361Sopenharmony_ci      # or it failed possibly due to a race condition.  Create the
387159b3361Sopenharmony_ci      # directory the slow way, step by step, checking for races as we go.
388159b3361Sopenharmony_ci
389159b3361Sopenharmony_ci      case $dstdir in
390159b3361Sopenharmony_ci        /*) prefix='/';;
391159b3361Sopenharmony_ci        [-=\(\)!]*) prefix='./';;
392159b3361Sopenharmony_ci        *)  prefix='';;
393159b3361Sopenharmony_ci      esac
394159b3361Sopenharmony_ci
395159b3361Sopenharmony_ci      oIFS=$IFS
396159b3361Sopenharmony_ci      IFS=/
397159b3361Sopenharmony_ci      set -f
398159b3361Sopenharmony_ci      set fnord $dstdir
399159b3361Sopenharmony_ci      shift
400159b3361Sopenharmony_ci      set +f
401159b3361Sopenharmony_ci      IFS=$oIFS
402159b3361Sopenharmony_ci
403159b3361Sopenharmony_ci      prefixes=
404159b3361Sopenharmony_ci
405159b3361Sopenharmony_ci      for d
406159b3361Sopenharmony_ci      do
407159b3361Sopenharmony_ci        test X"$d" = X && continue
408159b3361Sopenharmony_ci
409159b3361Sopenharmony_ci        prefix=$prefix$d
410159b3361Sopenharmony_ci        if test -d "$prefix"; then
411159b3361Sopenharmony_ci          prefixes=
412159b3361Sopenharmony_ci        else
413159b3361Sopenharmony_ci          if $posix_mkdir; then
414159b3361Sopenharmony_ci            (umask=$mkdir_umask &&
415159b3361Sopenharmony_ci             $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
416159b3361Sopenharmony_ci            # Don't fail if two instances are running concurrently.
417159b3361Sopenharmony_ci            test -d "$prefix" || exit 1
418159b3361Sopenharmony_ci          else
419159b3361Sopenharmony_ci            case $prefix in
420159b3361Sopenharmony_ci              *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
421159b3361Sopenharmony_ci              *) qprefix=$prefix;;
422159b3361Sopenharmony_ci            esac
423159b3361Sopenharmony_ci            prefixes="$prefixes '$qprefix'"
424159b3361Sopenharmony_ci          fi
425159b3361Sopenharmony_ci        fi
426159b3361Sopenharmony_ci        prefix=$prefix/
427159b3361Sopenharmony_ci      done
428159b3361Sopenharmony_ci
429159b3361Sopenharmony_ci      if test -n "$prefixes"; then
430159b3361Sopenharmony_ci        # Don't fail if two instances are running concurrently.
431159b3361Sopenharmony_ci        (umask $mkdir_umask &&
432159b3361Sopenharmony_ci         eval "\$doit_exec \$mkdirprog $prefixes") ||
433159b3361Sopenharmony_ci          test -d "$dstdir" || exit 1
434159b3361Sopenharmony_ci        obsolete_mkdir_used=true
435159b3361Sopenharmony_ci      fi
436159b3361Sopenharmony_ci    fi
437159b3361Sopenharmony_ci  fi
438159b3361Sopenharmony_ci
439159b3361Sopenharmony_ci  if test -n "$dir_arg"; then
440159b3361Sopenharmony_ci    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
441159b3361Sopenharmony_ci    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
442159b3361Sopenharmony_ci    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
443159b3361Sopenharmony_ci      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
444159b3361Sopenharmony_ci  else
445159b3361Sopenharmony_ci
446159b3361Sopenharmony_ci    # Make a couple of temp file names in the proper directory.
447159b3361Sopenharmony_ci    dsttmp=${dstdirslash}_inst.$$_
448159b3361Sopenharmony_ci    rmtmp=${dstdirslash}_rm.$$_
449159b3361Sopenharmony_ci
450159b3361Sopenharmony_ci    # Trap to clean up those temp files at exit.
451159b3361Sopenharmony_ci    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
452159b3361Sopenharmony_ci
453159b3361Sopenharmony_ci    # Copy the file name to the temp name.
454159b3361Sopenharmony_ci    (umask $cp_umask &&
455159b3361Sopenharmony_ci     { test -z "$stripcmd" || {
456159b3361Sopenharmony_ci	 # Create $dsttmp read-write so that cp doesn't create it read-only,
457159b3361Sopenharmony_ci	 # which would cause strip to fail.
458159b3361Sopenharmony_ci	 if test -z "$doit"; then
459159b3361Sopenharmony_ci	   : >"$dsttmp" # No need to fork-exec 'touch'.
460159b3361Sopenharmony_ci	 else
461159b3361Sopenharmony_ci	   $doit touch "$dsttmp"
462159b3361Sopenharmony_ci	 fi
463159b3361Sopenharmony_ci       }
464159b3361Sopenharmony_ci     } &&
465159b3361Sopenharmony_ci     $doit_exec $cpprog "$src" "$dsttmp") &&
466159b3361Sopenharmony_ci
467159b3361Sopenharmony_ci    # and set any options; do chmod last to preserve setuid bits.
468159b3361Sopenharmony_ci    #
469159b3361Sopenharmony_ci    # If any of these fail, we abort the whole thing.  If we want to
470159b3361Sopenharmony_ci    # ignore errors from any of these, just make sure not to ignore
471159b3361Sopenharmony_ci    # errors from the above "$doit $cpprog $src $dsttmp" command.
472159b3361Sopenharmony_ci    #
473159b3361Sopenharmony_ci    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
474159b3361Sopenharmony_ci    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
475159b3361Sopenharmony_ci    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
476159b3361Sopenharmony_ci    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
477159b3361Sopenharmony_ci
478159b3361Sopenharmony_ci    # If -C, don't bother to copy if it wouldn't change the file.
479159b3361Sopenharmony_ci    if $copy_on_change &&
480159b3361Sopenharmony_ci       old=`LC_ALL=C ls -dlL "$dst"     2>/dev/null` &&
481159b3361Sopenharmony_ci       new=`LC_ALL=C ls -dlL "$dsttmp"  2>/dev/null` &&
482159b3361Sopenharmony_ci       set -f &&
483159b3361Sopenharmony_ci       set X $old && old=:$2:$4:$5:$6 &&
484159b3361Sopenharmony_ci       set X $new && new=:$2:$4:$5:$6 &&
485159b3361Sopenharmony_ci       set +f &&
486159b3361Sopenharmony_ci       test "$old" = "$new" &&
487159b3361Sopenharmony_ci       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
488159b3361Sopenharmony_ci    then
489159b3361Sopenharmony_ci      rm -f "$dsttmp"
490159b3361Sopenharmony_ci    else
491159b3361Sopenharmony_ci      # Rename the file to the real destination.
492159b3361Sopenharmony_ci      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
493159b3361Sopenharmony_ci
494159b3361Sopenharmony_ci      # The rename failed, perhaps because mv can't rename something else
495159b3361Sopenharmony_ci      # to itself, or perhaps because mv is so ancient that it does not
496159b3361Sopenharmony_ci      # support -f.
497159b3361Sopenharmony_ci      {
498159b3361Sopenharmony_ci        # Now remove or move aside any old file at destination location.
499159b3361Sopenharmony_ci        # We try this two ways since rm can't unlink itself on some
500159b3361Sopenharmony_ci        # systems and the destination file might be busy for other
501159b3361Sopenharmony_ci        # reasons.  In this case, the final cleanup might fail but the new
502159b3361Sopenharmony_ci        # file should still install successfully.
503159b3361Sopenharmony_ci        {
504159b3361Sopenharmony_ci          test ! -f "$dst" ||
505159b3361Sopenharmony_ci          $doit $rmcmd -f "$dst" 2>/dev/null ||
506159b3361Sopenharmony_ci          { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
507159b3361Sopenharmony_ci            { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
508159b3361Sopenharmony_ci          } ||
509159b3361Sopenharmony_ci          { echo "$0: cannot unlink or rename $dst" >&2
510159b3361Sopenharmony_ci            (exit 1); exit 1
511159b3361Sopenharmony_ci          }
512159b3361Sopenharmony_ci        } &&
513159b3361Sopenharmony_ci
514159b3361Sopenharmony_ci        # Now rename the file to the real destination.
515159b3361Sopenharmony_ci        $doit $mvcmd "$dsttmp" "$dst"
516159b3361Sopenharmony_ci      }
517159b3361Sopenharmony_ci    fi || exit 1
518159b3361Sopenharmony_ci
519159b3361Sopenharmony_ci    trap '' 0
520159b3361Sopenharmony_ci  fi
521159b3361Sopenharmony_cidone
522159b3361Sopenharmony_ci
523159b3361Sopenharmony_ci# Local variables:
524159b3361Sopenharmony_ci# eval: (add-hook 'before-save-hook 'time-stamp)
525159b3361Sopenharmony_ci# time-stamp-start: "scriptversion="
526159b3361Sopenharmony_ci# time-stamp-format: "%:y-%02m-%02d.%02H"
527159b3361Sopenharmony_ci# time-stamp-time-zone: "UTC0"
528159b3361Sopenharmony_ci# time-stamp-end: "; # UTC"
529159b3361Sopenharmony_ci# End:
530