install-sh revision 313a12fd
127702724Smrg#!/bin/sh 227702724Smrg# install - install a program, script, or datafile 327702724Smrg 4313a12fdSmrgscriptversion=2011-11-20.07; # UTC 527702724Smrg 627702724Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 727702724Smrg# later released in X11R6 (xc/config/util/install.sh) with the 827702724Smrg# following copyright and license. 927702724Smrg# 1027702724Smrg# Copyright (C) 1994 X Consortium 1127702724Smrg# 1227702724Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 1327702724Smrg# of this software and associated documentation files (the "Software"), to 1427702724Smrg# deal in the Software without restriction, including without limitation the 1527702724Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1627702724Smrg# sell copies of the Software, and to permit persons to whom the Software is 1727702724Smrg# furnished to do so, subject to the following conditions: 1827702724Smrg# 1927702724Smrg# The above copyright notice and this permission notice shall be included in 2027702724Smrg# all copies or substantial portions of the Software. 2127702724Smrg# 2227702724Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2327702724Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2427702724Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2527702724Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2627702724Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 2727702724Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2827702724Smrg# 2927702724Smrg# Except as contained in this notice, the name of the X Consortium shall not 3027702724Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 3127702724Smrg# ings in this Software without prior written authorization from the X Consor- 3227702724Smrg# tium. 3327702724Smrg# 3427702724Smrg# 3527702724Smrg# FSF changes to this file are in the public domain. 3627702724Smrg# 3727702724Smrg# Calling this script install-sh is preferred over install.sh, to prevent 38313a12fdSmrg# 'make' implicit rules from creating a file called install from it 3927702724Smrg# when there is no Makefile. 4027702724Smrg# 4127702724Smrg# This script is compatible with the BSD install script, but was written 42e19dfac4Smrg# from scratch. 43e19dfac4Smrg 44e19dfac4Smrgnl=' 45e19dfac4Smrg' 46e19dfac4SmrgIFS=" "" $nl" 4727702724Smrg 4827702724Smrg# set DOITPROG to echo to test this script 4927702724Smrg 5027702724Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 51e19dfac4Smrgdoit=${DOITPROG-} 52e19dfac4Smrgif test -z "$doit"; then 53e19dfac4Smrg doit_exec=exec 54e19dfac4Smrgelse 55e19dfac4Smrg doit_exec=$doit 56e19dfac4Smrgfi 5727702724Smrg 58e19dfac4Smrg# Put in absolute file names if you don't have them in your path; 59e19dfac4Smrg# or use environment vars. 60e19dfac4Smrg 61e19dfac4Smrgchgrpprog=${CHGRPPROG-chgrp} 62e19dfac4Smrgchmodprog=${CHMODPROG-chmod} 63e19dfac4Smrgchownprog=${CHOWNPROG-chown} 64e19dfac4Smrgcmpprog=${CMPPROG-cmp} 65e19dfac4Smrgcpprog=${CPPROG-cp} 66e19dfac4Smrgmkdirprog=${MKDIRPROG-mkdir} 67e19dfac4Smrgmvprog=${MVPROG-mv} 68e19dfac4Smrgrmprog=${RMPROG-rm} 69e19dfac4Smrgstripprog=${STRIPPROG-strip} 70e19dfac4Smrg 71e19dfac4Smrgposix_glob='?' 72e19dfac4Smrginitialize_posix_glob=' 73e19dfac4Smrg test "$posix_glob" != "?" || { 74e19dfac4Smrg if (set -f) 2>/dev/null; then 75e19dfac4Smrg posix_glob= 76e19dfac4Smrg else 77e19dfac4Smrg posix_glob=: 78e19dfac4Smrg fi 79e19dfac4Smrg } 80e19dfac4Smrg' 8127702724Smrg 82e19dfac4Smrgposix_mkdir= 83e19dfac4Smrg 84e19dfac4Smrg# Desired mode of installed file. 85e19dfac4Smrgmode=0755 8627702724Smrg 8727702724Smrgchgrpcmd= 88e19dfac4Smrgchmodcmd=$chmodprog 89e19dfac4Smrgchowncmd= 90e19dfac4Smrgmvcmd=$mvprog 9127702724Smrgrmcmd="$rmprog -f" 92e19dfac4Smrgstripcmd= 93e19dfac4Smrg 9427702724Smrgsrc= 9527702724Smrgdst= 9627702724Smrgdir_arg= 97e19dfac4Smrgdst_arg= 98e19dfac4Smrg 99e19dfac4Smrgcopy_on_change=false 10027702724Smrgno_target_directory= 10127702724Smrg 102e19dfac4Smrgusage="\ 103e19dfac4SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 10427702724Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 10527702724Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 10627702724Smrg or: $0 [OPTION]... -d DIRECTORIES... 10727702724Smrg 10827702724SmrgIn the 1st form, copy SRCFILE to DSTFILE. 10927702724SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 11027702724SmrgIn the 4th, create DIRECTORIES. 11127702724Smrg 11227702724SmrgOptions: 113e19dfac4Smrg --help display this help and exit. 114e19dfac4Smrg --version display version info and exit. 115e19dfac4Smrg 116e19dfac4Smrg -c (ignored) 117e19dfac4Smrg -C install only if different (preserve the last data modification time) 118e19dfac4Smrg -d create directories instead of installing files. 119e19dfac4Smrg -g GROUP $chgrpprog installed files to GROUP. 120e19dfac4Smrg -m MODE $chmodprog installed files to MODE. 121e19dfac4Smrg -o USER $chownprog installed files to USER. 122e19dfac4Smrg -s $stripprog installed files. 123e19dfac4Smrg -t DIRECTORY install into DIRECTORY. 124e19dfac4Smrg -T report an error if DSTFILE is a directory. 12527702724Smrg 12627702724SmrgEnvironment variables override the default commands: 127e19dfac4Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 128e19dfac4Smrg RMPROG STRIPPROG 12927702724Smrg" 13027702724Smrg 131e19dfac4Smrgwhile test $# -ne 0; do 13227702724Smrg case $1 in 133e19dfac4Smrg -c) ;; 134e19dfac4Smrg 135e19dfac4Smrg -C) copy_on_change=true;; 13627702724Smrg 137e19dfac4Smrg -d) dir_arg=true;; 13827702724Smrg 13927702724Smrg -g) chgrpcmd="$chgrpprog $2" 140e19dfac4Smrg shift;; 14127702724Smrg 14227702724Smrg --help) echo "$usage"; exit $?;; 14327702724Smrg 144e19dfac4Smrg -m) mode=$2 145e19dfac4Smrg case $mode in 146e19dfac4Smrg *' '* | *' '* | *' 147e19dfac4Smrg'* | *'*'* | *'?'* | *'['*) 148e19dfac4Smrg echo "$0: invalid mode: $mode" >&2 149e19dfac4Smrg exit 1;; 150e19dfac4Smrg esac 151e19dfac4Smrg shift;; 15227702724Smrg 15327702724Smrg -o) chowncmd="$chownprog $2" 154e19dfac4Smrg shift;; 15527702724Smrg 156e19dfac4Smrg -s) stripcmd=$stripprog;; 15727702724Smrg 158e19dfac4Smrg -t) dst_arg=$2 159313a12fdSmrg # Protect names problematic for 'test' and other utilities. 160313a12fdSmrg case $dst_arg in 161313a12fdSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 162313a12fdSmrg esac 163e19dfac4Smrg shift;; 16427702724Smrg 165e19dfac4Smrg -T) no_target_directory=true;; 16627702724Smrg 16727702724Smrg --version) echo "$0 $scriptversion"; exit $?;; 16827702724Smrg 169e19dfac4Smrg --) shift 17027702724Smrg break;; 171e19dfac4Smrg 172e19dfac4Smrg -*) echo "$0: invalid option: $1" >&2 173e19dfac4Smrg exit 1;; 174e19dfac4Smrg 175e19dfac4Smrg *) break;; 17627702724Smrg esac 177e19dfac4Smrg shift 17827702724Smrgdone 17927702724Smrg 180e19dfac4Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 181e19dfac4Smrg # When -d is used, all remaining arguments are directories to create. 182e19dfac4Smrg # When -t is used, the destination is already specified. 183e19dfac4Smrg # Otherwise, the last argument is the destination. Remove it from $@. 184e19dfac4Smrg for arg 185e19dfac4Smrg do 186e19dfac4Smrg if test -n "$dst_arg"; then 187e19dfac4Smrg # $@ is not empty: it contains at least $arg. 188e19dfac4Smrg set fnord "$@" "$dst_arg" 189e19dfac4Smrg shift # fnord 190e19dfac4Smrg fi 191e19dfac4Smrg shift # arg 192e19dfac4Smrg dst_arg=$arg 193313a12fdSmrg # Protect names problematic for 'test' and other utilities. 194313a12fdSmrg case $dst_arg in 195313a12fdSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 196313a12fdSmrg esac 197e19dfac4Smrg done 198e19dfac4Smrgfi 199e19dfac4Smrg 200e19dfac4Smrgif test $# -eq 0; then 20127702724Smrg if test -z "$dir_arg"; then 20227702724Smrg echo "$0: no input file specified." >&2 20327702724Smrg exit 1 20427702724Smrg fi 205313a12fdSmrg # It's OK to call 'install-sh -d' without argument. 20627702724Smrg # This can happen when creating conditional directories. 20727702724Smrg exit 0 20827702724Smrgfi 20927702724Smrg 210e19dfac4Smrgif test -z "$dir_arg"; then 211313a12fdSmrg do_exit='(exit $ret); exit $ret' 212313a12fdSmrg trap "ret=129; $do_exit" 1 213313a12fdSmrg trap "ret=130; $do_exit" 2 214313a12fdSmrg trap "ret=141; $do_exit" 13 215313a12fdSmrg trap "ret=143; $do_exit" 15 216e19dfac4Smrg 217e19dfac4Smrg # Set umask so as not to create temps with too-generous modes. 218e19dfac4Smrg # However, 'strip' requires both read and write access to temps. 219e19dfac4Smrg case $mode in 220e19dfac4Smrg # Optimize common cases. 221e19dfac4Smrg *644) cp_umask=133;; 222e19dfac4Smrg *755) cp_umask=22;; 223e19dfac4Smrg 224e19dfac4Smrg *[0-7]) 225e19dfac4Smrg if test -z "$stripcmd"; then 226e19dfac4Smrg u_plus_rw= 227e19dfac4Smrg else 228e19dfac4Smrg u_plus_rw='% 200' 229e19dfac4Smrg fi 230e19dfac4Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 231e19dfac4Smrg *) 232e19dfac4Smrg if test -z "$stripcmd"; then 233e19dfac4Smrg u_plus_rw= 234e19dfac4Smrg else 235e19dfac4Smrg u_plus_rw=,u+rw 236e19dfac4Smrg fi 237e19dfac4Smrg cp_umask=$mode$u_plus_rw;; 238e19dfac4Smrg esac 239e19dfac4Smrgfi 240e19dfac4Smrg 24127702724Smrgfor src 24227702724Smrgdo 243313a12fdSmrg # Protect names problematic for 'test' and other utilities. 24427702724Smrg case $src in 245313a12fdSmrg -* | [=\(\)!]) src=./$src;; 24627702724Smrg esac 24727702724Smrg 24827702724Smrg if test -n "$dir_arg"; then 24927702724Smrg dst=$src 250e19dfac4Smrg dstdir=$dst 251e19dfac4Smrg test -d "$dstdir" 252e19dfac4Smrg dstdir_status=$? 25327702724Smrg else 254e19dfac4Smrg 25527702724Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 25627702724Smrg # might cause directories to be created, which would be especially bad 25727702724Smrg # if $src (and thus $dsttmp) contains '*'. 25827702724Smrg if test ! -f "$src" && test ! -d "$src"; then 25927702724Smrg echo "$0: $src does not exist." >&2 26027702724Smrg exit 1 26127702724Smrg fi 26227702724Smrg 263e19dfac4Smrg if test -z "$dst_arg"; then 26427702724Smrg echo "$0: no destination specified." >&2 26527702724Smrg exit 1 26627702724Smrg fi 267e19dfac4Smrg dst=$dst_arg 26827702724Smrg 26927702724Smrg # If destination is a directory, append the input filename; won't work 27027702724Smrg # if double slashes aren't ignored. 27127702724Smrg if test -d "$dst"; then 27227702724Smrg if test -n "$no_target_directory"; then 273e19dfac4Smrg echo "$0: $dst_arg: Is a directory" >&2 27427702724Smrg exit 1 27527702724Smrg fi 276e19dfac4Smrg dstdir=$dst 277e19dfac4Smrg dst=$dstdir/`basename "$src"` 278e19dfac4Smrg dstdir_status=0 279e19dfac4Smrg else 280e19dfac4Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 281e19dfac4Smrg dstdir=` 282e19dfac4Smrg (dirname "$dst") 2>/dev/null || 283e19dfac4Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 284e19dfac4Smrg X"$dst" : 'X\(//\)[^/]' \| \ 285e19dfac4Smrg X"$dst" : 'X\(//\)$' \| \ 286e19dfac4Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 287e19dfac4Smrg echo X"$dst" | 288e19dfac4Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 289e19dfac4Smrg s//\1/ 290e19dfac4Smrg q 291e19dfac4Smrg } 292e19dfac4Smrg /^X\(\/\/\)[^/].*/{ 293e19dfac4Smrg s//\1/ 294e19dfac4Smrg q 295e19dfac4Smrg } 296e19dfac4Smrg /^X\(\/\/\)$/{ 297e19dfac4Smrg s//\1/ 298e19dfac4Smrg q 299e19dfac4Smrg } 300e19dfac4Smrg /^X\(\/\).*/{ 301e19dfac4Smrg s//\1/ 302e19dfac4Smrg q 303e19dfac4Smrg } 304e19dfac4Smrg s/.*/./; q' 305e19dfac4Smrg ` 306e19dfac4Smrg 307e19dfac4Smrg test -d "$dstdir" 308e19dfac4Smrg dstdir_status=$? 30927702724Smrg fi 31027702724Smrg fi 31127702724Smrg 312e19dfac4Smrg obsolete_mkdir_used=false 313e19dfac4Smrg 314e19dfac4Smrg if test $dstdir_status != 0; then 315e19dfac4Smrg case $posix_mkdir in 316e19dfac4Smrg '') 317e19dfac4Smrg # Create intermediate dirs using mode 755 as modified by the umask. 318e19dfac4Smrg # This is like FreeBSD 'install' as of 1997-10-28. 319e19dfac4Smrg umask=`umask` 320e19dfac4Smrg case $stripcmd.$umask in 321e19dfac4Smrg # Optimize common cases. 322e19dfac4Smrg *[2367][2367]) mkdir_umask=$umask;; 323e19dfac4Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 324e19dfac4Smrg 325e19dfac4Smrg *[0-7]) 326e19dfac4Smrg mkdir_umask=`expr $umask + 22 \ 327e19dfac4Smrg - $umask % 100 % 40 + $umask % 20 \ 328e19dfac4Smrg - $umask % 10 % 4 + $umask % 2 329e19dfac4Smrg `;; 330e19dfac4Smrg *) mkdir_umask=$umask,go-w;; 331e19dfac4Smrg esac 332e19dfac4Smrg 333e19dfac4Smrg # With -d, create the new directory with the user-specified mode. 334e19dfac4Smrg # Otherwise, rely on $mkdir_umask. 335e19dfac4Smrg if test -n "$dir_arg"; then 336e19dfac4Smrg mkdir_mode=-m$mode 337e19dfac4Smrg else 338e19dfac4Smrg mkdir_mode= 339e19dfac4Smrg fi 340e19dfac4Smrg 341e19dfac4Smrg posix_mkdir=false 342e19dfac4Smrg case $umask in 343e19dfac4Smrg *[123567][0-7][0-7]) 344e19dfac4Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 345e19dfac4Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 346e19dfac4Smrg ;; 347e19dfac4Smrg *) 348e19dfac4Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 349e19dfac4Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 350e19dfac4Smrg 351e19dfac4Smrg if (umask $mkdir_umask && 352e19dfac4Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 353e19dfac4Smrg then 354e19dfac4Smrg if test -z "$dir_arg" || { 355e19dfac4Smrg # Check for POSIX incompatibilities with -m. 356e19dfac4Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 357313a12fdSmrg # other-writable bit of parent directory when it shouldn't. 358e19dfac4Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 359e19dfac4Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 360e19dfac4Smrg case $ls_ld_tmpdir in 361e19dfac4Smrg d????-?r-*) different_mode=700;; 362e19dfac4Smrg d????-?--*) different_mode=755;; 363e19dfac4Smrg *) false;; 364e19dfac4Smrg esac && 365e19dfac4Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 366e19dfac4Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 367e19dfac4Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 368e19dfac4Smrg } 369e19dfac4Smrg } 370e19dfac4Smrg then posix_mkdir=: 371e19dfac4Smrg fi 372e19dfac4Smrg rmdir "$tmpdir/d" "$tmpdir" 373e19dfac4Smrg else 374e19dfac4Smrg # Remove any dirs left behind by ancient mkdir implementations. 375e19dfac4Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 376e19dfac4Smrg fi 377e19dfac4Smrg trap '' 0;; 378e19dfac4Smrg esac;; 379e19dfac4Smrg esac 38027702724Smrg 381e19dfac4Smrg if 382e19dfac4Smrg $posix_mkdir && ( 383e19dfac4Smrg umask $mkdir_umask && 384e19dfac4Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 385e19dfac4Smrg ) 386e19dfac4Smrg then : 387e19dfac4Smrg else 38827702724Smrg 389e19dfac4Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 390e19dfac4Smrg # or it failed possibly due to a race condition. Create the 391e19dfac4Smrg # directory the slow way, step by step, checking for races as we go. 39227702724Smrg 393e19dfac4Smrg case $dstdir in 394e19dfac4Smrg /*) prefix='/';; 395313a12fdSmrg [-=\(\)!]*) prefix='./';; 396e19dfac4Smrg *) prefix='';; 397e19dfac4Smrg esac 39827702724Smrg 399e19dfac4Smrg eval "$initialize_posix_glob" 40027702724Smrg 401e19dfac4Smrg oIFS=$IFS 402e19dfac4Smrg IFS=/ 403e19dfac4Smrg $posix_glob set -f 404e19dfac4Smrg set fnord $dstdir 40527702724Smrg shift 406e19dfac4Smrg $posix_glob set +f 407e19dfac4Smrg IFS=$oIFS 408e19dfac4Smrg 409e19dfac4Smrg prefixes= 410e19dfac4Smrg 411e19dfac4Smrg for d 412e19dfac4Smrg do 413313a12fdSmrg test X"$d" = X && continue 414e19dfac4Smrg 415e19dfac4Smrg prefix=$prefix$d 416e19dfac4Smrg if test -d "$prefix"; then 417e19dfac4Smrg prefixes= 418e19dfac4Smrg else 419e19dfac4Smrg if $posix_mkdir; then 420e19dfac4Smrg (umask=$mkdir_umask && 421e19dfac4Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 422e19dfac4Smrg # Don't fail if two instances are running concurrently. 423e19dfac4Smrg test -d "$prefix" || exit 1 424e19dfac4Smrg else 425e19dfac4Smrg case $prefix in 426e19dfac4Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 427e19dfac4Smrg *) qprefix=$prefix;; 428e19dfac4Smrg esac 429e19dfac4Smrg prefixes="$prefixes '$qprefix'" 430e19dfac4Smrg fi 431e19dfac4Smrg fi 432e19dfac4Smrg prefix=$prefix/ 433e19dfac4Smrg done 434e19dfac4Smrg 435e19dfac4Smrg if test -n "$prefixes"; then 436e19dfac4Smrg # Don't fail if two instances are running concurrently. 437e19dfac4Smrg (umask $mkdir_umask && 438e19dfac4Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 439e19dfac4Smrg test -d "$dstdir" || exit 1 440e19dfac4Smrg obsolete_mkdir_used=true 44127702724Smrg fi 442e19dfac4Smrg fi 44327702724Smrg fi 44427702724Smrg 44527702724Smrg if test -n "$dir_arg"; then 446e19dfac4Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 447e19dfac4Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 448e19dfac4Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 449e19dfac4Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 45027702724Smrg else 45127702724Smrg 45227702724Smrg # Make a couple of temp file names in the proper directory. 45327702724Smrg dsttmp=$dstdir/_inst.$$_ 45427702724Smrg rmtmp=$dstdir/_rm.$$_ 45527702724Smrg 45627702724Smrg # Trap to clean up those temp files at exit. 45727702724Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 45827702724Smrg 45927702724Smrg # Copy the file name to the temp name. 460e19dfac4Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 46127702724Smrg 46227702724Smrg # and set any options; do chmod last to preserve setuid bits. 46327702724Smrg # 46427702724Smrg # If any of these fail, we abort the whole thing. If we want to 46527702724Smrg # ignore errors from any of these, just make sure not to ignore 46627702724Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 46727702724Smrg # 468e19dfac4Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 469e19dfac4Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 470e19dfac4Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 471e19dfac4Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 472e19dfac4Smrg 473e19dfac4Smrg # If -C, don't bother to copy if it wouldn't change the file. 474e19dfac4Smrg if $copy_on_change && 475e19dfac4Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 476e19dfac4Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 477e19dfac4Smrg 478e19dfac4Smrg eval "$initialize_posix_glob" && 479e19dfac4Smrg $posix_glob set -f && 480e19dfac4Smrg set X $old && old=:$2:$4:$5:$6 && 481e19dfac4Smrg set X $new && new=:$2:$4:$5:$6 && 482e19dfac4Smrg $posix_glob set +f && 483e19dfac4Smrg 484e19dfac4Smrg test "$old" = "$new" && 485e19dfac4Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 486e19dfac4Smrg then 487e19dfac4Smrg rm -f "$dsttmp" 488e19dfac4Smrg else 489e19dfac4Smrg # Rename the file to the real destination. 490e19dfac4Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 491e19dfac4Smrg 492e19dfac4Smrg # The rename failed, perhaps because mv can't rename something else 493e19dfac4Smrg # to itself, or perhaps because mv is so ancient that it does not 494e19dfac4Smrg # support -f. 495e19dfac4Smrg { 496e19dfac4Smrg # Now remove or move aside any old file at destination location. 497e19dfac4Smrg # We try this two ways since rm can't unlink itself on some 498e19dfac4Smrg # systems and the destination file might be busy for other 499e19dfac4Smrg # reasons. In this case, the final cleanup might fail but the new 500e19dfac4Smrg # file should still install successfully. 501e19dfac4Smrg { 502e19dfac4Smrg test ! -f "$dst" || 503e19dfac4Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 504e19dfac4Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 505e19dfac4Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 506e19dfac4Smrg } || 507e19dfac4Smrg { echo "$0: cannot unlink or rename $dst" >&2 508e19dfac4Smrg (exit 1); exit 1 509e19dfac4Smrg } 510e19dfac4Smrg } && 511e19dfac4Smrg 512e19dfac4Smrg # Now rename the file to the real destination. 513e19dfac4Smrg $doit $mvcmd "$dsttmp" "$dst" 514e19dfac4Smrg } 515e19dfac4Smrg fi || exit 1 516e19dfac4Smrg 517e19dfac4Smrg trap '' 0 518e19dfac4Smrg fi 51927702724Smrgdone 52027702724Smrg 52127702724Smrg# Local variables: 52227702724Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 52327702724Smrg# time-stamp-start: "scriptversion=" 52427702724Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 52500084f2cSmrg# time-stamp-time-zone: "UTC" 52600084f2cSmrg# time-stamp-end: "; # UTC" 52727702724Smrg# End: 528