#!/bin/sh
#
# $MidnightBSD: src/etc/rc.d/firstboot,v 1.4 2008/10/17 17:20:42 laffer1 Exp $

# PROVIDE: firstboot
# REQUIRE: NETWORKING cleanvar
# KEYWORD: nojail

. /etc/rc.subr

name="firstboot"
rcvar=
start_cmd="firstboot_start"

firstboot_start()
{
	local lsuffix
	local red
	local yellow
	local receipt

	lsuffix="\e[0m"
	red="\e[1;31;40m"
	yellow="\e[1;33;40m"
	receipt="/etc/fbreceipt"

	if [ ! -f ${receipt} ]; then
		echo -e "\r${red}MidnightBSD FirstBoot Configuration${lsuffix}"
		echo "This utility requires an active Internet connection."

		echo -e "\r${yellow}Would you like to report your install via bsdstats? (yes or no)${lsuffix}"
		read installbstat
		if [ ${installbstat} = "yes" ]; then
			if [ ! -f /usr/local/etc/rc.d/bsdstats.sh ]; then
				/sbin/ipfw disable firewall
				/usr/sbin/pkg_add -r bsdstats
				/sbin/ipfw enable firewall
			fi
			echo "bsdstats_enable=\"YES\"" >> /etc/rc.conf
		fi

		echo -e "\r${yellow}Do you wish to enable a graphical environment? (yes or no)${lsuffix}"
		read installgui

		if [ ${installgui} = "yes" ]; then
			echo -e "\r${red}Installing Graphical User Interface${lsuffix}"
#			KDE CASE
			if [ -f /usr/local/bin/kdm ]; then
				echo "KDE detected"
				echo "ttyv8 \"/usr/local/bin/kdm -nodaemon\" xterm on secure" >> /etc/ttys
			else
#			GNUSTEP/WindowMaker/Slim
				/sbin/ipfw disable firewall
				/usr/sbin/pkg_add -r gnustep
				/usr/sbin/pkg_add -r slim
				/usr/sbin/pkg_add -r windowmaker
				/sbin/ipfw enable firewall
				echo "slim_enable=\"YES\"" >> /etc/rc.conf
			fi
			echo "Please restart to enable graphical login."
			echo -e "\r${yellow}Done.${lsuffix}"
		else
			echo "To run this utility again, rm ${receipt} and restart."
		fi
		touch ${receipt}
	fi
}

load_rc_config $name
run_rc_command "$1"
