install-sh revision 5bcb6992
1bd1da9d7Smrg#!/bin/sh 2bd1da9d7Smrg# install - install a program, script, or datafile 3bd1da9d7Smrg 45bcb6992Smrgscriptversion=2009-04-28.21; # UTC 5bd1da9d7Smrg 6bd1da9d7Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7bd1da9d7Smrg# later released in X11R6 (xc/config/util/install.sh) with the 8bd1da9d7Smrg# following copyright and license. 9bd1da9d7Smrg# 10bd1da9d7Smrg# Copyright (C) 1994 X Consortium 11bd1da9d7Smrg# 12bd1da9d7Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13bd1da9d7Smrg# of this software and associated documentation files (the "Software"), to 14bd1da9d7Smrg# deal in the Software without restriction, including without limitation the 15bd1da9d7Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16bd1da9d7Smrg# sell copies of the Software, and to permit persons to whom the Software is 17bd1da9d7Smrg# furnished to do so, subject to the following conditions: 18bd1da9d7Smrg# 19bd1da9d7Smrg# The above copyright notice and this permission notice shall be included in 20bd1da9d7Smrg# all copies or substantial portions of the Software. 21bd1da9d7Smrg# 22bd1da9d7Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23bd1da9d7Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24bd1da9d7Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25bd1da9d7Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26bd1da9d7Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27bd1da9d7Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28bd1da9d7Smrg# 29bd1da9d7Smrg# Except as contained in this notice, the name of the X Consortium shall not 30bd1da9d7Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 31bd1da9d7Smrg# ings in this Software without prior written authorization from the X Consor- 32bd1da9d7Smrg# tium. 33bd1da9d7Smrg# 34bd1da9d7Smrg# 35bd1da9d7Smrg# FSF changes to this file are in the public domain. 36bd1da9d7Smrg# 37bd1da9d7Smrg# Calling this script install-sh is preferred over install.sh, to prevent 38bd1da9d7Smrg# `make' implicit rules from creating a file called install from it 39bd1da9d7Smrg# when there is no Makefile. 40bd1da9d7Smrg# 41bd1da9d7Smrg# This script is compatible with the BSD install script, but was written 425bcb6992Smrg# from scratch. 435bcb6992Smrg 445bcb6992Smrgnl=' 455bcb6992Smrg' 465bcb6992SmrgIFS=" "" $nl" 47bd1da9d7Smrg 48bd1da9d7Smrg# set DOITPROG to echo to test this script 49bd1da9d7Smrg 50bd1da9d7Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 515bcb6992Smrgdoit=${DOITPROG-} 525bcb6992Smrgif test -z "$doit"; then 535bcb6992Smrg doit_exec=exec 545bcb6992Smrgelse 555bcb6992Smrg doit_exec=$doit 565bcb6992Smrgfi 57bd1da9d7Smrg 585bcb6992Smrg# Put in absolute file names if you don't have them in your path; 595bcb6992Smrg# or use environment vars. 605bcb6992Smrg 615bcb6992Smrgchgrpprog=${CHGRPPROG-chgrp} 625bcb6992Smrgchmodprog=${CHMODPROG-chmod} 635bcb6992Smrgchownprog=${CHOWNPROG-chown} 645bcb6992Smrgcmpprog=${CMPPROG-cmp} 655bcb6992Smrgcpprog=${CPPROG-cp} 665bcb6992Smrgmkdirprog=${MKDIRPROG-mkdir} 675bcb6992Smrgmvprog=${MVPROG-mv} 685bcb6992Smrgrmprog=${RMPROG-rm} 695bcb6992Smrgstripprog=${STRIPPROG-strip} 705bcb6992Smrg 715bcb6992Smrgposix_glob='?' 725bcb6992Smrginitialize_posix_glob=' 735bcb6992Smrg test "$posix_glob" != "?" || { 745bcb6992Smrg if (set -f) 2>/dev/null; then 755bcb6992Smrg posix_glob= 765bcb6992Smrg else 775bcb6992Smrg posix_glob=: 785bcb6992Smrg fi 795bcb6992Smrg } 805bcb6992Smrg' 81bd1da9d7Smrg 825bcb6992Smrgposix_mkdir= 835bcb6992Smrg 845bcb6992Smrg# Desired mode of installed file. 855bcb6992Smrgmode=0755 86bd1da9d7Smrg 87bd1da9d7Smrgchgrpcmd= 885bcb6992Smrgchmodcmd=$chmodprog 895bcb6992Smrgchowncmd= 905bcb6992Smrgmvcmd=$mvprog 91bd1da9d7Smrgrmcmd="$rmprog -f" 925bcb6992Smrgstripcmd= 935bcb6992Smrg 94bd1da9d7Smrgsrc= 95bd1da9d7Smrgdst= 96bd1da9d7Smrgdir_arg= 975bcb6992Smrgdst_arg= 985bcb6992Smrg 995bcb6992Smrgcopy_on_change=false 100bd1da9d7Smrgno_target_directory= 101bd1da9d7Smrg 1025bcb6992Smrgusage="\ 1035bcb6992SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 104bd1da9d7Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 105bd1da9d7Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 106bd1da9d7Smrg or: $0 [OPTION]... -d DIRECTORIES... 107bd1da9d7Smrg 108bd1da9d7SmrgIn the 1st form, copy SRCFILE to DSTFILE. 109bd1da9d7SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 110bd1da9d7SmrgIn the 4th, create DIRECTORIES. 111bd1da9d7Smrg 112bd1da9d7SmrgOptions: 1135bcb6992Smrg --help display this help and exit. 1145bcb6992Smrg --version display version info and exit. 1155bcb6992Smrg 1165bcb6992Smrg -c (ignored) 1175bcb6992Smrg -C install only if different (preserve the last data modification time) 1185bcb6992Smrg -d create directories instead of installing files. 1195bcb6992Smrg -g GROUP $chgrpprog installed files to GROUP. 1205bcb6992Smrg -m MODE $chmodprog installed files to MODE. 1215bcb6992Smrg -o USER $chownprog installed files to USER. 1225bcb6992Smrg -s $stripprog installed files. 1235bcb6992Smrg -t DIRECTORY install into DIRECTORY. 1245bcb6992Smrg -T report an error if DSTFILE is a directory. 125bd1da9d7Smrg 126bd1da9d7SmrgEnvironment variables override the default commands: 1275bcb6992Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1285bcb6992Smrg RMPROG STRIPPROG 129bd1da9d7Smrg" 130bd1da9d7Smrg 1315bcb6992Smrgwhile test $# -ne 0; do 132bd1da9d7Smrg case $1 in 1335bcb6992Smrg -c) ;; 1345bcb6992Smrg 1355bcb6992Smrg -C) copy_on_change=true;; 136bd1da9d7Smrg 1375bcb6992Smrg -d) dir_arg=true;; 138bd1da9d7Smrg 139bd1da9d7Smrg -g) chgrpcmd="$chgrpprog $2" 1405bcb6992Smrg shift;; 141bd1da9d7Smrg 142bd1da9d7Smrg --help) echo "$usage"; exit $?;; 143bd1da9d7Smrg 1445bcb6992Smrg -m) mode=$2 1455bcb6992Smrg case $mode in 1465bcb6992Smrg *' '* | *' '* | *' 1475bcb6992Smrg'* | *'*'* | *'?'* | *'['*) 1485bcb6992Smrg echo "$0: invalid mode: $mode" >&2 1495bcb6992Smrg exit 1;; 1505bcb6992Smrg esac 1515bcb6992Smrg shift;; 152bd1da9d7Smrg 153bd1da9d7Smrg -o) chowncmd="$chownprog $2" 1545bcb6992Smrg shift;; 155bd1da9d7Smrg 1565bcb6992Smrg -s) stripcmd=$stripprog;; 157bd1da9d7Smrg 1585bcb6992Smrg -t) dst_arg=$2 1595bcb6992Smrg shift;; 160bd1da9d7Smrg 1615bcb6992Smrg -T) no_target_directory=true;; 162bd1da9d7Smrg 163bd1da9d7Smrg --version) echo "$0 $scriptversion"; exit $?;; 164bd1da9d7Smrg 1655bcb6992Smrg --) shift 166bd1da9d7Smrg break;; 1675bcb6992Smrg 1685bcb6992Smrg -*) echo "$0: invalid option: $1" >&2 1695bcb6992Smrg exit 1;; 1705bcb6992Smrg 1715bcb6992Smrg *) break;; 172bd1da9d7Smrg esac 1735bcb6992Smrg shift 174bd1da9d7Smrgdone 175bd1da9d7Smrg 1765bcb6992Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1775bcb6992Smrg # When -d is used, all remaining arguments are directories to create. 1785bcb6992Smrg # When -t is used, the destination is already specified. 1795bcb6992Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1805bcb6992Smrg for arg 1815bcb6992Smrg do 1825bcb6992Smrg if test -n "$dst_arg"; then 1835bcb6992Smrg # $@ is not empty: it contains at least $arg. 1845bcb6992Smrg set fnord "$@" "$dst_arg" 1855bcb6992Smrg shift # fnord 1865bcb6992Smrg fi 1875bcb6992Smrg shift # arg 1885bcb6992Smrg dst_arg=$arg 1895bcb6992Smrg done 1905bcb6992Smrgfi 1915bcb6992Smrg 1925bcb6992Smrgif test $# -eq 0; then 193bd1da9d7Smrg if test -z "$dir_arg"; then 194bd1da9d7Smrg echo "$0: no input file specified." >&2 195bd1da9d7Smrg exit 1 196bd1da9d7Smrg fi 197bd1da9d7Smrg # It's OK to call `install-sh -d' without argument. 198bd1da9d7Smrg # This can happen when creating conditional directories. 199bd1da9d7Smrg exit 0 200bd1da9d7Smrgfi 201bd1da9d7Smrg 2025bcb6992Smrgif test -z "$dir_arg"; then 2035bcb6992Smrg trap '(exit $?); exit' 1 2 13 15 2045bcb6992Smrg 2055bcb6992Smrg # Set umask so as not to create temps with too-generous modes. 2065bcb6992Smrg # However, 'strip' requires both read and write access to temps. 2075bcb6992Smrg case $mode in 2085bcb6992Smrg # Optimize common cases. 2095bcb6992Smrg *644) cp_umask=133;; 2105bcb6992Smrg *755) cp_umask=22;; 2115bcb6992Smrg 2125bcb6992Smrg *[0-7]) 2135bcb6992Smrg if test -z "$stripcmd"; then 2145bcb6992Smrg u_plus_rw= 2155bcb6992Smrg else 2165bcb6992Smrg u_plus_rw='% 200' 2175bcb6992Smrg fi 2185bcb6992Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2195bcb6992Smrg *) 2205bcb6992Smrg if test -z "$stripcmd"; then 2215bcb6992Smrg u_plus_rw= 2225bcb6992Smrg else 2235bcb6992Smrg u_plus_rw=,u+rw 2245bcb6992Smrg fi 2255bcb6992Smrg cp_umask=$mode$u_plus_rw;; 2265bcb6992Smrg esac 2275bcb6992Smrgfi 2285bcb6992Smrg 229bd1da9d7Smrgfor src 230bd1da9d7Smrgdo 231bd1da9d7Smrg # Protect names starting with `-'. 232bd1da9d7Smrg case $src in 2335bcb6992Smrg -*) src=./$src;; 234bd1da9d7Smrg esac 235bd1da9d7Smrg 236bd1da9d7Smrg if test -n "$dir_arg"; then 237bd1da9d7Smrg dst=$src 2385bcb6992Smrg dstdir=$dst 2395bcb6992Smrg test -d "$dstdir" 2405bcb6992Smrg dstdir_status=$? 241bd1da9d7Smrg else 2425bcb6992Smrg 243bd1da9d7Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 244bd1da9d7Smrg # might cause directories to be created, which would be especially bad 245bd1da9d7Smrg # if $src (and thus $dsttmp) contains '*'. 246bd1da9d7Smrg if test ! -f "$src" && test ! -d "$src"; then 247bd1da9d7Smrg echo "$0: $src does not exist." >&2 248bd1da9d7Smrg exit 1 249bd1da9d7Smrg fi 250bd1da9d7Smrg 2515bcb6992Smrg if test -z "$dst_arg"; then 252bd1da9d7Smrg echo "$0: no destination specified." >&2 253bd1da9d7Smrg exit 1 254bd1da9d7Smrg fi 255bd1da9d7Smrg 2565bcb6992Smrg dst=$dst_arg 257bd1da9d7Smrg # Protect names starting with `-'. 258bd1da9d7Smrg case $dst in 2595bcb6992Smrg -*) dst=./$dst;; 260bd1da9d7Smrg esac 261bd1da9d7Smrg 262bd1da9d7Smrg # If destination is a directory, append the input filename; won't work 263bd1da9d7Smrg # if double slashes aren't ignored. 264bd1da9d7Smrg if test -d "$dst"; then 265bd1da9d7Smrg if test -n "$no_target_directory"; then 2665bcb6992Smrg echo "$0: $dst_arg: Is a directory" >&2 267bd1da9d7Smrg exit 1 268bd1da9d7Smrg fi 2695bcb6992Smrg dstdir=$dst 2705bcb6992Smrg dst=$dstdir/`basename "$src"` 2715bcb6992Smrg dstdir_status=0 2725bcb6992Smrg else 2735bcb6992Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 2745bcb6992Smrg dstdir=` 2755bcb6992Smrg (dirname "$dst") 2>/dev/null || 2765bcb6992Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2775bcb6992Smrg X"$dst" : 'X\(//\)[^/]' \| \ 2785bcb6992Smrg X"$dst" : 'X\(//\)$' \| \ 2795bcb6992Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2805bcb6992Smrg echo X"$dst" | 2815bcb6992Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2825bcb6992Smrg s//\1/ 2835bcb6992Smrg q 2845bcb6992Smrg } 2855bcb6992Smrg /^X\(\/\/\)[^/].*/{ 2865bcb6992Smrg s//\1/ 2875bcb6992Smrg q 2885bcb6992Smrg } 2895bcb6992Smrg /^X\(\/\/\)$/{ 2905bcb6992Smrg s//\1/ 2915bcb6992Smrg q 2925bcb6992Smrg } 2935bcb6992Smrg /^X\(\/\).*/{ 2945bcb6992Smrg s//\1/ 2955bcb6992Smrg q 2965bcb6992Smrg } 2975bcb6992Smrg s/.*/./; q' 2985bcb6992Smrg ` 2995bcb6992Smrg 3005bcb6992Smrg test -d "$dstdir" 3015bcb6992Smrg dstdir_status=$? 302bd1da9d7Smrg fi 303bd1da9d7Smrg fi 304bd1da9d7Smrg 3055bcb6992Smrg obsolete_mkdir_used=false 3065bcb6992Smrg 3075bcb6992Smrg if test $dstdir_status != 0; then 3085bcb6992Smrg case $posix_mkdir in 3095bcb6992Smrg '') 3105bcb6992Smrg # Create intermediate dirs using mode 755 as modified by the umask. 3115bcb6992Smrg # This is like FreeBSD 'install' as of 1997-10-28. 3125bcb6992Smrg umask=`umask` 3135bcb6992Smrg case $stripcmd.$umask in 3145bcb6992Smrg # Optimize common cases. 3155bcb6992Smrg *[2367][2367]) mkdir_umask=$umask;; 3165bcb6992Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3175bcb6992Smrg 3185bcb6992Smrg *[0-7]) 3195bcb6992Smrg mkdir_umask=`expr $umask + 22 \ 3205bcb6992Smrg - $umask % 100 % 40 + $umask % 20 \ 3215bcb6992Smrg - $umask % 10 % 4 + $umask % 2 3225bcb6992Smrg `;; 3235bcb6992Smrg *) mkdir_umask=$umask,go-w;; 3245bcb6992Smrg esac 3255bcb6992Smrg 3265bcb6992Smrg # With -d, create the new directory with the user-specified mode. 3275bcb6992Smrg # Otherwise, rely on $mkdir_umask. 3285bcb6992Smrg if test -n "$dir_arg"; then 3295bcb6992Smrg mkdir_mode=-m$mode 3305bcb6992Smrg else 3315bcb6992Smrg mkdir_mode= 3325bcb6992Smrg fi 3335bcb6992Smrg 3345bcb6992Smrg posix_mkdir=false 3355bcb6992Smrg case $umask in 3365bcb6992Smrg *[123567][0-7][0-7]) 3375bcb6992Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3385bcb6992Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3395bcb6992Smrg ;; 3405bcb6992Smrg *) 3415bcb6992Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3425bcb6992Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3435bcb6992Smrg 3445bcb6992Smrg if (umask $mkdir_umask && 3455bcb6992Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3465bcb6992Smrg then 3475bcb6992Smrg if test -z "$dir_arg" || { 3485bcb6992Smrg # Check for POSIX incompatibilities with -m. 3495bcb6992Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3505bcb6992Smrg # other-writeable bit of parent directory when it shouldn't. 3515bcb6992Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3525bcb6992Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3535bcb6992Smrg case $ls_ld_tmpdir in 3545bcb6992Smrg d????-?r-*) different_mode=700;; 3555bcb6992Smrg d????-?--*) different_mode=755;; 3565bcb6992Smrg *) false;; 3575bcb6992Smrg esac && 3585bcb6992Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3595bcb6992Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3605bcb6992Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3615bcb6992Smrg } 3625bcb6992Smrg } 3635bcb6992Smrg then posix_mkdir=: 3645bcb6992Smrg fi 3655bcb6992Smrg rmdir "$tmpdir/d" "$tmpdir" 3665bcb6992Smrg else 3675bcb6992Smrg # Remove any dirs left behind by ancient mkdir implementations. 3685bcb6992Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3695bcb6992Smrg fi 3705bcb6992Smrg trap '' 0;; 3715bcb6992Smrg esac;; 3725bcb6992Smrg esac 373bd1da9d7Smrg 3745bcb6992Smrg if 3755bcb6992Smrg $posix_mkdir && ( 3765bcb6992Smrg umask $mkdir_umask && 3775bcb6992Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3785bcb6992Smrg ) 3795bcb6992Smrg then : 3805bcb6992Smrg else 381bd1da9d7Smrg 3825bcb6992Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3835bcb6992Smrg # or it failed possibly due to a race condition. Create the 3845bcb6992Smrg # directory the slow way, step by step, checking for races as we go. 385bd1da9d7Smrg 3865bcb6992Smrg case $dstdir in 3875bcb6992Smrg /*) prefix='/';; 3885bcb6992Smrg -*) prefix='./';; 3895bcb6992Smrg *) prefix='';; 3905bcb6992Smrg esac 391bd1da9d7Smrg 3925bcb6992Smrg eval "$initialize_posix_glob" 393bd1da9d7Smrg 3945bcb6992Smrg oIFS=$IFS 3955bcb6992Smrg IFS=/ 3965bcb6992Smrg $posix_glob set -f 3975bcb6992Smrg set fnord $dstdir 398bd1da9d7Smrg shift 3995bcb6992Smrg $posix_glob set +f 4005bcb6992Smrg IFS=$oIFS 4015bcb6992Smrg 4025bcb6992Smrg prefixes= 4035bcb6992Smrg 4045bcb6992Smrg for d 4055bcb6992Smrg do 4065bcb6992Smrg test -z "$d" && continue 4075bcb6992Smrg 4085bcb6992Smrg prefix=$prefix$d 4095bcb6992Smrg if test -d "$prefix"; then 4105bcb6992Smrg prefixes= 4115bcb6992Smrg else 4125bcb6992Smrg if $posix_mkdir; then 4135bcb6992Smrg (umask=$mkdir_umask && 4145bcb6992Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4155bcb6992Smrg # Don't fail if two instances are running concurrently. 4165bcb6992Smrg test -d "$prefix" || exit 1 4175bcb6992Smrg else 4185bcb6992Smrg case $prefix in 4195bcb6992Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4205bcb6992Smrg *) qprefix=$prefix;; 4215bcb6992Smrg esac 4225bcb6992Smrg prefixes="$prefixes '$qprefix'" 4235bcb6992Smrg fi 4245bcb6992Smrg fi 4255bcb6992Smrg prefix=$prefix/ 4265bcb6992Smrg done 4275bcb6992Smrg 4285bcb6992Smrg if test -n "$prefixes"; then 4295bcb6992Smrg # Don't fail if two instances are running concurrently. 4305bcb6992Smrg (umask $mkdir_umask && 4315bcb6992Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4325bcb6992Smrg test -d "$dstdir" || exit 1 4335bcb6992Smrg obsolete_mkdir_used=true 434bd1da9d7Smrg fi 4355bcb6992Smrg fi 436bd1da9d7Smrg fi 437bd1da9d7Smrg 438bd1da9d7Smrg if test -n "$dir_arg"; then 4395bcb6992Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4405bcb6992Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4415bcb6992Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4425bcb6992Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 443bd1da9d7Smrg else 444bd1da9d7Smrg 445bd1da9d7Smrg # Make a couple of temp file names in the proper directory. 446bd1da9d7Smrg dsttmp=$dstdir/_inst.$$_ 447bd1da9d7Smrg rmtmp=$dstdir/_rm.$$_ 448bd1da9d7Smrg 449bd1da9d7Smrg # Trap to clean up those temp files at exit. 450bd1da9d7Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 451bd1da9d7Smrg 452bd1da9d7Smrg # Copy the file name to the temp name. 4535bcb6992Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 454bd1da9d7Smrg 455bd1da9d7Smrg # and set any options; do chmod last to preserve setuid bits. 456bd1da9d7Smrg # 457bd1da9d7Smrg # If any of these fail, we abort the whole thing. If we want to 458bd1da9d7Smrg # ignore errors from any of these, just make sure not to ignore 459bd1da9d7Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 460bd1da9d7Smrg # 4615bcb6992Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4625bcb6992Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4635bcb6992Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4645bcb6992Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4655bcb6992Smrg 4665bcb6992Smrg # If -C, don't bother to copy if it wouldn't change the file. 4675bcb6992Smrg if $copy_on_change && 4685bcb6992Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4695bcb6992Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4705bcb6992Smrg 4715bcb6992Smrg eval "$initialize_posix_glob" && 4725bcb6992Smrg $posix_glob set -f && 4735bcb6992Smrg set X $old && old=:$2:$4:$5:$6 && 4745bcb6992Smrg set X $new && new=:$2:$4:$5:$6 && 4755bcb6992Smrg $posix_glob set +f && 4765bcb6992Smrg 4775bcb6992Smrg test "$old" = "$new" && 4785bcb6992Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4795bcb6992Smrg then 4805bcb6992Smrg rm -f "$dsttmp" 4815bcb6992Smrg else 4825bcb6992Smrg # Rename the file to the real destination. 4835bcb6992Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4845bcb6992Smrg 4855bcb6992Smrg # The rename failed, perhaps because mv can't rename something else 4865bcb6992Smrg # to itself, or perhaps because mv is so ancient that it does not 4875bcb6992Smrg # support -f. 4885bcb6992Smrg { 4895bcb6992Smrg # Now remove or move aside any old file at destination location. 4905bcb6992Smrg # We try this two ways since rm can't unlink itself on some 4915bcb6992Smrg # systems and the destination file might be busy for other 4925bcb6992Smrg # reasons. In this case, the final cleanup might fail but the new 4935bcb6992Smrg # file should still install successfully. 4945bcb6992Smrg { 4955bcb6992Smrg test ! -f "$dst" || 4965bcb6992Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 4975bcb6992Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 4985bcb6992Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 4995bcb6992Smrg } || 5005bcb6992Smrg { echo "$0: cannot unlink or rename $dst" >&2 5015bcb6992Smrg (exit 1); exit 1 5025bcb6992Smrg } 5035bcb6992Smrg } && 5045bcb6992Smrg 5055bcb6992Smrg # Now rename the file to the real destination. 5065bcb6992Smrg $doit $mvcmd "$dsttmp" "$dst" 5075bcb6992Smrg } 5085bcb6992Smrg fi || exit 1 5095bcb6992Smrg 5105bcb6992Smrg trap '' 0 5115bcb6992Smrg fi 512bd1da9d7Smrgdone 513bd1da9d7Smrg 514bd1da9d7Smrg# Local variables: 515bd1da9d7Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 516bd1da9d7Smrg# time-stamp-start: "scriptversion=" 517bd1da9d7Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5185bcb6992Smrg# time-stamp-time-zone: "UTC" 5195bcb6992Smrg# time-stamp-end: "; # UTC" 520bd1da9d7Smrg# End: 521