install-sh revision a747113422afaa29ce72d2c5ba7f0b7ea9ec2054
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff#!/bin/sh
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff#
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff# $NetBSD: install-sh.in,v 1.6 2012/01/11 13:07:31 hans Exp $
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff# This script now also installs multiple files, but might choke on installing
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff# multiple files with spaces in the file names.
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff#
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff# install - install a program, script, or datafile
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff# This comes from X11R5 (mit/util/scripts/install.sh).
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff#
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff# Copyright 1991 by the Massachusetts Institute of Technology
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff#
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff# Permission to use, copy, modify, distribute, and sell this software and its
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff# documentation for any purpose is hereby granted without fee, provided that
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff# the above copyright notice appear in all copies and that both that
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff# copyright notice and this permission notice appear in supporting
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff# documentation, and that the name of M.I.T. not be used in advertising or
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# publicity pertaining to distribution of the software without specific,
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence# written prior permission. M.I.T. makes no representations about the
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence# suitability of this software for any purpose. It is provided "as is"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# without express or implied warranty.
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff#
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# Calling this script install-sh is preferred over install.sh, to prevent
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# `make' implicit rules from creating a file called install from it
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# when there is no Makefile.
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff#
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# This script is compatible with the BSD install script, but was written
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# from scratch.
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# set DOITPROG to echo to test this script
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# Don't use :- since 4.3BSD and earlier shells don't like it.
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffdoit="${DOITPROG-}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# put in absolute paths if you don't have them in your path; or use env. vars.
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffawkprog="${AWKPROG-awk}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffmvprog="${MVPROG-mv}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffcpprog="${CPPROG-cp}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffchmodprog="${CHMODPROG-chmod}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffchownprog="${CHOWNPROG-chown}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffchgrpprog="${CHGRPPROG-chgrp}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffstripprog="${STRIPPROG-strip}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffrmprog="${RMPROG-rm}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffmkdirprog="${MKDIRPROG-mkdir}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffinstcmd="$cpprog"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffinstflags=""
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffpathcompchmodcmd="$chmodprog 755"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffchmodcmd="$chmodprog 755"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffchowncmd=""
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffchgrpcmd=""
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffstripcmd=""
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffstripflags=""
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffrmcmd="$rmprog -f"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffmvcmd="$mvprog"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffsrc=""
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffmsrc=""
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffdst=""
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffdir_arg=""
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffsuffix=""
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffsuffixfmt=""
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffwhile [ x"$1" != x ]; do
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff case $1 in
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff -b) suffix=".old"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff continue;;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff -B) suffixfmt="$2"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff continue;;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff -c) instcmd="$cpprog"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff continue;;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff -d) dir_arg=true
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff continue;;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff -m) chmodcmd="$chmodprog $2"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff continue;;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff -m*)
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff chmodcmd="$chmodprog ${1#-m}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff continue;;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff -o) chowncmd="$chownprog $2"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff continue;;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff -g) chgrpcmd="$chgrpprog $2"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff continue;;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff -s) stripcmd="$stripprog"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff continue;;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff -S) stripcmd="$stripprog"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff stripflags="-S $2 $stripflags"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff continue;;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff -p) instflags="-p"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff continue;;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff *) if [ x"$msrc" = x ]
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff then
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff msrc="$dst"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff else
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff msrc="$msrc $dst"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff fi
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff src="$dst"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff dst="$1"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff continue;;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff esac
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffdone
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffif [ x"$dir_arg" = x ]
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffthen
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff dstisfile=""
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if [ ! -d "$dst" ]
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff then
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if [ x"$msrc" = x"$src" ]
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff then
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff dstisfile=true
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff else
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff echo "install: destination is not a directory"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff exit 1
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff fi
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff fi
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffelse
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff msrc="$msrc $dst"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Grafffi
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffif [ x"$msrc" = x ]
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffthen
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff echo "install: no destination specified"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff exit 1
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Grafffi
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Grafffor srcarg in $msrc; do
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffif [ x"$dir_arg" != x ]; then
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff dstarg="$srcarg"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffelse
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff dstarg="$dst"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# Waiting for this to be detected by the "$instcmd $srcarg $dsttmp" command
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# might cause directories to be created, which would be especially bad
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# if $src (and thus $dsttmp) contains '*'.
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if [ -f "$srcarg" ]
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff then
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff doinst="$instcmd $instflags"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff elif [ -d "$srcarg" ]
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff then
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff echo "install: $srcarg: not a regular file"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff exit 1
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff elif [ "$srcarg" = "/dev/null" ]
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff then
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff doinst="$cpprog"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff else
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff echo "install: $srcarg does not exist"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff exit 1
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff fi
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# If destination is a directory, append the input filename; if your system
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# does not like double slashes in filenames, you may need to add some logic
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if [ -d "$dstarg" ]
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff then
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff dstarg="$dstarg"/`basename "$srcarg"`
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff fi
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Grafffi
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff## this sed command emulates the dirname command
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffdstdir=`echo "$dstarg" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# Make sure that the destination directory exists.
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# this part is taken from Noah Friedman's mkinstalldirs script
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# Skip lots of stat calls in the usual case.
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffif [ ! -d "$dstdir" ]; then
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael GraffdefaultIFS='
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff'
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael GraffIFS="${IFS-${defaultIFS}}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael GraffoIFS="${IFS}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff# Some sh's can't handle IFS=/ for some reason.
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael GraffIFS='%'
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffset - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael GraffIFS="${oIFS}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffpathcomp=''
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffwhile [ $# -ne 0 ] ; do
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff pathcomp="${pathcomp}${1}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff shift
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if [ ! -d "${pathcomp}" ] ;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff then
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff $doit $mkdirprog "${pathcomp}"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if [ x"$chowncmd" != x ]; then $doit $chowncmd "${pathcomp}"; else true ; fi &&
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "${pathcomp}"; else true ; fi &&
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if [ x"$pathcompchmodcmd" != x ]; then $doit $pathcompchmodcmd "${pathcomp}"; else true ; fi
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff else
1ee3b153b698e888e55dc944560c845ab6e2879aBrian Wellington true
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff fi
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff pathcomp="${pathcomp}/"
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffdone
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Grafffi
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if [ x"$dir_arg" != x ]
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff then
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if [ -d "$dstarg" ]; then
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff true
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff else
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff $doit $mkdirprog "$dstarg" &&
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dstarg"; else true ; fi &&
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dstarg"; else true ; fi &&
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dstarg"; else true ; fi
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff fi
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff else
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if [ x"$dstisfile" = x ]
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff then
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff file=$srcarg
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff else
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff file=$dst
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff fi
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff dstfile=`basename "$file"`
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff dstfinal="$dstdir/$dstfile"
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Make a backup file name in the proper directory.
case x$suffixfmt in
*%*) suffix=`echo x |
$awkprog -v bname="$dstfinal" -v fmt="$suffixfmt" '
{ cnt = 0;
do {
sfx = sprintf(fmt, cnt++);
name = bname sfx;
} while (system("test -f " name) == 0);
print sfx; }' -`;;
x) ;;
*) suffix="$suffixfmt";;
esac
dstbackup="$dstfinal$suffix"
# Move or copy the file name to the temp name
$doit $doinst $srcarg "$dsttmp" &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $stripflags "$dsttmp"; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else true;fi &&
# Now rename the file to the real destination.
if [ x"$suffix" != x ] && [ -f "$dstfinal" ]
then
$doit $mvcmd "$dstfinal" "$dstbackup"
else
$doit $rmcmd -f "$dstfinal"
fi &&
$doit $mvcmd "$dsttmp" "$dstfinal"
fi
done &&
exit 0