#!/bin/sh
#
# This script installs a given file in a given directory with a given
# permission.  The first argument is the name of the file (assumed to
# be in the current directory), the second is the name of the
# directory into which it should be installed, and the third is the
# octal number for the new permission.  If the file already exists in
# the target directory, it is first removed.  Then the file is copied
# and the permission is set.

if test ${1}"" = "" ; then
    echo "no source file given to suif-install" 1>&2
    exit 1
fi

if test ${2}"" = "" ; then
    echo "no destination given to suif-install" 1>&2
    exit 1
fi

if test ${3}"" = "" ; then
    echo "no permission setting given to suif-install" 1>&2
    exit 1
fi

rm -f ${2}/${1}~~~

cp ${1} ${2}/${1}~~~
if test ${?} != 0 ; then
    echo "unable to copy -- suif-install failed" 1>&2
    rm -f ${2}/${1}~~~
    exit 1
fi

chmod ${3} ${2}/${1}~~~
if test ${?} != 0 ; then
    echo "unable to chmod -- suif-install failed" 1>&2
    rm -f ${2}/${1}~~~
    exit 1
fi

mv -f ${2}/${1}~~~ ${2}/${1}
if test ${?} != 0 ; then
    echo "unable to mv -- suif-install failed" 1>&2
    rm -f ${2}/${1}~~~
    exit 1
fi

exit 0
