38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#! /bin/sh
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# install - install a program, script, or datafile
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# This comes from X11R5 (mit/util/scripts/install.sh).
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Copyright 1991 by the Massachusetts Institute of Technology
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync#
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#
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#
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
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# set DOITPROG to echo to test this script
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Don't use :- since 4.3BSD and earlier shells don't like it.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncdoit="${DOITPROG-}"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# put in absolute paths if you don't have them in your path; or use env. vars.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncmvprog="${MVPROG-mv}"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsynccpprog="${CPPROG-cp}"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncchmodprog="${CHMODPROG-chmod}"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncchownprog="${CHOWNPROG-chown}"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncchgrpprog="${CHGRPPROG-chgrp}"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncstripprog="${STRIPPROG-strip}"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncrmprog="${RMPROG-rm}"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncmkdirprog="${MKDIRPROG-mkdir}"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsynctransformbasename=""
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsynctransform_arg=""
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncinstcmd="$mvprog"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncchmodcmd="$chmodprog 0755"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncchowncmd=""
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncchgrpcmd=""
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncstripcmd=""
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncrmcmd="$rmprog -f"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncmvcmd="$mvprog"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncsrc=""
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncdst=""
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncdir_arg=""
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncwhile [ x"$1" != x ]; do
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync case $1 in
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync -c) instcmd="$cpprog"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync shift
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync continue;;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync -d) dir_arg=true
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync shift
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync continue;;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync -m) chmodcmd="$chmodprog $2"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync shift
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync shift
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync continue;;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync -o) chowncmd="$chownprog $2"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync shift
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync shift
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync continue;;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync -g) chgrpcmd="$chgrpprog $2"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync shift
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync shift
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync continue;;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync -s) stripcmd="$stripprog"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync shift
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync continue;;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync -t=*) transformarg=`echo $1 | sed 's/-t=//'`
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync shift
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync continue;;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync shift
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync continue;;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync *) if [ x"$src" = x ]
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync then
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync src=$1
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync else
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync # this colon is to work around a 386BSD /bin/sh bug
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync :
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync dst=$1
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync fi
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync shift
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync continue;;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync esac
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncdone
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncif [ x"$src" = x ]
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncthen
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync echo "install: no input file specified"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync exit 1
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncelse
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync true
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncfi
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncif [ x"$dir_arg" != x ]; then
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync dst=$src
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync src=""
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ -d $dst ]; then
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync instcmd=:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync else
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync instcmd=mkdir
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync fi
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncelse
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
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
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ -f $src -o -d $src ]
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync then
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync true
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync else
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync echo "install: $src does not exist"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync exit 1
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync fi
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ x"$dst" = x ]
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync then
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync echo "install: no destination specified"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync exit 1
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync else
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync true
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync fi
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
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
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ -d $dst ]
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync then
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync dst="$dst"/`basename $src`
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync else
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync true
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync fi
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncfi
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync## this sed command emulates the dirname command
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncdstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Make sure that the destination directory exists.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# this part is taken from Noah Friedman's mkinstalldirs script
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Skip lots of stat calls in the usual case.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncif [ ! -d "$dstdir" ]; then
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncdefaultIFS='
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync'
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncIFS="${IFS-${defaultIFS}}"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncoIFS="${IFS}"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Some sh's can't handle IFS=/ for some reason.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncIFS='%'
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncset - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncIFS="${oIFS}"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncpathcomp=''
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncwhile [ $# -ne 0 ] ; do
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync pathcomp="${pathcomp}${1}"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync shift
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ ! -d "${pathcomp}" ] ;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync then
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync $mkdirprog "${pathcomp}"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync else
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync true
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync fi
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync pathcomp="${pathcomp}/"
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncdone
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncfi
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncif [ x"$dir_arg" != x ]
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncthen
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync $doit $instcmd $dst &&
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
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
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncelse
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# If we're going to rename the final executable, determine the name now.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ x"$transformarg" = x ]
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync then
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync dstfile=`basename $dst`
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync else
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync dstfile=`basename $dst $transformbasename |
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync sed $transformarg`$transformbasename
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync fi
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# don't allow the sed command to completely eliminate the filename
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if [ x"$dstfile" = x ]
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync then
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync dstfile=`basename $dst`
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync else
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync true
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync fi
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Make a temp file name in the proper directory.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync dsttmp=$dstdir/#inst.$$#
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Move or copy the file name to the temp name
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync $doit $instcmd $src $dsttmp &&
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync trap "rm -f ${dsttmp}" 0 &&
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# and set any options; do chmod last to preserve setuid bits
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
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
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
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync# Now rename the file to the real destination.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync $doit $rmcmd -f $dstdir/$dstfile &&
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync $doit $mvcmd $dsttmp $dstdir/$dstfile
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncfi &&
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncexit 0