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