#! /bin/bash

fcopy -Bvr /etc/fai
fcopy -Bv /etc/fai/apt/sources.list /etc/dhcp/dhcpd.conf
fcopy -v /etc/rc.local

if [ $FAI_ACTION = "install" ]; then

    # use the same sources.list for the server itself and the clients
    cp -a $target/etc/fai/apt $target/etc/

    rm -f $target/etc/resolv.conf

    # faiserver uses its own apt cache
    ainsl -av /etc/apt/apt.conf.d/02proxy 'Acquire::http::Proxy "http://127.0.0.1:3142";'

    # create some host entries
    ainsl /etc/hosts "192.168.33.250 faiserver"  # that's me
    ainsl /etc/hosts "192.168.33.101 demohost"
    ainsl /etc/hosts "192.168.33.102 xfcehost"
    # add entries for 10 hosts called client 01 .. 10
    perl -e 'for (1..10) {printf "192.168.33.%s client%02s\n",50+$_,$_;}' >> $target/etc/hosts

    # workaround for #676883, this disables NFS v4, so the nfsroot is exported via NFS v3
    mkdir $target/srv/nfs4
    ainsl /etc/exports '/srv/nfs4  192.168.33.0/24(fsid=0,async,ro,no_subtree_check,no_root_squash)'

    # add access via apt-cacher-ng
    sed -i -e 's#http://#&localhost:3142/#' $target/etc/fai/nfsroot.conf $target/etc/fai/apt/sources.list

    # copy base file for faster building of nfsroot
    cp -p /var/tmp/base.tar.xz $target/var/tmp
fi
