install-sh revision 8512f934
196c5ddc4Srjs#!/bin/sh 296c5ddc4Srjs# install - install a program, script, or datafile 396c5ddc4Srjs 496c5ddc4Srjsscriptversion=2009-04-28.21; # UTC 596c5ddc4Srjs 696c5ddc4Srjs# This originates from X11R5 (mit/util/scripts/install.sh), which was 796c5ddc4Srjs# later released in X11R6 (xc/config/util/install.sh) with the 896c5ddc4Srjs# following copyright and license. 996c5ddc4Srjs# 1096c5ddc4Srjs# Copyright (C) 1994 X Consortium 1196c5ddc4Srjs# 1296c5ddc4Srjs# Permission is hereby granted, free of charge, to any person obtaining a copy 1396c5ddc4Srjs# of this software and associated documentation files (the "Software"), to 1496c5ddc4Srjs# deal in the Software without restriction, including without limitation the 1596c5ddc4Srjs# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1696c5ddc4Srjs# sell copies of the Software, and to permit persons to whom the Software is 1796c5ddc4Srjs# furnished to do so, subject to the following conditions: 1896c5ddc4Srjs# 1996c5ddc4Srjs# The above copyright notice and this permission notice shall be included in 2096c5ddc4Srjs# all copies or substantial portions of the Software. 2196c5ddc4Srjs# 2296c5ddc4Srjs# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2396c5ddc4Srjs# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2496c5ddc4Srjs# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2596c5ddc4Srjs# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2696c5ddc4Srjs# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 2796c5ddc4Srjs# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2896c5ddc4Srjs# 2996c5ddc4Srjs# Except as contained in this notice, the name of the X Consortium shall not 3096c5ddc4Srjs# be used in advertising or otherwise to promote the sale, use or other deal- 3196c5ddc4Srjs# ings in this Software without prior written authorization from the X Consor- 3296c5ddc4Srjs# tium. 3396c5ddc4Srjs# 3496c5ddc4Srjs# 3596c5ddc4Srjs# FSF changes to this file are in the public domain. 3696c5ddc4Srjs# 3796c5ddc4Srjs# Calling this script install-sh is preferred over install.sh, to prevent 3896c5ddc4Srjs# `make' implicit rules from creating a file called install from it 3996c5ddc4Srjs# when there is no Makefile. 4096c5ddc4Srjs# 4196c5ddc4Srjs# This script is compatible with the BSD install script, but was written 4296c5ddc4Srjs# from scratch. 4396c5ddc4Srjs 4496c5ddc4Srjsnl=' 4596c5ddc4Srjs' 4696c5ddc4SrjsIFS=" "" $nl" 4796c5ddc4Srjs 4896c5ddc4Srjs# set DOITPROG to echo to test this script 4996c5ddc4Srjs 5096c5ddc4Srjs# Don't use :- since 4.3BSD and earlier shells don't like it. 5196c5ddc4Srjsdoit=${DOITPROG-} 5296c5ddc4Srjsif test -z "$doit"; then 5396c5ddc4Srjs doit_exec=exec 5496c5ddc4Srjselse 5596c5ddc4Srjs doit_exec=$doit 5696c5ddc4Srjsfi 5796c5ddc4Srjs 5896c5ddc4Srjs# Put in absolute file names if you don't have them in your path; 5996c5ddc4Srjs# or use environment vars. 6096c5ddc4Srjs 6196c5ddc4Srjschgrpprog=${CHGRPPROG-chgrp} 6296c5ddc4Srjschmodprog=${CHMODPROG-chmod} 6396c5ddc4Srjschownprog=${CHOWNPROG-chown} 6496c5ddc4Srjscmpprog=${CMPPROG-cmp} 6596c5ddc4Srjscpprog=${CPPROG-cp} 6696c5ddc4Srjsmkdirprog=${MKDIRPROG-mkdir} 6796c5ddc4Srjsmvprog=${MVPROG-mv} 6896c5ddc4Srjsrmprog=${RMPROG-rm} 6996c5ddc4Srjsstripprog=${STRIPPROG-strip} 7096c5ddc4Srjs 7196c5ddc4Srjsposix_glob='?' 7296c5ddc4Srjsinitialize_posix_glob=' 7396c5ddc4Srjs test "$posix_glob" != "?" || { 7496c5ddc4Srjs if (set -f) 2>/dev/null; then 7596c5ddc4Srjs posix_glob= 7696c5ddc4Srjs else 7796c5ddc4Srjs posix_glob=: 7896c5ddc4Srjs fi 7996c5ddc4Srjs } 8096c5ddc4Srjs' 8196c5ddc4Srjs 8296c5ddc4Srjsposix_mkdir= 8396c5ddc4Srjs 8496c5ddc4Srjs# Desired mode of installed file. 8596c5ddc4Srjsmode=0755 8696c5ddc4Srjs 8796c5ddc4Srjschgrpcmd= 8896c5ddc4Srjschmodcmd=$chmodprog 8996c5ddc4Srjschowncmd= 9096c5ddc4Srjsmvcmd=$mvprog 9196c5ddc4Srjsrmcmd="$rmprog -f" 9296c5ddc4Srjsstripcmd= 9396c5ddc4Srjs 9496c5ddc4Srjssrc= 9596c5ddc4Srjsdst= 9696c5ddc4Srjsdir_arg= 9796c5ddc4Srjsdst_arg= 9896c5ddc4Srjs 9996c5ddc4Srjscopy_on_change=false 10096c5ddc4Srjsno_target_directory= 10196c5ddc4Srjs 10296c5ddc4Srjsusage="\ 10396c5ddc4SrjsUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 10496c5ddc4Srjs or: $0 [OPTION]... SRCFILES... DIRECTORY 10596c5ddc4Srjs or: $0 [OPTION]... -t DIRECTORY SRCFILES... 10696c5ddc4Srjs or: $0 [OPTION]... -d DIRECTORIES... 10796c5ddc4Srjs 10896c5ddc4SrjsIn the 1st form, copy SRCFILE to DSTFILE. 10996c5ddc4SrjsIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 11096c5ddc4SrjsIn the 4th, create DIRECTORIES. 11196c5ddc4Srjs 11296c5ddc4SrjsOptions: 11396c5ddc4Srjs --help display this help and exit. 11496c5ddc4Srjs --version display version info and exit. 11596c5ddc4Srjs 11696c5ddc4Srjs -c (ignored) 11796c5ddc4Srjs -C install only if different (preserve the last data modification time) 11896c5ddc4Srjs -d create directories instead of installing files. 11996c5ddc4Srjs -g GROUP $chgrpprog installed files to GROUP. 12096c5ddc4Srjs -m MODE $chmodprog installed files to MODE. 12196c5ddc4Srjs -o USER $chownprog installed files to USER. 12296c5ddc4Srjs -s $stripprog installed files. 12396c5ddc4Srjs -t DIRECTORY install into DIRECTORY. 12496c5ddc4Srjs -T report an error if DSTFILE is a directory. 12596c5ddc4Srjs 12696c5ddc4SrjsEnvironment variables override the default commands: 12796c5ddc4Srjs CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 12896c5ddc4Srjs RMPROG STRIPPROG 12996c5ddc4Srjs" 13096c5ddc4Srjs 13196c5ddc4Srjswhile test $# -ne 0; do 13296c5ddc4Srjs case $1 in 13396c5ddc4Srjs -c) ;; 13496c5ddc4Srjs 13596c5ddc4Srjs -C) copy_on_change=true;; 13696c5ddc4Srjs 13796c5ddc4Srjs -d) dir_arg=true;; 13896c5ddc4Srjs 13996c5ddc4Srjs -g) chgrpcmd="$chgrpprog $2" 14096c5ddc4Srjs shift;; 14196c5ddc4Srjs 14296c5ddc4Srjs --help) echo "$usage"; exit $?;; 14396c5ddc4Srjs 14496c5ddc4Srjs -m) mode=$2 14596c5ddc4Srjs case $mode in 14696c5ddc4Srjs *' '* | *' '* | *' 14796c5ddc4Srjs'* | *'*'* | *'?'* | *'['*) 14896c5ddc4Srjs echo "$0: invalid mode: $mode" >&2 14996c5ddc4Srjs exit 1;; 15096c5ddc4Srjs esac 15196c5ddc4Srjs shift;; 15296c5ddc4Srjs 15396c5ddc4Srjs -o) chowncmd="$chownprog $2" 15496c5ddc4Srjs shift;; 15596c5ddc4Srjs 15696c5ddc4Srjs -s) stripcmd=$stripprog;; 15796c5ddc4Srjs 15896c5ddc4Srjs -t) dst_arg=$2 15996c5ddc4Srjs shift;; 16096c5ddc4Srjs 16196c5ddc4Srjs -T) no_target_directory=true;; 16296c5ddc4Srjs 16396c5ddc4Srjs --version) echo "$0 $scriptversion"; exit $?;; 16496c5ddc4Srjs 16596c5ddc4Srjs --) shift 16696c5ddc4Srjs break;; 16796c5ddc4Srjs 16896c5ddc4Srjs -*) echo "$0: invalid option: $1" >&2 16996c5ddc4Srjs exit 1;; 17096c5ddc4Srjs 17196c5ddc4Srjs *) break;; 17296c5ddc4Srjs esac 17396c5ddc4Srjs shift 17496c5ddc4Srjsdone 17596c5ddc4Srjs 17696c5ddc4Srjsif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 17796c5ddc4Srjs # When -d is used, all remaining arguments are directories to create. 17896c5ddc4Srjs # When -t is used, the destination is already specified. 17996c5ddc4Srjs # Otherwise, the last argument is the destination. Remove it from $@. 18096c5ddc4Srjs for arg 18196c5ddc4Srjs do 18296c5ddc4Srjs if test -n "$dst_arg"; then 18396c5ddc4Srjs # $@ is not empty: it contains at least $arg. 18496c5ddc4Srjs set fnord "$@" "$dst_arg" 18596c5ddc4Srjs shift # fnord 18696c5ddc4Srjs fi 18796c5ddc4Srjs shift # arg 18896c5ddc4Srjs dst_arg=$arg 18996c5ddc4Srjs done 19096c5ddc4Srjsfi 19196c5ddc4Srjs 19296c5ddc4Srjsif test $# -eq 0; then 19396c5ddc4Srjs if test -z "$dir_arg"; then 19496c5ddc4Srjs echo "$0: no input file specified." >&2 19596c5ddc4Srjs exit 1 19696c5ddc4Srjs fi 19796c5ddc4Srjs # It's OK to call `install-sh -d' without argument. 19896c5ddc4Srjs # This can happen when creating conditional directories. 19996c5ddc4Srjs exit 0 20096c5ddc4Srjsfi 20196c5ddc4Srjs 20296c5ddc4Srjsif test -z "$dir_arg"; then 20396c5ddc4Srjs trap '(exit $?); exit' 1 2 13 15 20496c5ddc4Srjs 20596c5ddc4Srjs # Set umask so as not to create temps with too-generous modes. 20696c5ddc4Srjs # However, 'strip' requires both read and write access to temps. 20796c5ddc4Srjs case $mode in 20896c5ddc4Srjs # Optimize common cases. 20996c5ddc4Srjs *644) cp_umask=133;; 21096c5ddc4Srjs *755) cp_umask=22;; 21196c5ddc4Srjs 21296c5ddc4Srjs *[0-7]) 21396c5ddc4Srjs if test -z "$stripcmd"; then 21496c5ddc4Srjs u_plus_rw= 21596c5ddc4Srjs else 21696c5ddc4Srjs u_plus_rw='% 200' 21796c5ddc4Srjs fi 21896c5ddc4Srjs cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 21996c5ddc4Srjs *) 22096c5ddc4Srjs if test -z "$stripcmd"; then 22196c5ddc4Srjs u_plus_rw= 22296c5ddc4Srjs else 22396c5ddc4Srjs u_plus_rw=,u+rw 22496c5ddc4Srjs fi 22596c5ddc4Srjs cp_umask=$mode$u_plus_rw;; 22696c5ddc4Srjs esac 22796c5ddc4Srjsfi 22896c5ddc4Srjs 22996c5ddc4Srjsfor src 23096c5ddc4Srjsdo 23196c5ddc4Srjs # Protect names starting with `-'. 23296c5ddc4Srjs case $src in 23396c5ddc4Srjs -*) src=./$src;; 23496c5ddc4Srjs esac 23596c5ddc4Srjs 23696c5ddc4Srjs if test -n "$dir_arg"; then 23796c5ddc4Srjs dst=$src 23896c5ddc4Srjs dstdir=$dst 23996c5ddc4Srjs test -d "$dstdir" 24096c5ddc4Srjs dstdir_status=$? 24196c5ddc4Srjs else 24296c5ddc4Srjs 24396c5ddc4Srjs # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 24496c5ddc4Srjs # might cause directories to be created, which would be especially bad 24596c5ddc4Srjs # if $src (and thus $dsttmp) contains '*'. 24696c5ddc4Srjs if test ! -f "$src" && test ! -d "$src"; then 24796c5ddc4Srjs echo "$0: $src does not exist." >&2 24896c5ddc4Srjs exit 1 24996c5ddc4Srjs fi 25096c5ddc4Srjs 25196c5ddc4Srjs if test -z "$dst_arg"; then 25296c5ddc4Srjs echo "$0: no destination specified." >&2 25396c5ddc4Srjs exit 1 25496c5ddc4Srjs fi 25596c5ddc4Srjs 25696c5ddc4Srjs dst=$dst_arg 25796c5ddc4Srjs # Protect names starting with `-'. 25896c5ddc4Srjs case $dst in 25996c5ddc4Srjs -*) dst=./$dst;; 26096c5ddc4Srjs esac 26196c5ddc4Srjs 26296c5ddc4Srjs # If destination is a directory, append the input filename; won't work 26396c5ddc4Srjs # if double slashes aren't ignored. 26496c5ddc4Srjs if test -d "$dst"; then 26596c5ddc4Srjs if test -n "$no_target_directory"; then 26696c5ddc4Srjs echo "$0: $dst_arg: Is a directory" >&2 26796c5ddc4Srjs exit 1 26896c5ddc4Srjs fi 26996c5ddc4Srjs dstdir=$dst 27096c5ddc4Srjs dst=$dstdir/`basename "$src"` 27196c5ddc4Srjs dstdir_status=0 27296c5ddc4Srjs else 27396c5ddc4Srjs # Prefer dirname, but fall back on a substitute if dirname fails. 27496c5ddc4Srjs dstdir=` 27596c5ddc4Srjs (dirname "$dst") 2>/dev/null || 27696c5ddc4Srjs expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 27796c5ddc4Srjs X"$dst" : 'X\(//\)[^/]' \| \ 27896c5ddc4Srjs X"$dst" : 'X\(//\)$' \| \ 27996c5ddc4Srjs X"$dst" : 'X\(/\)' \| . 2>/dev/null || 28096c5ddc4Srjs echo X"$dst" | 28196c5ddc4Srjs sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 28296c5ddc4Srjs s//\1/ 28396c5ddc4Srjs q 28496c5ddc4Srjs } 28596c5ddc4Srjs /^X\(\/\/\)[^/].*/{ 28696c5ddc4Srjs s//\1/ 28796c5ddc4Srjs q 28896c5ddc4Srjs } 28996c5ddc4Srjs /^X\(\/\/\)$/{ 29096c5ddc4Srjs s//\1/ 29196c5ddc4Srjs q 29296c5ddc4Srjs } 29396c5ddc4Srjs /^X\(\/\).*/{ 29496c5ddc4Srjs s//\1/ 29596c5ddc4Srjs q 29696c5ddc4Srjs } 29796c5ddc4Srjs s/.*/./; q' 29896c5ddc4Srjs ` 29996c5ddc4Srjs 30096c5ddc4Srjs test -d "$dstdir" 30196c5ddc4Srjs dstdir_status=$? 30296c5ddc4Srjs fi 30396c5ddc4Srjs fi 30496c5ddc4Srjs 30596c5ddc4Srjs obsolete_mkdir_used=false 30696c5ddc4Srjs 30796c5ddc4Srjs if test $dstdir_status != 0; then 30896c5ddc4Srjs case $posix_mkdir in 30996c5ddc4Srjs '') 31096c5ddc4Srjs # Create intermediate dirs using mode 755 as modified by the umask. 31196c5ddc4Srjs # This is like FreeBSD 'install' as of 1997-10-28. 31296c5ddc4Srjs umask=`umask` 31396c5ddc4Srjs case $stripcmd.$umask in 31496c5ddc4Srjs # Optimize common cases. 31596c5ddc4Srjs *[2367][2367]) mkdir_umask=$umask;; 31696c5ddc4Srjs .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 31796c5ddc4Srjs 31896c5ddc4Srjs *[0-7]) 31996c5ddc4Srjs mkdir_umask=`expr $umask + 22 \ 32096c5ddc4Srjs - $umask % 100 % 40 + $umask % 20 \ 32196c5ddc4Srjs - $umask % 10 % 4 + $umask % 2 32296c5ddc4Srjs `;; 32396c5ddc4Srjs *) mkdir_umask=$umask,go-w;; 32496c5ddc4Srjs esac 32596c5ddc4Srjs 32696c5ddc4Srjs # With -d, create the new directory with the user-specified mode. 32796c5ddc4Srjs # Otherwise, rely on $mkdir_umask. 32896c5ddc4Srjs if test -n "$dir_arg"; then 32996c5ddc4Srjs mkdir_mode=-m$mode 33096c5ddc4Srjs else 33196c5ddc4Srjs mkdir_mode= 33296c5ddc4Srjs fi 33396c5ddc4Srjs 33496c5ddc4Srjs posix_mkdir=false 33596c5ddc4Srjs case $umask in 33696c5ddc4Srjs *[123567][0-7][0-7]) 33796c5ddc4Srjs # POSIX mkdir -p sets u+wx bits regardless of umask, which 33896c5ddc4Srjs # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 33996c5ddc4Srjs ;; 34096c5ddc4Srjs *) 34196c5ddc4Srjs tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 34296c5ddc4Srjs trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 34396c5ddc4Srjs 34496c5ddc4Srjs if (umask $mkdir_umask && 34596c5ddc4Srjs exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 34696c5ddc4Srjs then 34796c5ddc4Srjs if test -z "$dir_arg" || { 34896c5ddc4Srjs # Check for POSIX incompatibilities with -m. 34996c5ddc4Srjs # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 35096c5ddc4Srjs # other-writeable bit of parent directory when it shouldn't. 35196c5ddc4Srjs # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 35296c5ddc4Srjs ls_ld_tmpdir=`ls -ld "$tmpdir"` 35396c5ddc4Srjs case $ls_ld_tmpdir in 35496c5ddc4Srjs d????-?r-*) different_mode=700;; 35596c5ddc4Srjs d????-?--*) different_mode=755;; 35696c5ddc4Srjs *) false;; 35796c5ddc4Srjs esac && 35896c5ddc4Srjs $mkdirprog -m$different_mode -p -- "$tmpdir" && { 35996c5ddc4Srjs ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 36096c5ddc4Srjs test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 36196c5ddc4Srjs } 36296c5ddc4Srjs } 36396c5ddc4Srjs then posix_mkdir=: 36496c5ddc4Srjs fi 36596c5ddc4Srjs rmdir "$tmpdir/d" "$tmpdir" 36696c5ddc4Srjs else 36796c5ddc4Srjs # Remove any dirs left behind by ancient mkdir implementations. 36896c5ddc4Srjs rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 36996c5ddc4Srjs fi 37096c5ddc4Srjs trap '' 0;; 37196c5ddc4Srjs esac;; 37296c5ddc4Srjs esac 37396c5ddc4Srjs 37496c5ddc4Srjs if 37596c5ddc4Srjs $posix_mkdir && ( 37696c5ddc4Srjs umask $mkdir_umask && 37796c5ddc4Srjs $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 37896c5ddc4Srjs ) 37996c5ddc4Srjs then : 38096c5ddc4Srjs else 38196c5ddc4Srjs 38296c5ddc4Srjs # The umask is ridiculous, or mkdir does not conform to POSIX, 38396c5ddc4Srjs # or it failed possibly due to a race condition. Create the 38496c5ddc4Srjs # directory the slow way, step by step, checking for races as we go. 38596c5ddc4Srjs 38696c5ddc4Srjs case $dstdir in 38796c5ddc4Srjs /*) prefix='/';; 38896c5ddc4Srjs -*) prefix='./';; 38996c5ddc4Srjs *) prefix='';; 39096c5ddc4Srjs esac 39196c5ddc4Srjs 39296c5ddc4Srjs eval "$initialize_posix_glob" 39396c5ddc4Srjs 39496c5ddc4Srjs oIFS=$IFS 39596c5ddc4Srjs IFS=/ 39696c5ddc4Srjs $posix_glob set -f 39796c5ddc4Srjs set fnord $dstdir 39896c5ddc4Srjs shift 39996c5ddc4Srjs $posix_glob set +f 40096c5ddc4Srjs IFS=$oIFS 40196c5ddc4Srjs 40296c5ddc4Srjs prefixes= 40396c5ddc4Srjs 40496c5ddc4Srjs for d 40596c5ddc4Srjs do 40696c5ddc4Srjs test -z "$d" && continue 40796c5ddc4Srjs 40896c5ddc4Srjs prefix=$prefix$d 40996c5ddc4Srjs if test -d "$prefix"; then 41096c5ddc4Srjs prefixes= 41196c5ddc4Srjs else 41296c5ddc4Srjs if $posix_mkdir; then 41396c5ddc4Srjs (umask=$mkdir_umask && 41496c5ddc4Srjs $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 41596c5ddc4Srjs # Don't fail if two instances are running concurrently. 41696c5ddc4Srjs test -d "$prefix" || exit 1 41796c5ddc4Srjs else 41896c5ddc4Srjs case $prefix in 41996c5ddc4Srjs *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 42096c5ddc4Srjs *) qprefix=$prefix;; 42196c5ddc4Srjs esac 42296c5ddc4Srjs prefixes="$prefixes '$qprefix'" 42396c5ddc4Srjs fi 42496c5ddc4Srjs fi 42596c5ddc4Srjs prefix=$prefix/ 42696c5ddc4Srjs done 42796c5ddc4Srjs 42896c5ddc4Srjs if test -n "$prefixes"; then 42996c5ddc4Srjs # Don't fail if two instances are running concurrently. 43096c5ddc4Srjs (umask $mkdir_umask && 43196c5ddc4Srjs eval "\$doit_exec \$mkdirprog $prefixes") || 43296c5ddc4Srjs test -d "$dstdir" || exit 1 43396c5ddc4Srjs obsolete_mkdir_used=true 43496c5ddc4Srjs fi 43596c5ddc4Srjs fi 43696c5ddc4Srjs fi 43796c5ddc4Srjs 43896c5ddc4Srjs if test -n "$dir_arg"; then 43996c5ddc4Srjs { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 44096c5ddc4Srjs { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 44196c5ddc4Srjs { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 44296c5ddc4Srjs test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 44396c5ddc4Srjs else 44496c5ddc4Srjs 44596c5ddc4Srjs # Make a couple of temp file names in the proper directory. 44696c5ddc4Srjs dsttmp=$dstdir/_inst.$$_ 44796c5ddc4Srjs rmtmp=$dstdir/_rm.$$_ 44896c5ddc4Srjs 44996c5ddc4Srjs # Trap to clean up those temp files at exit. 45096c5ddc4Srjs trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 45196c5ddc4Srjs 45296c5ddc4Srjs # Copy the file name to the temp name. 45396c5ddc4Srjs (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 45496c5ddc4Srjs 45596c5ddc4Srjs # and set any options; do chmod last to preserve setuid bits. 45696c5ddc4Srjs # 45796c5ddc4Srjs # If any of these fail, we abort the whole thing. If we want to 45896c5ddc4Srjs # ignore errors from any of these, just make sure not to ignore 45996c5ddc4Srjs # errors from the above "$doit $cpprog $src $dsttmp" command. 46096c5ddc4Srjs # 46196c5ddc4Srjs { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 46296c5ddc4Srjs { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 46396c5ddc4Srjs { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 46496c5ddc4Srjs { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 46596c5ddc4Srjs 46696c5ddc4Srjs # If -C, don't bother to copy if it wouldn't change the file. 46796c5ddc4Srjs if $copy_on_change && 46896c5ddc4Srjs old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 46996c5ddc4Srjs new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 47096c5ddc4Srjs 47196c5ddc4Srjs eval "$initialize_posix_glob" && 47296c5ddc4Srjs $posix_glob set -f && 47396c5ddc4Srjs set X $old && old=:$2:$4:$5:$6 && 47496c5ddc4Srjs set X $new && new=:$2:$4:$5:$6 && 47596c5ddc4Srjs $posix_glob set +f && 47696c5ddc4Srjs 47796c5ddc4Srjs test "$old" = "$new" && 47896c5ddc4Srjs $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 47996c5ddc4Srjs then 48096c5ddc4Srjs rm -f "$dsttmp" 48196c5ddc4Srjs else 48296c5ddc4Srjs # Rename the file to the real destination. 48396c5ddc4Srjs $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 48496c5ddc4Srjs 48596c5ddc4Srjs # The rename failed, perhaps because mv can't rename something else 48696c5ddc4Srjs # to itself, or perhaps because mv is so ancient that it does not 48796c5ddc4Srjs # support -f. 48896c5ddc4Srjs { 48996c5ddc4Srjs # Now remove or move aside any old file at destination location. 49096c5ddc4Srjs # We try this two ways since rm can't unlink itself on some 49196c5ddc4Srjs # systems and the destination file might be busy for other 49296c5ddc4Srjs # reasons. In this case, the final cleanup might fail but the new 49396c5ddc4Srjs # file should still install successfully. 49496c5ddc4Srjs { 49596c5ddc4Srjs test ! -f "$dst" || 49696c5ddc4Srjs $doit $rmcmd -f "$dst" 2>/dev/null || 49796c5ddc4Srjs { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 49896c5ddc4Srjs { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 49996c5ddc4Srjs } || 50096c5ddc4Srjs { echo "$0: cannot unlink or rename $dst" >&2 50196c5ddc4Srjs (exit 1); exit 1 50296c5ddc4Srjs } 50396c5ddc4Srjs } && 50496c5ddc4Srjs 50596c5ddc4Srjs # Now rename the file to the real destination. 50696c5ddc4Srjs $doit $mvcmd "$dsttmp" "$dst" 50796c5ddc4Srjs } 50896c5ddc4Srjs fi || exit 1 50996c5ddc4Srjs 51096c5ddc4Srjs trap '' 0 51196c5ddc4Srjs fi 51296c5ddc4Srjsdone 51396c5ddc4Srjs 51496c5ddc4Srjs# Local variables: 51596c5ddc4Srjs# eval: (add-hook 'write-file-hooks 'time-stamp) 51696c5ddc4Srjs# time-stamp-start: "scriptversion=" 51796c5ddc4Srjs# time-stamp-format: "%:y-%02m-%02d.%02H" 51896c5ddc4Srjs# time-stamp-time-zone: "UTC" 51996c5ddc4Srjs# time-stamp-end: "; # UTC" 52096c5ddc4Srjs# End: 52196c5ddc4Srjs