install-sh revision e7fdea5f
1067610f1Smrg#!/bin/sh 2067610f1Smrg# install - install a program, script, or datafile 3067610f1Smrg 4e7fdea5fSmrgscriptversion=2011-11-20.07; # UTC 5067610f1Smrg 6067610f1Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7067610f1Smrg# later released in X11R6 (xc/config/util/install.sh) with the 8067610f1Smrg# following copyright and license. 9067610f1Smrg# 10067610f1Smrg# Copyright (C) 1994 X Consortium 11067610f1Smrg# 12067610f1Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13067610f1Smrg# of this software and associated documentation files (the "Software"), to 14067610f1Smrg# deal in the Software without restriction, including without limitation the 15067610f1Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16067610f1Smrg# sell copies of the Software, and to permit persons to whom the Software is 17067610f1Smrg# furnished to do so, subject to the following conditions: 18067610f1Smrg# 19067610f1Smrg# The above copyright notice and this permission notice shall be included in 20067610f1Smrg# all copies or substantial portions of the Software. 21067610f1Smrg# 22067610f1Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23067610f1Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24067610f1Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25067610f1Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26067610f1Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27067610f1Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28067610f1Smrg# 29067610f1Smrg# Except as contained in this notice, the name of the X Consortium shall not 30067610f1Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 31067610f1Smrg# ings in this Software without prior written authorization from the X Consor- 32067610f1Smrg# tium. 33067610f1Smrg# 34067610f1Smrg# 35067610f1Smrg# FSF changes to this file are in the public domain. 36067610f1Smrg# 37067610f1Smrg# Calling this script install-sh is preferred over install.sh, to prevent 38e7fdea5fSmrg# 'make' implicit rules from creating a file called install from it 39067610f1Smrg# when there is no Makefile. 40067610f1Smrg# 41067610f1Smrg# This script is compatible with the BSD install script, but was written 42067610f1Smrg# from scratch. 43067610f1Smrg 44067610f1Smrgnl=' 45067610f1Smrg' 46067610f1SmrgIFS=" "" $nl" 47067610f1Smrg 48067610f1Smrg# set DOITPROG to echo to test this script 49067610f1Smrg 50067610f1Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 517e6533d5Smrgdoit=${DOITPROG-} 52067610f1Smrgif test -z "$doit"; then 53067610f1Smrg doit_exec=exec 54067610f1Smrgelse 55067610f1Smrg doit_exec=$doit 56067610f1Smrgfi 57067610f1Smrg 58067610f1Smrg# Put in absolute file names if you don't have them in your path; 59067610f1Smrg# or use environment vars. 60067610f1Smrg 617e6533d5Smrgchgrpprog=${CHGRPPROG-chgrp} 627e6533d5Smrgchmodprog=${CHMODPROG-chmod} 637e6533d5Smrgchownprog=${CHOWNPROG-chown} 647e6533d5Smrgcmpprog=${CMPPROG-cmp} 657e6533d5Smrgcpprog=${CPPROG-cp} 667e6533d5Smrgmkdirprog=${MKDIRPROG-mkdir} 677e6533d5Smrgmvprog=${MVPROG-mv} 687e6533d5Smrgrmprog=${RMPROG-rm} 697e6533d5Smrgstripprog=${STRIPPROG-strip} 707e6533d5Smrg 717e6533d5Smrgposix_glob='?' 727e6533d5Smrginitialize_posix_glob=' 737e6533d5Smrg test "$posix_glob" != "?" || { 747e6533d5Smrg if (set -f) 2>/dev/null; then 757e6533d5Smrg posix_glob= 767e6533d5Smrg else 777e6533d5Smrg posix_glob=: 787e6533d5Smrg fi 797e6533d5Smrg } 807e6533d5Smrg' 81067610f1Smrg 82067610f1Smrgposix_mkdir= 83067610f1Smrg 84067610f1Smrg# Desired mode of installed file. 85067610f1Smrgmode=0755 86067610f1Smrg 877e6533d5Smrgchgrpcmd= 88067610f1Smrgchmodcmd=$chmodprog 89067610f1Smrgchowncmd= 907e6533d5Smrgmvcmd=$mvprog 91067610f1Smrgrmcmd="$rmprog -f" 927e6533d5Smrgstripcmd= 937e6533d5Smrg 94067610f1Smrgsrc= 95067610f1Smrgdst= 96067610f1Smrgdir_arg= 977e6533d5Smrgdst_arg= 987e6533d5Smrg 997e6533d5Smrgcopy_on_change=false 100067610f1Smrgno_target_directory= 101067610f1Smrg 1027e6533d5Smrgusage="\ 1037e6533d5SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 104067610f1Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 105067610f1Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 106067610f1Smrg or: $0 [OPTION]... -d DIRECTORIES... 107067610f1Smrg 108067610f1SmrgIn the 1st form, copy SRCFILE to DSTFILE. 109067610f1SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 110067610f1SmrgIn the 4th, create DIRECTORIES. 111067610f1Smrg 112067610f1SmrgOptions: 1137e6533d5Smrg --help display this help and exit. 1147e6533d5Smrg --version display version info and exit. 1157e6533d5Smrg 1167e6533d5Smrg -c (ignored) 1177e6533d5Smrg -C install only if different (preserve the last data modification time) 1187e6533d5Smrg -d create directories instead of installing files. 1197e6533d5Smrg -g GROUP $chgrpprog installed files to GROUP. 1207e6533d5Smrg -m MODE $chmodprog installed files to MODE. 1217e6533d5Smrg -o USER $chownprog installed files to USER. 1227e6533d5Smrg -s $stripprog installed files. 1237e6533d5Smrg -t DIRECTORY install into DIRECTORY. 1247e6533d5Smrg -T report an error if DSTFILE is a directory. 125067610f1Smrg 126067610f1SmrgEnvironment variables override the default commands: 1277e6533d5Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1287e6533d5Smrg RMPROG STRIPPROG 129067610f1Smrg" 130067610f1Smrg 131067610f1Smrgwhile test $# -ne 0; do 132067610f1Smrg case $1 in 1337e6533d5Smrg -c) ;; 1347e6533d5Smrg 1357e6533d5Smrg -C) copy_on_change=true;; 136067610f1Smrg 1377e6533d5Smrg -d) dir_arg=true;; 138067610f1Smrg 139067610f1Smrg -g) chgrpcmd="$chgrpprog $2" 1407e6533d5Smrg shift;; 141067610f1Smrg 142067610f1Smrg --help) echo "$usage"; exit $?;; 143067610f1Smrg 144067610f1Smrg -m) mode=$2 145067610f1Smrg case $mode in 146067610f1Smrg *' '* | *' '* | *' 147067610f1Smrg'* | *'*'* | *'?'* | *'['*) 148067610f1Smrg echo "$0: invalid mode: $mode" >&2 149067610f1Smrg exit 1;; 150067610f1Smrg esac 1517e6533d5Smrg shift;; 152067610f1Smrg 153067610f1Smrg -o) chowncmd="$chownprog $2" 1547e6533d5Smrg shift;; 155067610f1Smrg 1567e6533d5Smrg -s) stripcmd=$stripprog;; 157067610f1Smrg 1587e6533d5Smrg -t) dst_arg=$2 159e7fdea5fSmrg # Protect names problematic for 'test' and other utilities. 160aea1d7ffSmrg case $dst_arg in 161aea1d7ffSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 162aea1d7ffSmrg esac 1637e6533d5Smrg shift;; 164067610f1Smrg 1657e6533d5Smrg -T) no_target_directory=true;; 166067610f1Smrg 167067610f1Smrg --version) echo "$0 $scriptversion"; exit $?;; 168067610f1Smrg 169067610f1Smrg --) shift 170067610f1Smrg break;; 171067610f1Smrg 172067610f1Smrg -*) echo "$0: invalid option: $1" >&2 173067610f1Smrg exit 1;; 174067610f1Smrg 175067610f1Smrg *) break;; 176067610f1Smrg esac 1777e6533d5Smrg shift 178067610f1Smrgdone 179067610f1Smrg 1807e6533d5Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 181067610f1Smrg # When -d is used, all remaining arguments are directories to create. 182067610f1Smrg # When -t is used, the destination is already specified. 183067610f1Smrg # Otherwise, the last argument is the destination. Remove it from $@. 184067610f1Smrg for arg 185067610f1Smrg do 1867e6533d5Smrg if test -n "$dst_arg"; then 187067610f1Smrg # $@ is not empty: it contains at least $arg. 1887e6533d5Smrg set fnord "$@" "$dst_arg" 189067610f1Smrg shift # fnord 190067610f1Smrg fi 191067610f1Smrg shift # arg 1927e6533d5Smrg dst_arg=$arg 193e7fdea5fSmrg # Protect names problematic for 'test' and other utilities. 194aea1d7ffSmrg case $dst_arg in 195aea1d7ffSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 196aea1d7ffSmrg esac 197067610f1Smrg done 198067610f1Smrgfi 199067610f1Smrg 200067610f1Smrgif test $# -eq 0; then 201067610f1Smrg if test -z "$dir_arg"; then 202067610f1Smrg echo "$0: no input file specified." >&2 203067610f1Smrg exit 1 204067610f1Smrg fi 205e7fdea5fSmrg # It's OK to call 'install-sh -d' without argument. 206067610f1Smrg # This can happen when creating conditional directories. 207067610f1Smrg exit 0 208067610f1Smrgfi 209067610f1Smrg 210067610f1Smrgif test -z "$dir_arg"; then 211aea1d7ffSmrg do_exit='(exit $ret); exit $ret' 212aea1d7ffSmrg trap "ret=129; $do_exit" 1 213aea1d7ffSmrg trap "ret=130; $do_exit" 2 214aea1d7ffSmrg trap "ret=141; $do_exit" 13 215aea1d7ffSmrg trap "ret=143; $do_exit" 15 216067610f1Smrg 217067610f1Smrg # Set umask so as not to create temps with too-generous modes. 218067610f1Smrg # However, 'strip' requires both read and write access to temps. 219067610f1Smrg case $mode in 220067610f1Smrg # Optimize common cases. 221067610f1Smrg *644) cp_umask=133;; 222067610f1Smrg *755) cp_umask=22;; 223067610f1Smrg 224067610f1Smrg *[0-7]) 225067610f1Smrg if test -z "$stripcmd"; then 226067610f1Smrg u_plus_rw= 227067610f1Smrg else 228067610f1Smrg u_plus_rw='% 200' 229067610f1Smrg fi 230067610f1Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 231067610f1Smrg *) 232067610f1Smrg if test -z "$stripcmd"; then 233067610f1Smrg u_plus_rw= 234067610f1Smrg else 235067610f1Smrg u_plus_rw=,u+rw 236067610f1Smrg fi 237067610f1Smrg cp_umask=$mode$u_plus_rw;; 238067610f1Smrg esac 239067610f1Smrgfi 240067610f1Smrg 241067610f1Smrgfor src 242067610f1Smrgdo 243e7fdea5fSmrg # Protect names problematic for 'test' and other utilities. 244067610f1Smrg case $src in 245aea1d7ffSmrg -* | [=\(\)!]) src=./$src;; 246067610f1Smrg esac 247067610f1Smrg 248067610f1Smrg if test -n "$dir_arg"; then 249067610f1Smrg dst=$src 250067610f1Smrg dstdir=$dst 251067610f1Smrg test -d "$dstdir" 252067610f1Smrg dstdir_status=$? 253067610f1Smrg else 254067610f1Smrg 255067610f1Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 256067610f1Smrg # might cause directories to be created, which would be especially bad 257067610f1Smrg # if $src (and thus $dsttmp) contains '*'. 258067610f1Smrg if test ! -f "$src" && test ! -d "$src"; then 259067610f1Smrg echo "$0: $src does not exist." >&2 260067610f1Smrg exit 1 261067610f1Smrg fi 262067610f1Smrg 2637e6533d5Smrg if test -z "$dst_arg"; then 264067610f1Smrg echo "$0: no destination specified." >&2 265067610f1Smrg exit 1 266067610f1Smrg fi 2677e6533d5Smrg dst=$dst_arg 268067610f1Smrg 269067610f1Smrg # If destination is a directory, append the input filename; won't work 270067610f1Smrg # if double slashes aren't ignored. 271067610f1Smrg if test -d "$dst"; then 272067610f1Smrg if test -n "$no_target_directory"; then 2737e6533d5Smrg echo "$0: $dst_arg: Is a directory" >&2 274067610f1Smrg exit 1 275067610f1Smrg fi 276067610f1Smrg dstdir=$dst 277067610f1Smrg dst=$dstdir/`basename "$src"` 278067610f1Smrg dstdir_status=0 279067610f1Smrg else 280067610f1Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 281067610f1Smrg dstdir=` 282067610f1Smrg (dirname "$dst") 2>/dev/null || 283067610f1Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 284067610f1Smrg X"$dst" : 'X\(//\)[^/]' \| \ 285067610f1Smrg X"$dst" : 'X\(//\)$' \| \ 286067610f1Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 287067610f1Smrg echo X"$dst" | 288067610f1Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 289067610f1Smrg s//\1/ 290067610f1Smrg q 291067610f1Smrg } 292067610f1Smrg /^X\(\/\/\)[^/].*/{ 293067610f1Smrg s//\1/ 294067610f1Smrg q 295067610f1Smrg } 296067610f1Smrg /^X\(\/\/\)$/{ 297067610f1Smrg s//\1/ 298067610f1Smrg q 299067610f1Smrg } 300067610f1Smrg /^X\(\/\).*/{ 301067610f1Smrg s//\1/ 302067610f1Smrg q 303067610f1Smrg } 304067610f1Smrg s/.*/./; q' 305067610f1Smrg ` 306067610f1Smrg 307067610f1Smrg test -d "$dstdir" 308067610f1Smrg dstdir_status=$? 309067610f1Smrg fi 310067610f1Smrg fi 311067610f1Smrg 312067610f1Smrg obsolete_mkdir_used=false 313067610f1Smrg 314067610f1Smrg if test $dstdir_status != 0; then 315067610f1Smrg case $posix_mkdir in 316067610f1Smrg '') 317067610f1Smrg # Create intermediate dirs using mode 755 as modified by the umask. 318067610f1Smrg # This is like FreeBSD 'install' as of 1997-10-28. 319067610f1Smrg umask=`umask` 320067610f1Smrg case $stripcmd.$umask in 321067610f1Smrg # Optimize common cases. 322067610f1Smrg *[2367][2367]) mkdir_umask=$umask;; 323067610f1Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 324067610f1Smrg 325067610f1Smrg *[0-7]) 326067610f1Smrg mkdir_umask=`expr $umask + 22 \ 327067610f1Smrg - $umask % 100 % 40 + $umask % 20 \ 328067610f1Smrg - $umask % 10 % 4 + $umask % 2 329067610f1Smrg `;; 330067610f1Smrg *) mkdir_umask=$umask,go-w;; 331067610f1Smrg esac 332067610f1Smrg 333067610f1Smrg # With -d, create the new directory with the user-specified mode. 334067610f1Smrg # Otherwise, rely on $mkdir_umask. 335067610f1Smrg if test -n "$dir_arg"; then 336067610f1Smrg mkdir_mode=-m$mode 337067610f1Smrg else 338067610f1Smrg mkdir_mode= 339067610f1Smrg fi 340067610f1Smrg 341067610f1Smrg posix_mkdir=false 342067610f1Smrg case $umask in 343067610f1Smrg *[123567][0-7][0-7]) 344067610f1Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 345067610f1Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 346067610f1Smrg ;; 347067610f1Smrg *) 348067610f1Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 349067610f1Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 350067610f1Smrg 351067610f1Smrg if (umask $mkdir_umask && 352067610f1Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 353067610f1Smrg then 354067610f1Smrg if test -z "$dir_arg" || { 355067610f1Smrg # Check for POSIX incompatibilities with -m. 356067610f1Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 357e7fdea5fSmrg # other-writable bit of parent directory when it shouldn't. 358067610f1Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 359067610f1Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 360067610f1Smrg case $ls_ld_tmpdir in 361067610f1Smrg d????-?r-*) different_mode=700;; 362067610f1Smrg d????-?--*) different_mode=755;; 363067610f1Smrg *) false;; 364067610f1Smrg esac && 365067610f1Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 366067610f1Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 367067610f1Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 368067610f1Smrg } 369067610f1Smrg } 370067610f1Smrg then posix_mkdir=: 371067610f1Smrg fi 372067610f1Smrg rmdir "$tmpdir/d" "$tmpdir" 373067610f1Smrg else 374067610f1Smrg # Remove any dirs left behind by ancient mkdir implementations. 375067610f1Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 376067610f1Smrg fi 377067610f1Smrg trap '' 0;; 378067610f1Smrg esac;; 379067610f1Smrg esac 380067610f1Smrg 381067610f1Smrg if 382067610f1Smrg $posix_mkdir && ( 383067610f1Smrg umask $mkdir_umask && 384067610f1Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 385067610f1Smrg ) 386067610f1Smrg then : 387067610f1Smrg else 388067610f1Smrg 389067610f1Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 390067610f1Smrg # or it failed possibly due to a race condition. Create the 391067610f1Smrg # directory the slow way, step by step, checking for races as we go. 392067610f1Smrg 393067610f1Smrg case $dstdir in 3947e6533d5Smrg /*) prefix='/';; 395aea1d7ffSmrg [-=\(\)!]*) prefix='./';; 3967e6533d5Smrg *) prefix='';; 397067610f1Smrg esac 398067610f1Smrg 3997e6533d5Smrg eval "$initialize_posix_glob" 400067610f1Smrg 401067610f1Smrg oIFS=$IFS 402067610f1Smrg IFS=/ 4037e6533d5Smrg $posix_glob set -f 404067610f1Smrg set fnord $dstdir 405067610f1Smrg shift 4067e6533d5Smrg $posix_glob set +f 407067610f1Smrg IFS=$oIFS 408067610f1Smrg 409067610f1Smrg prefixes= 410067610f1Smrg 411067610f1Smrg for d 412067610f1Smrg do 413aea1d7ffSmrg test X"$d" = X && continue 414067610f1Smrg 415067610f1Smrg prefix=$prefix$d 416067610f1Smrg if test -d "$prefix"; then 417067610f1Smrg prefixes= 418067610f1Smrg else 419067610f1Smrg if $posix_mkdir; then 420067610f1Smrg (umask=$mkdir_umask && 421067610f1Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 422067610f1Smrg # Don't fail if two instances are running concurrently. 423067610f1Smrg test -d "$prefix" || exit 1 424067610f1Smrg else 425067610f1Smrg case $prefix in 426067610f1Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 427067610f1Smrg *) qprefix=$prefix;; 428067610f1Smrg esac 429067610f1Smrg prefixes="$prefixes '$qprefix'" 430067610f1Smrg fi 431067610f1Smrg fi 432067610f1Smrg prefix=$prefix/ 433067610f1Smrg done 434067610f1Smrg 435067610f1Smrg if test -n "$prefixes"; then 436067610f1Smrg # Don't fail if two instances are running concurrently. 437067610f1Smrg (umask $mkdir_umask && 438067610f1Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 439067610f1Smrg test -d "$dstdir" || exit 1 440067610f1Smrg obsolete_mkdir_used=true 441067610f1Smrg fi 442067610f1Smrg fi 443067610f1Smrg fi 444067610f1Smrg 445067610f1Smrg if test -n "$dir_arg"; then 446067610f1Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 447067610f1Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 448067610f1Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 449067610f1Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 450067610f1Smrg else 451067610f1Smrg 452067610f1Smrg # Make a couple of temp file names in the proper directory. 453067610f1Smrg dsttmp=$dstdir/_inst.$$_ 454067610f1Smrg rmtmp=$dstdir/_rm.$$_ 455067610f1Smrg 456067610f1Smrg # Trap to clean up those temp files at exit. 457067610f1Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 458067610f1Smrg 459067610f1Smrg # Copy the file name to the temp name. 460067610f1Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 461067610f1Smrg 462067610f1Smrg # and set any options; do chmod last to preserve setuid bits. 463067610f1Smrg # 464067610f1Smrg # If any of these fail, we abort the whole thing. If we want to 465067610f1Smrg # ignore errors from any of these, just make sure not to ignore 466067610f1Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 467067610f1Smrg # 4687e6533d5Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4697e6533d5Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4707e6533d5Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4717e6533d5Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4727e6533d5Smrg 4737e6533d5Smrg # If -C, don't bother to copy if it wouldn't change the file. 4747e6533d5Smrg if $copy_on_change && 4757e6533d5Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4767e6533d5Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4777e6533d5Smrg 4787e6533d5Smrg eval "$initialize_posix_glob" && 4797e6533d5Smrg $posix_glob set -f && 4807e6533d5Smrg set X $old && old=:$2:$4:$5:$6 && 4817e6533d5Smrg set X $new && new=:$2:$4:$5:$6 && 4827e6533d5Smrg $posix_glob set +f && 4837e6533d5Smrg 4847e6533d5Smrg test "$old" = "$new" && 4857e6533d5Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4867e6533d5Smrg then 4877e6533d5Smrg rm -f "$dsttmp" 4887e6533d5Smrg else 4897e6533d5Smrg # Rename the file to the real destination. 4907e6533d5Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4917e6533d5Smrg 4927e6533d5Smrg # The rename failed, perhaps because mv can't rename something else 4937e6533d5Smrg # to itself, or perhaps because mv is so ancient that it does not 4947e6533d5Smrg # support -f. 4957e6533d5Smrg { 4967e6533d5Smrg # Now remove or move aside any old file at destination location. 4977e6533d5Smrg # We try this two ways since rm can't unlink itself on some 4987e6533d5Smrg # systems and the destination file might be busy for other 4997e6533d5Smrg # reasons. In this case, the final cleanup might fail but the new 5007e6533d5Smrg # file should still install successfully. 5017e6533d5Smrg { 5027e6533d5Smrg test ! -f "$dst" || 5037e6533d5Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 5047e6533d5Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 5057e6533d5Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 5067e6533d5Smrg } || 5077e6533d5Smrg { echo "$0: cannot unlink or rename $dst" >&2 5087e6533d5Smrg (exit 1); exit 1 5097e6533d5Smrg } 5107e6533d5Smrg } && 5117e6533d5Smrg 5127e6533d5Smrg # Now rename the file to the real destination. 5137e6533d5Smrg $doit $mvcmd "$dsttmp" "$dst" 5147e6533d5Smrg } 5157e6533d5Smrg fi || exit 1 516067610f1Smrg 517067610f1Smrg trap '' 0 518067610f1Smrg fi 519067610f1Smrgdone 520067610f1Smrg 521067610f1Smrg# Local variables: 522067610f1Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 523067610f1Smrg# time-stamp-start: "scriptversion=" 524067610f1Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5257e6533d5Smrg# time-stamp-time-zone: "UTC" 5267e6533d5Smrg# time-stamp-end: "; # UTC" 527067610f1Smrg# End: 528