install-sh revision 3e6697d4
10e20ee16Smrg#!/bin/sh 20e20ee16Smrg# install - install a program, script, or datafile 33e6697d4Smrg 43e6697d4Smrgscriptversion=2009-04-28.21; # UTC 53e6697d4Smrg 60e20ee16Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 70e20ee16Smrg# later released in X11R6 (xc/config/util/install.sh) with the 80e20ee16Smrg# following copyright and license. 90e20ee16Smrg# 100e20ee16Smrg# Copyright (C) 1994 X Consortium 110e20ee16Smrg# 120e20ee16Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 130e20ee16Smrg# of this software and associated documentation files (the "Software"), to 140e20ee16Smrg# deal in the Software without restriction, including without limitation the 150e20ee16Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 160e20ee16Smrg# sell copies of the Software, and to permit persons to whom the Software is 170e20ee16Smrg# furnished to do so, subject to the following conditions: 180e20ee16Smrg# 190e20ee16Smrg# The above copyright notice and this permission notice shall be included in 200e20ee16Smrg# all copies or substantial portions of the Software. 210e20ee16Smrg# 220e20ee16Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 230e20ee16Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 240e20ee16Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 250e20ee16Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 260e20ee16Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 270e20ee16Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 280e20ee16Smrg# 290e20ee16Smrg# Except as contained in this notice, the name of the X Consortium shall not 300e20ee16Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 310e20ee16Smrg# ings in this Software without prior written authorization from the X Consor- 320e20ee16Smrg# tium. 330e20ee16Smrg# 340e20ee16Smrg# 350e20ee16Smrg# FSF changes to this file are in the public domain. 360e20ee16Smrg# 370e20ee16Smrg# Calling this script install-sh is preferred over install.sh, to prevent 380e20ee16Smrg# `make' implicit rules from creating a file called install from it 390e20ee16Smrg# when there is no Makefile. 400e20ee16Smrg# 410e20ee16Smrg# This script is compatible with the BSD install script, but was written 423e6697d4Smrg# from scratch. 430e20ee16Smrg 443e6697d4Smrgnl=' 453e6697d4Smrg' 463e6697d4SmrgIFS=" "" $nl" 470e20ee16Smrg 480e20ee16Smrg# set DOITPROG to echo to test this script 490e20ee16Smrg 500e20ee16Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 513e6697d4Smrgdoit=${DOITPROG-} 523e6697d4Smrgif test -z "$doit"; then 533e6697d4Smrg doit_exec=exec 540e20ee16Smrgelse 553e6697d4Smrg doit_exec=$doit 560e20ee16Smrgfi 570e20ee16Smrg 583e6697d4Smrg# Put in absolute file names if you don't have them in your path; 593e6697d4Smrg# or use environment vars. 603e6697d4Smrg 613e6697d4Smrgchgrpprog=${CHGRPPROG-chgrp} 623e6697d4Smrgchmodprog=${CHMODPROG-chmod} 633e6697d4Smrgchownprog=${CHOWNPROG-chown} 643e6697d4Smrgcmpprog=${CMPPROG-cmp} 653e6697d4Smrgcpprog=${CPPROG-cp} 663e6697d4Smrgmkdirprog=${MKDIRPROG-mkdir} 673e6697d4Smrgmvprog=${MVPROG-mv} 683e6697d4Smrgrmprog=${RMPROG-rm} 693e6697d4Smrgstripprog=${STRIPPROG-strip} 703e6697d4Smrg 713e6697d4Smrgposix_glob='?' 723e6697d4Smrginitialize_posix_glob=' 733e6697d4Smrg test "$posix_glob" != "?" || { 743e6697d4Smrg if (set -f) 2>/dev/null; then 753e6697d4Smrg posix_glob= 763e6697d4Smrg else 773e6697d4Smrg posix_glob=: 783e6697d4Smrg fi 793e6697d4Smrg } 803e6697d4Smrg' 813e6697d4Smrg 823e6697d4Smrgposix_mkdir= 833e6697d4Smrg 843e6697d4Smrg# Desired mode of installed file. 853e6697d4Smrgmode=0755 863e6697d4Smrg 873e6697d4Smrgchgrpcmd= 883e6697d4Smrgchmodcmd=$chmodprog 893e6697d4Smrgchowncmd= 903e6697d4Smrgmvcmd=$mvprog 913e6697d4Smrgrmcmd="$rmprog -f" 923e6697d4Smrgstripcmd= 930e20ee16Smrg 943e6697d4Smrgsrc= 953e6697d4Smrgdst= 963e6697d4Smrgdir_arg= 973e6697d4Smrgdst_arg= 980e20ee16Smrg 993e6697d4Smrgcopy_on_change=false 1003e6697d4Smrgno_target_directory= 1010e20ee16Smrg 1023e6697d4Smrgusage="\ 1033e6697d4SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1043e6697d4Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1053e6697d4Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1063e6697d4Smrg or: $0 [OPTION]... -d DIRECTORIES... 1070e20ee16Smrg 1083e6697d4SmrgIn the 1st form, copy SRCFILE to DSTFILE. 1093e6697d4SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1103e6697d4SmrgIn the 4th, create DIRECTORIES. 1110e20ee16Smrg 1123e6697d4SmrgOptions: 1133e6697d4Smrg --help display this help and exit. 1143e6697d4Smrg --version display version info and exit. 1150e20ee16Smrg 1163e6697d4Smrg -c (ignored) 1173e6697d4Smrg -C install only if different (preserve the last data modification time) 1183e6697d4Smrg -d create directories instead of installing files. 1193e6697d4Smrg -g GROUP $chgrpprog installed files to GROUP. 1203e6697d4Smrg -m MODE $chmodprog installed files to MODE. 1213e6697d4Smrg -o USER $chownprog installed files to USER. 1223e6697d4Smrg -s $stripprog installed files. 1233e6697d4Smrg -t DIRECTORY install into DIRECTORY. 1243e6697d4Smrg -T report an error if DSTFILE is a directory. 1250e20ee16Smrg 1263e6697d4SmrgEnvironment variables override the default commands: 1273e6697d4Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1283e6697d4Smrg RMPROG STRIPPROG 1293e6697d4Smrg" 1300e20ee16Smrg 1313e6697d4Smrgwhile test $# -ne 0; do 1323e6697d4Smrg case $1 in 1333e6697d4Smrg -c) ;; 1340e20ee16Smrg 1353e6697d4Smrg -C) copy_on_change=true;; 1360e20ee16Smrg 1373e6697d4Smrg -d) dir_arg=true;; 1380e20ee16Smrg 1393e6697d4Smrg -g) chgrpcmd="$chgrpprog $2" 1403e6697d4Smrg shift;; 1410e20ee16Smrg 1423e6697d4Smrg --help) echo "$usage"; exit $?;; 1430e20ee16Smrg 1443e6697d4Smrg -m) mode=$2 1453e6697d4Smrg case $mode in 1463e6697d4Smrg *' '* | *' '* | *' 1473e6697d4Smrg'* | *'*'* | *'?'* | *'['*) 1483e6697d4Smrg echo "$0: invalid mode: $mode" >&2 1493e6697d4Smrg exit 1;; 1503e6697d4Smrg esac 1513e6697d4Smrg shift;; 1520e20ee16Smrg 1533e6697d4Smrg -o) chowncmd="$chownprog $2" 1543e6697d4Smrg shift;; 1550e20ee16Smrg 1563e6697d4Smrg -s) stripcmd=$stripprog;; 1570e20ee16Smrg 1583e6697d4Smrg -t) dst_arg=$2 1593e6697d4Smrg shift;; 1600e20ee16Smrg 1613e6697d4Smrg -T) no_target_directory=true;; 1620e20ee16Smrg 1633e6697d4Smrg --version) echo "$0 $scriptversion"; exit $?;; 1640e20ee16Smrg 1653e6697d4Smrg --) shift 1663e6697d4Smrg break;; 1670e20ee16Smrg 1683e6697d4Smrg -*) echo "$0: invalid option: $1" >&2 1693e6697d4Smrg exit 1;; 1700e20ee16Smrg 1713e6697d4Smrg *) break;; 1723e6697d4Smrg esac 1733e6697d4Smrg shift 1743e6697d4Smrgdone 1750e20ee16Smrg 1763e6697d4Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1773e6697d4Smrg # When -d is used, all remaining arguments are directories to create. 1783e6697d4Smrg # When -t is used, the destination is already specified. 1793e6697d4Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1803e6697d4Smrg for arg 1813e6697d4Smrg do 1823e6697d4Smrg if test -n "$dst_arg"; then 1833e6697d4Smrg # $@ is not empty: it contains at least $arg. 1843e6697d4Smrg set fnord "$@" "$dst_arg" 1853e6697d4Smrg shift # fnord 1863e6697d4Smrg fi 1873e6697d4Smrg shift # arg 1883e6697d4Smrg dst_arg=$arg 1893e6697d4Smrg done 1903e6697d4Smrgfi 1910e20ee16Smrg 1923e6697d4Smrgif test $# -eq 0; then 1933e6697d4Smrg if test -z "$dir_arg"; then 1943e6697d4Smrg echo "$0: no input file specified." >&2 1953e6697d4Smrg exit 1 1963e6697d4Smrg fi 1973e6697d4Smrg # It's OK to call `install-sh -d' without argument. 1983e6697d4Smrg # This can happen when creating conditional directories. 1993e6697d4Smrg exit 0 2003e6697d4Smrgfi 2010e20ee16Smrg 2023e6697d4Smrgif test -z "$dir_arg"; then 2033e6697d4Smrg trap '(exit $?); exit' 1 2 13 15 2043e6697d4Smrg 2053e6697d4Smrg # Set umask so as not to create temps with too-generous modes. 2063e6697d4Smrg # However, 'strip' requires both read and write access to temps. 2073e6697d4Smrg case $mode in 2083e6697d4Smrg # Optimize common cases. 2093e6697d4Smrg *644) cp_umask=133;; 2103e6697d4Smrg *755) cp_umask=22;; 2113e6697d4Smrg 2123e6697d4Smrg *[0-7]) 2133e6697d4Smrg if test -z "$stripcmd"; then 2143e6697d4Smrg u_plus_rw= 2153e6697d4Smrg else 2163e6697d4Smrg u_plus_rw='% 200' 2173e6697d4Smrg fi 2183e6697d4Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2193e6697d4Smrg *) 2203e6697d4Smrg if test -z "$stripcmd"; then 2213e6697d4Smrg u_plus_rw= 2223e6697d4Smrg else 2233e6697d4Smrg u_plus_rw=,u+rw 2243e6697d4Smrg fi 2253e6697d4Smrg cp_umask=$mode$u_plus_rw;; 2263e6697d4Smrg esac 2273e6697d4Smrgfi 2280e20ee16Smrg 2293e6697d4Smrgfor src 2303e6697d4Smrgdo 2313e6697d4Smrg # Protect names starting with `-'. 2323e6697d4Smrg case $src in 2333e6697d4Smrg -*) src=./$src;; 2343e6697d4Smrg esac 2353e6697d4Smrg 2363e6697d4Smrg if test -n "$dir_arg"; then 2373e6697d4Smrg dst=$src 2383e6697d4Smrg dstdir=$dst 2393e6697d4Smrg test -d "$dstdir" 2403e6697d4Smrg dstdir_status=$? 2413e6697d4Smrg else 2423e6697d4Smrg 2433e6697d4Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2443e6697d4Smrg # might cause directories to be created, which would be especially bad 2453e6697d4Smrg # if $src (and thus $dsttmp) contains '*'. 2463e6697d4Smrg if test ! -f "$src" && test ! -d "$src"; then 2473e6697d4Smrg echo "$0: $src does not exist." >&2 2483e6697d4Smrg exit 1 2493e6697d4Smrg fi 2503e6697d4Smrg 2513e6697d4Smrg if test -z "$dst_arg"; then 2523e6697d4Smrg echo "$0: no destination specified." >&2 2533e6697d4Smrg exit 1 2543e6697d4Smrg fi 2553e6697d4Smrg 2563e6697d4Smrg dst=$dst_arg 2573e6697d4Smrg # Protect names starting with `-'. 2583e6697d4Smrg case $dst in 2593e6697d4Smrg -*) dst=./$dst;; 2603e6697d4Smrg esac 2610e20ee16Smrg 2623e6697d4Smrg # If destination is a directory, append the input filename; won't work 2633e6697d4Smrg # if double slashes aren't ignored. 2643e6697d4Smrg if test -d "$dst"; then 2653e6697d4Smrg if test -n "$no_target_directory"; then 2663e6697d4Smrg echo "$0: $dst_arg: Is a directory" >&2 2673e6697d4Smrg exit 1 2683e6697d4Smrg fi 2693e6697d4Smrg dstdir=$dst 2703e6697d4Smrg dst=$dstdir/`basename "$src"` 2713e6697d4Smrg dstdir_status=0 2723e6697d4Smrg else 2733e6697d4Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 2743e6697d4Smrg dstdir=` 2753e6697d4Smrg (dirname "$dst") 2>/dev/null || 2763e6697d4Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2773e6697d4Smrg X"$dst" : 'X\(//\)[^/]' \| \ 2783e6697d4Smrg X"$dst" : 'X\(//\)$' \| \ 2793e6697d4Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2803e6697d4Smrg echo X"$dst" | 2813e6697d4Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2823e6697d4Smrg s//\1/ 2833e6697d4Smrg q 2843e6697d4Smrg } 2853e6697d4Smrg /^X\(\/\/\)[^/].*/{ 2863e6697d4Smrg s//\1/ 2873e6697d4Smrg q 2883e6697d4Smrg } 2893e6697d4Smrg /^X\(\/\/\)$/{ 2903e6697d4Smrg s//\1/ 2913e6697d4Smrg q 2923e6697d4Smrg } 2933e6697d4Smrg /^X\(\/\).*/{ 2943e6697d4Smrg s//\1/ 2953e6697d4Smrg q 2963e6697d4Smrg } 2973e6697d4Smrg s/.*/./; q' 2983e6697d4Smrg ` 2993e6697d4Smrg 3003e6697d4Smrg test -d "$dstdir" 3013e6697d4Smrg dstdir_status=$? 3023e6697d4Smrg fi 3033e6697d4Smrg fi 3043e6697d4Smrg 3053e6697d4Smrg obsolete_mkdir_used=false 3063e6697d4Smrg 3073e6697d4Smrg if test $dstdir_status != 0; then 3083e6697d4Smrg case $posix_mkdir in 3093e6697d4Smrg '') 3103e6697d4Smrg # Create intermediate dirs using mode 755 as modified by the umask. 3113e6697d4Smrg # This is like FreeBSD 'install' as of 1997-10-28. 3123e6697d4Smrg umask=`umask` 3133e6697d4Smrg case $stripcmd.$umask in 3143e6697d4Smrg # Optimize common cases. 3153e6697d4Smrg *[2367][2367]) mkdir_umask=$umask;; 3163e6697d4Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3173e6697d4Smrg 3183e6697d4Smrg *[0-7]) 3193e6697d4Smrg mkdir_umask=`expr $umask + 22 \ 3203e6697d4Smrg - $umask % 100 % 40 + $umask % 20 \ 3213e6697d4Smrg - $umask % 10 % 4 + $umask % 2 3223e6697d4Smrg `;; 3233e6697d4Smrg *) mkdir_umask=$umask,go-w;; 3243e6697d4Smrg esac 3253e6697d4Smrg 3263e6697d4Smrg # With -d, create the new directory with the user-specified mode. 3273e6697d4Smrg # Otherwise, rely on $mkdir_umask. 3283e6697d4Smrg if test -n "$dir_arg"; then 3293e6697d4Smrg mkdir_mode=-m$mode 3300e20ee16Smrg else 3313e6697d4Smrg mkdir_mode= 3320e20ee16Smrg fi 3330e20ee16Smrg 3343e6697d4Smrg posix_mkdir=false 3353e6697d4Smrg case $umask in 3363e6697d4Smrg *[123567][0-7][0-7]) 3373e6697d4Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3383e6697d4Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3393e6697d4Smrg ;; 3403e6697d4Smrg *) 3413e6697d4Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3423e6697d4Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3433e6697d4Smrg 3443e6697d4Smrg if (umask $mkdir_umask && 3453e6697d4Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3463e6697d4Smrg then 3473e6697d4Smrg if test -z "$dir_arg" || { 3483e6697d4Smrg # Check for POSIX incompatibilities with -m. 3493e6697d4Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3503e6697d4Smrg # other-writeable bit of parent directory when it shouldn't. 3513e6697d4Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3523e6697d4Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3533e6697d4Smrg case $ls_ld_tmpdir in 3543e6697d4Smrg d????-?r-*) different_mode=700;; 3553e6697d4Smrg d????-?--*) different_mode=755;; 3563e6697d4Smrg *) false;; 3573e6697d4Smrg esac && 3583e6697d4Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3593e6697d4Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3603e6697d4Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3613e6697d4Smrg } 3623e6697d4Smrg } 3633e6697d4Smrg then posix_mkdir=: 3643e6697d4Smrg fi 3653e6697d4Smrg rmdir "$tmpdir/d" "$tmpdir" 3663e6697d4Smrg else 3673e6697d4Smrg # Remove any dirs left behind by ancient mkdir implementations. 3683e6697d4Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3693e6697d4Smrg fi 3703e6697d4Smrg trap '' 0;; 3713e6697d4Smrg esac;; 3723e6697d4Smrg esac 3730e20ee16Smrg 3743e6697d4Smrg if 3753e6697d4Smrg $posix_mkdir && ( 3763e6697d4Smrg umask $mkdir_umask && 3773e6697d4Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3783e6697d4Smrg ) 3793e6697d4Smrg then : 3803e6697d4Smrg else 3813e6697d4Smrg 3823e6697d4Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3833e6697d4Smrg # or it failed possibly due to a race condition. Create the 3843e6697d4Smrg # directory the slow way, step by step, checking for races as we go. 3853e6697d4Smrg 3863e6697d4Smrg case $dstdir in 3873e6697d4Smrg /*) prefix='/';; 3883e6697d4Smrg -*) prefix='./';; 3893e6697d4Smrg *) prefix='';; 3903e6697d4Smrg esac 3913e6697d4Smrg 3923e6697d4Smrg eval "$initialize_posix_glob" 3933e6697d4Smrg 3943e6697d4Smrg oIFS=$IFS 3953e6697d4Smrg IFS=/ 3963e6697d4Smrg $posix_glob set -f 3973e6697d4Smrg set fnord $dstdir 3983e6697d4Smrg shift 3993e6697d4Smrg $posix_glob set +f 4003e6697d4Smrg IFS=$oIFS 4013e6697d4Smrg 4023e6697d4Smrg prefixes= 4033e6697d4Smrg 4043e6697d4Smrg for d 4053e6697d4Smrg do 4063e6697d4Smrg test -z "$d" && continue 4073e6697d4Smrg 4083e6697d4Smrg prefix=$prefix$d 4093e6697d4Smrg if test -d "$prefix"; then 4103e6697d4Smrg prefixes= 4113e6697d4Smrg else 4123e6697d4Smrg if $posix_mkdir; then 4133e6697d4Smrg (umask=$mkdir_umask && 4143e6697d4Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4153e6697d4Smrg # Don't fail if two instances are running concurrently. 4163e6697d4Smrg test -d "$prefix" || exit 1 4173e6697d4Smrg else 4183e6697d4Smrg case $prefix in 4193e6697d4Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4203e6697d4Smrg *) qprefix=$prefix;; 4213e6697d4Smrg esac 4223e6697d4Smrg prefixes="$prefixes '$qprefix'" 4233e6697d4Smrg fi 4243e6697d4Smrg fi 4253e6697d4Smrg prefix=$prefix/ 4263e6697d4Smrg done 4273e6697d4Smrg 4283e6697d4Smrg if test -n "$prefixes"; then 4293e6697d4Smrg # Don't fail if two instances are running concurrently. 4303e6697d4Smrg (umask $mkdir_umask && 4313e6697d4Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4323e6697d4Smrg test -d "$dstdir" || exit 1 4333e6697d4Smrg obsolete_mkdir_used=true 4343e6697d4Smrg fi 4353e6697d4Smrg fi 4363e6697d4Smrg fi 4373e6697d4Smrg 4383e6697d4Smrg if test -n "$dir_arg"; then 4393e6697d4Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4403e6697d4Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4413e6697d4Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4423e6697d4Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4433e6697d4Smrg else 4443e6697d4Smrg 4453e6697d4Smrg # Make a couple of temp file names in the proper directory. 4463e6697d4Smrg dsttmp=$dstdir/_inst.$$_ 4473e6697d4Smrg rmtmp=$dstdir/_rm.$$_ 4483e6697d4Smrg 4493e6697d4Smrg # Trap to clean up those temp files at exit. 4503e6697d4Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4513e6697d4Smrg 4523e6697d4Smrg # Copy the file name to the temp name. 4533e6697d4Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4543e6697d4Smrg 4553e6697d4Smrg # and set any options; do chmod last to preserve setuid bits. 4563e6697d4Smrg # 4573e6697d4Smrg # If any of these fail, we abort the whole thing. If we want to 4583e6697d4Smrg # ignore errors from any of these, just make sure not to ignore 4593e6697d4Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4603e6697d4Smrg # 4613e6697d4Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4623e6697d4Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4633e6697d4Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4643e6697d4Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4653e6697d4Smrg 4663e6697d4Smrg # If -C, don't bother to copy if it wouldn't change the file. 4673e6697d4Smrg if $copy_on_change && 4683e6697d4Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4693e6697d4Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4703e6697d4Smrg 4713e6697d4Smrg eval "$initialize_posix_glob" && 4723e6697d4Smrg $posix_glob set -f && 4733e6697d4Smrg set X $old && old=:$2:$4:$5:$6 && 4743e6697d4Smrg set X $new && new=:$2:$4:$5:$6 && 4753e6697d4Smrg $posix_glob set +f && 4763e6697d4Smrg 4773e6697d4Smrg test "$old" = "$new" && 4783e6697d4Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4793e6697d4Smrg then 4803e6697d4Smrg rm -f "$dsttmp" 4813e6697d4Smrg else 4823e6697d4Smrg # Rename the file to the real destination. 4833e6697d4Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4843e6697d4Smrg 4853e6697d4Smrg # The rename failed, perhaps because mv can't rename something else 4863e6697d4Smrg # to itself, or perhaps because mv is so ancient that it does not 4873e6697d4Smrg # support -f. 4883e6697d4Smrg { 4893e6697d4Smrg # Now remove or move aside any old file at destination location. 4903e6697d4Smrg # We try this two ways since rm can't unlink itself on some 4913e6697d4Smrg # systems and the destination file might be busy for other 4923e6697d4Smrg # reasons. In this case, the final cleanup might fail but the new 4933e6697d4Smrg # file should still install successfully. 4943e6697d4Smrg { 4953e6697d4Smrg test ! -f "$dst" || 4963e6697d4Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 4973e6697d4Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 4983e6697d4Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 4993e6697d4Smrg } || 5003e6697d4Smrg { echo "$0: cannot unlink or rename $dst" >&2 5013e6697d4Smrg (exit 1); exit 1 5023e6697d4Smrg } 5033e6697d4Smrg } && 5043e6697d4Smrg 5053e6697d4Smrg # Now rename the file to the real destination. 5063e6697d4Smrg $doit $mvcmd "$dsttmp" "$dst" 5073e6697d4Smrg } 5083e6697d4Smrg fi || exit 1 5093e6697d4Smrg 5103e6697d4Smrg trap '' 0 5113e6697d4Smrg fi 5123e6697d4Smrgdone 5130e20ee16Smrg 5143e6697d4Smrg# Local variables: 5153e6697d4Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5163e6697d4Smrg# time-stamp-start: "scriptversion=" 5173e6697d4Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5183e6697d4Smrg# time-stamp-time-zone: "UTC" 5193e6697d4Smrg# time-stamp-end: "; # UTC" 5203e6697d4Smrg# End: 521