#! /bin/bash

# setup script that is only run once at boot time
# set up an FAI install server

set -o pipefail

echo ""
echo "Setting up the FAI install server"
echo ""
sleep 5

. /etc/fai/fai.conf
. /etc/fai/nfsroot.conf

# copy the simple examples
if [ ! -d "$FAI_CONFIGDIR/class" ]; then
    mkdir -p $FAI_CONFIGDIR
    cp -a /usr/share/doc/fai-doc/examples/simple/* $FAI_CONFIGDIR
fi

# setup network
ip link set eth0 up
dhclient eth0  # connection to the outside world (hopefully)
ip addr add 192.168.33.250/24 brd + dev eth0 # (fixed address of faiserver)
[ -x /etc/init.d/nscd ] && /etc/init.d/nscd restart

fai-setup -B /var/tmp/base.tar.xz -v 2>&1 | tee /var/log/fai-setup.log
[ $? -eq 0 ] && rm /var/tmp/base.tar.xz

# create default pxelinux boot configuration (boot from local disk)
fai-chboot -o default

echo "Log files are saved to /var/log/fai-setup.log"

# move me away
mv $0 /var/tmp
exit 0
