install-sh revision 1d05b0c9
11fb077a1Smrg#!/bin/sh 21fb077a1Smrg# install - install a program, script, or datafile 31fb077a1Smrg 41d05b0c9Smrgscriptversion=2011-01-19.21; # UTC 51fb077a1Smrg 61fb077a1Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 71fb077a1Smrg# later released in X11R6 (xc/config/util/install.sh) with the 81fb077a1Smrg# following copyright and license. 91fb077a1Smrg# 101fb077a1Smrg# Copyright (C) 1994 X Consortium 111fb077a1Smrg# 121fb077a1Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 131fb077a1Smrg# of this software and associated documentation files (the "Software"), to 141fb077a1Smrg# deal in the Software without restriction, including without limitation the 151fb077a1Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 161fb077a1Smrg# sell copies of the Software, and to permit persons to whom the Software is 171fb077a1Smrg# furnished to do so, subject to the following conditions: 181fb077a1Smrg# 191fb077a1Smrg# The above copyright notice and this permission notice shall be included in 201fb077a1Smrg# all copies or substantial portions of the Software. 211fb077a1Smrg# 221fb077a1Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 231fb077a1Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 241fb077a1Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 251fb077a1Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 261fb077a1Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 271fb077a1Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 281fb077a1Smrg# 291fb077a1Smrg# Except as contained in this notice, the name of the X Consortium shall not 301fb077a1Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 311fb077a1Smrg# ings in this Software without prior written authorization from the X Consor- 321fb077a1Smrg# tium. 331fb077a1Smrg# 341fb077a1Smrg# 351fb077a1Smrg# FSF changes to this file are in the public domain. 361fb077a1Smrg# 371fb077a1Smrg# Calling this script install-sh is preferred over install.sh, to prevent 381fb077a1Smrg# `make' implicit rules from creating a file called install from it 391fb077a1Smrg# when there is no Makefile. 401fb077a1Smrg# 411fb077a1Smrg# This script is compatible with the BSD install script, but was written 421fb077a1Smrg# from scratch. 431fb077a1Smrg 441fb077a1Smrgnl=' 451fb077a1Smrg' 461fb077a1SmrgIFS=" "" $nl" 471fb077a1Smrg 481fb077a1Smrg# set DOITPROG to echo to test this script 491fb077a1Smrg 501fb077a1Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 51a5a92c01Smrgdoit=${DOITPROG-} 521fb077a1Smrgif test -z "$doit"; then 531fb077a1Smrg doit_exec=exec 541fb077a1Smrgelse 551fb077a1Smrg doit_exec=$doit 561fb077a1Smrgfi 571fb077a1Smrg 581fb077a1Smrg# Put in absolute file names if you don't have them in your path; 591fb077a1Smrg# or use environment vars. 601fb077a1Smrg 61a5a92c01Smrgchgrpprog=${CHGRPPROG-chgrp} 62a5a92c01Smrgchmodprog=${CHMODPROG-chmod} 63a5a92c01Smrgchownprog=${CHOWNPROG-chown} 64a5a92c01Smrgcmpprog=${CMPPROG-cmp} 65a5a92c01Smrgcpprog=${CPPROG-cp} 66a5a92c01Smrgmkdirprog=${MKDIRPROG-mkdir} 67a5a92c01Smrgmvprog=${MVPROG-mv} 68a5a92c01Smrgrmprog=${RMPROG-rm} 69a5a92c01Smrgstripprog=${STRIPPROG-strip} 70a5a92c01Smrg 71a5a92c01Smrgposix_glob='?' 72a5a92c01Smrginitialize_posix_glob=' 73a5a92c01Smrg test "$posix_glob" != "?" || { 74a5a92c01Smrg if (set -f) 2>/dev/null; then 75a5a92c01Smrg posix_glob= 76a5a92c01Smrg else 77a5a92c01Smrg posix_glob=: 78a5a92c01Smrg fi 79a5a92c01Smrg } 80a5a92c01Smrg' 811fb077a1Smrg 821fb077a1Smrgposix_mkdir= 831fb077a1Smrg 841fb077a1Smrg# Desired mode of installed file. 851fb077a1Smrgmode=0755 861fb077a1Smrg 87a5a92c01Smrgchgrpcmd= 881fb077a1Smrgchmodcmd=$chmodprog 891fb077a1Smrgchowncmd= 90a5a92c01Smrgmvcmd=$mvprog 911fb077a1Smrgrmcmd="$rmprog -f" 92a5a92c01Smrgstripcmd= 93a5a92c01Smrg 941fb077a1Smrgsrc= 951fb077a1Smrgdst= 961fb077a1Smrgdir_arg= 97a5a92c01Smrgdst_arg= 98a5a92c01Smrg 99a5a92c01Smrgcopy_on_change=false 1001fb077a1Smrgno_target_directory= 1011fb077a1Smrg 102a5a92c01Smrgusage="\ 103a5a92c01SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1041fb077a1Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1051fb077a1Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1061fb077a1Smrg or: $0 [OPTION]... -d DIRECTORIES... 1071fb077a1Smrg 1081fb077a1SmrgIn the 1st form, copy SRCFILE to DSTFILE. 1091fb077a1SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1101fb077a1SmrgIn the 4th, create DIRECTORIES. 1111fb077a1Smrg 1121fb077a1SmrgOptions: 113a5a92c01Smrg --help display this help and exit. 114a5a92c01Smrg --version display version info and exit. 115a5a92c01Smrg 116a5a92c01Smrg -c (ignored) 117a5a92c01Smrg -C install only if different (preserve the last data modification time) 118a5a92c01Smrg -d create directories instead of installing files. 119a5a92c01Smrg -g GROUP $chgrpprog installed files to GROUP. 120a5a92c01Smrg -m MODE $chmodprog installed files to MODE. 121a5a92c01Smrg -o USER $chownprog installed files to USER. 122a5a92c01Smrg -s $stripprog installed files. 123a5a92c01Smrg -t DIRECTORY install into DIRECTORY. 124a5a92c01Smrg -T report an error if DSTFILE is a directory. 1251fb077a1Smrg 1261fb077a1SmrgEnvironment variables override the default commands: 127a5a92c01Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 128a5a92c01Smrg RMPROG STRIPPROG 1291fb077a1Smrg" 1301fb077a1Smrg 1311fb077a1Smrgwhile test $# -ne 0; do 1321fb077a1Smrg case $1 in 133a5a92c01Smrg -c) ;; 134a5a92c01Smrg 135a5a92c01Smrg -C) copy_on_change=true;; 1361fb077a1Smrg 137a5a92c01Smrg -d) dir_arg=true;; 1381fb077a1Smrg 1391fb077a1Smrg -g) chgrpcmd="$chgrpprog $2" 140a5a92c01Smrg shift;; 1411fb077a1Smrg 1421fb077a1Smrg --help) echo "$usage"; exit $?;; 1431fb077a1Smrg 1441fb077a1Smrg -m) mode=$2 1451fb077a1Smrg case $mode in 1461fb077a1Smrg *' '* | *' '* | *' 1471fb077a1Smrg'* | *'*'* | *'?'* | *'['*) 1481fb077a1Smrg echo "$0: invalid mode: $mode" >&2 1491fb077a1Smrg exit 1;; 1501fb077a1Smrg esac 151a5a92c01Smrg shift;; 1521fb077a1Smrg 1531fb077a1Smrg -o) chowncmd="$chownprog $2" 154a5a92c01Smrg shift;; 1551fb077a1Smrg 156a5a92c01Smrg -s) stripcmd=$stripprog;; 1571fb077a1Smrg 158a5a92c01Smrg -t) dst_arg=$2 1591d05b0c9Smrg # Protect names problematic for `test' and other utilities. 1601d05b0c9Smrg case $dst_arg in 1611d05b0c9Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1621d05b0c9Smrg esac 163a5a92c01Smrg shift;; 1641fb077a1Smrg 165a5a92c01Smrg -T) no_target_directory=true;; 1661fb077a1Smrg 1671fb077a1Smrg --version) echo "$0 $scriptversion"; exit $?;; 1681fb077a1Smrg 1691fb077a1Smrg --) shift 1701fb077a1Smrg break;; 1711fb077a1Smrg 1721fb077a1Smrg -*) echo "$0: invalid option: $1" >&2 1731fb077a1Smrg exit 1;; 1741fb077a1Smrg 1751fb077a1Smrg *) break;; 1761fb077a1Smrg esac 177a5a92c01Smrg shift 1781fb077a1Smrgdone 1791fb077a1Smrg 180a5a92c01Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1811fb077a1Smrg # When -d is used, all remaining arguments are directories to create. 1821fb077a1Smrg # When -t is used, the destination is already specified. 1831fb077a1Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1841fb077a1Smrg for arg 1851fb077a1Smrg do 186a5a92c01Smrg if test -n "$dst_arg"; then 1871fb077a1Smrg # $@ is not empty: it contains at least $arg. 188a5a92c01Smrg set fnord "$@" "$dst_arg" 1891fb077a1Smrg shift # fnord 1901fb077a1Smrg fi 1911fb077a1Smrg shift # arg 192a5a92c01Smrg dst_arg=$arg 1931d05b0c9Smrg # Protect names problematic for `test' and other utilities. 1941d05b0c9Smrg case $dst_arg in 1951d05b0c9Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1961d05b0c9Smrg esac 1971fb077a1Smrg done 1981fb077a1Smrgfi 1991fb077a1Smrg 2001fb077a1Smrgif test $# -eq 0; then 2011fb077a1Smrg if test -z "$dir_arg"; then 2021fb077a1Smrg echo "$0: no input file specified." >&2 2031fb077a1Smrg exit 1 2041fb077a1Smrg fi 2051fb077a1Smrg # It's OK to call `install-sh -d' without argument. 2061fb077a1Smrg # This can happen when creating conditional directories. 2071fb077a1Smrg exit 0 2081fb077a1Smrgfi 2091fb077a1Smrg 2101fb077a1Smrgif test -z "$dir_arg"; then 2111d05b0c9Smrg do_exit='(exit $ret); exit $ret' 2121d05b0c9Smrg trap "ret=129; $do_exit" 1 2131d05b0c9Smrg trap "ret=130; $do_exit" 2 2141d05b0c9Smrg trap "ret=141; $do_exit" 13 2151d05b0c9Smrg trap "ret=143; $do_exit" 15 2161fb077a1Smrg 2171fb077a1Smrg # Set umask so as not to create temps with too-generous modes. 2181fb077a1Smrg # However, 'strip' requires both read and write access to temps. 2191fb077a1Smrg case $mode in 2201fb077a1Smrg # Optimize common cases. 2211fb077a1Smrg *644) cp_umask=133;; 2221fb077a1Smrg *755) cp_umask=22;; 2231fb077a1Smrg 2241fb077a1Smrg *[0-7]) 2251fb077a1Smrg if test -z "$stripcmd"; then 2261fb077a1Smrg u_plus_rw= 2271fb077a1Smrg else 2281fb077a1Smrg u_plus_rw='% 200' 2291fb077a1Smrg fi 2301fb077a1Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2311fb077a1Smrg *) 2321fb077a1Smrg if test -z "$stripcmd"; then 2331fb077a1Smrg u_plus_rw= 2341fb077a1Smrg else 2351fb077a1Smrg u_plus_rw=,u+rw 2361fb077a1Smrg fi 2371fb077a1Smrg cp_umask=$mode$u_plus_rw;; 2381fb077a1Smrg esac 2391fb077a1Smrgfi 2401fb077a1Smrg 2411fb077a1Smrgfor src 2421fb077a1Smrgdo 2431d05b0c9Smrg # Protect names problematic for `test' and other utilities. 2441fb077a1Smrg case $src in 2451d05b0c9Smrg -* | [=\(\)!]) src=./$src;; 2461fb077a1Smrg esac 2471fb077a1Smrg 2481fb077a1Smrg if test -n "$dir_arg"; then 2491fb077a1Smrg dst=$src 2501fb077a1Smrg dstdir=$dst 2511fb077a1Smrg test -d "$dstdir" 2521fb077a1Smrg dstdir_status=$? 2531fb077a1Smrg else 2541fb077a1Smrg 2551fb077a1Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2561fb077a1Smrg # might cause directories to be created, which would be especially bad 2571fb077a1Smrg # if $src (and thus $dsttmp) contains '*'. 2581fb077a1Smrg if test ! -f "$src" && test ! -d "$src"; then 2591fb077a1Smrg echo "$0: $src does not exist." >&2 2601fb077a1Smrg exit 1 2611fb077a1Smrg fi 2621fb077a1Smrg 263a5a92c01Smrg if test -z "$dst_arg"; then 2641fb077a1Smrg echo "$0: no destination specified." >&2 2651fb077a1Smrg exit 1 2661fb077a1Smrg fi 267a5a92c01Smrg dst=$dst_arg 2681fb077a1Smrg 2691fb077a1Smrg # If destination is a directory, append the input filename; won't work 2701fb077a1Smrg # if double slashes aren't ignored. 2711fb077a1Smrg if test -d "$dst"; then 2721fb077a1Smrg if test -n "$no_target_directory"; then 273a5a92c01Smrg echo "$0: $dst_arg: Is a directory" >&2 2741fb077a1Smrg exit 1 2751fb077a1Smrg fi 2761fb077a1Smrg dstdir=$dst 2771fb077a1Smrg dst=$dstdir/`basename "$src"` 2781fb077a1Smrg dstdir_status=0 2791fb077a1Smrg else 2801fb077a1Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 2811fb077a1Smrg dstdir=` 2821fb077a1Smrg (dirname "$dst") 2>/dev/null || 2831fb077a1Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2841fb077a1Smrg X"$dst" : 'X\(//\)[^/]' \| \ 2851fb077a1Smrg X"$dst" : 'X\(//\)$' \| \ 2861fb077a1Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2871fb077a1Smrg echo X"$dst" | 2881fb077a1Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2891fb077a1Smrg s//\1/ 2901fb077a1Smrg q 2911fb077a1Smrg } 2921fb077a1Smrg /^X\(\/\/\)[^/].*/{ 2931fb077a1Smrg s//\1/ 2941fb077a1Smrg q 2951fb077a1Smrg } 2961fb077a1Smrg /^X\(\/\/\)$/{ 2971fb077a1Smrg s//\1/ 2981fb077a1Smrg q 2991fb077a1Smrg } 3001fb077a1Smrg /^X\(\/\).*/{ 3011fb077a1Smrg s//\1/ 3021fb077a1Smrg q 3031fb077a1Smrg } 3041fb077a1Smrg s/.*/./; q' 3051fb077a1Smrg ` 3061fb077a1Smrg 3071fb077a1Smrg test -d "$dstdir" 3081fb077a1Smrg dstdir_status=$? 3091fb077a1Smrg fi 3101fb077a1Smrg fi 3111fb077a1Smrg 3121fb077a1Smrg obsolete_mkdir_used=false 3131fb077a1Smrg 3141fb077a1Smrg if test $dstdir_status != 0; then 3151fb077a1Smrg case $posix_mkdir in 3161fb077a1Smrg '') 3171fb077a1Smrg # Create intermediate dirs using mode 755 as modified by the umask. 3181fb077a1Smrg # This is like FreeBSD 'install' as of 1997-10-28. 3191fb077a1Smrg umask=`umask` 3201fb077a1Smrg case $stripcmd.$umask in 3211fb077a1Smrg # Optimize common cases. 3221fb077a1Smrg *[2367][2367]) mkdir_umask=$umask;; 3231fb077a1Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3241fb077a1Smrg 3251fb077a1Smrg *[0-7]) 3261fb077a1Smrg mkdir_umask=`expr $umask + 22 \ 3271fb077a1Smrg - $umask % 100 % 40 + $umask % 20 \ 3281fb077a1Smrg - $umask % 10 % 4 + $umask % 2 3291fb077a1Smrg `;; 3301fb077a1Smrg *) mkdir_umask=$umask,go-w;; 3311fb077a1Smrg esac 3321fb077a1Smrg 3331fb077a1Smrg # With -d, create the new directory with the user-specified mode. 3341fb077a1Smrg # Otherwise, rely on $mkdir_umask. 3351fb077a1Smrg if test -n "$dir_arg"; then 3361fb077a1Smrg mkdir_mode=-m$mode 3371fb077a1Smrg else 3381fb077a1Smrg mkdir_mode= 3391fb077a1Smrg fi 3401fb077a1Smrg 3411fb077a1Smrg posix_mkdir=false 3421fb077a1Smrg case $umask in 3431fb077a1Smrg *[123567][0-7][0-7]) 3441fb077a1Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3451fb077a1Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3461fb077a1Smrg ;; 3471fb077a1Smrg *) 3481fb077a1Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3491fb077a1Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3501fb077a1Smrg 3511fb077a1Smrg if (umask $mkdir_umask && 3521fb077a1Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3531fb077a1Smrg then 3541fb077a1Smrg if test -z "$dir_arg" || { 3551fb077a1Smrg # Check for POSIX incompatibilities with -m. 3561fb077a1Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3571fb077a1Smrg # other-writeable bit of parent directory when it shouldn't. 3581fb077a1Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3591fb077a1Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3601fb077a1Smrg case $ls_ld_tmpdir in 3611fb077a1Smrg d????-?r-*) different_mode=700;; 3621fb077a1Smrg d????-?--*) different_mode=755;; 3631fb077a1Smrg *) false;; 3641fb077a1Smrg esac && 3651fb077a1Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3661fb077a1Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3671fb077a1Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3681fb077a1Smrg } 3691fb077a1Smrg } 3701fb077a1Smrg then posix_mkdir=: 3711fb077a1Smrg fi 3721fb077a1Smrg rmdir "$tmpdir/d" "$tmpdir" 3731fb077a1Smrg else 3741fb077a1Smrg # Remove any dirs left behind by ancient mkdir implementations. 3751fb077a1Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3761fb077a1Smrg fi 3771fb077a1Smrg trap '' 0;; 3781fb077a1Smrg esac;; 3791fb077a1Smrg esac 3801fb077a1Smrg 3811fb077a1Smrg if 3821fb077a1Smrg $posix_mkdir && ( 3831fb077a1Smrg umask $mkdir_umask && 3841fb077a1Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3851fb077a1Smrg ) 3861fb077a1Smrg then : 3871fb077a1Smrg else 3881fb077a1Smrg 3891fb077a1Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3901fb077a1Smrg # or it failed possibly due to a race condition. Create the 3911fb077a1Smrg # directory the slow way, step by step, checking for races as we go. 3921fb077a1Smrg 3931fb077a1Smrg case $dstdir in 394a5a92c01Smrg /*) prefix='/';; 3951d05b0c9Smrg [-=\(\)!]*) prefix='./';; 396a5a92c01Smrg *) prefix='';; 3971fb077a1Smrg esac 3981fb077a1Smrg 399a5a92c01Smrg eval "$initialize_posix_glob" 4001fb077a1Smrg 4011fb077a1Smrg oIFS=$IFS 4021fb077a1Smrg IFS=/ 403a5a92c01Smrg $posix_glob set -f 4041fb077a1Smrg set fnord $dstdir 4051fb077a1Smrg shift 406a5a92c01Smrg $posix_glob set +f 4071fb077a1Smrg IFS=$oIFS 4081fb077a1Smrg 4091fb077a1Smrg prefixes= 4101fb077a1Smrg 4111fb077a1Smrg for d 4121fb077a1Smrg do 4131d05b0c9Smrg test X"$d" = X && continue 4141fb077a1Smrg 4151fb077a1Smrg prefix=$prefix$d 4161fb077a1Smrg if test -d "$prefix"; then 4171fb077a1Smrg prefixes= 4181fb077a1Smrg else 4191fb077a1Smrg if $posix_mkdir; then 4201fb077a1Smrg (umask=$mkdir_umask && 4211fb077a1Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4221fb077a1Smrg # Don't fail if two instances are running concurrently. 4231fb077a1Smrg test -d "$prefix" || exit 1 4241fb077a1Smrg else 4251fb077a1Smrg case $prefix in 4261fb077a1Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4271fb077a1Smrg *) qprefix=$prefix;; 4281fb077a1Smrg esac 4291fb077a1Smrg prefixes="$prefixes '$qprefix'" 4301fb077a1Smrg fi 4311fb077a1Smrg fi 4321fb077a1Smrg prefix=$prefix/ 4331fb077a1Smrg done 4341fb077a1Smrg 4351fb077a1Smrg if test -n "$prefixes"; then 4361fb077a1Smrg # Don't fail if two instances are running concurrently. 4371fb077a1Smrg (umask $mkdir_umask && 4381fb077a1Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4391fb077a1Smrg test -d "$dstdir" || exit 1 4401fb077a1Smrg obsolete_mkdir_used=true 4411fb077a1Smrg fi 4421fb077a1Smrg fi 4431fb077a1Smrg fi 4441fb077a1Smrg 4451fb077a1Smrg if test -n "$dir_arg"; then 4461fb077a1Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4471fb077a1Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4481fb077a1Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4491fb077a1Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4501fb077a1Smrg else 4511fb077a1Smrg 4521fb077a1Smrg # Make a couple of temp file names in the proper directory. 4531fb077a1Smrg dsttmp=$dstdir/_inst.$$_ 4541fb077a1Smrg rmtmp=$dstdir/_rm.$$_ 4551fb077a1Smrg 4561fb077a1Smrg # Trap to clean up those temp files at exit. 4571fb077a1Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4581fb077a1Smrg 4591fb077a1Smrg # Copy the file name to the temp name. 4601fb077a1Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4611fb077a1Smrg 4621fb077a1Smrg # and set any options; do chmod last to preserve setuid bits. 4631fb077a1Smrg # 4641fb077a1Smrg # If any of these fail, we abort the whole thing. If we want to 4651fb077a1Smrg # ignore errors from any of these, just make sure not to ignore 4661fb077a1Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4671fb077a1Smrg # 468a5a92c01Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 469a5a92c01Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 470a5a92c01Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 471a5a92c01Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 472a5a92c01Smrg 473a5a92c01Smrg # If -C, don't bother to copy if it wouldn't change the file. 474a5a92c01Smrg if $copy_on_change && 475a5a92c01Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 476a5a92c01Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 477a5a92c01Smrg 478a5a92c01Smrg eval "$initialize_posix_glob" && 479a5a92c01Smrg $posix_glob set -f && 480a5a92c01Smrg set X $old && old=:$2:$4:$5:$6 && 481a5a92c01Smrg set X $new && new=:$2:$4:$5:$6 && 482a5a92c01Smrg $posix_glob set +f && 483a5a92c01Smrg 484a5a92c01Smrg test "$old" = "$new" && 485a5a92c01Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 486a5a92c01Smrg then 487a5a92c01Smrg rm -f "$dsttmp" 488a5a92c01Smrg else 489a5a92c01Smrg # Rename the file to the real destination. 490a5a92c01Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 491a5a92c01Smrg 492a5a92c01Smrg # The rename failed, perhaps because mv can't rename something else 493a5a92c01Smrg # to itself, or perhaps because mv is so ancient that it does not 494a5a92c01Smrg # support -f. 495a5a92c01Smrg { 496a5a92c01Smrg # Now remove or move aside any old file at destination location. 497a5a92c01Smrg # We try this two ways since rm can't unlink itself on some 498a5a92c01Smrg # systems and the destination file might be busy for other 499a5a92c01Smrg # reasons. In this case, the final cleanup might fail but the new 500a5a92c01Smrg # file should still install successfully. 501a5a92c01Smrg { 502a5a92c01Smrg test ! -f "$dst" || 503a5a92c01Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 504a5a92c01Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 505a5a92c01Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 506a5a92c01Smrg } || 507a5a92c01Smrg { echo "$0: cannot unlink or rename $dst" >&2 508a5a92c01Smrg (exit 1); exit 1 509a5a92c01Smrg } 510a5a92c01Smrg } && 511a5a92c01Smrg 512a5a92c01Smrg # Now rename the file to the real destination. 513a5a92c01Smrg $doit $mvcmd "$dsttmp" "$dst" 514a5a92c01Smrg } 515a5a92c01Smrg fi || exit 1 5161fb077a1Smrg 5171fb077a1Smrg trap '' 0 5181fb077a1Smrg fi 5191fb077a1Smrgdone 5201fb077a1Smrg 5211fb077a1Smrg# Local variables: 5221fb077a1Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5231fb077a1Smrg# time-stamp-start: "scriptversion=" 5241fb077a1Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 525a5a92c01Smrg# time-stamp-time-zone: "UTC" 526a5a92c01Smrg# time-stamp-end: "; # UTC" 5271fb077a1Smrg# End: 528