1428d7b3dSmrg#!/bin/sh 2428d7b3dSmrg# install - install a program, script, or datafile 3428d7b3dSmrg 4428d7b3dSmrgscriptversion=2011-11-20.07; # UTC 5428d7b3dSmrg 6428d7b3dSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7428d7b3dSmrg# later released in X11R6 (xc/config/util/install.sh) with the 8428d7b3dSmrg# following copyright and license. 9428d7b3dSmrg# 10428d7b3dSmrg# Copyright (C) 1994 X Consortium 11428d7b3dSmrg# 12428d7b3dSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13428d7b3dSmrg# of this software and associated documentation files (the "Software"), to 14428d7b3dSmrg# deal in the Software without restriction, including without limitation the 15428d7b3dSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16428d7b3dSmrg# sell copies of the Software, and to permit persons to whom the Software is 17428d7b3dSmrg# furnished to do so, subject to the following conditions: 18428d7b3dSmrg# 19428d7b3dSmrg# The above copyright notice and this permission notice shall be included in 20428d7b3dSmrg# all copies or substantial portions of the Software. 21428d7b3dSmrg# 22428d7b3dSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23428d7b3dSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24428d7b3dSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25428d7b3dSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26428d7b3dSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27428d7b3dSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28428d7b3dSmrg# 29428d7b3dSmrg# Except as contained in this notice, the name of the X Consortium shall not 30428d7b3dSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 31428d7b3dSmrg# ings in this Software without prior written authorization from the X Consor- 32428d7b3dSmrg# tium. 33428d7b3dSmrg# 34428d7b3dSmrg# 35428d7b3dSmrg# FSF changes to this file are in the public domain. 36428d7b3dSmrg# 37428d7b3dSmrg# Calling this script install-sh is preferred over install.sh, to prevent 38428d7b3dSmrg# 'make' implicit rules from creating a file called install from it 39428d7b3dSmrg# when there is no Makefile. 40428d7b3dSmrg# 41428d7b3dSmrg# This script is compatible with the BSD install script, but was written 42428d7b3dSmrg# from scratch. 43428d7b3dSmrg 44428d7b3dSmrgnl=' 45428d7b3dSmrg' 46428d7b3dSmrgIFS=" "" $nl" 47428d7b3dSmrg 48428d7b3dSmrg# set DOITPROG to echo to test this script 49428d7b3dSmrg 50428d7b3dSmrg# Don't use :- since 4.3BSD and earlier shells don't like it. 51428d7b3dSmrgdoit=${DOITPROG-} 52428d7b3dSmrgif test -z "$doit"; then 53428d7b3dSmrg doit_exec=exec 54428d7b3dSmrgelse 55428d7b3dSmrg doit_exec=$doit 56428d7b3dSmrgfi 57428d7b3dSmrg 58428d7b3dSmrg# Put in absolute file names if you don't have them in your path; 59428d7b3dSmrg# or use environment vars. 60428d7b3dSmrg 61428d7b3dSmrgchgrpprog=${CHGRPPROG-chgrp} 62428d7b3dSmrgchmodprog=${CHMODPROG-chmod} 63428d7b3dSmrgchownprog=${CHOWNPROG-chown} 64428d7b3dSmrgcmpprog=${CMPPROG-cmp} 65428d7b3dSmrgcpprog=${CPPROG-cp} 66428d7b3dSmrgmkdirprog=${MKDIRPROG-mkdir} 67428d7b3dSmrgmvprog=${MVPROG-mv} 68428d7b3dSmrgrmprog=${RMPROG-rm} 69428d7b3dSmrgstripprog=${STRIPPROG-strip} 70428d7b3dSmrg 71428d7b3dSmrgposix_glob='?' 72428d7b3dSmrginitialize_posix_glob=' 73428d7b3dSmrg test "$posix_glob" != "?" || { 74428d7b3dSmrg if (set -f) 2>/dev/null; then 75428d7b3dSmrg posix_glob= 76428d7b3dSmrg else 77428d7b3dSmrg posix_glob=: 78428d7b3dSmrg fi 79428d7b3dSmrg } 80428d7b3dSmrg' 81428d7b3dSmrg 82428d7b3dSmrgposix_mkdir= 83428d7b3dSmrg 84428d7b3dSmrg# Desired mode of installed file. 85428d7b3dSmrgmode=0755 86428d7b3dSmrg 87428d7b3dSmrgchgrpcmd= 88428d7b3dSmrgchmodcmd=$chmodprog 89428d7b3dSmrgchowncmd= 90428d7b3dSmrgmvcmd=$mvprog 91428d7b3dSmrgrmcmd="$rmprog -f" 92428d7b3dSmrgstripcmd= 93428d7b3dSmrg 94428d7b3dSmrgsrc= 95428d7b3dSmrgdst= 96428d7b3dSmrgdir_arg= 97428d7b3dSmrgdst_arg= 98428d7b3dSmrg 99428d7b3dSmrgcopy_on_change=false 100428d7b3dSmrgno_target_directory= 101428d7b3dSmrg 102428d7b3dSmrgusage="\ 103428d7b3dSmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 104428d7b3dSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 105428d7b3dSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 106428d7b3dSmrg or: $0 [OPTION]... -d DIRECTORIES... 107428d7b3dSmrg 108428d7b3dSmrgIn the 1st form, copy SRCFILE to DSTFILE. 109428d7b3dSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 110428d7b3dSmrgIn the 4th, create DIRECTORIES. 111428d7b3dSmrg 112428d7b3dSmrgOptions: 113428d7b3dSmrg --help display this help and exit. 114428d7b3dSmrg --version display version info and exit. 115428d7b3dSmrg 116428d7b3dSmrg -c (ignored) 117428d7b3dSmrg -C install only if different (preserve the last data modification time) 118428d7b3dSmrg -d create directories instead of installing files. 119428d7b3dSmrg -g GROUP $chgrpprog installed files to GROUP. 120428d7b3dSmrg -m MODE $chmodprog installed files to MODE. 121428d7b3dSmrg -o USER $chownprog installed files to USER. 122428d7b3dSmrg -s $stripprog installed files. 123428d7b3dSmrg -t DIRECTORY install into DIRECTORY. 124428d7b3dSmrg -T report an error if DSTFILE is a directory. 125428d7b3dSmrg 126428d7b3dSmrgEnvironment variables override the default commands: 127428d7b3dSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 128428d7b3dSmrg RMPROG STRIPPROG 129428d7b3dSmrg" 130428d7b3dSmrg 131428d7b3dSmrgwhile test $# -ne 0; do 132428d7b3dSmrg case $1 in 133428d7b3dSmrg -c) ;; 134428d7b3dSmrg 135428d7b3dSmrg -C) copy_on_change=true;; 136428d7b3dSmrg 137428d7b3dSmrg -d) dir_arg=true;; 138428d7b3dSmrg 139428d7b3dSmrg -g) chgrpcmd="$chgrpprog $2" 140428d7b3dSmrg shift;; 141428d7b3dSmrg 142428d7b3dSmrg --help) echo "$usage"; exit $?;; 143428d7b3dSmrg 144428d7b3dSmrg -m) mode=$2 145428d7b3dSmrg case $mode in 146428d7b3dSmrg *' '* | *' '* | *' 147428d7b3dSmrg'* | *'*'* | *'?'* | *'['*) 148428d7b3dSmrg echo "$0: invalid mode: $mode" >&2 149428d7b3dSmrg exit 1;; 150428d7b3dSmrg esac 151428d7b3dSmrg shift;; 152428d7b3dSmrg 153428d7b3dSmrg -o) chowncmd="$chownprog $2" 154428d7b3dSmrg shift;; 155428d7b3dSmrg 156428d7b3dSmrg -s) stripcmd=$stripprog;; 157428d7b3dSmrg 158428d7b3dSmrg -t) dst_arg=$2 159428d7b3dSmrg # Protect names problematic for 'test' and other utilities. 160428d7b3dSmrg case $dst_arg in 161428d7b3dSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 162428d7b3dSmrg esac 163428d7b3dSmrg shift;; 164428d7b3dSmrg 165428d7b3dSmrg -T) no_target_directory=true;; 166428d7b3dSmrg 167428d7b3dSmrg --version) echo "$0 $scriptversion"; exit $?;; 168428d7b3dSmrg 169428d7b3dSmrg --) shift 170428d7b3dSmrg break;; 171428d7b3dSmrg 172428d7b3dSmrg -*) echo "$0: invalid option: $1" >&2 173428d7b3dSmrg exit 1;; 174428d7b3dSmrg 175428d7b3dSmrg *) break;; 176428d7b3dSmrg esac 177428d7b3dSmrg shift 178428d7b3dSmrgdone 179428d7b3dSmrg 180428d7b3dSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 181428d7b3dSmrg # When -d is used, all remaining arguments are directories to create. 182428d7b3dSmrg # When -t is used, the destination is already specified. 183428d7b3dSmrg # Otherwise, the last argument is the destination. Remove it from $@. 184428d7b3dSmrg for arg 185428d7b3dSmrg do 186428d7b3dSmrg if test -n "$dst_arg"; then 187428d7b3dSmrg # $@ is not empty: it contains at least $arg. 188428d7b3dSmrg set fnord "$@" "$dst_arg" 189428d7b3dSmrg shift # fnord 190428d7b3dSmrg fi 191428d7b3dSmrg shift # arg 192428d7b3dSmrg dst_arg=$arg 193428d7b3dSmrg # Protect names problematic for 'test' and other utilities. 194428d7b3dSmrg case $dst_arg in 195428d7b3dSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 196428d7b3dSmrg esac 197428d7b3dSmrg done 198428d7b3dSmrgfi 199428d7b3dSmrg 200428d7b3dSmrgif test $# -eq 0; then 201428d7b3dSmrg if test -z "$dir_arg"; then 202428d7b3dSmrg echo "$0: no input file specified." >&2 203428d7b3dSmrg exit 1 204428d7b3dSmrg fi 205428d7b3dSmrg # It's OK to call 'install-sh -d' without argument. 206428d7b3dSmrg # This can happen when creating conditional directories. 207428d7b3dSmrg exit 0 208428d7b3dSmrgfi 209428d7b3dSmrg 210428d7b3dSmrgif test -z "$dir_arg"; then 211428d7b3dSmrg do_exit='(exit $ret); exit $ret' 212428d7b3dSmrg trap "ret=129; $do_exit" 1 213428d7b3dSmrg trap "ret=130; $do_exit" 2 214428d7b3dSmrg trap "ret=141; $do_exit" 13 215428d7b3dSmrg trap "ret=143; $do_exit" 15 216428d7b3dSmrg 217428d7b3dSmrg # Set umask so as not to create temps with too-generous modes. 218428d7b3dSmrg # However, 'strip' requires both read and write access to temps. 219428d7b3dSmrg case $mode in 220428d7b3dSmrg # Optimize common cases. 221428d7b3dSmrg *644) cp_umask=133;; 222428d7b3dSmrg *755) cp_umask=22;; 223428d7b3dSmrg 224428d7b3dSmrg *[0-7]) 225428d7b3dSmrg if test -z "$stripcmd"; then 226428d7b3dSmrg u_plus_rw= 227428d7b3dSmrg else 228428d7b3dSmrg u_plus_rw='% 200' 229428d7b3dSmrg fi 230428d7b3dSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 231428d7b3dSmrg *) 232428d7b3dSmrg if test -z "$stripcmd"; then 233428d7b3dSmrg u_plus_rw= 234428d7b3dSmrg else 235428d7b3dSmrg u_plus_rw=,u+rw 236428d7b3dSmrg fi 237428d7b3dSmrg cp_umask=$mode$u_plus_rw;; 238428d7b3dSmrg esac 239428d7b3dSmrgfi 240428d7b3dSmrg 241428d7b3dSmrgfor src 242428d7b3dSmrgdo 243428d7b3dSmrg # Protect names problematic for 'test' and other utilities. 244428d7b3dSmrg case $src in 245428d7b3dSmrg -* | [=\(\)!]) src=./$src;; 246428d7b3dSmrg esac 247428d7b3dSmrg 248428d7b3dSmrg if test -n "$dir_arg"; then 249428d7b3dSmrg dst=$src 250428d7b3dSmrg dstdir=$dst 251428d7b3dSmrg test -d "$dstdir" 252428d7b3dSmrg dstdir_status=$? 253428d7b3dSmrg else 254428d7b3dSmrg 255428d7b3dSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 256428d7b3dSmrg # might cause directories to be created, which would be especially bad 257428d7b3dSmrg # if $src (and thus $dsttmp) contains '*'. 258428d7b3dSmrg if test ! -f "$src" && test ! -d "$src"; then 259428d7b3dSmrg echo "$0: $src does not exist." >&2 260428d7b3dSmrg exit 1 261428d7b3dSmrg fi 262428d7b3dSmrg 263428d7b3dSmrg if test -z "$dst_arg"; then 264428d7b3dSmrg echo "$0: no destination specified." >&2 265428d7b3dSmrg exit 1 266428d7b3dSmrg fi 267428d7b3dSmrg dst=$dst_arg 268428d7b3dSmrg 269428d7b3dSmrg # If destination is a directory, append the input filename; won't work 270428d7b3dSmrg # if double slashes aren't ignored. 271428d7b3dSmrg if test -d "$dst"; then 272428d7b3dSmrg if test -n "$no_target_directory"; then 273428d7b3dSmrg echo "$0: $dst_arg: Is a directory" >&2 274428d7b3dSmrg exit 1 275428d7b3dSmrg fi 276428d7b3dSmrg dstdir=$dst 277428d7b3dSmrg dst=$dstdir/`basename "$src"` 278428d7b3dSmrg dstdir_status=0 279428d7b3dSmrg else 280428d7b3dSmrg # Prefer dirname, but fall back on a substitute if dirname fails. 281428d7b3dSmrg dstdir=` 282428d7b3dSmrg (dirname "$dst") 2>/dev/null || 283428d7b3dSmrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 284428d7b3dSmrg X"$dst" : 'X\(//\)[^/]' \| \ 285428d7b3dSmrg X"$dst" : 'X\(//\)$' \| \ 286428d7b3dSmrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 287428d7b3dSmrg echo X"$dst" | 288428d7b3dSmrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 289428d7b3dSmrg s//\1/ 290428d7b3dSmrg q 291428d7b3dSmrg } 292428d7b3dSmrg /^X\(\/\/\)[^/].*/{ 293428d7b3dSmrg s//\1/ 294428d7b3dSmrg q 295428d7b3dSmrg } 296428d7b3dSmrg /^X\(\/\/\)$/{ 297428d7b3dSmrg s//\1/ 298428d7b3dSmrg q 299428d7b3dSmrg } 300428d7b3dSmrg /^X\(\/\).*/{ 301428d7b3dSmrg s//\1/ 302428d7b3dSmrg q 303428d7b3dSmrg } 304428d7b3dSmrg s/.*/./; q' 305428d7b3dSmrg ` 306428d7b3dSmrg 307428d7b3dSmrg test -d "$dstdir" 308428d7b3dSmrg dstdir_status=$? 309428d7b3dSmrg fi 310428d7b3dSmrg fi 311428d7b3dSmrg 312428d7b3dSmrg obsolete_mkdir_used=false 313428d7b3dSmrg 314428d7b3dSmrg if test $dstdir_status != 0; then 315428d7b3dSmrg case $posix_mkdir in 316428d7b3dSmrg '') 317428d7b3dSmrg # Create intermediate dirs using mode 755 as modified by the umask. 318428d7b3dSmrg # This is like FreeBSD 'install' as of 1997-10-28. 319428d7b3dSmrg umask=`umask` 320428d7b3dSmrg case $stripcmd.$umask in 321428d7b3dSmrg # Optimize common cases. 322428d7b3dSmrg *[2367][2367]) mkdir_umask=$umask;; 323428d7b3dSmrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 324428d7b3dSmrg 325428d7b3dSmrg *[0-7]) 326428d7b3dSmrg mkdir_umask=`expr $umask + 22 \ 327428d7b3dSmrg - $umask % 100 % 40 + $umask % 20 \ 328428d7b3dSmrg - $umask % 10 % 4 + $umask % 2 329428d7b3dSmrg `;; 330428d7b3dSmrg *) mkdir_umask=$umask,go-w;; 331428d7b3dSmrg esac 332428d7b3dSmrg 333428d7b3dSmrg # With -d, create the new directory with the user-specified mode. 334428d7b3dSmrg # Otherwise, rely on $mkdir_umask. 335428d7b3dSmrg if test -n "$dir_arg"; then 336428d7b3dSmrg mkdir_mode=-m$mode 337428d7b3dSmrg else 338428d7b3dSmrg mkdir_mode= 339428d7b3dSmrg fi 340428d7b3dSmrg 341428d7b3dSmrg posix_mkdir=false 342428d7b3dSmrg case $umask in 343428d7b3dSmrg *[123567][0-7][0-7]) 344428d7b3dSmrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 345428d7b3dSmrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 346428d7b3dSmrg ;; 347428d7b3dSmrg *) 348428d7b3dSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 349428d7b3dSmrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 350428d7b3dSmrg 351428d7b3dSmrg if (umask $mkdir_umask && 352428d7b3dSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 353428d7b3dSmrg then 354428d7b3dSmrg if test -z "$dir_arg" || { 355428d7b3dSmrg # Check for POSIX incompatibilities with -m. 356428d7b3dSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 357428d7b3dSmrg # other-writable bit of parent directory when it shouldn't. 358428d7b3dSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 359428d7b3dSmrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 360428d7b3dSmrg case $ls_ld_tmpdir in 361428d7b3dSmrg d????-?r-*) different_mode=700;; 362428d7b3dSmrg d????-?--*) different_mode=755;; 363428d7b3dSmrg *) false;; 364428d7b3dSmrg esac && 365428d7b3dSmrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 366428d7b3dSmrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 367428d7b3dSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 368428d7b3dSmrg } 369428d7b3dSmrg } 370428d7b3dSmrg then posix_mkdir=: 371428d7b3dSmrg fi 372428d7b3dSmrg rmdir "$tmpdir/d" "$tmpdir" 373428d7b3dSmrg else 374428d7b3dSmrg # Remove any dirs left behind by ancient mkdir implementations. 375428d7b3dSmrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 376428d7b3dSmrg fi 377428d7b3dSmrg trap '' 0;; 378428d7b3dSmrg esac;; 379428d7b3dSmrg esac 380428d7b3dSmrg 381428d7b3dSmrg if 382428d7b3dSmrg $posix_mkdir && ( 383428d7b3dSmrg umask $mkdir_umask && 384428d7b3dSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 385428d7b3dSmrg ) 386428d7b3dSmrg then : 387428d7b3dSmrg else 388428d7b3dSmrg 389428d7b3dSmrg # The umask is ridiculous, or mkdir does not conform to POSIX, 390428d7b3dSmrg # or it failed possibly due to a race condition. Create the 391428d7b3dSmrg # directory the slow way, step by step, checking for races as we go. 392428d7b3dSmrg 393428d7b3dSmrg case $dstdir in 394428d7b3dSmrg /*) prefix='/';; 395428d7b3dSmrg [-=\(\)!]*) prefix='./';; 396428d7b3dSmrg *) prefix='';; 397428d7b3dSmrg esac 398428d7b3dSmrg 399428d7b3dSmrg eval "$initialize_posix_glob" 400428d7b3dSmrg 401428d7b3dSmrg oIFS=$IFS 402428d7b3dSmrg IFS=/ 403428d7b3dSmrg $posix_glob set -f 404428d7b3dSmrg set fnord $dstdir 405428d7b3dSmrg shift 406428d7b3dSmrg $posix_glob set +f 407428d7b3dSmrg IFS=$oIFS 408428d7b3dSmrg 409428d7b3dSmrg prefixes= 410428d7b3dSmrg 411428d7b3dSmrg for d 412428d7b3dSmrg do 413428d7b3dSmrg test X"$d" = X && continue 414428d7b3dSmrg 415428d7b3dSmrg prefix=$prefix$d 416428d7b3dSmrg if test -d "$prefix"; then 417428d7b3dSmrg prefixes= 418428d7b3dSmrg else 419428d7b3dSmrg if $posix_mkdir; then 420428d7b3dSmrg (umask=$mkdir_umask && 421428d7b3dSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 422428d7b3dSmrg # Don't fail if two instances are running concurrently. 423428d7b3dSmrg test -d "$prefix" || exit 1 424428d7b3dSmrg else 425428d7b3dSmrg case $prefix in 426428d7b3dSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 427428d7b3dSmrg *) qprefix=$prefix;; 428428d7b3dSmrg esac 429428d7b3dSmrg prefixes="$prefixes '$qprefix'" 430428d7b3dSmrg fi 431428d7b3dSmrg fi 432428d7b3dSmrg prefix=$prefix/ 433428d7b3dSmrg done 434428d7b3dSmrg 435428d7b3dSmrg if test -n "$prefixes"; then 436428d7b3dSmrg # Don't fail if two instances are running concurrently. 437428d7b3dSmrg (umask $mkdir_umask && 438428d7b3dSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 439428d7b3dSmrg test -d "$dstdir" || exit 1 440428d7b3dSmrg obsolete_mkdir_used=true 441428d7b3dSmrg fi 442428d7b3dSmrg fi 443428d7b3dSmrg fi 444428d7b3dSmrg 445428d7b3dSmrg if test -n "$dir_arg"; then 446428d7b3dSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 447428d7b3dSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 448428d7b3dSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 449428d7b3dSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 450428d7b3dSmrg else 451428d7b3dSmrg 452428d7b3dSmrg # Make a couple of temp file names in the proper directory. 453428d7b3dSmrg dsttmp=$dstdir/_inst.$$_ 454428d7b3dSmrg rmtmp=$dstdir/_rm.$$_ 455428d7b3dSmrg 456428d7b3dSmrg # Trap to clean up those temp files at exit. 457428d7b3dSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 458428d7b3dSmrg 459428d7b3dSmrg # Copy the file name to the temp name. 460428d7b3dSmrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 461428d7b3dSmrg 462428d7b3dSmrg # and set any options; do chmod last to preserve setuid bits. 463428d7b3dSmrg # 464428d7b3dSmrg # If any of these fail, we abort the whole thing. If we want to 465428d7b3dSmrg # ignore errors from any of these, just make sure not to ignore 466428d7b3dSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 467428d7b3dSmrg # 468428d7b3dSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 469428d7b3dSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 470428d7b3dSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 471428d7b3dSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 472428d7b3dSmrg 473428d7b3dSmrg # If -C, don't bother to copy if it wouldn't change the file. 474428d7b3dSmrg if $copy_on_change && 475428d7b3dSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 476428d7b3dSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 477428d7b3dSmrg 478428d7b3dSmrg eval "$initialize_posix_glob" && 479428d7b3dSmrg $posix_glob set -f && 480428d7b3dSmrg set X $old && old=:$2:$4:$5:$6 && 481428d7b3dSmrg set X $new && new=:$2:$4:$5:$6 && 482428d7b3dSmrg $posix_glob set +f && 483428d7b3dSmrg 484428d7b3dSmrg test "$old" = "$new" && 485428d7b3dSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 486428d7b3dSmrg then 487428d7b3dSmrg rm -f "$dsttmp" 488428d7b3dSmrg else 489428d7b3dSmrg # Rename the file to the real destination. 490428d7b3dSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 491428d7b3dSmrg 492428d7b3dSmrg # The rename failed, perhaps because mv can't rename something else 493428d7b3dSmrg # to itself, or perhaps because mv is so ancient that it does not 494428d7b3dSmrg # support -f. 495428d7b3dSmrg { 496428d7b3dSmrg # Now remove or move aside any old file at destination location. 497428d7b3dSmrg # We try this two ways since rm can't unlink itself on some 498428d7b3dSmrg # systems and the destination file might be busy for other 499428d7b3dSmrg # reasons. In this case, the final cleanup might fail but the new 500428d7b3dSmrg # file should still install successfully. 501428d7b3dSmrg { 502428d7b3dSmrg test ! -f "$dst" || 503428d7b3dSmrg $doit $rmcmd -f "$dst" 2>/dev/null || 504428d7b3dSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 505428d7b3dSmrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 506428d7b3dSmrg } || 507428d7b3dSmrg { echo "$0: cannot unlink or rename $dst" >&2 508428d7b3dSmrg (exit 1); exit 1 509428d7b3dSmrg } 510428d7b3dSmrg } && 511428d7b3dSmrg 512428d7b3dSmrg # Now rename the file to the real destination. 513428d7b3dSmrg $doit $mvcmd "$dsttmp" "$dst" 514428d7b3dSmrg } 515428d7b3dSmrg fi || exit 1 516428d7b3dSmrg 517428d7b3dSmrg trap '' 0 518428d7b3dSmrg fi 519428d7b3dSmrgdone 520428d7b3dSmrg 521428d7b3dSmrg# Local variables: 522428d7b3dSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 523428d7b3dSmrg# time-stamp-start: "scriptversion=" 524428d7b3dSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 525428d7b3dSmrg# time-stamp-time-zone: "UTC" 526428d7b3dSmrg# time-stamp-end: "; # UTC" 527428d7b3dSmrg# End: 528