#!/bin/sh
#
# Copyright 2002-2005 G.U.F.I. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#  1.Redistributions of source code must retain the above copyright notice,
#    this list of conditions and the following disclaimer.
#  2.Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation 
#    and/or other materials provided with the distribution. 
#
# THIS SOFTWARE IS PROVIDED BY G.U.F.I. ``AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are
# those of the authors and should not be interpreted as representing official
# policies, either expressed or implied, of the G.U.F.I.
#
# $Id: web_installer,v 1.3 2005/05/01 18:43:31 saturnero Exp $
#
# Change thttpd.conf.sample defaults to work with BSD Installer
#

#if ( -r /var/run/thttpd.pid ) then
#    set THTTPDPID=`cat /var/run/thttpd.pid`
#    if ( `ps -p $THTTPDPID | grep "thttpd"` != "" ) then
#        kill $THTTPDPID && killall thttpd
#    endif
#endif

#sed "s/\/usr\/local\/www\/logs\/thttpd.log/\/tmp\/thttpd.log/" \
#        < /usr/local/etc/thttpd.conf.sample \
#        > /tmp/thttpd.conf1
#sed "s/chroot//" \
#        < /tmp/thttpd.conf1 \
#        > /tmp/thttpd.conf2
#sed "s/\/usr\/local\/www\/data/\/usr\/local\/www/" \
#        < /tmp/thttpd.conf2 > /tmp/thttpd.conf

#
# Start THTTPD
#
#/usr/local/sbin/thttpd -C /tmp/thttpd.conf >/dev/null &

#
# Mount needed root parts for BSD Installer
#

cd /usr/local/www
tar -cf - * | (cd /root/www; tar vfx -)

echo "Mounting /RelaxBSD/usr..."
MD_LOCAL=`mdconfig -a -t vnode -f /RelaxBSD/uzip/usr.uzip`
mount -r /dev/$MD_LOCAL.uzip /RelaxBSD/usr

echo "Mounting /RelaxBSD/var..."
MD_LOCAL=`mdconfig -a -f /RelaxBSD/uzip/var.uzip`
mount -r /dev/$MD_LOCAL.uzip /FreeSBIE/var
mount -t unionfs /.var /RelaxBSD/var

#
# Launch the backend
#
echo Lunching BSD Installer backend...
/usr/local/sbin/dfuibe_installer -o /RelaxBSD/ >/dev/null 2>&1 &

#
# Launch FireFox
#
daemon /usr/X11R6/bin/firefox "http://localhost/"
