#!/bin/sh
#
#   "SystemImager" 
#
#   Copyright (C) 1999-2004 Brian Elliott Finley 
#
#   $Id: rcS 3701 2006-08-02 07:33:45Z arighi $
#
#   Others who have contributed to this code:
#       Charles C. Bennett, Jr. <ccb@acm.org>
#       Sean Dague <japh@us.ibm.com>
#       Dann Frazier <dannf@dannf.org>
#       Curtis Zinzilieta <czinzilieta@valinux.com>
#

#set -x         # can be uncommented for debug purposes

#################################################################################
#   Load functions and other variables
#
. /etc/init.d/functions
#
################################################################################

#################################################################################
#
#   main
#
{

switch_root_to_tmpfs

mount_proc

monitor_save_dmesg

mount_sys

mount_pts

get_arch

adjust_arch

ifconfig_loopback

load_my_modules

start_udevd

start_hotplug

# Need to do this prior to read_local_cfg to get last_root parameter, 
# if specified. -BEF-
variableize_kernel_append_parameters

read_kernel_append_parameters

read_local_cfg

# Re-read kernel append parameters -- we want them to override what's in 
# the local.cfg files. -BEF-
read_kernel_append_parameters

start_network
beep

ping_test

if [ ! -z $MONITOR_SERVER ]; then
    init_monitor_server
fi

start_syslogd

if [ ! -z $FLAMETHROWER_DIRECTORY_PORTBASE ]; then
    get_flamethrower_directory
fi

get_torrents_directory

get_boel_binaries_tarball
beep

tmpfs_watcher

get_scripts_directory

autodetect_hardware_and_load_modules

if [ ! -z $SSH_DOWNLOAD_URL ]; then
    echo
    echo start_ssh
    start_ssh
fi

# HOSTNAME may already be set via local.cfg -BEF-
if [ -z $HOSTNAME ]; then
    get_hostname_by_hosts_file
fi

if [ -z $HOSTNAME ]; then
    get_hostname_by_dns
fi

if [ ! -z $HOSTNAME ]; then
    echo
    echo "This hosts name is: $HOSTNAME"
fi

run_pre_install_scripts

# If none of SCRIPTNAME, HOSTNAME, or IMAGENAME is set, then we cannot proceed.
# (IMAGENAME may have been set by local.cfg).  -BEF-
if [ -z $SCRIPTNAME ] && [ -z $IMAGENAME ] && [ -z $HOSTNAME ]; then
    logmsg
    logmsg "FATAL:  None of SCRIPTNAME, IMAGENAME, or HOSTNAME were set, and I"
    logmsg "can no proceed!  (Scottish accent -- think Groundskeeper Willie)"
    logmsg
    logmsg "HOSTNAME is what most people use, and I try to determine it automatically"
    logmsg "from this hosts IP address ($IPADDR) in the following order:"
    logmsg
    logmsg "  1)  /var/lib/systemimager/scripts/hosts on your imageserver"
    logmsg "  2)  DNS"
    logmsg
    logmsg "Finally, you can explicitly set many variables pre-boot, including SCRIPTNAME,"
    logmsg "IMAGENAME, and HOSTNAME, as kernel append parameters or with a local.cfg file."
    logmsg
    shellout
fi
    
choose_autoinstall_script

write_variables
beep

run_autoinstall_script

} 2>&1 | send_monitor_stdout

#
#################################################################################

exit 0

