install-sh revision 63847c39
176888252Smrg#!/bin/sh 276888252Smrg# install - install a program, script, or datafile 376888252Smrg 463847c39Smrgscriptversion=2011-01-19.21; # UTC 576888252Smrg 676888252Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 776888252Smrg# later released in X11R6 (xc/config/util/install.sh) with the 876888252Smrg# following copyright and license. 976888252Smrg# 1076888252Smrg# Copyright (C) 1994 X Consortium 1176888252Smrg# 1276888252Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 1376888252Smrg# of this software and associated documentation files (the "Software"), to 1476888252Smrg# deal in the Software without restriction, including without limitation the 1576888252Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1676888252Smrg# sell copies of the Software, and to permit persons to whom the Software is 1776888252Smrg# furnished to do so, subject to the following conditions: 1876888252Smrg# 1976888252Smrg# The above copyright notice and this permission notice shall be included in 2076888252Smrg# all copies or substantial portions of the Software. 2176888252Smrg# 2276888252Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2376888252Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2476888252Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2576888252Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2676888252Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 2776888252Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2876888252Smrg# 2976888252Smrg# Except as contained in this notice, the name of the X Consortium shall not 3076888252Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 3176888252Smrg# ings in this Software without prior written authorization from the X Consor- 3276888252Smrg# tium. 3376888252Smrg# 3476888252Smrg# 3576888252Smrg# FSF changes to this file are in the public domain. 3676888252Smrg# 3776888252Smrg# Calling this script install-sh is preferred over install.sh, to prevent 3876888252Smrg# `make' implicit rules from creating a file called install from it 3976888252Smrg# when there is no Makefile. 4076888252Smrg# 4176888252Smrg# This script is compatible with the BSD install script, but was written 421ae1b5e8Smrg# from scratch. 431ae1b5e8Smrg 441ae1b5e8Smrgnl=' 451ae1b5e8Smrg' 461ae1b5e8SmrgIFS=" "" $nl" 4776888252Smrg 4876888252Smrg# set DOITPROG to echo to test this script 4976888252Smrg 5076888252Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 5186dafe34Smrgdoit=${DOITPROG-} 521ae1b5e8Smrgif test -z "$doit"; then 531ae1b5e8Smrg doit_exec=exec 541ae1b5e8Smrgelse 551ae1b5e8Smrg doit_exec=$doit 561ae1b5e8Smrgfi 5776888252Smrg 581ae1b5e8Smrg# Put in absolute file names if you don't have them in your path; 591ae1b5e8Smrg# or use environment vars. 6076888252Smrg 6186dafe34Smrgchgrpprog=${CHGRPPROG-chgrp} 6286dafe34Smrgchmodprog=${CHMODPROG-chmod} 6386dafe34Smrgchownprog=${CHOWNPROG-chown} 6486dafe34Smrgcmpprog=${CMPPROG-cmp} 6586dafe34Smrgcpprog=${CPPROG-cp} 6686dafe34Smrgmkdirprog=${MKDIRPROG-mkdir} 6786dafe34Smrgmvprog=${MVPROG-mv} 6886dafe34Smrgrmprog=${RMPROG-rm} 6986dafe34Smrgstripprog=${STRIPPROG-strip} 7086dafe34Smrg 7186dafe34Smrgposix_glob='?' 7286dafe34Smrginitialize_posix_glob=' 7386dafe34Smrg test "$posix_glob" != "?" || { 7486dafe34Smrg if (set -f) 2>/dev/null; then 7586dafe34Smrg posix_glob= 7686dafe34Smrg else 7786dafe34Smrg posix_glob=: 7886dafe34Smrg fi 7986dafe34Smrg } 8086dafe34Smrg' 8176888252Smrg 821ae1b5e8Smrgposix_mkdir= 831ae1b5e8Smrg 841ae1b5e8Smrg# Desired mode of installed file. 851ae1b5e8Smrgmode=0755 861ae1b5e8Smrg 8786dafe34Smrgchgrpcmd= 881ae1b5e8Smrgchmodcmd=$chmodprog 8976888252Smrgchowncmd= 9086dafe34Smrgmvcmd=$mvprog 9176888252Smrgrmcmd="$rmprog -f" 9286dafe34Smrgstripcmd= 9386dafe34Smrg 9476888252Smrgsrc= 9576888252Smrgdst= 9676888252Smrgdir_arg= 9786dafe34Smrgdst_arg= 9886dafe34Smrg 9986dafe34Smrgcopy_on_change=false 10076888252Smrgno_target_directory= 10176888252Smrg 10286dafe34Smrgusage="\ 10386dafe34SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 10476888252Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 10576888252Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 10676888252Smrg or: $0 [OPTION]... -d DIRECTORIES... 10776888252Smrg 10876888252SmrgIn the 1st form, copy SRCFILE to DSTFILE. 10976888252SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 11076888252SmrgIn the 4th, create DIRECTORIES. 11176888252Smrg 11276888252SmrgOptions: 11386dafe34Smrg --help display this help and exit. 11486dafe34Smrg --version display version info and exit. 11586dafe34Smrg 11686dafe34Smrg -c (ignored) 11786dafe34Smrg -C install only if different (preserve the last data modification time) 11886dafe34Smrg -d create directories instead of installing files. 11986dafe34Smrg -g GROUP $chgrpprog installed files to GROUP. 12086dafe34Smrg -m MODE $chmodprog installed files to MODE. 12186dafe34Smrg -o USER $chownprog installed files to USER. 12286dafe34Smrg -s $stripprog installed files. 12386dafe34Smrg -t DIRECTORY install into DIRECTORY. 12486dafe34Smrg -T report an error if DSTFILE is a directory. 12576888252Smrg 12676888252SmrgEnvironment variables override the default commands: 12786dafe34Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 12886dafe34Smrg RMPROG STRIPPROG 12976888252Smrg" 13076888252Smrg 1311ae1b5e8Smrgwhile test $# -ne 0; do 13276888252Smrg case $1 in 13386dafe34Smrg -c) ;; 13486dafe34Smrg 13586dafe34Smrg -C) copy_on_change=true;; 13676888252Smrg 13786dafe34Smrg -d) dir_arg=true;; 13876888252Smrg 13976888252Smrg -g) chgrpcmd="$chgrpprog $2" 14086dafe34Smrg shift;; 14176888252Smrg 14276888252Smrg --help) echo "$usage"; exit $?;; 14376888252Smrg 1441ae1b5e8Smrg -m) mode=$2 1451ae1b5e8Smrg case $mode in 1461ae1b5e8Smrg *' '* | *' '* | *' 1471ae1b5e8Smrg'* | *'*'* | *'?'* | *'['*) 1481ae1b5e8Smrg echo "$0: invalid mode: $mode" >&2 1491ae1b5e8Smrg exit 1;; 1501ae1b5e8Smrg esac 15186dafe34Smrg shift;; 15276888252Smrg 15376888252Smrg -o) chowncmd="$chownprog $2" 15486dafe34Smrg shift;; 15576888252Smrg 15686dafe34Smrg -s) stripcmd=$stripprog;; 15776888252Smrg 15886dafe34Smrg -t) dst_arg=$2 15963847c39Smrg # Protect names problematic for `test' and other utilities. 16063847c39Smrg case $dst_arg in 16163847c39Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 16263847c39Smrg esac 16386dafe34Smrg shift;; 16476888252Smrg 16586dafe34Smrg -T) no_target_directory=true;; 16676888252Smrg 16776888252Smrg --version) echo "$0 $scriptversion"; exit $?;; 16876888252Smrg 1691ae1b5e8Smrg --) shift 17076888252Smrg break;; 1711ae1b5e8Smrg 1721ae1b5e8Smrg -*) echo "$0: invalid option: $1" >&2 1731ae1b5e8Smrg exit 1;; 1741ae1b5e8Smrg 1751ae1b5e8Smrg *) break;; 17676888252Smrg esac 17786dafe34Smrg shift 17876888252Smrgdone 17976888252Smrg 18086dafe34Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1811ae1b5e8Smrg # When -d is used, all remaining arguments are directories to create. 1821ae1b5e8Smrg # When -t is used, the destination is already specified. 1831ae1b5e8Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1841ae1b5e8Smrg for arg 1851ae1b5e8Smrg do 18686dafe34Smrg if test -n "$dst_arg"; then 1871ae1b5e8Smrg # $@ is not empty: it contains at least $arg. 18886dafe34Smrg set fnord "$@" "$dst_arg" 1891ae1b5e8Smrg shift # fnord 1901ae1b5e8Smrg fi 1911ae1b5e8Smrg shift # arg 19286dafe34Smrg dst_arg=$arg 19363847c39Smrg # Protect names problematic for `test' and other utilities. 19463847c39Smrg case $dst_arg in 19563847c39Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 19663847c39Smrg esac 1971ae1b5e8Smrg done 1981ae1b5e8Smrgfi 1991ae1b5e8Smrg 2001ae1b5e8Smrgif test $# -eq 0; then 20176888252Smrg if test -z "$dir_arg"; then 20276888252Smrg echo "$0: no input file specified." >&2 20376888252Smrg exit 1 20476888252Smrg fi 20576888252Smrg # It's OK to call `install-sh -d' without argument. 20676888252Smrg # This can happen when creating conditional directories. 20776888252Smrg exit 0 20876888252Smrgfi 20976888252Smrg 2101ae1b5e8Smrgif test -z "$dir_arg"; then 21163847c39Smrg do_exit='(exit $ret); exit $ret' 21263847c39Smrg trap "ret=129; $do_exit" 1 21363847c39Smrg trap "ret=130; $do_exit" 2 21463847c39Smrg trap "ret=141; $do_exit" 13 21563847c39Smrg trap "ret=143; $do_exit" 15 2161ae1b5e8Smrg 2171ae1b5e8Smrg # Set umask so as not to create temps with too-generous modes. 2181ae1b5e8Smrg # However, 'strip' requires both read and write access to temps. 2191ae1b5e8Smrg case $mode in 2201ae1b5e8Smrg # Optimize common cases. 2211ae1b5e8Smrg *644) cp_umask=133;; 2221ae1b5e8Smrg *755) cp_umask=22;; 2231ae1b5e8Smrg 2241ae1b5e8Smrg *[0-7]) 2251ae1b5e8Smrg if test -z "$stripcmd"; then 2261ae1b5e8Smrg u_plus_rw= 2271ae1b5e8Smrg else 2281ae1b5e8Smrg u_plus_rw='% 200' 2291ae1b5e8Smrg fi 2301ae1b5e8Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2311ae1b5e8Smrg *) 2321ae1b5e8Smrg if test -z "$stripcmd"; then 2331ae1b5e8Smrg u_plus_rw= 2341ae1b5e8Smrg else 2351ae1b5e8Smrg u_plus_rw=,u+rw 2361ae1b5e8Smrg fi 2371ae1b5e8Smrg cp_umask=$mode$u_plus_rw;; 2381ae1b5e8Smrg esac 2391ae1b5e8Smrgfi 2401ae1b5e8Smrg 24176888252Smrgfor src 24276888252Smrgdo 24363847c39Smrg # Protect names problematic for `test' and other utilities. 24476888252Smrg case $src in 24563847c39Smrg -* | [=\(\)!]) src=./$src;; 24676888252Smrg esac 24776888252Smrg 24876888252Smrg if test -n "$dir_arg"; then 24976888252Smrg dst=$src 2501ae1b5e8Smrg dstdir=$dst 2511ae1b5e8Smrg test -d "$dstdir" 2521ae1b5e8Smrg dstdir_status=$? 25376888252Smrg else 2541ae1b5e8Smrg 25576888252Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 25676888252Smrg # might cause directories to be created, which would be especially bad 25776888252Smrg # if $src (and thus $dsttmp) contains '*'. 25876888252Smrg if test ! -f "$src" && test ! -d "$src"; then 25976888252Smrg echo "$0: $src does not exist." >&2 26076888252Smrg exit 1 26176888252Smrg fi 26276888252Smrg 26386dafe34Smrg if test -z "$dst_arg"; then 26476888252Smrg echo "$0: no destination specified." >&2 26576888252Smrg exit 1 26676888252Smrg fi 26786dafe34Smrg dst=$dst_arg 26876888252Smrg 26976888252Smrg # If destination is a directory, append the input filename; won't work 27076888252Smrg # if double slashes aren't ignored. 27176888252Smrg if test -d "$dst"; then 27276888252Smrg if test -n "$no_target_directory"; then 27386dafe34Smrg echo "$0: $dst_arg: Is a directory" >&2 27476888252Smrg exit 1 27576888252Smrg fi 2761ae1b5e8Smrg dstdir=$dst 2771ae1b5e8Smrg dst=$dstdir/`basename "$src"` 2781ae1b5e8Smrg dstdir_status=0 2791ae1b5e8Smrg else 2801ae1b5e8Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 2811ae1b5e8Smrg dstdir=` 2821ae1b5e8Smrg (dirname "$dst") 2>/dev/null || 2831ae1b5e8Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2841ae1b5e8Smrg X"$dst" : 'X\(//\)[^/]' \| \ 2851ae1b5e8Smrg X"$dst" : 'X\(//\)$' \| \ 2861ae1b5e8Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2871ae1b5e8Smrg echo X"$dst" | 2881ae1b5e8Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2891ae1b5e8Smrg s//\1/ 2901ae1b5e8Smrg q 2911ae1b5e8Smrg } 2921ae1b5e8Smrg /^X\(\/\/\)[^/].*/{ 2931ae1b5e8Smrg s//\1/ 2941ae1b5e8Smrg q 2951ae1b5e8Smrg } 2961ae1b5e8Smrg /^X\(\/\/\)$/{ 2971ae1b5e8Smrg s//\1/ 2981ae1b5e8Smrg q 2991ae1b5e8Smrg } 3001ae1b5e8Smrg /^X\(\/\).*/{ 3011ae1b5e8Smrg s//\1/ 3021ae1b5e8Smrg q 3031ae1b5e8Smrg } 3041ae1b5e8Smrg s/.*/./; q' 3051ae1b5e8Smrg ` 3061ae1b5e8Smrg 3071ae1b5e8Smrg test -d "$dstdir" 3081ae1b5e8Smrg dstdir_status=$? 30976888252Smrg fi 31076888252Smrg fi 31176888252Smrg 3121ae1b5e8Smrg obsolete_mkdir_used=false 3131ae1b5e8Smrg 3141ae1b5e8Smrg if test $dstdir_status != 0; then 3151ae1b5e8Smrg case $posix_mkdir in 3161ae1b5e8Smrg '') 3171ae1b5e8Smrg # Create intermediate dirs using mode 755 as modified by the umask. 3181ae1b5e8Smrg # This is like FreeBSD 'install' as of 1997-10-28. 3191ae1b5e8Smrg umask=`umask` 3201ae1b5e8Smrg case $stripcmd.$umask in 3211ae1b5e8Smrg # Optimize common cases. 3221ae1b5e8Smrg *[2367][2367]) mkdir_umask=$umask;; 3231ae1b5e8Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3241ae1b5e8Smrg 3251ae1b5e8Smrg *[0-7]) 3261ae1b5e8Smrg mkdir_umask=`expr $umask + 22 \ 3271ae1b5e8Smrg - $umask % 100 % 40 + $umask % 20 \ 3281ae1b5e8Smrg - $umask % 10 % 4 + $umask % 2 3291ae1b5e8Smrg `;; 3301ae1b5e8Smrg *) mkdir_umask=$umask,go-w;; 3311ae1b5e8Smrg esac 3321ae1b5e8Smrg 3331ae1b5e8Smrg # With -d, create the new directory with the user-specified mode. 3341ae1b5e8Smrg # Otherwise, rely on $mkdir_umask. 3351ae1b5e8Smrg if test -n "$dir_arg"; then 3361ae1b5e8Smrg mkdir_mode=-m$mode 3371ae1b5e8Smrg else 3381ae1b5e8Smrg mkdir_mode= 3391ae1b5e8Smrg fi 3401ae1b5e8Smrg 3411ae1b5e8Smrg posix_mkdir=false 3421ae1b5e8Smrg case $umask in 3431ae1b5e8Smrg *[123567][0-7][0-7]) 3441ae1b5e8Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3451ae1b5e8Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3461ae1b5e8Smrg ;; 3471ae1b5e8Smrg *) 3481ae1b5e8Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3491ae1b5e8Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3501ae1b5e8Smrg 3511ae1b5e8Smrg if (umask $mkdir_umask && 3521ae1b5e8Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3531ae1b5e8Smrg then 3541ae1b5e8Smrg if test -z "$dir_arg" || { 3551ae1b5e8Smrg # Check for POSIX incompatibilities with -m. 3561ae1b5e8Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3571ae1b5e8Smrg # other-writeable bit of parent directory when it shouldn't. 3581ae1b5e8Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3591ae1b5e8Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3601ae1b5e8Smrg case $ls_ld_tmpdir in 3611ae1b5e8Smrg d????-?r-*) different_mode=700;; 3621ae1b5e8Smrg d????-?--*) different_mode=755;; 3631ae1b5e8Smrg *) false;; 3641ae1b5e8Smrg esac && 3651ae1b5e8Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3661ae1b5e8Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3671ae1b5e8Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3681ae1b5e8Smrg } 3691ae1b5e8Smrg } 3701ae1b5e8Smrg then posix_mkdir=: 3711ae1b5e8Smrg fi 3721ae1b5e8Smrg rmdir "$tmpdir/d" "$tmpdir" 3731ae1b5e8Smrg else 3741ae1b5e8Smrg # Remove any dirs left behind by ancient mkdir implementations. 3751ae1b5e8Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3761ae1b5e8Smrg fi 3771ae1b5e8Smrg trap '' 0;; 3781ae1b5e8Smrg esac;; 3791ae1b5e8Smrg esac 38076888252Smrg 3811ae1b5e8Smrg if 3821ae1b5e8Smrg $posix_mkdir && ( 3831ae1b5e8Smrg umask $mkdir_umask && 3841ae1b5e8Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3851ae1b5e8Smrg ) 3861ae1b5e8Smrg then : 3871ae1b5e8Smrg else 38876888252Smrg 3891ae1b5e8Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3901ae1b5e8Smrg # or it failed possibly due to a race condition. Create the 3911ae1b5e8Smrg # directory the slow way, step by step, checking for races as we go. 3921ae1b5e8Smrg 3931ae1b5e8Smrg case $dstdir in 39486dafe34Smrg /*) prefix='/';; 39563847c39Smrg [-=\(\)!]*) prefix='./';; 39686dafe34Smrg *) prefix='';; 3971ae1b5e8Smrg esac 3981ae1b5e8Smrg 39986dafe34Smrg eval "$initialize_posix_glob" 4001ae1b5e8Smrg 4011ae1b5e8Smrg oIFS=$IFS 4021ae1b5e8Smrg IFS=/ 40386dafe34Smrg $posix_glob set -f 4041ae1b5e8Smrg set fnord $dstdir 40576888252Smrg shift 40686dafe34Smrg $posix_glob set +f 4071ae1b5e8Smrg IFS=$oIFS 4081ae1b5e8Smrg 4091ae1b5e8Smrg prefixes= 4101ae1b5e8Smrg 4111ae1b5e8Smrg for d 4121ae1b5e8Smrg do 41363847c39Smrg test X"$d" = X && continue 4141ae1b5e8Smrg 4151ae1b5e8Smrg prefix=$prefix$d 4161ae1b5e8Smrg if test -d "$prefix"; then 4171ae1b5e8Smrg prefixes= 4181ae1b5e8Smrg else 4191ae1b5e8Smrg if $posix_mkdir; then 4201ae1b5e8Smrg (umask=$mkdir_umask && 4211ae1b5e8Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4221ae1b5e8Smrg # Don't fail if two instances are running concurrently. 4231ae1b5e8Smrg test -d "$prefix" || exit 1 4241ae1b5e8Smrg else 4251ae1b5e8Smrg case $prefix in 4261ae1b5e8Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4271ae1b5e8Smrg *) qprefix=$prefix;; 4281ae1b5e8Smrg esac 4291ae1b5e8Smrg prefixes="$prefixes '$qprefix'" 4301ae1b5e8Smrg fi 4311ae1b5e8Smrg fi 4321ae1b5e8Smrg prefix=$prefix/ 4331ae1b5e8Smrg done 4341ae1b5e8Smrg 4351ae1b5e8Smrg if test -n "$prefixes"; then 4361ae1b5e8Smrg # Don't fail if two instances are running concurrently. 4371ae1b5e8Smrg (umask $mkdir_umask && 4381ae1b5e8Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4391ae1b5e8Smrg test -d "$dstdir" || exit 1 4401ae1b5e8Smrg obsolete_mkdir_used=true 44176888252Smrg fi 4421ae1b5e8Smrg fi 44376888252Smrg fi 44476888252Smrg 44576888252Smrg if test -n "$dir_arg"; then 4461ae1b5e8Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4471ae1b5e8Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4481ae1b5e8Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4491ae1b5e8Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 45076888252Smrg else 45176888252Smrg 45276888252Smrg # Make a couple of temp file names in the proper directory. 45376888252Smrg dsttmp=$dstdir/_inst.$$_ 45476888252Smrg rmtmp=$dstdir/_rm.$$_ 45576888252Smrg 45676888252Smrg # Trap to clean up those temp files at exit. 45776888252Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 45876888252Smrg 45976888252Smrg # Copy the file name to the temp name. 4601ae1b5e8Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 46176888252Smrg 46276888252Smrg # and set any options; do chmod last to preserve setuid bits. 46376888252Smrg # 46476888252Smrg # If any of these fail, we abort the whole thing. If we want to 46576888252Smrg # ignore errors from any of these, just make sure not to ignore 46676888252Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 46776888252Smrg # 46886dafe34Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 46986dafe34Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 47086dafe34Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 47186dafe34Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 47286dafe34Smrg 47386dafe34Smrg # If -C, don't bother to copy if it wouldn't change the file. 47486dafe34Smrg if $copy_on_change && 47586dafe34Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 47686dafe34Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 47786dafe34Smrg 47886dafe34Smrg eval "$initialize_posix_glob" && 47986dafe34Smrg $posix_glob set -f && 48086dafe34Smrg set X $old && old=:$2:$4:$5:$6 && 48186dafe34Smrg set X $new && new=:$2:$4:$5:$6 && 48286dafe34Smrg $posix_glob set +f && 48386dafe34Smrg 48486dafe34Smrg test "$old" = "$new" && 48586dafe34Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 48686dafe34Smrg then 48786dafe34Smrg rm -f "$dsttmp" 48886dafe34Smrg else 48986dafe34Smrg # Rename the file to the real destination. 49086dafe34Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 49186dafe34Smrg 49286dafe34Smrg # The rename failed, perhaps because mv can't rename something else 49386dafe34Smrg # to itself, or perhaps because mv is so ancient that it does not 49486dafe34Smrg # support -f. 49586dafe34Smrg { 49686dafe34Smrg # Now remove or move aside any old file at destination location. 49786dafe34Smrg # We try this two ways since rm can't unlink itself on some 49886dafe34Smrg # systems and the destination file might be busy for other 49986dafe34Smrg # reasons. In this case, the final cleanup might fail but the new 50086dafe34Smrg # file should still install successfully. 50186dafe34Smrg { 50286dafe34Smrg test ! -f "$dst" || 50386dafe34Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 50486dafe34Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 50586dafe34Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 50686dafe34Smrg } || 50786dafe34Smrg { echo "$0: cannot unlink or rename $dst" >&2 50886dafe34Smrg (exit 1); exit 1 50986dafe34Smrg } 51086dafe34Smrg } && 51186dafe34Smrg 51286dafe34Smrg # Now rename the file to the real destination. 51386dafe34Smrg $doit $mvcmd "$dsttmp" "$dst" 51486dafe34Smrg } 51586dafe34Smrg fi || exit 1 51676888252Smrg 5171ae1b5e8Smrg trap '' 0 5181ae1b5e8Smrg fi 5191ae1b5e8Smrgdone 52076888252Smrg 52176888252Smrg# Local variables: 52276888252Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 52376888252Smrg# time-stamp-start: "scriptversion=" 52476888252Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 525d8556812Smrg# time-stamp-time-zone: "UTC" 526d8556812Smrg# time-stamp-end: "; # UTC" 52776888252Smrg# End: 528