#!/bin/sh

# -----------------------------------------
# ----- web server instalation v.0.1 ------
# ----- http://www.freebsdonline.com ------------
# ---------------------------
# -----------------------------------------
# Description: cvsup kernel and base, compile kernel

# define variables
SERVER_NAME="WEBSERVER"

# install cvsup package
pkg_add -r cvsup-without-gui >>/tmp/install.log 2>&1
#rehash

# configurare cvsup
cp /usr/share/examples/cvsup/cvs-supfile cvs-supfile

echo '# ------------- cvs-supfile --------------' > cvs-supfile
echo '*default host=cvsup12.FreeBSD.org' >>cvs-supfile
echo '*default base=/usr' >>cvs-supfile
echo '*default prefix=/usr' >>cvs-supfile
echo '*default release=cvs' >>cvs-supfile
echo '*default delete use-rel-suffix' >>cvs-supfile
echo '*default tag=RELENG_6_2' >>cvs-supfile
echo '*default compress' >>cvs-supfile
echo 'src-all' >>cvs-supfile
echo 'ports-all tag=.' >>cvs-supfile
echo '# ------------ end cvs-supfile ----------' >>cvs-supfile

# starting cvsup process
/usr/local/bin/cvsup -L2 cvs-supfile >>/tmp/install.log 2>&1
echo "Your sources are syncronized!"

# copy makefile
cp configs/make.conf /etc/make.conf >>/tmp/install.log 2>&1

# configure kernel
cp configs/SERVER /usr/src/sys/i386/conf/$SERVER_NAME >>/tmp/install.log 2>&1
echo "ident $SERVER_NAME" >>/usr/src/sys/i386/conf/$SERVER_NAME

# rebuild kernel and world
cd / >>/tmp/install.log 2>&1
mergemaster -pai >>/tmp/install.log 2>&1
cd /usr/src >>/tmp/install.log 2>&1
make -j2 buildworld >>/tmp/install.log 2>&1
make -j2 buildkernel KERNCONF=$SERVER_NAME >>/tmp/install.log 2>&1
make installkernel KERNCONF=$SERVER_NAME >>/tmp/install.log 2>&1
cd / >>/tmp/install.log 2>&1
mergemaster -ai >>/tmp/install.log 2>&1

# set firewall and then reboot
echo "firewall_enable="YES" >>/etc/rc.conf
echo "firewall_type="OPEN" >>/etc/rc.conf

echo "Reboot your sistem!"


