install-sh revision 7366012a
17a0395d0Smrg#!/bin/sh 27a0395d0Smrg# install - install a program, script, or datafile 37a0395d0Smrg 47366012aSmrgscriptversion=2009-04-28.21; # UTC 57a0395d0Smrg 67a0395d0Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 77a0395d0Smrg# later released in X11R6 (xc/config/util/install.sh) with the 87a0395d0Smrg# following copyright and license. 97a0395d0Smrg# 107a0395d0Smrg# Copyright (C) 1994 X Consortium 117a0395d0Smrg# 127a0395d0Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 137a0395d0Smrg# of this software and associated documentation files (the "Software"), to 147a0395d0Smrg# deal in the Software without restriction, including without limitation the 157a0395d0Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 167a0395d0Smrg# sell copies of the Software, and to permit persons to whom the Software is 177a0395d0Smrg# furnished to do so, subject to the following conditions: 187a0395d0Smrg# 197a0395d0Smrg# The above copyright notice and this permission notice shall be included in 207a0395d0Smrg# all copies or substantial portions of the Software. 217a0395d0Smrg# 227a0395d0Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 237a0395d0Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 247a0395d0Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 257a0395d0Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 267a0395d0Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 277a0395d0Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 287a0395d0Smrg# 297a0395d0Smrg# Except as contained in this notice, the name of the X Consortium shall not 307a0395d0Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 317a0395d0Smrg# ings in this Software without prior written authorization from the X Consor- 327a0395d0Smrg# tium. 337a0395d0Smrg# 347a0395d0Smrg# 357a0395d0Smrg# FSF changes to this file are in the public domain. 367a0395d0Smrg# 377a0395d0Smrg# Calling this script install-sh is preferred over install.sh, to prevent 387a0395d0Smrg# `make' implicit rules from creating a file called install from it 397a0395d0Smrg# when there is no Makefile. 407a0395d0Smrg# 417a0395d0Smrg# This script is compatible with the BSD install script, but was written 427a0395d0Smrg# from scratch. 437a0395d0Smrg 447a0395d0Smrgnl=' 457a0395d0Smrg' 467a0395d0SmrgIFS=" "" $nl" 477a0395d0Smrg 487a0395d0Smrg# set DOITPROG to echo to test this script 497a0395d0Smrg 507a0395d0Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 517a0395d0Smrgdoit=${DOITPROG-} 527a0395d0Smrgif test -z "$doit"; then 537a0395d0Smrg doit_exec=exec 547a0395d0Smrgelse 557a0395d0Smrg doit_exec=$doit 567a0395d0Smrgfi 577a0395d0Smrg 587a0395d0Smrg# Put in absolute file names if you don't have them in your path; 597a0395d0Smrg# or use environment vars. 607a0395d0Smrg 617a0395d0Smrgchgrpprog=${CHGRPPROG-chgrp} 627a0395d0Smrgchmodprog=${CHMODPROG-chmod} 637a0395d0Smrgchownprog=${CHOWNPROG-chown} 647a0395d0Smrgcmpprog=${CMPPROG-cmp} 657a0395d0Smrgcpprog=${CPPROG-cp} 667a0395d0Smrgmkdirprog=${MKDIRPROG-mkdir} 677a0395d0Smrgmvprog=${MVPROG-mv} 687a0395d0Smrgrmprog=${RMPROG-rm} 697a0395d0Smrgstripprog=${STRIPPROG-strip} 707a0395d0Smrg 717a0395d0Smrgposix_glob='?' 727a0395d0Smrginitialize_posix_glob=' 737a0395d0Smrg test "$posix_glob" != "?" || { 747a0395d0Smrg if (set -f) 2>/dev/null; then 757a0395d0Smrg posix_glob= 767a0395d0Smrg else 777a0395d0Smrg posix_glob=: 787a0395d0Smrg fi 797a0395d0Smrg } 807a0395d0Smrg' 817a0395d0Smrg 827a0395d0Smrgposix_mkdir= 837a0395d0Smrg 847a0395d0Smrg# Desired mode of installed file. 857a0395d0Smrgmode=0755 867a0395d0Smrg 877a0395d0Smrgchgrpcmd= 887a0395d0Smrgchmodcmd=$chmodprog 897a0395d0Smrgchowncmd= 907a0395d0Smrgmvcmd=$mvprog 917a0395d0Smrgrmcmd="$rmprog -f" 927a0395d0Smrgstripcmd= 937a0395d0Smrg 947a0395d0Smrgsrc= 957a0395d0Smrgdst= 967a0395d0Smrgdir_arg= 977a0395d0Smrgdst_arg= 987a0395d0Smrg 997a0395d0Smrgcopy_on_change=false 1007a0395d0Smrgno_target_directory= 1017a0395d0Smrg 1027a0395d0Smrgusage="\ 1037a0395d0SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1047a0395d0Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1057a0395d0Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1067a0395d0Smrg or: $0 [OPTION]... -d DIRECTORIES... 1077a0395d0Smrg 1087a0395d0SmrgIn the 1st form, copy SRCFILE to DSTFILE. 1097a0395d0SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1107a0395d0SmrgIn the 4th, create DIRECTORIES. 1117a0395d0Smrg 1127a0395d0SmrgOptions: 1137a0395d0Smrg --help display this help and exit. 1147a0395d0Smrg --version display version info and exit. 1157a0395d0Smrg 1167a0395d0Smrg -c (ignored) 1177a0395d0Smrg -C install only if different (preserve the last data modification time) 1187a0395d0Smrg -d create directories instead of installing files. 1197a0395d0Smrg -g GROUP $chgrpprog installed files to GROUP. 1207a0395d0Smrg -m MODE $chmodprog installed files to MODE. 1217a0395d0Smrg -o USER $chownprog installed files to USER. 1227a0395d0Smrg -s $stripprog installed files. 1237a0395d0Smrg -t DIRECTORY install into DIRECTORY. 1247a0395d0Smrg -T report an error if DSTFILE is a directory. 1257a0395d0Smrg 1267a0395d0SmrgEnvironment variables override the default commands: 1277a0395d0Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1287a0395d0Smrg RMPROG STRIPPROG 1297a0395d0Smrg" 1307a0395d0Smrg 1317a0395d0Smrgwhile test $# -ne 0; do 1327a0395d0Smrg case $1 in 1337a0395d0Smrg -c) ;; 1347a0395d0Smrg 1357a0395d0Smrg -C) copy_on_change=true;; 1367a0395d0Smrg 1377a0395d0Smrg -d) dir_arg=true;; 1387a0395d0Smrg 1397a0395d0Smrg -g) chgrpcmd="$chgrpprog $2" 1407a0395d0Smrg shift;; 1417a0395d0Smrg 1427a0395d0Smrg --help) echo "$usage"; exit $?;; 1437a0395d0Smrg 1447a0395d0Smrg -m) mode=$2 1457a0395d0Smrg case $mode in 1467a0395d0Smrg *' '* | *' '* | *' 1477a0395d0Smrg'* | *'*'* | *'?'* | *'['*) 1487a0395d0Smrg echo "$0: invalid mode: $mode" >&2 1497a0395d0Smrg exit 1;; 1507a0395d0Smrg esac 1517a0395d0Smrg shift;; 1527a0395d0Smrg 1537a0395d0Smrg -o) chowncmd="$chownprog $2" 1547a0395d0Smrg shift;; 1557a0395d0Smrg 1567a0395d0Smrg -s) stripcmd=$stripprog;; 1577a0395d0Smrg 1587a0395d0Smrg -t) dst_arg=$2 1597a0395d0Smrg shift;; 1607a0395d0Smrg 1617a0395d0Smrg -T) no_target_directory=true;; 1627a0395d0Smrg 1637a0395d0Smrg --version) echo "$0 $scriptversion"; exit $?;; 1647a0395d0Smrg 1657a0395d0Smrg --) shift 1667a0395d0Smrg break;; 1677a0395d0Smrg 1687a0395d0Smrg -*) echo "$0: invalid option: $1" >&2 1697a0395d0Smrg exit 1;; 1707a0395d0Smrg 1717a0395d0Smrg *) break;; 1727a0395d0Smrg esac 1737a0395d0Smrg shift 1747a0395d0Smrgdone 1757a0395d0Smrg 1767a0395d0Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1777a0395d0Smrg # When -d is used, all remaining arguments are directories to create. 1787a0395d0Smrg # When -t is used, the destination is already specified. 1797a0395d0Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1807a0395d0Smrg for arg 1817a0395d0Smrg do 1827a0395d0Smrg if test -n "$dst_arg"; then 1837a0395d0Smrg # $@ is not empty: it contains at least $arg. 1847a0395d0Smrg set fnord "$@" "$dst_arg" 1857a0395d0Smrg shift # fnord 1867a0395d0Smrg fi 1877a0395d0Smrg shift # arg 1887a0395d0Smrg dst_arg=$arg 1897a0395d0Smrg done 1907a0395d0Smrgfi 1917a0395d0Smrg 1927a0395d0Smrgif test $# -eq 0; then 1937a0395d0Smrg if test -z "$dir_arg"; then 1947a0395d0Smrg echo "$0: no input file specified." >&2 1957a0395d0Smrg exit 1 1967a0395d0Smrg fi 1977a0395d0Smrg # It's OK to call `install-sh -d' without argument. 1987a0395d0Smrg # This can happen when creating conditional directories. 1997a0395d0Smrg exit 0 2007a0395d0Smrgfi 2017a0395d0Smrg 2027a0395d0Smrgif test -z "$dir_arg"; then 2037a0395d0Smrg trap '(exit $?); exit' 1 2 13 15 2047a0395d0Smrg 2057a0395d0Smrg # Set umask so as not to create temps with too-generous modes. 2067a0395d0Smrg # However, 'strip' requires both read and write access to temps. 2077a0395d0Smrg case $mode in 2087a0395d0Smrg # Optimize common cases. 2097a0395d0Smrg *644) cp_umask=133;; 2107a0395d0Smrg *755) cp_umask=22;; 2117a0395d0Smrg 2127a0395d0Smrg *[0-7]) 2137a0395d0Smrg if test -z "$stripcmd"; then 2147a0395d0Smrg u_plus_rw= 2157a0395d0Smrg else 2167a0395d0Smrg u_plus_rw='% 200' 2177a0395d0Smrg fi 2187a0395d0Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2197a0395d0Smrg *) 2207a0395d0Smrg if test -z "$stripcmd"; then 2217a0395d0Smrg u_plus_rw= 2227a0395d0Smrg else 2237a0395d0Smrg u_plus_rw=,u+rw 2247a0395d0Smrg fi 2257a0395d0Smrg cp_umask=$mode$u_plus_rw;; 2267a0395d0Smrg esac 2277a0395d0Smrgfi 2287a0395d0Smrg 2297a0395d0Smrgfor src 2307a0395d0Smrgdo 2317a0395d0Smrg # Protect names starting with `-'. 2327a0395d0Smrg case $src in 2337a0395d0Smrg -*) src=./$src;; 2347a0395d0Smrg esac 2357a0395d0Smrg 2367a0395d0Smrg if test -n "$dir_arg"; then 2377a0395d0Smrg dst=$src 2387a0395d0Smrg dstdir=$dst 2397a0395d0Smrg test -d "$dstdir" 2407a0395d0Smrg dstdir_status=$? 2417a0395d0Smrg else 2427a0395d0Smrg 2437a0395d0Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2447a0395d0Smrg # might cause directories to be created, which would be especially bad 2457a0395d0Smrg # if $src (and thus $dsttmp) contains '*'. 2467a0395d0Smrg if test ! -f "$src" && test ! -d "$src"; then 2477a0395d0Smrg echo "$0: $src does not exist." >&2 2487a0395d0Smrg exit 1 2497a0395d0Smrg fi 2507a0395d0Smrg 2517a0395d0Smrg if test -z "$dst_arg"; then 2527a0395d0Smrg echo "$0: no destination specified." >&2 2537a0395d0Smrg exit 1 2547a0395d0Smrg fi 2557a0395d0Smrg 2567a0395d0Smrg dst=$dst_arg 2577a0395d0Smrg # Protect names starting with `-'. 2587a0395d0Smrg case $dst in 2597a0395d0Smrg -*) dst=./$dst;; 2607a0395d0Smrg esac 2617a0395d0Smrg 2627a0395d0Smrg # If destination is a directory, append the input filename; won't work 2637a0395d0Smrg # if double slashes aren't ignored. 2647a0395d0Smrg if test -d "$dst"; then 2657a0395d0Smrg if test -n "$no_target_directory"; then 2667a0395d0Smrg echo "$0: $dst_arg: Is a directory" >&2 2677a0395d0Smrg exit 1 2687a0395d0Smrg fi 2697a0395d0Smrg dstdir=$dst 2707a0395d0Smrg dst=$dstdir/`basename "$src"` 2717a0395d0Smrg dstdir_status=0 2727a0395d0Smrg else 2737a0395d0Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 2747a0395d0Smrg dstdir=` 2757a0395d0Smrg (dirname "$dst") 2>/dev/null || 2767a0395d0Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2777a0395d0Smrg X"$dst" : 'X\(//\)[^/]' \| \ 2787a0395d0Smrg X"$dst" : 'X\(//\)$' \| \ 2797a0395d0Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2807a0395d0Smrg echo X"$dst" | 2817a0395d0Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2827a0395d0Smrg s//\1/ 2837a0395d0Smrg q 2847a0395d0Smrg } 2857a0395d0Smrg /^X\(\/\/\)[^/].*/{ 2867a0395d0Smrg s//\1/ 2877a0395d0Smrg q 2887a0395d0Smrg } 2897a0395d0Smrg /^X\(\/\/\)$/{ 2907a0395d0Smrg s//\1/ 2917a0395d0Smrg q 2927a0395d0Smrg } 2937a0395d0Smrg /^X\(\/\).*/{ 2947a0395d0Smrg s//\1/ 2957a0395d0Smrg q 2967a0395d0Smrg } 2977a0395d0Smrg s/.*/./; q' 2987a0395d0Smrg ` 2997a0395d0Smrg 3007a0395d0Smrg test -d "$dstdir" 3017a0395d0Smrg dstdir_status=$? 3027a0395d0Smrg fi 3037a0395d0Smrg fi 3047a0395d0Smrg 3057a0395d0Smrg obsolete_mkdir_used=false 3067a0395d0Smrg 3077a0395d0Smrg if test $dstdir_status != 0; then 3087a0395d0Smrg case $posix_mkdir in 3097a0395d0Smrg '') 3107a0395d0Smrg # Create intermediate dirs using mode 755 as modified by the umask. 3117a0395d0Smrg # This is like FreeBSD 'install' as of 1997-10-28. 3127a0395d0Smrg umask=`umask` 3137a0395d0Smrg case $stripcmd.$umask in 3147a0395d0Smrg # Optimize common cases. 3157a0395d0Smrg *[2367][2367]) mkdir_umask=$umask;; 3167a0395d0Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3177a0395d0Smrg 3187a0395d0Smrg *[0-7]) 3197a0395d0Smrg mkdir_umask=`expr $umask + 22 \ 3207a0395d0Smrg - $umask % 100 % 40 + $umask % 20 \ 3217a0395d0Smrg - $umask % 10 % 4 + $umask % 2 3227a0395d0Smrg `;; 3237a0395d0Smrg *) mkdir_umask=$umask,go-w;; 3247a0395d0Smrg esac 3257a0395d0Smrg 3267a0395d0Smrg # With -d, create the new directory with the user-specified mode. 3277a0395d0Smrg # Otherwise, rely on $mkdir_umask. 3287a0395d0Smrg if test -n "$dir_arg"; then 3297a0395d0Smrg mkdir_mode=-m$mode 3307a0395d0Smrg else 3317a0395d0Smrg mkdir_mode= 3327a0395d0Smrg fi 3337a0395d0Smrg 3347a0395d0Smrg posix_mkdir=false 3357a0395d0Smrg case $umask in 3367a0395d0Smrg *[123567][0-7][0-7]) 3377a0395d0Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3387a0395d0Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3397a0395d0Smrg ;; 3407a0395d0Smrg *) 3417a0395d0Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3427a0395d0Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3437a0395d0Smrg 3447a0395d0Smrg if (umask $mkdir_umask && 3457a0395d0Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3467a0395d0Smrg then 3477a0395d0Smrg if test -z "$dir_arg" || { 3487a0395d0Smrg # Check for POSIX incompatibilities with -m. 3497a0395d0Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3507a0395d0Smrg # other-writeable bit of parent directory when it shouldn't. 3517a0395d0Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3527a0395d0Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3537a0395d0Smrg case $ls_ld_tmpdir in 3547a0395d0Smrg d????-?r-*) different_mode=700;; 3557a0395d0Smrg d????-?--*) different_mode=755;; 3567a0395d0Smrg *) false;; 3577a0395d0Smrg esac && 3587a0395d0Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3597a0395d0Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3607a0395d0Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3617a0395d0Smrg } 3627a0395d0Smrg } 3637a0395d0Smrg then posix_mkdir=: 3647a0395d0Smrg fi 3657a0395d0Smrg rmdir "$tmpdir/d" "$tmpdir" 3667a0395d0Smrg else 3677a0395d0Smrg # Remove any dirs left behind by ancient mkdir implementations. 3687a0395d0Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3697a0395d0Smrg fi 3707a0395d0Smrg trap '' 0;; 3717a0395d0Smrg esac;; 3727a0395d0Smrg esac 3737a0395d0Smrg 3747a0395d0Smrg if 3757a0395d0Smrg $posix_mkdir && ( 3767a0395d0Smrg umask $mkdir_umask && 3777a0395d0Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3787a0395d0Smrg ) 3797a0395d0Smrg then : 3807a0395d0Smrg else 3817a0395d0Smrg 3827a0395d0Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3837a0395d0Smrg # or it failed possibly due to a race condition. Create the 3847a0395d0Smrg # directory the slow way, step by step, checking for races as we go. 3857a0395d0Smrg 3867a0395d0Smrg case $dstdir in 3877a0395d0Smrg /*) prefix='/';; 3887a0395d0Smrg -*) prefix='./';; 3897a0395d0Smrg *) prefix='';; 3907a0395d0Smrg esac 3917a0395d0Smrg 3927a0395d0Smrg eval "$initialize_posix_glob" 3937a0395d0Smrg 3947a0395d0Smrg oIFS=$IFS 3957a0395d0Smrg IFS=/ 3967a0395d0Smrg $posix_glob set -f 3977a0395d0Smrg set fnord $dstdir 3987a0395d0Smrg shift 3997a0395d0Smrg $posix_glob set +f 4007a0395d0Smrg IFS=$oIFS 4017a0395d0Smrg 4027a0395d0Smrg prefixes= 4037a0395d0Smrg 4047a0395d0Smrg for d 4057a0395d0Smrg do 4067a0395d0Smrg test -z "$d" && continue 4077a0395d0Smrg 4087a0395d0Smrg prefix=$prefix$d 4097a0395d0Smrg if test -d "$prefix"; then 4107a0395d0Smrg prefixes= 4117a0395d0Smrg else 4127a0395d0Smrg if $posix_mkdir; then 4137a0395d0Smrg (umask=$mkdir_umask && 4147a0395d0Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4157a0395d0Smrg # Don't fail if two instances are running concurrently. 4167a0395d0Smrg test -d "$prefix" || exit 1 4177a0395d0Smrg else 4187a0395d0Smrg case $prefix in 4197a0395d0Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4207a0395d0Smrg *) qprefix=$prefix;; 4217a0395d0Smrg esac 4227a0395d0Smrg prefixes="$prefixes '$qprefix'" 4237a0395d0Smrg fi 4247a0395d0Smrg fi 4257a0395d0Smrg prefix=$prefix/ 4267a0395d0Smrg done 4277a0395d0Smrg 4287a0395d0Smrg if test -n "$prefixes"; then 4297a0395d0Smrg # Don't fail if two instances are running concurrently. 4307a0395d0Smrg (umask $mkdir_umask && 4317a0395d0Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4327a0395d0Smrg test -d "$dstdir" || exit 1 4337a0395d0Smrg obsolete_mkdir_used=true 4347a0395d0Smrg fi 4357a0395d0Smrg fi 4367a0395d0Smrg fi 4377a0395d0Smrg 4387a0395d0Smrg if test -n "$dir_arg"; then 4397a0395d0Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4407a0395d0Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4417a0395d0Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4427a0395d0Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4437a0395d0Smrg else 4447a0395d0Smrg 4457a0395d0Smrg # Make a couple of temp file names in the proper directory. 4467a0395d0Smrg dsttmp=$dstdir/_inst.$$_ 4477a0395d0Smrg rmtmp=$dstdir/_rm.$$_ 4487a0395d0Smrg 4497a0395d0Smrg # Trap to clean up those temp files at exit. 4507a0395d0Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4517a0395d0Smrg 4527a0395d0Smrg # Copy the file name to the temp name. 4537a0395d0Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4547a0395d0Smrg 4557a0395d0Smrg # and set any options; do chmod last to preserve setuid bits. 4567a0395d0Smrg # 4577a0395d0Smrg # If any of these fail, we abort the whole thing. If we want to 4587a0395d0Smrg # ignore errors from any of these, just make sure not to ignore 4597a0395d0Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4607a0395d0Smrg # 4617a0395d0Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4627a0395d0Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4637a0395d0Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4647a0395d0Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4657a0395d0Smrg 4667a0395d0Smrg # If -C, don't bother to copy if it wouldn't change the file. 4677a0395d0Smrg if $copy_on_change && 4687a0395d0Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4697a0395d0Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4707a0395d0Smrg 4717a0395d0Smrg eval "$initialize_posix_glob" && 4727a0395d0Smrg $posix_glob set -f && 4737a0395d0Smrg set X $old && old=:$2:$4:$5:$6 && 4747a0395d0Smrg set X $new && new=:$2:$4:$5:$6 && 4757a0395d0Smrg $posix_glob set +f && 4767a0395d0Smrg 4777a0395d0Smrg test "$old" = "$new" && 4787a0395d0Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4797a0395d0Smrg then 4807a0395d0Smrg rm -f "$dsttmp" 4817a0395d0Smrg else 4827a0395d0Smrg # Rename the file to the real destination. 4837a0395d0Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4847a0395d0Smrg 4857a0395d0Smrg # The rename failed, perhaps because mv can't rename something else 4867a0395d0Smrg # to itself, or perhaps because mv is so ancient that it does not 4877a0395d0Smrg # support -f. 4887a0395d0Smrg { 4897a0395d0Smrg # Now remove or move aside any old file at destination location. 4907a0395d0Smrg # We try this two ways since rm can't unlink itself on some 4917a0395d0Smrg # systems and the destination file might be busy for other 4927a0395d0Smrg # reasons. In this case, the final cleanup might fail but the new 4937a0395d0Smrg # file should still install successfully. 4947a0395d0Smrg { 4957a0395d0Smrg test ! -f "$dst" || 4967a0395d0Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 4977a0395d0Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 4987a0395d0Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 4997a0395d0Smrg } || 5007a0395d0Smrg { echo "$0: cannot unlink or rename $dst" >&2 5017a0395d0Smrg (exit 1); exit 1 5027a0395d0Smrg } 5037a0395d0Smrg } && 5047a0395d0Smrg 5057a0395d0Smrg # Now rename the file to the real destination. 5067a0395d0Smrg $doit $mvcmd "$dsttmp" "$dst" 5077a0395d0Smrg } 5087a0395d0Smrg fi || exit 1 5097a0395d0Smrg 5107a0395d0Smrg trap '' 0 5117a0395d0Smrg fi 5127a0395d0Smrgdone 5137a0395d0Smrg 5147a0395d0Smrg# Local variables: 5157a0395d0Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5167a0395d0Smrg# time-stamp-start: "scriptversion=" 5177a0395d0Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5187366012aSmrg# time-stamp-time-zone: "UTC" 5197366012aSmrg# time-stamp-end: "; # UTC" 5207a0395d0Smrg# End: 521