#!/bin/sh
#
#   "SystemImager" 
#
#   Copyright (C) 1999-2004 Brian Elliott Finley 
#
#   $Id: rcS 3268 2005-11-22 14:25:38Z 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>
#
#   2004.03.24  Brian Elliott Finley
#   - get entire scripts directory at once, whether using rsync or multicast
#   2004.04.02  Brian Elliott Finley
#   - tmpfs_watcher must start after boel_binaries
#   2004.04.14  Brian Elliott Finley
#   - add pre-install script support at Rick Bradshaw's request
#   2004.06.04  Brian Elliott Finley
#   - add support for SCRIPTNAME as a pre-boot variable
#   - improve some of the "these settings override those settings logic"
#   2004.06.04  Brian Elliott Finley
#   - add support for SCRIPTNAME as a pre-boot variable
#

#set -x         # can be uncommented for debug purposes

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

#################################################################################
#
#   main
#
switch_root_to_tmpfs

mount_proc

mount_dev_on_devfs

# this must be here to avoid read only fs errors, or other ugly stuff. -BEF-
# this is no longer needed to use UYOK features. -AR-
# check_version

get_arch

adjust_arch

ifconfig_loopback

load_my_modules

# 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_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
#
#################################################################################

exit 0

