#!/bin/bash

set -e

CONFDIR="/srv/fai/config"

if [ "$FAI_ACTION" == "install" ] ; then
    ## Copy the config space to the faiserver:
    echo -n "Cleaning config space ... "
    rm -rf $target/$CONFDIR
    echo "done."

    mkdir -p $target/$CONFDIR
    cp -a /var/lib/fai/config/* $target/$CONFDIR
    echo "New config space copied to faiserver."
fi
chmod 770 $target/$CONFDIR
chown root:adm $target/$CONFDIR

if [ ! -d $target/$CONFDIR/.git ] ; then
    ## Use git to track modifications of the config space:
    export HOME="/root"
    $ROOTCMD git config --global user.name  root
    $ROOTCMD git config --global user.email root@$HOSTNAME
    $ROOTCMD git config --global color.ui auto
    $ROOTCMD git init $CONFDIR
    $ROOTCMD git --git-dir=$CONFDIR/.git --work-tree=$CONFDIR add .
    $ROOTCMD git --git-dir=$CONFDIR/.git commit -m "Initial commit"
fi
