#!/bin/sh
#
# install-darwin.sh used to install SSWF from a .dmg
# on Mac OS/X 10.x
# Written by Alexis Wilke
#
# Copyright (c) 2004-2009 Made to Order Software Corp.
#
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and
# associated documentation files (the "Software"), to
# deal in the Software without restriction, including
# without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom
# the Software is furnished to do so, subject to the
# following conditions:
#
# The above copyright notice and this permission notice
# shall be included in all copies or substantial
# portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
# ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
# EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#


set -e

echo "This script will install SSWF on your Macintosh"
echo "It requires at least Mac OS/X 10.0 -- thought it only was"
echo "tested on Mac OS/X 10.3 at this time"
echo
echo "Note: for the installation to succeed you need to be root"
echo "      thus you need to run this script as root or use 'sudo';"
echo "      for instance:"
echo "          su"
echo "          install.sh"
echo "      or:"
echo "          sudo install.sh"
echo "      To use 'su' you need to know the root password. To use"
echo "      sudo, you need to enter your own password and have"
echo "      administrative rights."
echo
echo "If you want to proceed, type 'yes' at the prompt and then enter."
echo "For each file to be overwritten, you will be prompted for confirmation."

# You have 10 minutes to answer or it cancels
answer="no"
read -p "So (yes/[no])? " -t 600 answer

if test "$answer" != "yes"
then
	echo "WARNING: Installation aborted"
	exit 1;
fi

p=`dirname "$0"`
cd "$p/sswf-"*

# Files which already exist?
found=false
for f in `find usr`;
do
	if test -f /$f
	then
		echo $f already exists
		found=true
	fi
done
if $found
then
	echo "WARNING: some of the files to be installed already exist on your system!"
	read -p "Do you want to continue (yes/[no])? " -t 600 answer

	if test "$answer" != "yes"
	then
		echo "WARNING: Installation aborted"
		exit 1;
	fi
fi

echo "Copying from '`pwd`/usr' to '/.'"
tar -cf - usr | tar -xvf - -C /
