install-sh revision ef421f66f47224a42073deaf087378c5d0c9952e
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# $NetBSD: install-sh.in,v 1.4 2007/07/12 18:32:50 jlam Exp $
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# This script now also installs multiple files, but might choke on installing
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# multiple files with spaces in the file names.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# install - install a program, script, or datafile
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# This comes from X11R5 (mit/util/scripts/install.sh).
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Copyright 1991 by the Massachusetts Institute of Technology
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Permission to use, copy, modify, distribute, and sell this software and its
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# documentation for any purpose is hereby granted without fee, provided that
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# the above copyright notice appear in all copies and that both that
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# copyright notice and this permission notice appear in supporting
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# documentation, and that the name of M.I.T. not be used in advertising or
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# publicity pertaining to distribution of the software without specific,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# written prior permission. M.I.T. makes no representations about the
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# suitability of this software for any purpose. It is provided "as is"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# without express or implied warranty.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Calling this script install-sh is preferred over install.sh, to prevent
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# `make' implicit rules from creating a file called install from it
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# when there is no Makefile.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# This script is compatible with the BSD install script, but was written
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# from scratch.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# set DOITPROG to echo to test this script
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Don't use :- since 4.3BSD and earlier shells don't like it.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# put in absolute paths if you don't have them in your path; or use env. vars.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntwhile [ x"$1" != x ]; do
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *) if [ x"$msrc" = x ]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ ! -d "$dst" ]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo "install: destination is not a directory"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntif [ x"$msrc" = x ]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo "install: no destination specified"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntif [ x"$dir_arg" != x ]; then
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Waiting for this to be detected by the "$instcmd $srcarg $dsttmp" command
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# might cause directories to be created, which would be especially bad
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# if $src (and thus $dsttmp) contains '*'.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt elif [ -d "$srcarg" ]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo "install: $srcarg: not a regular file"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo "install: $srcarg does not exist"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# If destination is a directory, append the input filename; if your system
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# does not like double slashes in filenames, you may need to add some logic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt## this sed command emulates the dirname command
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntdstdir=`echo "$dstarg" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Make sure that the destination directory exists.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# this part is taken from Noah Friedman's mkinstalldirs script
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Skip lots of stat calls in the usual case.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntif [ ! -d "$dstdir" ]; then
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Some sh's can't handle IFS=/ for some reason.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntset - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ ! -d "${pathcomp}" ] ;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ x"$chowncmd" != x ]; then $doit $chowncmd "${pathcomp}"; else true ; fi &&
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "${pathcomp}"; else true ; fi &&
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ x"$pathcompchmodcmd" != x ]; then $doit $pathcompchmodcmd "${pathcomp}"; else true ; fi
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ x"$dir_arg" != x ]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ -d "$dstarg" ]; then
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dstarg"; else true ; fi &&
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dstarg"; else true ; fi &&
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dstarg"; else true ; fi
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ x"$dstisfile" = x ]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Make a temp file name in the proper directory.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Make a backup file name in the proper directory.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt $awkprog -v bname="$dstfinal" -v fmt="$suffixfmt" '
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt sfx = sprintf(fmt, cnt++);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt name = bname sfx;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt } while (system("test -f " name) == 0);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Move or copy the file name to the temp name
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# and set any options; do chmod last to preserve setuid bits
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# If any of these fail, we abort the whole thing. If we want to
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# ignore errors from any of these, just make sure not to ignore
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# errors from the above "$doit $instcmd $src $dsttmp" command.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else true;fi &&
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else true;fi &&
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ x"$stripcmd" != x ]; then $doit $stripcmd $stripflags "$dsttmp"; else true;fi &&
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else true;fi &&
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Now rename the file to the real destination.