38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# install - install a program, script, or datafile
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# This comes from X11R5 (mit/util/scripts/install.sh).
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Copyright 1991 by the Massachusetts Institute of Technology
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Permission to use, copy, modify, distribute, and sell this software and its
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# documentation for any purpose is hereby granted without fee, provided that
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# the above copyright notice appear in all copies and that both that
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# copyright notice and this permission notice appear in supporting
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# documentation, and that the name of M.I.T. not be used in advertising or
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# publicity pertaining to distribution of the software without specific,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# written prior permission. M.I.T. makes no representations about the
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# suitability of this software for any purpose. It is provided "as is"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# without express or implied warranty.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Calling this script install-sh is preferred over install.sh, to prevent
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# `make' implicit rules from creating a file called install from it
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# when there is no Makefile.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# This script is compatible with the BSD install script, but was written
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# from scratch. It can only install one file at a time, a restriction
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# shared with many OS's install programs.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# set DOITPROG to echo to test this script
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Don't use :- since 4.3BSD and earlier shells don't like it.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# put in absolute paths if you don't have them in your path; or use env. vars.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncwhile [ x"$1" != x ]; do
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *) if [ x"$src" = x ]
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync # this colon is to work around a 386BSD /bin/sh bug
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncif [ x"$src" = x ]
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync echo "install: no input file specified"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncif [ x"$dir_arg" != x ]; then
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ -d $dst ]; then
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# might cause directories to be created, which would be especially bad
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# if $src (and thus $dsttmp) contains '*'.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync echo "install: $src does not exist"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ x"$dst" = x ]
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync echo "install: no destination specified"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# If destination is a directory, append the input filename; if your system
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# does not like double slashes in filenames, you may need to add some logic
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync## this sed command emulates the dirname command
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncdstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Make sure that the destination directory exists.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# this part is taken from Noah Friedman's mkinstalldirs script
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Skip lots of stat calls in the usual case.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncif [ ! -d "$dstdir" ]; then
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Some sh's can't handle IFS=/ for some reason.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncset - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ ! -d "${pathcomp}" ] ;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncif [ x"$dir_arg" != x ]
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# If we're going to rename the final executable, determine the name now.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# don't allow the sed command to completely eliminate the filename
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ x"$dstfile" = x ]
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Make a temp file name in the proper directory.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Move or copy the file name to the temp name
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# and set any options; do chmod last to preserve setuid bits
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# If any of these fail, we abort the whole thing. If we want to
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# ignore errors from any of these, just make sure not to ignore
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# errors from the above "$doit $instcmd $src $dsttmp" command.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Now rename the file to the real destination.