install-sh revision 05bee9bc
1ff7e0accSmrg#!/bin/sh 2ff7e0accSmrg# install - install a program, script, or datafile 3ff7e0accSmrg 405bee9bcSmrgscriptversion=2011-11-20.07; # UTC 5ff7e0accSmrg 6ff7e0accSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7ff7e0accSmrg# later released in X11R6 (xc/config/util/install.sh) with the 8ff7e0accSmrg# following copyright and license. 9ff7e0accSmrg# 10ff7e0accSmrg# Copyright (C) 1994 X Consortium 11ff7e0accSmrg# 12ff7e0accSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13ff7e0accSmrg# of this software and associated documentation files (the "Software"), to 14ff7e0accSmrg# deal in the Software without restriction, including without limitation the 15ff7e0accSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16ff7e0accSmrg# sell copies of the Software, and to permit persons to whom the Software is 17ff7e0accSmrg# furnished to do so, subject to the following conditions: 18ff7e0accSmrg# 19ff7e0accSmrg# The above copyright notice and this permission notice shall be included in 20ff7e0accSmrg# all copies or substantial portions of the Software. 21ff7e0accSmrg# 22ff7e0accSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23ff7e0accSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24ff7e0accSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25ff7e0accSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26ff7e0accSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27ff7e0accSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28ff7e0accSmrg# 29ff7e0accSmrg# Except as contained in this notice, the name of the X Consortium shall not 30ff7e0accSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 31ff7e0accSmrg# ings in this Software without prior written authorization from the X Consor- 32ff7e0accSmrg# tium. 33ff7e0accSmrg# 34ff7e0accSmrg# 35ff7e0accSmrg# FSF changes to this file are in the public domain. 36ff7e0accSmrg# 37ff7e0accSmrg# Calling this script install-sh is preferred over install.sh, to prevent 3805bee9bcSmrg# 'make' implicit rules from creating a file called install from it 39ff7e0accSmrg# when there is no Makefile. 40ff7e0accSmrg# 41ff7e0accSmrg# This script is compatible with the BSD install script, but was written 42ff7e0accSmrg# from scratch. 43ff7e0accSmrg 44ff7e0accSmrgnl=' 45ff7e0accSmrg' 46ff7e0accSmrgIFS=" "" $nl" 47ff7e0accSmrg 48ff7e0accSmrg# set DOITPROG to echo to test this script 49ff7e0accSmrg 50ff7e0accSmrg# Don't use :- since 4.3BSD and earlier shells don't like it. 51a005d216Smrgdoit=${DOITPROG-} 52ff7e0accSmrgif test -z "$doit"; then 53ff7e0accSmrg doit_exec=exec 54ff7e0accSmrgelse 55ff7e0accSmrg doit_exec=$doit 56ff7e0accSmrgfi 57ff7e0accSmrg 58ff7e0accSmrg# Put in absolute file names if you don't have them in your path; 59ff7e0accSmrg# or use environment vars. 60ff7e0accSmrg 61a005d216Smrgchgrpprog=${CHGRPPROG-chgrp} 62a005d216Smrgchmodprog=${CHMODPROG-chmod} 63a005d216Smrgchownprog=${CHOWNPROG-chown} 64a005d216Smrgcmpprog=${CMPPROG-cmp} 65a005d216Smrgcpprog=${CPPROG-cp} 66a005d216Smrgmkdirprog=${MKDIRPROG-mkdir} 67a005d216Smrgmvprog=${MVPROG-mv} 68a005d216Smrgrmprog=${RMPROG-rm} 69a005d216Smrgstripprog=${STRIPPROG-strip} 70a005d216Smrg 71a005d216Smrgposix_glob='?' 72a005d216Smrginitialize_posix_glob=' 73a005d216Smrg test "$posix_glob" != "?" || { 74a005d216Smrg if (set -f) 2>/dev/null; then 75a005d216Smrg posix_glob= 76a005d216Smrg else 77a005d216Smrg posix_glob=: 78a005d216Smrg fi 79a005d216Smrg } 80a005d216Smrg' 81ff7e0accSmrg 82ff7e0accSmrgposix_mkdir= 83ff7e0accSmrg 84ff7e0accSmrg# Desired mode of installed file. 85ff7e0accSmrgmode=0755 86ff7e0accSmrg 87a005d216Smrgchgrpcmd= 88ff7e0accSmrgchmodcmd=$chmodprog 89ff7e0accSmrgchowncmd= 90a005d216Smrgmvcmd=$mvprog 91ff7e0accSmrgrmcmd="$rmprog -f" 92a005d216Smrgstripcmd= 93a005d216Smrg 94ff7e0accSmrgsrc= 95ff7e0accSmrgdst= 96ff7e0accSmrgdir_arg= 97a005d216Smrgdst_arg= 98a005d216Smrg 99a005d216Smrgcopy_on_change=false 100ff7e0accSmrgno_target_directory= 101ff7e0accSmrg 102a005d216Smrgusage="\ 103a005d216SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 104ff7e0accSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 105ff7e0accSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 106ff7e0accSmrg or: $0 [OPTION]... -d DIRECTORIES... 107ff7e0accSmrg 108ff7e0accSmrgIn the 1st form, copy SRCFILE to DSTFILE. 109ff7e0accSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 110ff7e0accSmrgIn the 4th, create DIRECTORIES. 111ff7e0accSmrg 112ff7e0accSmrgOptions: 113a005d216Smrg --help display this help and exit. 114a005d216Smrg --version display version info and exit. 115a005d216Smrg 116a005d216Smrg -c (ignored) 117a005d216Smrg -C install only if different (preserve the last data modification time) 118a005d216Smrg -d create directories instead of installing files. 119a005d216Smrg -g GROUP $chgrpprog installed files to GROUP. 120a005d216Smrg -m MODE $chmodprog installed files to MODE. 121a005d216Smrg -o USER $chownprog installed files to USER. 122a005d216Smrg -s $stripprog installed files. 123a005d216Smrg -t DIRECTORY install into DIRECTORY. 124a005d216Smrg -T report an error if DSTFILE is a directory. 125ff7e0accSmrg 126ff7e0accSmrgEnvironment variables override the default commands: 127a005d216Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 128a005d216Smrg RMPROG STRIPPROG 129ff7e0accSmrg" 130ff7e0accSmrg 131ff7e0accSmrgwhile test $# -ne 0; do 132ff7e0accSmrg case $1 in 133a005d216Smrg -c) ;; 134a005d216Smrg 135a005d216Smrg -C) copy_on_change=true;; 136ff7e0accSmrg 137a005d216Smrg -d) dir_arg=true;; 138ff7e0accSmrg 139ff7e0accSmrg -g) chgrpcmd="$chgrpprog $2" 140a005d216Smrg shift;; 141ff7e0accSmrg 142ff7e0accSmrg --help) echo "$usage"; exit $?;; 143ff7e0accSmrg 144ff7e0accSmrg -m) mode=$2 145ff7e0accSmrg case $mode in 146ff7e0accSmrg *' '* | *' '* | *' 147ff7e0accSmrg'* | *'*'* | *'?'* | *'['*) 148ff7e0accSmrg echo "$0: invalid mode: $mode" >&2 149ff7e0accSmrg exit 1;; 150ff7e0accSmrg esac 151a005d216Smrg shift;; 152ff7e0accSmrg 153ff7e0accSmrg -o) chowncmd="$chownprog $2" 154a005d216Smrg shift;; 155ff7e0accSmrg 156a005d216Smrg -s) stripcmd=$stripprog;; 157ff7e0accSmrg 158a005d216Smrg -t) dst_arg=$2 15905bee9bcSmrg # Protect names problematic for 'test' and other utilities. 16005bee9bcSmrg case $dst_arg in 16105bee9bcSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 16205bee9bcSmrg esac 163a005d216Smrg shift;; 164ff7e0accSmrg 165a005d216Smrg -T) no_target_directory=true;; 166ff7e0accSmrg 167ff7e0accSmrg --version) echo "$0 $scriptversion"; exit $?;; 168ff7e0accSmrg 169ff7e0accSmrg --) shift 170ff7e0accSmrg break;; 171ff7e0accSmrg 172ff7e0accSmrg -*) echo "$0: invalid option: $1" >&2 173ff7e0accSmrg exit 1;; 174ff7e0accSmrg 175ff7e0accSmrg *) break;; 176ff7e0accSmrg esac 177a005d216Smrg shift 178ff7e0accSmrgdone 179ff7e0accSmrg 180a005d216Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 181ff7e0accSmrg # When -d is used, all remaining arguments are directories to create. 182ff7e0accSmrg # When -t is used, the destination is already specified. 183ff7e0accSmrg # Otherwise, the last argument is the destination. Remove it from $@. 184ff7e0accSmrg for arg 185ff7e0accSmrg do 186a005d216Smrg if test -n "$dst_arg"; then 187ff7e0accSmrg # $@ is not empty: it contains at least $arg. 188a005d216Smrg set fnord "$@" "$dst_arg" 189ff7e0accSmrg shift # fnord 190ff7e0accSmrg fi 191ff7e0accSmrg shift # arg 192a005d216Smrg dst_arg=$arg 19305bee9bcSmrg # Protect names problematic for 'test' and other utilities. 19405bee9bcSmrg case $dst_arg in 19505bee9bcSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 19605bee9bcSmrg esac 197ff7e0accSmrg done 198ff7e0accSmrgfi 199ff7e0accSmrg 200ff7e0accSmrgif test $# -eq 0; then 201ff7e0accSmrg if test -z "$dir_arg"; then 202ff7e0accSmrg echo "$0: no input file specified." >&2 203ff7e0accSmrg exit 1 204ff7e0accSmrg fi 20505bee9bcSmrg # It's OK to call 'install-sh -d' without argument. 206ff7e0accSmrg # This can happen when creating conditional directories. 207ff7e0accSmrg exit 0 208ff7e0accSmrgfi 209ff7e0accSmrg 210ff7e0accSmrgif test -z "$dir_arg"; then 21105bee9bcSmrg do_exit='(exit $ret); exit $ret' 21205bee9bcSmrg trap "ret=129; $do_exit" 1 21305bee9bcSmrg trap "ret=130; $do_exit" 2 21405bee9bcSmrg trap "ret=141; $do_exit" 13 21505bee9bcSmrg trap "ret=143; $do_exit" 15 216ff7e0accSmrg 217ff7e0accSmrg # Set umask so as not to create temps with too-generous modes. 218ff7e0accSmrg # However, 'strip' requires both read and write access to temps. 219ff7e0accSmrg case $mode in 220ff7e0accSmrg # Optimize common cases. 221ff7e0accSmrg *644) cp_umask=133;; 222ff7e0accSmrg *755) cp_umask=22;; 223ff7e0accSmrg 224ff7e0accSmrg *[0-7]) 225ff7e0accSmrg if test -z "$stripcmd"; then 226ff7e0accSmrg u_plus_rw= 227ff7e0accSmrg else 228ff7e0accSmrg u_plus_rw='% 200' 229ff7e0accSmrg fi 230ff7e0accSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 231ff7e0accSmrg *) 232ff7e0accSmrg if test -z "$stripcmd"; then 233ff7e0accSmrg u_plus_rw= 234ff7e0accSmrg else 235ff7e0accSmrg u_plus_rw=,u+rw 236ff7e0accSmrg fi 237ff7e0accSmrg cp_umask=$mode$u_plus_rw;; 238ff7e0accSmrg esac 239ff7e0accSmrgfi 240ff7e0accSmrg 241ff7e0accSmrgfor src 242ff7e0accSmrgdo 24305bee9bcSmrg # Protect names problematic for 'test' and other utilities. 244ff7e0accSmrg case $src in 24505bee9bcSmrg -* | [=\(\)!]) src=./$src;; 246ff7e0accSmrg esac 247ff7e0accSmrg 248ff7e0accSmrg if test -n "$dir_arg"; then 249ff7e0accSmrg dst=$src 250ff7e0accSmrg dstdir=$dst 251ff7e0accSmrg test -d "$dstdir" 252ff7e0accSmrg dstdir_status=$? 253ff7e0accSmrg else 254ff7e0accSmrg 255ff7e0accSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 256ff7e0accSmrg # might cause directories to be created, which would be especially bad 257ff7e0accSmrg # if $src (and thus $dsttmp) contains '*'. 258ff7e0accSmrg if test ! -f "$src" && test ! -d "$src"; then 259ff7e0accSmrg echo "$0: $src does not exist." >&2 260ff7e0accSmrg exit 1 261ff7e0accSmrg fi 262ff7e0accSmrg 263a005d216Smrg if test -z "$dst_arg"; then 264ff7e0accSmrg echo "$0: no destination specified." >&2 265ff7e0accSmrg exit 1 266ff7e0accSmrg fi 267a005d216Smrg dst=$dst_arg 268ff7e0accSmrg 269ff7e0accSmrg # If destination is a directory, append the input filename; won't work 270ff7e0accSmrg # if double slashes aren't ignored. 271ff7e0accSmrg if test -d "$dst"; then 272ff7e0accSmrg if test -n "$no_target_directory"; then 273a005d216Smrg echo "$0: $dst_arg: Is a directory" >&2 274ff7e0accSmrg exit 1 275ff7e0accSmrg fi 276ff7e0accSmrg dstdir=$dst 277ff7e0accSmrg dst=$dstdir/`basename "$src"` 278ff7e0accSmrg dstdir_status=0 279ff7e0accSmrg else 280ff7e0accSmrg # Prefer dirname, but fall back on a substitute if dirname fails. 281ff7e0accSmrg dstdir=` 282ff7e0accSmrg (dirname "$dst") 2>/dev/null || 283ff7e0accSmrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 284ff7e0accSmrg X"$dst" : 'X\(//\)[^/]' \| \ 285ff7e0accSmrg X"$dst" : 'X\(//\)$' \| \ 286ff7e0accSmrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 287ff7e0accSmrg echo X"$dst" | 288ff7e0accSmrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 289ff7e0accSmrg s//\1/ 290ff7e0accSmrg q 291ff7e0accSmrg } 292ff7e0accSmrg /^X\(\/\/\)[^/].*/{ 293ff7e0accSmrg s//\1/ 294ff7e0accSmrg q 295ff7e0accSmrg } 296ff7e0accSmrg /^X\(\/\/\)$/{ 297ff7e0accSmrg s//\1/ 298ff7e0accSmrg q 299ff7e0accSmrg } 300ff7e0accSmrg /^X\(\/\).*/{ 301ff7e0accSmrg s//\1/ 302ff7e0accSmrg q 303ff7e0accSmrg } 304ff7e0accSmrg s/.*/./; q' 305ff7e0accSmrg ` 306ff7e0accSmrg 307ff7e0accSmrg test -d "$dstdir" 308ff7e0accSmrg dstdir_status=$? 309ff7e0accSmrg fi 310ff7e0accSmrg fi 311ff7e0accSmrg 312ff7e0accSmrg obsolete_mkdir_used=false 313ff7e0accSmrg 314ff7e0accSmrg if test $dstdir_status != 0; then 315ff7e0accSmrg case $posix_mkdir in 316ff7e0accSmrg '') 317ff7e0accSmrg # Create intermediate dirs using mode 755 as modified by the umask. 318ff7e0accSmrg # This is like FreeBSD 'install' as of 1997-10-28. 319ff7e0accSmrg umask=`umask` 320ff7e0accSmrg case $stripcmd.$umask in 321ff7e0accSmrg # Optimize common cases. 322ff7e0accSmrg *[2367][2367]) mkdir_umask=$umask;; 323ff7e0accSmrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 324ff7e0accSmrg 325ff7e0accSmrg *[0-7]) 326ff7e0accSmrg mkdir_umask=`expr $umask + 22 \ 327ff7e0accSmrg - $umask % 100 % 40 + $umask % 20 \ 328ff7e0accSmrg - $umask % 10 % 4 + $umask % 2 329ff7e0accSmrg `;; 330ff7e0accSmrg *) mkdir_umask=$umask,go-w;; 331ff7e0accSmrg esac 332ff7e0accSmrg 333ff7e0accSmrg # With -d, create the new directory with the user-specified mode. 334ff7e0accSmrg # Otherwise, rely on $mkdir_umask. 335ff7e0accSmrg if test -n "$dir_arg"; then 336ff7e0accSmrg mkdir_mode=-m$mode 337ff7e0accSmrg else 338ff7e0accSmrg mkdir_mode= 339ff7e0accSmrg fi 340ff7e0accSmrg 341ff7e0accSmrg posix_mkdir=false 342ff7e0accSmrg case $umask in 343ff7e0accSmrg *[123567][0-7][0-7]) 344ff7e0accSmrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 345ff7e0accSmrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 346ff7e0accSmrg ;; 347ff7e0accSmrg *) 348ff7e0accSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 349ff7e0accSmrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 350ff7e0accSmrg 351ff7e0accSmrg if (umask $mkdir_umask && 352ff7e0accSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 353ff7e0accSmrg then 354ff7e0accSmrg if test -z "$dir_arg" || { 355ff7e0accSmrg # Check for POSIX incompatibilities with -m. 356ff7e0accSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 35705bee9bcSmrg # other-writable bit of parent directory when it shouldn't. 358ff7e0accSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 359ff7e0accSmrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 360ff7e0accSmrg case $ls_ld_tmpdir in 361ff7e0accSmrg d????-?r-*) different_mode=700;; 362ff7e0accSmrg d????-?--*) different_mode=755;; 363ff7e0accSmrg *) false;; 364ff7e0accSmrg esac && 365ff7e0accSmrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 366ff7e0accSmrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 367ff7e0accSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 368ff7e0accSmrg } 369ff7e0accSmrg } 370ff7e0accSmrg then posix_mkdir=: 371ff7e0accSmrg fi 372ff7e0accSmrg rmdir "$tmpdir/d" "$tmpdir" 373ff7e0accSmrg else 374ff7e0accSmrg # Remove any dirs left behind by ancient mkdir implementations. 375ff7e0accSmrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 376ff7e0accSmrg fi 377ff7e0accSmrg trap '' 0;; 378ff7e0accSmrg esac;; 379ff7e0accSmrg esac 380ff7e0accSmrg 381ff7e0accSmrg if 382ff7e0accSmrg $posix_mkdir && ( 383ff7e0accSmrg umask $mkdir_umask && 384ff7e0accSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 385ff7e0accSmrg ) 386ff7e0accSmrg then : 387ff7e0accSmrg else 388ff7e0accSmrg 389ff7e0accSmrg # The umask is ridiculous, or mkdir does not conform to POSIX, 390ff7e0accSmrg # or it failed possibly due to a race condition. Create the 391ff7e0accSmrg # directory the slow way, step by step, checking for races as we go. 392ff7e0accSmrg 393ff7e0accSmrg case $dstdir in 394a005d216Smrg /*) prefix='/';; 39505bee9bcSmrg [-=\(\)!]*) prefix='./';; 396a005d216Smrg *) prefix='';; 397ff7e0accSmrg esac 398ff7e0accSmrg 399a005d216Smrg eval "$initialize_posix_glob" 400ff7e0accSmrg 401ff7e0accSmrg oIFS=$IFS 402ff7e0accSmrg IFS=/ 403a005d216Smrg $posix_glob set -f 404ff7e0accSmrg set fnord $dstdir 405ff7e0accSmrg shift 406a005d216Smrg $posix_glob set +f 407ff7e0accSmrg IFS=$oIFS 408ff7e0accSmrg 409ff7e0accSmrg prefixes= 410ff7e0accSmrg 411ff7e0accSmrg for d 412ff7e0accSmrg do 41305bee9bcSmrg test X"$d" = X && continue 414ff7e0accSmrg 415ff7e0accSmrg prefix=$prefix$d 416ff7e0accSmrg if test -d "$prefix"; then 417ff7e0accSmrg prefixes= 418ff7e0accSmrg else 419ff7e0accSmrg if $posix_mkdir; then 420ff7e0accSmrg (umask=$mkdir_umask && 421ff7e0accSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 422ff7e0accSmrg # Don't fail if two instances are running concurrently. 423ff7e0accSmrg test -d "$prefix" || exit 1 424ff7e0accSmrg else 425ff7e0accSmrg case $prefix in 426ff7e0accSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 427ff7e0accSmrg *) qprefix=$prefix;; 428ff7e0accSmrg esac 429ff7e0accSmrg prefixes="$prefixes '$qprefix'" 430ff7e0accSmrg fi 431ff7e0accSmrg fi 432ff7e0accSmrg prefix=$prefix/ 433ff7e0accSmrg done 434ff7e0accSmrg 435ff7e0accSmrg if test -n "$prefixes"; then 436ff7e0accSmrg # Don't fail if two instances are running concurrently. 437ff7e0accSmrg (umask $mkdir_umask && 438ff7e0accSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 439ff7e0accSmrg test -d "$dstdir" || exit 1 440ff7e0accSmrg obsolete_mkdir_used=true 441ff7e0accSmrg fi 442ff7e0accSmrg fi 443ff7e0accSmrg fi 444ff7e0accSmrg 445ff7e0accSmrg if test -n "$dir_arg"; then 446ff7e0accSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 447ff7e0accSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 448ff7e0accSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 449ff7e0accSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 450ff7e0accSmrg else 451ff7e0accSmrg 452ff7e0accSmrg # Make a couple of temp file names in the proper directory. 453ff7e0accSmrg dsttmp=$dstdir/_inst.$$_ 454ff7e0accSmrg rmtmp=$dstdir/_rm.$$_ 455ff7e0accSmrg 456ff7e0accSmrg # Trap to clean up those temp files at exit. 457ff7e0accSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 458ff7e0accSmrg 459ff7e0accSmrg # Copy the file name to the temp name. 460ff7e0accSmrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 461ff7e0accSmrg 462ff7e0accSmrg # and set any options; do chmod last to preserve setuid bits. 463ff7e0accSmrg # 464ff7e0accSmrg # If any of these fail, we abort the whole thing. If we want to 465ff7e0accSmrg # ignore errors from any of these, just make sure not to ignore 466ff7e0accSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 467ff7e0accSmrg # 468a005d216Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 469a005d216Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 470a005d216Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 471a005d216Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 472a005d216Smrg 473a005d216Smrg # If -C, don't bother to copy if it wouldn't change the file. 474a005d216Smrg if $copy_on_change && 475a005d216Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 476a005d216Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 477a005d216Smrg 478a005d216Smrg eval "$initialize_posix_glob" && 479a005d216Smrg $posix_glob set -f && 480a005d216Smrg set X $old && old=:$2:$4:$5:$6 && 481a005d216Smrg set X $new && new=:$2:$4:$5:$6 && 482a005d216Smrg $posix_glob set +f && 483a005d216Smrg 484a005d216Smrg test "$old" = "$new" && 485a005d216Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 486a005d216Smrg then 487a005d216Smrg rm -f "$dsttmp" 488a005d216Smrg else 489a005d216Smrg # Rename the file to the real destination. 490a005d216Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 491a005d216Smrg 492a005d216Smrg # The rename failed, perhaps because mv can't rename something else 493a005d216Smrg # to itself, or perhaps because mv is so ancient that it does not 494a005d216Smrg # support -f. 495a005d216Smrg { 496a005d216Smrg # Now remove or move aside any old file at destination location. 497a005d216Smrg # We try this two ways since rm can't unlink itself on some 498a005d216Smrg # systems and the destination file might be busy for other 499a005d216Smrg # reasons. In this case, the final cleanup might fail but the new 500a005d216Smrg # file should still install successfully. 501a005d216Smrg { 502a005d216Smrg test ! -f "$dst" || 503a005d216Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 504a005d216Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 505a005d216Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 506a005d216Smrg } || 507a005d216Smrg { echo "$0: cannot unlink or rename $dst" >&2 508a005d216Smrg (exit 1); exit 1 509a005d216Smrg } 510a005d216Smrg } && 511a005d216Smrg 512a005d216Smrg # Now rename the file to the real destination. 513a005d216Smrg $doit $mvcmd "$dsttmp" "$dst" 514a005d216Smrg } 515a005d216Smrg fi || exit 1 516ff7e0accSmrg 517ff7e0accSmrg trap '' 0 518ff7e0accSmrg fi 519ff7e0accSmrgdone 520ff7e0accSmrg 521ff7e0accSmrg# Local variables: 522ff7e0accSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 523ff7e0accSmrg# time-stamp-start: "scriptversion=" 524ff7e0accSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 52510998002Smrg# time-stamp-time-zone: "UTC" 52610998002Smrg# time-stamp-end: "; # UTC" 527ff7e0accSmrg# End: 528