a180a41bba1d50822df23fff0099e90b86638b89vboxsync#!/bin/sh
a180a41bba1d50822df23fff0099e90b86638b89vboxsync#
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# install - install a program, script, or datafile
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# This comes from X11R5 (mit/util/scripts/install.sh).
a180a41bba1d50822df23fff0099e90b86638b89vboxsync#
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# Copyright 1991 by the Massachusetts Institute of Technology
a180a41bba1d50822df23fff0099e90b86638b89vboxsync#
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# Permission to use, copy, modify, distribute, and sell this software and its
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# documentation for any purpose is hereby granted without fee, provided that
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# the above copyright notice appear in all copies and that both that
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# copyright notice and this permission notice appear in supporting
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# documentation, and that the name of M.I.T. not be used in advertising or
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# publicity pertaining to distribution of the software without specific,
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# written prior permission. M.I.T. makes no representations about the
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# suitability of this software for any purpose. It is provided "as is"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# without express or implied warranty.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync#
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# Calling this script install-sh is preferred over install.sh, to prevent
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# `make' implicit rules from creating a file called install from it
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# when there is no Makefile.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync#
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# This script is compatible with the BSD install script, but was written
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# from scratch. It can only install one file at a time, a restriction
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# shared with many OS's install programs.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# set DOITPROG to echo to test this script
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# Don't use :- since 4.3BSD and earlier shells don't like it.
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncdoit="${DOITPROG-}"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# put in absolute paths if you don't have them in your path; or use env. vars.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncmvprog="${MVPROG-mv}"
a180a41bba1d50822df23fff0099e90b86638b89vboxsynccpprog="${CPPROG-cp}"
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncchmodprog="${CHMODPROG-chmod}"
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncchownprog="${CHOWNPROG-chown}"
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncchgrpprog="${CHGRPPROG-chgrp}"
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncstripprog="${STRIPPROG-strip}"
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncrmprog="${RMPROG-rm}"
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncmkdirprog="${MKDIRPROG-mkdir}"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsynctransformbasename=""
a180a41bba1d50822df23fff0099e90b86638b89vboxsynctransform_arg=""
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncinstcmd="$mvprog"
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncchmodcmd="$chmodprog 0755"
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncchowncmd=""
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncchgrpcmd=""
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncstripcmd=""
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncrmcmd="$rmprog -f"
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncmvcmd="$mvprog"
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncsrc=""
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncdst=""
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncdir_arg=""
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncwhile [ x"$1" != x ]; do
a180a41bba1d50822df23fff0099e90b86638b89vboxsync case $1 in
a180a41bba1d50822df23fff0099e90b86638b89vboxsync -c) instcmd="$cpprog"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync shift
a180a41bba1d50822df23fff0099e90b86638b89vboxsync continue;;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync -d) dir_arg=true
a180a41bba1d50822df23fff0099e90b86638b89vboxsync shift
a180a41bba1d50822df23fff0099e90b86638b89vboxsync continue;;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync -m) chmodcmd="$chmodprog $2"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync shift
a180a41bba1d50822df23fff0099e90b86638b89vboxsync shift
a180a41bba1d50822df23fff0099e90b86638b89vboxsync continue;;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync -o) chowncmd="$chownprog $2"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync shift
a180a41bba1d50822df23fff0099e90b86638b89vboxsync shift
a180a41bba1d50822df23fff0099e90b86638b89vboxsync continue;;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync -g) chgrpcmd="$chgrpprog $2"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync shift
a180a41bba1d50822df23fff0099e90b86638b89vboxsync shift
a180a41bba1d50822df23fff0099e90b86638b89vboxsync continue;;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync -s) stripcmd="$stripprog"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync shift
a180a41bba1d50822df23fff0099e90b86638b89vboxsync continue;;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync -t=*) transformarg=`echo $1 | sed 's/-t=//'`
a180a41bba1d50822df23fff0099e90b86638b89vboxsync shift
a180a41bba1d50822df23fff0099e90b86638b89vboxsync continue;;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
a180a41bba1d50822df23fff0099e90b86638b89vboxsync shift
a180a41bba1d50822df23fff0099e90b86638b89vboxsync continue;;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync *) if [ x"$src" = x ]
a180a41bba1d50822df23fff0099e90b86638b89vboxsync then
a180a41bba1d50822df23fff0099e90b86638b89vboxsync src=$1
a180a41bba1d50822df23fff0099e90b86638b89vboxsync else
a180a41bba1d50822df23fff0099e90b86638b89vboxsync # this colon is to work around a 386BSD /bin/sh bug
a180a41bba1d50822df23fff0099e90b86638b89vboxsync :
a180a41bba1d50822df23fff0099e90b86638b89vboxsync dst=$1
a180a41bba1d50822df23fff0099e90b86638b89vboxsync fi
a180a41bba1d50822df23fff0099e90b86638b89vboxsync shift
a180a41bba1d50822df23fff0099e90b86638b89vboxsync continue;;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync esac
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncdone
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncif [ x"$src" = x ]
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncthen
a180a41bba1d50822df23fff0099e90b86638b89vboxsync echo "install: no input file specified"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync exit 1
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncelse
a180a41bba1d50822df23fff0099e90b86638b89vboxsync :
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncfi
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncif [ x"$dir_arg" != x ]; then
a180a41bba1d50822df23fff0099e90b86638b89vboxsync dst=$src
a180a41bba1d50822df23fff0099e90b86638b89vboxsync src=""
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if [ -d $dst ]; then
a180a41bba1d50822df23fff0099e90b86638b89vboxsync instcmd=:
a180a41bba1d50822df23fff0099e90b86638b89vboxsync chmodcmd=""
a180a41bba1d50822df23fff0099e90b86638b89vboxsync else
a180a41bba1d50822df23fff0099e90b86638b89vboxsync instcmd=$mkdirprog
a180a41bba1d50822df23fff0099e90b86638b89vboxsync fi
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncelse
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# might cause directories to be created, which would be especially bad
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# if $src (and thus $dsttmp) contains '*'.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if [ -f "$src" ] || [ -d "$src" ]
a180a41bba1d50822df23fff0099e90b86638b89vboxsync then
a180a41bba1d50822df23fff0099e90b86638b89vboxsync :
a180a41bba1d50822df23fff0099e90b86638b89vboxsync else
a180a41bba1d50822df23fff0099e90b86638b89vboxsync echo "install: $src does not exist"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync exit 1
a180a41bba1d50822df23fff0099e90b86638b89vboxsync fi
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if [ x"$dst" = x ]
a180a41bba1d50822df23fff0099e90b86638b89vboxsync then
a180a41bba1d50822df23fff0099e90b86638b89vboxsync echo "install: no destination specified"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync exit 1
a180a41bba1d50822df23fff0099e90b86638b89vboxsync else
a180a41bba1d50822df23fff0099e90b86638b89vboxsync :
a180a41bba1d50822df23fff0099e90b86638b89vboxsync fi
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# If destination is a directory, append the input filename; if your system
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# does not like double slashes in filenames, you may need to add some logic
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if [ -d $dst ]
a180a41bba1d50822df23fff0099e90b86638b89vboxsync then
a180a41bba1d50822df23fff0099e90b86638b89vboxsync dst="$dst"/`basename $src`
a180a41bba1d50822df23fff0099e90b86638b89vboxsync else
a180a41bba1d50822df23fff0099e90b86638b89vboxsync :
a180a41bba1d50822df23fff0099e90b86638b89vboxsync fi
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncfi
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync## this sed command emulates the dirname command
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncdstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# Make sure that the destination directory exists.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# this part is taken from Noah Friedman's mkinstalldirs script
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# Skip lots of stat calls in the usual case.
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncif [ ! -d "$dstdir" ]; then
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncdefaultIFS='
a180a41bba1d50822df23fff0099e90b86638b89vboxsync '
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncIFS="${IFS-${defaultIFS}}"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncoIFS="${IFS}"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# Some sh's can't handle IFS=/ for some reason.
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncIFS='%'
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncset - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncIFS="${oIFS}"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncpathcomp=''
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncwhile [ $# -ne 0 ] ; do
a180a41bba1d50822df23fff0099e90b86638b89vboxsync pathcomp="${pathcomp}${1}"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync shift
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if [ ! -d "${pathcomp}" ] ;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync then
a180a41bba1d50822df23fff0099e90b86638b89vboxsync $mkdirprog "${pathcomp}"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync else
a180a41bba1d50822df23fff0099e90b86638b89vboxsync :
a180a41bba1d50822df23fff0099e90b86638b89vboxsync fi
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync pathcomp="${pathcomp}/"
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncdone
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncfi
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncif [ x"$dir_arg" != x ]
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncthen
a180a41bba1d50822df23fff0099e90b86638b89vboxsync $doit $instcmd $dst &&
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else : ; fi &&
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else : ; fi &&
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else : ; fi &&
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else : ; fi
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncelse
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# If we're going to rename the final executable, determine the name now.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if [ x"$transformarg" = x ]
a180a41bba1d50822df23fff0099e90b86638b89vboxsync then
a180a41bba1d50822df23fff0099e90b86638b89vboxsync dstfile=`basename $dst`
a180a41bba1d50822df23fff0099e90b86638b89vboxsync else
a180a41bba1d50822df23fff0099e90b86638b89vboxsync dstfile=`basename $dst $transformbasename |
a180a41bba1d50822df23fff0099e90b86638b89vboxsync sed $transformarg`$transformbasename
a180a41bba1d50822df23fff0099e90b86638b89vboxsync fi
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# don't allow the sed command to completely eliminate the filename
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if [ x"$dstfile" = x ]
a180a41bba1d50822df23fff0099e90b86638b89vboxsync then
a180a41bba1d50822df23fff0099e90b86638b89vboxsync dstfile=`basename $dst`
a180a41bba1d50822df23fff0099e90b86638b89vboxsync else
a180a41bba1d50822df23fff0099e90b86638b89vboxsync :
a180a41bba1d50822df23fff0099e90b86638b89vboxsync fi
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# Make a temp file name in the proper directory.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync dsttmp=$dstdir/#inst.$$#
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# Move or copy the file name to the temp name
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync $doit $instcmd $src $dsttmp &&
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync trap "rm -f ${dsttmp}" 0 &&
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# and set any options; do chmod last to preserve setuid bits
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# If any of these fail, we abort the whole thing. If we want to
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# ignore errors from any of these, just make sure not to ignore
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# errors from the above "$doit $instcmd $src $dsttmp" command.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else :;fi &&
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else :;fi &&
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else :;fi &&
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else :;fi &&
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync# Now rename the file to the real destination.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync $doit $rmcmd -f $dstdir/$dstfile &&
a180a41bba1d50822df23fff0099e90b86638b89vboxsync $doit $mvcmd $dsttmp $dstdir/$dstfile
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncfi &&
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncexit 0