install-sh revision cfcf9057
16f03b1f6Smrg#!/bin/sh 26f03b1f6Smrg# install - install a program, script, or datafile 36f03b1f6Smrg 4cfcf9057Smrgscriptversion=2018-03-11.20; # UTC 56f03b1f6Smrg 66f03b1f6Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 76f03b1f6Smrg# later released in X11R6 (xc/config/util/install.sh) with the 86f03b1f6Smrg# following copyright and license. 96f03b1f6Smrg# 106f03b1f6Smrg# Copyright (C) 1994 X Consortium 116f03b1f6Smrg# 126f03b1f6Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 136f03b1f6Smrg# of this software and associated documentation files (the "Software"), to 146f03b1f6Smrg# deal in the Software without restriction, including without limitation the 156f03b1f6Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 166f03b1f6Smrg# sell copies of the Software, and to permit persons to whom the Software is 176f03b1f6Smrg# furnished to do so, subject to the following conditions: 186f03b1f6Smrg# 196f03b1f6Smrg# The above copyright notice and this permission notice shall be included in 206f03b1f6Smrg# all copies or substantial portions of the Software. 216f03b1f6Smrg# 226f03b1f6Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 236f03b1f6Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 246f03b1f6Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 256f03b1f6Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 266f03b1f6Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 276f03b1f6Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 286f03b1f6Smrg# 296f03b1f6Smrg# Except as contained in this notice, the name of the X Consortium shall not 306f03b1f6Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 316f03b1f6Smrg# ings in this Software without prior written authorization from the X Consor- 326f03b1f6Smrg# tium. 336f03b1f6Smrg# 346f03b1f6Smrg# 356f03b1f6Smrg# FSF changes to this file are in the public domain. 366f03b1f6Smrg# 376f03b1f6Smrg# Calling this script install-sh is preferred over install.sh, to prevent 3817caa701Smrg# 'make' implicit rules from creating a file called install from it 396f03b1f6Smrg# when there is no Makefile. 406f03b1f6Smrg# 416f03b1f6Smrg# This script is compatible with the BSD install script, but was written 4298af18c5Smrg# from scratch. 4398af18c5Smrg 44c1e3c5d0Smrgtab=' ' 4598af18c5Smrgnl=' 4698af18c5Smrg' 47c1e3c5d0SmrgIFS=" $tab$nl" 486f03b1f6Smrg 49c1e3c5d0Smrg# Set DOITPROG to "echo" to test this script. 506f03b1f6Smrg 5198af18c5Smrgdoit=${DOITPROG-} 52c1e3c5d0Smrgdoit_exec=${doit:-exec} 536f03b1f6Smrg 5498af18c5Smrg# Put in absolute file names if you don't have them in your path; 5598af18c5Smrg# or use environment vars. 5698af18c5Smrg 5798af18c5Smrgchgrpprog=${CHGRPPROG-chgrp} 5898af18c5Smrgchmodprog=${CHMODPROG-chmod} 5998af18c5Smrgchownprog=${CHOWNPROG-chown} 6098af18c5Smrgcmpprog=${CMPPROG-cmp} 6198af18c5Smrgcpprog=${CPPROG-cp} 6298af18c5Smrgmkdirprog=${MKDIRPROG-mkdir} 6398af18c5Smrgmvprog=${MVPROG-mv} 6498af18c5Smrgrmprog=${RMPROG-rm} 6598af18c5Smrgstripprog=${STRIPPROG-strip} 6698af18c5Smrg 6798af18c5Smrgposix_mkdir= 6898af18c5Smrg 6998af18c5Smrg# Desired mode of installed file. 7098af18c5Smrgmode=0755 716f03b1f6Smrg 726f03b1f6Smrgchgrpcmd= 7398af18c5Smrgchmodcmd=$chmodprog 7498af18c5Smrgchowncmd= 7598af18c5Smrgmvcmd=$mvprog 766f03b1f6Smrgrmcmd="$rmprog -f" 7798af18c5Smrgstripcmd= 7898af18c5Smrg 796f03b1f6Smrgsrc= 806f03b1f6Smrgdst= 816f03b1f6Smrgdir_arg= 8298af18c5Smrgdst_arg= 8398af18c5Smrg 8498af18c5Smrgcopy_on_change=false 85c1e3c5d0Smrgis_target_a_directory=possibly 866f03b1f6Smrg 8798af18c5Smrgusage="\ 8898af18c5SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 896f03b1f6Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 906f03b1f6Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 916f03b1f6Smrg or: $0 [OPTION]... -d DIRECTORIES... 926f03b1f6Smrg 936f03b1f6SmrgIn the 1st form, copy SRCFILE to DSTFILE. 946f03b1f6SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 956f03b1f6SmrgIn the 4th, create DIRECTORIES. 966f03b1f6Smrg 976f03b1f6SmrgOptions: 9898af18c5Smrg --help display this help and exit. 9998af18c5Smrg --version display version info and exit. 10098af18c5Smrg 10198af18c5Smrg -c (ignored) 10298af18c5Smrg -C install only if different (preserve the last data modification time) 10398af18c5Smrg -d create directories instead of installing files. 10498af18c5Smrg -g GROUP $chgrpprog installed files to GROUP. 10598af18c5Smrg -m MODE $chmodprog installed files to MODE. 10698af18c5Smrg -o USER $chownprog installed files to USER. 10798af18c5Smrg -s $stripprog installed files. 10898af18c5Smrg -t DIRECTORY install into DIRECTORY. 10998af18c5Smrg -T report an error if DSTFILE is a directory. 1106f03b1f6Smrg 1116f03b1f6SmrgEnvironment variables override the default commands: 11298af18c5Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 11398af18c5Smrg RMPROG STRIPPROG 1146f03b1f6Smrg" 1156f03b1f6Smrg 11698af18c5Smrgwhile test $# -ne 0; do 1176f03b1f6Smrg case $1 in 11898af18c5Smrg -c) ;; 11998af18c5Smrg 12098af18c5Smrg -C) copy_on_change=true;; 1216f03b1f6Smrg 12298af18c5Smrg -d) dir_arg=true;; 1236f03b1f6Smrg 1246f03b1f6Smrg -g) chgrpcmd="$chgrpprog $2" 125c1e3c5d0Smrg shift;; 1266f03b1f6Smrg 1276f03b1f6Smrg --help) echo "$usage"; exit $?;; 1286f03b1f6Smrg 12998af18c5Smrg -m) mode=$2 130c1e3c5d0Smrg case $mode in 131c1e3c5d0Smrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 132c1e3c5d0Smrg echo "$0: invalid mode: $mode" >&2 133c1e3c5d0Smrg exit 1;; 134c1e3c5d0Smrg esac 135c1e3c5d0Smrg shift;; 1366f03b1f6Smrg 1376f03b1f6Smrg -o) chowncmd="$chownprog $2" 138c1e3c5d0Smrg shift;; 1396f03b1f6Smrg 14098af18c5Smrg -s) stripcmd=$stripprog;; 1416f03b1f6Smrg 142c1e3c5d0Smrg -t) 143c1e3c5d0Smrg is_target_a_directory=always 144c1e3c5d0Smrg dst_arg=$2 145c1e3c5d0Smrg # Protect names problematic for 'test' and other utilities. 146c1e3c5d0Smrg case $dst_arg in 147c1e3c5d0Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 148c1e3c5d0Smrg esac 149c1e3c5d0Smrg shift;; 1506f03b1f6Smrg 151c1e3c5d0Smrg -T) is_target_a_directory=never;; 1526f03b1f6Smrg 1536f03b1f6Smrg --version) echo "$0 $scriptversion"; exit $?;; 1546f03b1f6Smrg 155c1e3c5d0Smrg --) shift 156c1e3c5d0Smrg break;; 15798af18c5Smrg 158c1e3c5d0Smrg -*) echo "$0: invalid option: $1" >&2 159c1e3c5d0Smrg exit 1;; 16098af18c5Smrg 16198af18c5Smrg *) break;; 1626f03b1f6Smrg esac 16398af18c5Smrg shift 1646f03b1f6Smrgdone 1656f03b1f6Smrg 166c1e3c5d0Smrg# We allow the use of options -d and -T together, by making -d 167c1e3c5d0Smrg# take the precedence; this is for compatibility with GNU install. 168c1e3c5d0Smrg 169c1e3c5d0Smrgif test -n "$dir_arg"; then 170c1e3c5d0Smrg if test -n "$dst_arg"; then 171c1e3c5d0Smrg echo "$0: target directory not allowed when installing a directory." >&2 172c1e3c5d0Smrg exit 1 173c1e3c5d0Smrg fi 174c1e3c5d0Smrgfi 175c1e3c5d0Smrg 17698af18c5Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 17798af18c5Smrg # When -d is used, all remaining arguments are directories to create. 17898af18c5Smrg # When -t is used, the destination is already specified. 17998af18c5Smrg # Otherwise, the last argument is the destination. Remove it from $@. 18098af18c5Smrg for arg 18198af18c5Smrg do 18298af18c5Smrg if test -n "$dst_arg"; then 18398af18c5Smrg # $@ is not empty: it contains at least $arg. 18498af18c5Smrg set fnord "$@" "$dst_arg" 18598af18c5Smrg shift # fnord 18698af18c5Smrg fi 18798af18c5Smrg shift # arg 18898af18c5Smrg dst_arg=$arg 18917caa701Smrg # Protect names problematic for 'test' and other utilities. 19017caa701Smrg case $dst_arg in 19117caa701Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 19217caa701Smrg esac 19398af18c5Smrg done 19498af18c5Smrgfi 19598af18c5Smrg 19698af18c5Smrgif test $# -eq 0; then 1976f03b1f6Smrg if test -z "$dir_arg"; then 1986f03b1f6Smrg echo "$0: no input file specified." >&2 1996f03b1f6Smrg exit 1 2006f03b1f6Smrg fi 20117caa701Smrg # It's OK to call 'install-sh -d' without argument. 2026f03b1f6Smrg # This can happen when creating conditional directories. 2036f03b1f6Smrg exit 0 2046f03b1f6Smrgfi 2056f03b1f6Smrg 206c1e3c5d0Smrgif test -z "$dir_arg"; then 207c1e3c5d0Smrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 208c1e3c5d0Smrg if test ! -d "$dst_arg"; then 209c1e3c5d0Smrg echo "$0: $dst_arg: Is not a directory." >&2 210c1e3c5d0Smrg exit 1 211c1e3c5d0Smrg fi 212c1e3c5d0Smrg fi 213c1e3c5d0Smrgfi 214c1e3c5d0Smrg 21598af18c5Smrgif test -z "$dir_arg"; then 21617caa701Smrg do_exit='(exit $ret); exit $ret' 21717caa701Smrg trap "ret=129; $do_exit" 1 21817caa701Smrg trap "ret=130; $do_exit" 2 21917caa701Smrg trap "ret=141; $do_exit" 13 22017caa701Smrg trap "ret=143; $do_exit" 15 22198af18c5Smrg 22298af18c5Smrg # Set umask so as not to create temps with too-generous modes. 22398af18c5Smrg # However, 'strip' requires both read and write access to temps. 22498af18c5Smrg case $mode in 22598af18c5Smrg # Optimize common cases. 22698af18c5Smrg *644) cp_umask=133;; 22798af18c5Smrg *755) cp_umask=22;; 22898af18c5Smrg 22998af18c5Smrg *[0-7]) 23098af18c5Smrg if test -z "$stripcmd"; then 231c1e3c5d0Smrg u_plus_rw= 23298af18c5Smrg else 233c1e3c5d0Smrg u_plus_rw='% 200' 23498af18c5Smrg fi 23598af18c5Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 23698af18c5Smrg *) 23798af18c5Smrg if test -z "$stripcmd"; then 238c1e3c5d0Smrg u_plus_rw= 23998af18c5Smrg else 240c1e3c5d0Smrg u_plus_rw=,u+rw 24198af18c5Smrg fi 24298af18c5Smrg cp_umask=$mode$u_plus_rw;; 24398af18c5Smrg esac 24498af18c5Smrgfi 24598af18c5Smrg 2466f03b1f6Smrgfor src 2476f03b1f6Smrgdo 24817caa701Smrg # Protect names problematic for 'test' and other utilities. 2496f03b1f6Smrg case $src in 25017caa701Smrg -* | [=\(\)!]) src=./$src;; 2516f03b1f6Smrg esac 2526f03b1f6Smrg 2536f03b1f6Smrg if test -n "$dir_arg"; then 2546f03b1f6Smrg dst=$src 25598af18c5Smrg dstdir=$dst 25698af18c5Smrg test -d "$dstdir" 25798af18c5Smrg dstdir_status=$? 2586f03b1f6Smrg else 25998af18c5Smrg 2606f03b1f6Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2616f03b1f6Smrg # might cause directories to be created, which would be especially bad 2626f03b1f6Smrg # if $src (and thus $dsttmp) contains '*'. 2636f03b1f6Smrg if test ! -f "$src" && test ! -d "$src"; then 2646f03b1f6Smrg echo "$0: $src does not exist." >&2 2656f03b1f6Smrg exit 1 2666f03b1f6Smrg fi 2676f03b1f6Smrg 26898af18c5Smrg if test -z "$dst_arg"; then 2696f03b1f6Smrg echo "$0: no destination specified." >&2 2706f03b1f6Smrg exit 1 2716f03b1f6Smrg fi 27298af18c5Smrg dst=$dst_arg 2736f03b1f6Smrg 274cfcf9057Smrg # If destination is a directory, append the input filename. 2756f03b1f6Smrg if test -d "$dst"; then 276c1e3c5d0Smrg if test "$is_target_a_directory" = never; then 277c1e3c5d0Smrg echo "$0: $dst_arg: Is a directory" >&2 278c1e3c5d0Smrg exit 1 2796f03b1f6Smrg fi 28098af18c5Smrg dstdir=$dst 281cfcf9057Smrg dstbase=`basename "$src"` 282cfcf9057Smrg case $dst in 283cfcf9057Smrg */) dst=$dst$dstbase;; 284cfcf9057Smrg *) dst=$dst/$dstbase;; 285cfcf9057Smrg esac 28698af18c5Smrg dstdir_status=0 28798af18c5Smrg else 288c1e3c5d0Smrg dstdir=`dirname "$dst"` 28998af18c5Smrg test -d "$dstdir" 29098af18c5Smrg dstdir_status=$? 2916f03b1f6Smrg fi 2926f03b1f6Smrg fi 2936f03b1f6Smrg 294cfcf9057Smrg case $dstdir in 295cfcf9057Smrg */) dstdirslash=$dstdir;; 296cfcf9057Smrg *) dstdirslash=$dstdir/;; 297cfcf9057Smrg esac 298cfcf9057Smrg 29998af18c5Smrg obsolete_mkdir_used=false 30098af18c5Smrg 30198af18c5Smrg if test $dstdir_status != 0; then 30298af18c5Smrg case $posix_mkdir in 30398af18c5Smrg '') 304c1e3c5d0Smrg # Create intermediate dirs using mode 755 as modified by the umask. 305c1e3c5d0Smrg # This is like FreeBSD 'install' as of 1997-10-28. 306c1e3c5d0Smrg umask=`umask` 307c1e3c5d0Smrg case $stripcmd.$umask in 308c1e3c5d0Smrg # Optimize common cases. 309c1e3c5d0Smrg *[2367][2367]) mkdir_umask=$umask;; 310c1e3c5d0Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 311c1e3c5d0Smrg 312c1e3c5d0Smrg *[0-7]) 313c1e3c5d0Smrg mkdir_umask=`expr $umask + 22 \ 314c1e3c5d0Smrg - $umask % 100 % 40 + $umask % 20 \ 315c1e3c5d0Smrg - $umask % 10 % 4 + $umask % 2 316c1e3c5d0Smrg `;; 317c1e3c5d0Smrg *) mkdir_umask=$umask,go-w;; 318c1e3c5d0Smrg esac 319c1e3c5d0Smrg 320c1e3c5d0Smrg # With -d, create the new directory with the user-specified mode. 321c1e3c5d0Smrg # Otherwise, rely on $mkdir_umask. 322c1e3c5d0Smrg if test -n "$dir_arg"; then 323c1e3c5d0Smrg mkdir_mode=-m$mode 324c1e3c5d0Smrg else 325c1e3c5d0Smrg mkdir_mode= 326c1e3c5d0Smrg fi 327c1e3c5d0Smrg 328c1e3c5d0Smrg posix_mkdir=false 329c1e3c5d0Smrg case $umask in 330c1e3c5d0Smrg *[123567][0-7][0-7]) 331c1e3c5d0Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 332c1e3c5d0Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 333c1e3c5d0Smrg ;; 334c1e3c5d0Smrg *) 335cfcf9057Smrg # Note that $RANDOM variable is not portable (e.g. dash); Use it 336cfcf9057Smrg # here however when possible just to lower collision chance. 337c1e3c5d0Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 338c1e3c5d0Smrg 339cfcf9057Smrg trap 'ret=$?; rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null; exit $ret' 0 340cfcf9057Smrg 341cfcf9057Smrg # Because "mkdir -p" follows existing symlinks and we likely work 342cfcf9057Smrg # directly in world-writeable /tmp, make sure that the '$tmpdir' 343cfcf9057Smrg # directory is successfully created first before we actually test 344cfcf9057Smrg # 'mkdir -p' feature. 345c1e3c5d0Smrg if (umask $mkdir_umask && 346cfcf9057Smrg $mkdirprog $mkdir_mode "$tmpdir" && 347cfcf9057Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 348c1e3c5d0Smrg then 349c1e3c5d0Smrg if test -z "$dir_arg" || { 350c1e3c5d0Smrg # Check for POSIX incompatibilities with -m. 351c1e3c5d0Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 352c1e3c5d0Smrg # other-writable bit of parent directory when it shouldn't. 353c1e3c5d0Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 354cfcf9057Smrg test_tmpdir="$tmpdir/a" 355cfcf9057Smrg ls_ld_tmpdir=`ls -ld "$test_tmpdir"` 356c1e3c5d0Smrg case $ls_ld_tmpdir in 357c1e3c5d0Smrg d????-?r-*) different_mode=700;; 358c1e3c5d0Smrg d????-?--*) different_mode=755;; 359c1e3c5d0Smrg *) false;; 360c1e3c5d0Smrg esac && 361cfcf9057Smrg $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { 362cfcf9057Smrg ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` 363c1e3c5d0Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 364c1e3c5d0Smrg } 365c1e3c5d0Smrg } 366c1e3c5d0Smrg then posix_mkdir=: 367c1e3c5d0Smrg fi 368cfcf9057Smrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 369c1e3c5d0Smrg else 370c1e3c5d0Smrg # Remove any dirs left behind by ancient mkdir implementations. 371cfcf9057Smrg rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null 372c1e3c5d0Smrg fi 373c1e3c5d0Smrg trap '' 0;; 374c1e3c5d0Smrg esac;; 37598af18c5Smrg esac 3766f03b1f6Smrg 37798af18c5Smrg if 37898af18c5Smrg $posix_mkdir && ( 379c1e3c5d0Smrg umask $mkdir_umask && 380c1e3c5d0Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 38198af18c5Smrg ) 38298af18c5Smrg then : 38398af18c5Smrg else 3846f03b1f6Smrg 38598af18c5Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 38698af18c5Smrg # or it failed possibly due to a race condition. Create the 38798af18c5Smrg # directory the slow way, step by step, checking for races as we go. 3886f03b1f6Smrg 38998af18c5Smrg case $dstdir in 390c1e3c5d0Smrg /*) prefix='/';; 391c1e3c5d0Smrg [-=\(\)!]*) prefix='./';; 392c1e3c5d0Smrg *) prefix='';; 39398af18c5Smrg esac 3946f03b1f6Smrg 39598af18c5Smrg oIFS=$IFS 39698af18c5Smrg IFS=/ 397c1e3c5d0Smrg set -f 39898af18c5Smrg set fnord $dstdir 3996f03b1f6Smrg shift 400c1e3c5d0Smrg set +f 40198af18c5Smrg IFS=$oIFS 40298af18c5Smrg 40398af18c5Smrg prefixes= 40498af18c5Smrg 40598af18c5Smrg for d 40698af18c5Smrg do 407c1e3c5d0Smrg test X"$d" = X && continue 408c1e3c5d0Smrg 409c1e3c5d0Smrg prefix=$prefix$d 410c1e3c5d0Smrg if test -d "$prefix"; then 411c1e3c5d0Smrg prefixes= 412c1e3c5d0Smrg else 413c1e3c5d0Smrg if $posix_mkdir; then 414c1e3c5d0Smrg (umask=$mkdir_umask && 415c1e3c5d0Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 416c1e3c5d0Smrg # Don't fail if two instances are running concurrently. 417c1e3c5d0Smrg test -d "$prefix" || exit 1 418c1e3c5d0Smrg else 419c1e3c5d0Smrg case $prefix in 420c1e3c5d0Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 421c1e3c5d0Smrg *) qprefix=$prefix;; 422c1e3c5d0Smrg esac 423c1e3c5d0Smrg prefixes="$prefixes '$qprefix'" 424c1e3c5d0Smrg fi 425c1e3c5d0Smrg fi 426c1e3c5d0Smrg prefix=$prefix/ 42798af18c5Smrg done 42898af18c5Smrg 42998af18c5Smrg if test -n "$prefixes"; then 430c1e3c5d0Smrg # Don't fail if two instances are running concurrently. 431c1e3c5d0Smrg (umask $mkdir_umask && 432c1e3c5d0Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 433c1e3c5d0Smrg test -d "$dstdir" || exit 1 434c1e3c5d0Smrg obsolete_mkdir_used=true 4356f03b1f6Smrg fi 43698af18c5Smrg fi 4376f03b1f6Smrg fi 4386f03b1f6Smrg 4396f03b1f6Smrg if test -n "$dir_arg"; then 44098af18c5Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 44198af18c5Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 44298af18c5Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 44398af18c5Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4446f03b1f6Smrg else 4456f03b1f6Smrg 4466f03b1f6Smrg # Make a couple of temp file names in the proper directory. 447cfcf9057Smrg dsttmp=${dstdirslash}_inst.$$_ 448cfcf9057Smrg rmtmp=${dstdirslash}_rm.$$_ 4496f03b1f6Smrg 4506f03b1f6Smrg # Trap to clean up those temp files at exit. 4516f03b1f6Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4526f03b1f6Smrg 4536f03b1f6Smrg # Copy the file name to the temp name. 45498af18c5Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4556f03b1f6Smrg 4566f03b1f6Smrg # and set any options; do chmod last to preserve setuid bits. 4576f03b1f6Smrg # 4586f03b1f6Smrg # If any of these fail, we abort the whole thing. If we want to 4596f03b1f6Smrg # ignore errors from any of these, just make sure not to ignore 4606f03b1f6Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4616f03b1f6Smrg # 46298af18c5Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 46398af18c5Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 46498af18c5Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 46598af18c5Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 46698af18c5Smrg 46798af18c5Smrg # If -C, don't bother to copy if it wouldn't change the file. 46898af18c5Smrg if $copy_on_change && 469c1e3c5d0Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 470c1e3c5d0Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 471c1e3c5d0Smrg set -f && 47298af18c5Smrg set X $old && old=:$2:$4:$5:$6 && 47398af18c5Smrg set X $new && new=:$2:$4:$5:$6 && 474c1e3c5d0Smrg set +f && 47598af18c5Smrg test "$old" = "$new" && 47698af18c5Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 47798af18c5Smrg then 47898af18c5Smrg rm -f "$dsttmp" 47998af18c5Smrg else 48098af18c5Smrg # Rename the file to the real destination. 48198af18c5Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 48298af18c5Smrg 48398af18c5Smrg # The rename failed, perhaps because mv can't rename something else 48498af18c5Smrg # to itself, or perhaps because mv is so ancient that it does not 48598af18c5Smrg # support -f. 48698af18c5Smrg { 487c1e3c5d0Smrg # Now remove or move aside any old file at destination location. 488c1e3c5d0Smrg # We try this two ways since rm can't unlink itself on some 489c1e3c5d0Smrg # systems and the destination file might be busy for other 490c1e3c5d0Smrg # reasons. In this case, the final cleanup might fail but the new 491c1e3c5d0Smrg # file should still install successfully. 492c1e3c5d0Smrg { 493c1e3c5d0Smrg test ! -f "$dst" || 494c1e3c5d0Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 495c1e3c5d0Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 496c1e3c5d0Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 497c1e3c5d0Smrg } || 498c1e3c5d0Smrg { echo "$0: cannot unlink or rename $dst" >&2 499c1e3c5d0Smrg (exit 1); exit 1 500c1e3c5d0Smrg } 501c1e3c5d0Smrg } && 502c1e3c5d0Smrg 503c1e3c5d0Smrg # Now rename the file to the real destination. 504c1e3c5d0Smrg $doit $mvcmd "$dsttmp" "$dst" 50598af18c5Smrg } 50698af18c5Smrg fi || exit 1 50798af18c5Smrg 50898af18c5Smrg trap '' 0 50998af18c5Smrg fi 5106f03b1f6Smrgdone 5116f03b1f6Smrg 5126f03b1f6Smrg# Local variables: 513cfcf9057Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 5146f03b1f6Smrg# time-stamp-start: "scriptversion=" 5156f03b1f6Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 516cfcf9057Smrg# time-stamp-time-zone: "UTC0" 51798af18c5Smrg# time-stamp-end: "; # UTC" 5186f03b1f6Smrg# End: 519