install-sh revision 7ce7e03c
1f7ec340bSmacallan#!/bin/sh 2f7ec340bSmacallan# install - install a program, script, or datafile 3f7ec340bSmacallan 47ce7e03cSmrgscriptversion=2006-12-25.00 5f7ec340bSmacallan 6f7ec340bSmacallan# This originates from X11R5 (mit/util/scripts/install.sh), which was 7f7ec340bSmacallan# later released in X11R6 (xc/config/util/install.sh) with the 8f7ec340bSmacallan# following copyright and license. 9f7ec340bSmacallan# 10f7ec340bSmacallan# Copyright (C) 1994 X Consortium 11f7ec340bSmacallan# 12f7ec340bSmacallan# Permission is hereby granted, free of charge, to any person obtaining a copy 13f7ec340bSmacallan# of this software and associated documentation files (the "Software"), to 14f7ec340bSmacallan# deal in the Software without restriction, including without limitation the 15f7ec340bSmacallan# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16f7ec340bSmacallan# sell copies of the Software, and to permit persons to whom the Software is 17f7ec340bSmacallan# furnished to do so, subject to the following conditions: 18f7ec340bSmacallan# 19f7ec340bSmacallan# The above copyright notice and this permission notice shall be included in 20f7ec340bSmacallan# all copies or substantial portions of the Software. 21f7ec340bSmacallan# 22f7ec340bSmacallan# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23f7ec340bSmacallan# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24f7ec340bSmacallan# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25f7ec340bSmacallan# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26f7ec340bSmacallan# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27f7ec340bSmacallan# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28f7ec340bSmacallan# 29f7ec340bSmacallan# Except as contained in this notice, the name of the X Consortium shall not 30f7ec340bSmacallan# be used in advertising or otherwise to promote the sale, use or other deal- 31f7ec340bSmacallan# ings in this Software without prior written authorization from the X Consor- 32f7ec340bSmacallan# tium. 33f7ec340bSmacallan# 34f7ec340bSmacallan# 35f7ec340bSmacallan# FSF changes to this file are in the public domain. 36f7ec340bSmacallan# 37f7ec340bSmacallan# Calling this script install-sh is preferred over install.sh, to prevent 38f7ec340bSmacallan# `make' implicit rules from creating a file called install from it 39f7ec340bSmacallan# when there is no Makefile. 40f7ec340bSmacallan# 41f7ec340bSmacallan# This script is compatible with the BSD install script, but was written 427ce7e03cSmrg# from scratch. 437ce7e03cSmrg 447ce7e03cSmrgnl=' 457ce7e03cSmrg' 467ce7e03cSmrgIFS=" "" $nl" 47f7ec340bSmacallan 48f7ec340bSmacallan# set DOITPROG to echo to test this script 49f7ec340bSmacallan 50f7ec340bSmacallan# Don't use :- since 4.3BSD and earlier shells don't like it. 517ce7e03cSmrgdoit=${DOITPROG-} 527ce7e03cSmrgif test -z "$doit"; then 537ce7e03cSmrg doit_exec=exec 547ce7e03cSmrgelse 557ce7e03cSmrg doit_exec=$doit 567ce7e03cSmrgfi 57f7ec340bSmacallan 587ce7e03cSmrg# Put in absolute file names if you don't have them in your path; 597ce7e03cSmrg# or use environment vars. 607ce7e03cSmrg 617ce7e03cSmrgchgrpprog=${CHGRPPROG-chgrp} 627ce7e03cSmrgchmodprog=${CHMODPROG-chmod} 637ce7e03cSmrgchownprog=${CHOWNPROG-chown} 647ce7e03cSmrgcmpprog=${CMPPROG-cmp} 657ce7e03cSmrgcpprog=${CPPROG-cp} 667ce7e03cSmrgmkdirprog=${MKDIRPROG-mkdir} 677ce7e03cSmrgmvprog=${MVPROG-mv} 687ce7e03cSmrgrmprog=${RMPROG-rm} 697ce7e03cSmrgstripprog=${STRIPPROG-strip} 707ce7e03cSmrg 717ce7e03cSmrgposix_glob='?' 727ce7e03cSmrginitialize_posix_glob=' 737ce7e03cSmrg test "$posix_glob" != "?" || { 747ce7e03cSmrg if (set -f) 2>/dev/null; then 757ce7e03cSmrg posix_glob= 767ce7e03cSmrg else 777ce7e03cSmrg posix_glob=: 787ce7e03cSmrg fi 797ce7e03cSmrg } 807ce7e03cSmrg' 81f7ec340bSmacallan 827ce7e03cSmrgposix_mkdir= 837ce7e03cSmrg 847ce7e03cSmrg# Desired mode of installed file. 857ce7e03cSmrgmode=0755 86f7ec340bSmacallan 87f7ec340bSmacallanchgrpcmd= 887ce7e03cSmrgchmodcmd=$chmodprog 897ce7e03cSmrgchowncmd= 907ce7e03cSmrgmvcmd=$mvprog 91f7ec340bSmacallanrmcmd="$rmprog -f" 927ce7e03cSmrgstripcmd= 937ce7e03cSmrg 94f7ec340bSmacallansrc= 95f7ec340bSmacallandst= 96f7ec340bSmacallandir_arg= 977ce7e03cSmrgdst_arg= 987ce7e03cSmrg 997ce7e03cSmrgcopy_on_change=false 100f7ec340bSmacallanno_target_directory= 101f7ec340bSmacallan 1027ce7e03cSmrgusage="\ 1037ce7e03cSmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 104f7ec340bSmacallan or: $0 [OPTION]... SRCFILES... DIRECTORY 105f7ec340bSmacallan or: $0 [OPTION]... -t DIRECTORY SRCFILES... 106f7ec340bSmacallan or: $0 [OPTION]... -d DIRECTORIES... 107f7ec340bSmacallan 108f7ec340bSmacallanIn the 1st form, copy SRCFILE to DSTFILE. 109f7ec340bSmacallanIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 110f7ec340bSmacallanIn the 4th, create DIRECTORIES. 111f7ec340bSmacallan 112f7ec340bSmacallanOptions: 1137ce7e03cSmrg --help display this help and exit. 1147ce7e03cSmrg --version display version info and exit. 1157ce7e03cSmrg 1167ce7e03cSmrg -c (ignored) 1177ce7e03cSmrg -C install only if different (preserve the last data modification time) 1187ce7e03cSmrg -d create directories instead of installing files. 1197ce7e03cSmrg -g GROUP $chgrpprog installed files to GROUP. 1207ce7e03cSmrg -m MODE $chmodprog installed files to MODE. 1217ce7e03cSmrg -o USER $chownprog installed files to USER. 1227ce7e03cSmrg -s $stripprog installed files. 1237ce7e03cSmrg -t DIRECTORY install into DIRECTORY. 1247ce7e03cSmrg -T report an error if DSTFILE is a directory. 125f7ec340bSmacallan 126f7ec340bSmacallanEnvironment variables override the default commands: 1277ce7e03cSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1287ce7e03cSmrg RMPROG STRIPPROG 129f7ec340bSmacallan" 130f7ec340bSmacallan 1317ce7e03cSmrgwhile test $# -ne 0; do 132f7ec340bSmacallan case $1 in 1337ce7e03cSmrg -c) ;; 1347ce7e03cSmrg 1357ce7e03cSmrg -C) copy_on_change=true;; 136f7ec340bSmacallan 1377ce7e03cSmrg -d) dir_arg=true;; 138f7ec340bSmacallan 139f7ec340bSmacallan -g) chgrpcmd="$chgrpprog $2" 1407ce7e03cSmrg shift;; 141f7ec340bSmacallan 142f7ec340bSmacallan --help) echo "$usage"; exit $?;; 143f7ec340bSmacallan 1447ce7e03cSmrg -m) mode=$2 1457ce7e03cSmrg case $mode in 1467ce7e03cSmrg *' '* | *' '* | *' 1477ce7e03cSmrg'* | *'*'* | *'?'* | *'['*) 1487ce7e03cSmrg echo "$0: invalid mode: $mode" >&2 1497ce7e03cSmrg exit 1;; 1507ce7e03cSmrg esac 1517ce7e03cSmrg shift;; 152f7ec340bSmacallan 153f7ec340bSmacallan -o) chowncmd="$chownprog $2" 1547ce7e03cSmrg shift;; 155f7ec340bSmacallan 1567ce7e03cSmrg -s) stripcmd=$stripprog;; 157f7ec340bSmacallan 1587ce7e03cSmrg -t) dst_arg=$2 1597ce7e03cSmrg shift;; 160f7ec340bSmacallan 1617ce7e03cSmrg -T) no_target_directory=true;; 162f7ec340bSmacallan 163f7ec340bSmacallan --version) echo "$0 $scriptversion"; exit $?;; 164f7ec340bSmacallan 1657ce7e03cSmrg --) shift 166f7ec340bSmacallan break;; 1677ce7e03cSmrg 1687ce7e03cSmrg -*) echo "$0: invalid option: $1" >&2 1697ce7e03cSmrg exit 1;; 1707ce7e03cSmrg 1717ce7e03cSmrg *) break;; 172f7ec340bSmacallan esac 1737ce7e03cSmrg shift 174f7ec340bSmacallandone 175f7ec340bSmacallan 1767ce7e03cSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1777ce7e03cSmrg # When -d is used, all remaining arguments are directories to create. 1787ce7e03cSmrg # When -t is used, the destination is already specified. 1797ce7e03cSmrg # Otherwise, the last argument is the destination. Remove it from $@. 1807ce7e03cSmrg for arg 1817ce7e03cSmrg do 1827ce7e03cSmrg if test -n "$dst_arg"; then 1837ce7e03cSmrg # $@ is not empty: it contains at least $arg. 1847ce7e03cSmrg set fnord "$@" "$dst_arg" 1857ce7e03cSmrg shift # fnord 1867ce7e03cSmrg fi 1877ce7e03cSmrg shift # arg 1887ce7e03cSmrg dst_arg=$arg 1897ce7e03cSmrg done 1907ce7e03cSmrgfi 1917ce7e03cSmrg 1927ce7e03cSmrgif test $# -eq 0; then 193f7ec340bSmacallan if test -z "$dir_arg"; then 194f7ec340bSmacallan echo "$0: no input file specified." >&2 195f7ec340bSmacallan exit 1 196f7ec340bSmacallan fi 197f7ec340bSmacallan # It's OK to call `install-sh -d' without argument. 198f7ec340bSmacallan # This can happen when creating conditional directories. 199f7ec340bSmacallan exit 0 200f7ec340bSmacallanfi 201f7ec340bSmacallan 2027ce7e03cSmrgif test -z "$dir_arg"; then 2037ce7e03cSmrg trap '(exit $?); exit' 1 2 13 15 2047ce7e03cSmrg 2057ce7e03cSmrg # Set umask so as not to create temps with too-generous modes. 2067ce7e03cSmrg # However, 'strip' requires both read and write access to temps. 2077ce7e03cSmrg case $mode in 2087ce7e03cSmrg # Optimize common cases. 2097ce7e03cSmrg *644) cp_umask=133;; 2107ce7e03cSmrg *755) cp_umask=22;; 2117ce7e03cSmrg 2127ce7e03cSmrg *[0-7]) 2137ce7e03cSmrg if test -z "$stripcmd"; then 2147ce7e03cSmrg u_plus_rw= 2157ce7e03cSmrg else 2167ce7e03cSmrg u_plus_rw='% 200' 2177ce7e03cSmrg fi 2187ce7e03cSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2197ce7e03cSmrg *) 2207ce7e03cSmrg if test -z "$stripcmd"; then 2217ce7e03cSmrg u_plus_rw= 2227ce7e03cSmrg else 2237ce7e03cSmrg u_plus_rw=,u+rw 2247ce7e03cSmrg fi 2257ce7e03cSmrg cp_umask=$mode$u_plus_rw;; 2267ce7e03cSmrg esac 2277ce7e03cSmrgfi 2287ce7e03cSmrg 229f7ec340bSmacallanfor src 230f7ec340bSmacallando 231f7ec340bSmacallan # Protect names starting with `-'. 232f7ec340bSmacallan case $src in 2337ce7e03cSmrg -*) src=./$src;; 234f7ec340bSmacallan esac 235f7ec340bSmacallan 236f7ec340bSmacallan if test -n "$dir_arg"; then 237f7ec340bSmacallan dst=$src 2387ce7e03cSmrg dstdir=$dst 2397ce7e03cSmrg test -d "$dstdir" 2407ce7e03cSmrg dstdir_status=$? 241f7ec340bSmacallan else 2427ce7e03cSmrg 243f7ec340bSmacallan # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 244f7ec340bSmacallan # might cause directories to be created, which would be especially bad 245f7ec340bSmacallan # if $src (and thus $dsttmp) contains '*'. 246f7ec340bSmacallan if test ! -f "$src" && test ! -d "$src"; then 247f7ec340bSmacallan echo "$0: $src does not exist." >&2 248f7ec340bSmacallan exit 1 249f7ec340bSmacallan fi 250f7ec340bSmacallan 2517ce7e03cSmrg if test -z "$dst_arg"; then 252f7ec340bSmacallan echo "$0: no destination specified." >&2 253f7ec340bSmacallan exit 1 254f7ec340bSmacallan fi 255f7ec340bSmacallan 2567ce7e03cSmrg dst=$dst_arg 257f7ec340bSmacallan # Protect names starting with `-'. 258f7ec340bSmacallan case $dst in 2597ce7e03cSmrg -*) dst=./$dst;; 260f7ec340bSmacallan esac 261f7ec340bSmacallan 262f7ec340bSmacallan # If destination is a directory, append the input filename; won't work 263f7ec340bSmacallan # if double slashes aren't ignored. 264f7ec340bSmacallan if test -d "$dst"; then 265f7ec340bSmacallan if test -n "$no_target_directory"; then 2667ce7e03cSmrg echo "$0: $dst_arg: Is a directory" >&2 267f7ec340bSmacallan exit 1 268f7ec340bSmacallan fi 2697ce7e03cSmrg dstdir=$dst 2707ce7e03cSmrg dst=$dstdir/`basename "$src"` 2717ce7e03cSmrg dstdir_status=0 2727ce7e03cSmrg else 2737ce7e03cSmrg # Prefer dirname, but fall back on a substitute if dirname fails. 2747ce7e03cSmrg dstdir=` 2757ce7e03cSmrg (dirname "$dst") 2>/dev/null || 2767ce7e03cSmrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2777ce7e03cSmrg X"$dst" : 'X\(//\)[^/]' \| \ 2787ce7e03cSmrg X"$dst" : 'X\(//\)$' \| \ 2797ce7e03cSmrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2807ce7e03cSmrg echo X"$dst" | 2817ce7e03cSmrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2827ce7e03cSmrg s//\1/ 2837ce7e03cSmrg q 2847ce7e03cSmrg } 2857ce7e03cSmrg /^X\(\/\/\)[^/].*/{ 2867ce7e03cSmrg s//\1/ 2877ce7e03cSmrg q 2887ce7e03cSmrg } 2897ce7e03cSmrg /^X\(\/\/\)$/{ 2907ce7e03cSmrg s//\1/ 2917ce7e03cSmrg q 2927ce7e03cSmrg } 2937ce7e03cSmrg /^X\(\/\).*/{ 2947ce7e03cSmrg s//\1/ 2957ce7e03cSmrg q 2967ce7e03cSmrg } 2977ce7e03cSmrg s/.*/./; q' 2987ce7e03cSmrg ` 2997ce7e03cSmrg 3007ce7e03cSmrg test -d "$dstdir" 3017ce7e03cSmrg dstdir_status=$? 302f7ec340bSmacallan fi 303f7ec340bSmacallan fi 304f7ec340bSmacallan 3057ce7e03cSmrg obsolete_mkdir_used=false 3067ce7e03cSmrg 3077ce7e03cSmrg if test $dstdir_status != 0; then 3087ce7e03cSmrg case $posix_mkdir in 3097ce7e03cSmrg '') 3107ce7e03cSmrg # Create intermediate dirs using mode 755 as modified by the umask. 3117ce7e03cSmrg # This is like FreeBSD 'install' as of 1997-10-28. 3127ce7e03cSmrg umask=`umask` 3137ce7e03cSmrg case $stripcmd.$umask in 3147ce7e03cSmrg # Optimize common cases. 3157ce7e03cSmrg *[2367][2367]) mkdir_umask=$umask;; 3167ce7e03cSmrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3177ce7e03cSmrg 3187ce7e03cSmrg *[0-7]) 3197ce7e03cSmrg mkdir_umask=`expr $umask + 22 \ 3207ce7e03cSmrg - $umask % 100 % 40 + $umask % 20 \ 3217ce7e03cSmrg - $umask % 10 % 4 + $umask % 2 3227ce7e03cSmrg `;; 3237ce7e03cSmrg *) mkdir_umask=$umask,go-w;; 3247ce7e03cSmrg esac 3257ce7e03cSmrg 3267ce7e03cSmrg # With -d, create the new directory with the user-specified mode. 3277ce7e03cSmrg # Otherwise, rely on $mkdir_umask. 3287ce7e03cSmrg if test -n "$dir_arg"; then 3297ce7e03cSmrg mkdir_mode=-m$mode 3307ce7e03cSmrg else 3317ce7e03cSmrg mkdir_mode= 3327ce7e03cSmrg fi 3337ce7e03cSmrg 3347ce7e03cSmrg posix_mkdir=false 3357ce7e03cSmrg case $umask in 3367ce7e03cSmrg *[123567][0-7][0-7]) 3377ce7e03cSmrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3387ce7e03cSmrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3397ce7e03cSmrg ;; 3407ce7e03cSmrg *) 3417ce7e03cSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3427ce7e03cSmrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3437ce7e03cSmrg 3447ce7e03cSmrg if (umask $mkdir_umask && 3457ce7e03cSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3467ce7e03cSmrg then 3477ce7e03cSmrg if test -z "$dir_arg" || { 3487ce7e03cSmrg # Check for POSIX incompatibilities with -m. 3497ce7e03cSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3507ce7e03cSmrg # other-writeable bit of parent directory when it shouldn't. 3517ce7e03cSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3527ce7e03cSmrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3537ce7e03cSmrg case $ls_ld_tmpdir in 3547ce7e03cSmrg d????-?r-*) different_mode=700;; 3557ce7e03cSmrg d????-?--*) different_mode=755;; 3567ce7e03cSmrg *) false;; 3577ce7e03cSmrg esac && 3587ce7e03cSmrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3597ce7e03cSmrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3607ce7e03cSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3617ce7e03cSmrg } 3627ce7e03cSmrg } 3637ce7e03cSmrg then posix_mkdir=: 3647ce7e03cSmrg fi 3657ce7e03cSmrg rmdir "$tmpdir/d" "$tmpdir" 3667ce7e03cSmrg else 3677ce7e03cSmrg # Remove any dirs left behind by ancient mkdir implementations. 3687ce7e03cSmrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3697ce7e03cSmrg fi 3707ce7e03cSmrg trap '' 0;; 3717ce7e03cSmrg esac;; 3727ce7e03cSmrg esac 373f7ec340bSmacallan 3747ce7e03cSmrg if 3757ce7e03cSmrg $posix_mkdir && ( 3767ce7e03cSmrg umask $mkdir_umask && 3777ce7e03cSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3787ce7e03cSmrg ) 3797ce7e03cSmrg then : 3807ce7e03cSmrg else 381f7ec340bSmacallan 3827ce7e03cSmrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3837ce7e03cSmrg # or it failed possibly due to a race condition. Create the 3847ce7e03cSmrg # directory the slow way, step by step, checking for races as we go. 385f7ec340bSmacallan 3867ce7e03cSmrg case $dstdir in 3877ce7e03cSmrg /*) prefix='/';; 3887ce7e03cSmrg -*) prefix='./';; 3897ce7e03cSmrg *) prefix='';; 3907ce7e03cSmrg esac 391f7ec340bSmacallan 3927ce7e03cSmrg eval "$initialize_posix_glob" 393f7ec340bSmacallan 3947ce7e03cSmrg oIFS=$IFS 3957ce7e03cSmrg IFS=/ 3967ce7e03cSmrg $posix_glob set -f 3977ce7e03cSmrg set fnord $dstdir 398f7ec340bSmacallan shift 3997ce7e03cSmrg $posix_glob set +f 4007ce7e03cSmrg IFS=$oIFS 4017ce7e03cSmrg 4027ce7e03cSmrg prefixes= 4037ce7e03cSmrg 4047ce7e03cSmrg for d 4057ce7e03cSmrg do 4067ce7e03cSmrg test -z "$d" && continue 4077ce7e03cSmrg 4087ce7e03cSmrg prefix=$prefix$d 4097ce7e03cSmrg if test -d "$prefix"; then 4107ce7e03cSmrg prefixes= 4117ce7e03cSmrg else 4127ce7e03cSmrg if $posix_mkdir; then 4137ce7e03cSmrg (umask=$mkdir_umask && 4147ce7e03cSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4157ce7e03cSmrg # Don't fail if two instances are running concurrently. 4167ce7e03cSmrg test -d "$prefix" || exit 1 4177ce7e03cSmrg else 4187ce7e03cSmrg case $prefix in 4197ce7e03cSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4207ce7e03cSmrg *) qprefix=$prefix;; 4217ce7e03cSmrg esac 4227ce7e03cSmrg prefixes="$prefixes '$qprefix'" 4237ce7e03cSmrg fi 4247ce7e03cSmrg fi 4257ce7e03cSmrg prefix=$prefix/ 4267ce7e03cSmrg done 4277ce7e03cSmrg 4287ce7e03cSmrg if test -n "$prefixes"; then 4297ce7e03cSmrg # Don't fail if two instances are running concurrently. 4307ce7e03cSmrg (umask $mkdir_umask && 4317ce7e03cSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 4327ce7e03cSmrg test -d "$dstdir" || exit 1 4337ce7e03cSmrg obsolete_mkdir_used=true 434f7ec340bSmacallan fi 4357ce7e03cSmrg fi 436f7ec340bSmacallan fi 437f7ec340bSmacallan 438f7ec340bSmacallan if test -n "$dir_arg"; then 4397ce7e03cSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4407ce7e03cSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4417ce7e03cSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4427ce7e03cSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 443f7ec340bSmacallan else 444f7ec340bSmacallan 445f7ec340bSmacallan # Make a couple of temp file names in the proper directory. 446f7ec340bSmacallan dsttmp=$dstdir/_inst.$$_ 447f7ec340bSmacallan rmtmp=$dstdir/_rm.$$_ 448f7ec340bSmacallan 449f7ec340bSmacallan # Trap to clean up those temp files at exit. 450f7ec340bSmacallan trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 451f7ec340bSmacallan 452f7ec340bSmacallan # Copy the file name to the temp name. 4537ce7e03cSmrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 454f7ec340bSmacallan 455f7ec340bSmacallan # and set any options; do chmod last to preserve setuid bits. 456f7ec340bSmacallan # 457f7ec340bSmacallan # If any of these fail, we abort the whole thing. If we want to 458f7ec340bSmacallan # ignore errors from any of these, just make sure not to ignore 459f7ec340bSmacallan # errors from the above "$doit $cpprog $src $dsttmp" command. 460f7ec340bSmacallan # 4617ce7e03cSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4627ce7e03cSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4637ce7e03cSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4647ce7e03cSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4657ce7e03cSmrg 4667ce7e03cSmrg # If -C, don't bother to copy if it wouldn't change the file. 4677ce7e03cSmrg if $copy_on_change && 4687ce7e03cSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4697ce7e03cSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4707ce7e03cSmrg 4717ce7e03cSmrg eval "$initialize_posix_glob" && 4727ce7e03cSmrg $posix_glob set -f && 4737ce7e03cSmrg set X $old && old=:$2:$4:$5:$6 && 4747ce7e03cSmrg set X $new && new=:$2:$4:$5:$6 && 4757ce7e03cSmrg $posix_glob set +f && 4767ce7e03cSmrg 4777ce7e03cSmrg test "$old" = "$new" && 4787ce7e03cSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4797ce7e03cSmrg then 4807ce7e03cSmrg rm -f "$dsttmp" 4817ce7e03cSmrg else 4827ce7e03cSmrg # Rename the file to the real destination. 4837ce7e03cSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4847ce7e03cSmrg 4857ce7e03cSmrg # The rename failed, perhaps because mv can't rename something else 4867ce7e03cSmrg # to itself, or perhaps because mv is so ancient that it does not 4877ce7e03cSmrg # support -f. 4887ce7e03cSmrg { 4897ce7e03cSmrg # Now remove or move aside any old file at destination location. 4907ce7e03cSmrg # We try this two ways since rm can't unlink itself on some 4917ce7e03cSmrg # systems and the destination file might be busy for other 4927ce7e03cSmrg # reasons. In this case, the final cleanup might fail but the new 4937ce7e03cSmrg # file should still install successfully. 4947ce7e03cSmrg { 4957ce7e03cSmrg test ! -f "$dst" || 4967ce7e03cSmrg $doit $rmcmd -f "$dst" 2>/dev/null || 4977ce7e03cSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 4987ce7e03cSmrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 4997ce7e03cSmrg } || 5007ce7e03cSmrg { echo "$0: cannot unlink or rename $dst" >&2 5017ce7e03cSmrg (exit 1); exit 1 5027ce7e03cSmrg } 5037ce7e03cSmrg } && 5047ce7e03cSmrg 5057ce7e03cSmrg # Now rename the file to the real destination. 5067ce7e03cSmrg $doit $mvcmd "$dsttmp" "$dst" 5077ce7e03cSmrg } 5087ce7e03cSmrg fi || exit 1 5097ce7e03cSmrg 5107ce7e03cSmrg trap '' 0 5117ce7e03cSmrg fi 512f7ec340bSmacallandone 513f7ec340bSmacallan 514f7ec340bSmacallan# Local variables: 515f7ec340bSmacallan# eval: (add-hook 'write-file-hooks 'time-stamp) 516f7ec340bSmacallan# time-stamp-start: "scriptversion=" 517f7ec340bSmacallan# time-stamp-format: "%:y-%02m-%02d.%02H" 518f7ec340bSmacallan# time-stamp-end: "$" 519f7ec340bSmacallan# End: 520