#!/bin/sh

# hack for lxc
IP=`ip route get 1.1.1.1 | sed -n -e's/.*src //; s/ .*//; p; q'`
echo "IP address is $IP"

HOSTNAME=`cat /etc/hosts| grep '127.0.1.1' | awk '{print $NF; exit}'`
echo "Hostname was: $HOSTNAME"

if [ -z $HOSTNAME ]; then
    HOSTNAME=autopkgtest
    hostname $HOSTNAME
    echo $HOSTNAME > /etc/hostname
fi

echo "$IP $HOSTNAME.debci $HOSTNAME" >> /etc/hosts

echo "/etc/hosts now has:"
cat /etc/hosts

/usr/sbin/setup-ds --silent -- \
	General.FullMachineName=$HOSTNAME.debci\
	General.SuiteSpotUserID=dirsrv\
	General.SuiteSpotGroup=dirsrv\
	slapd.ServerPort=1389\
	slapd.ServerIdentifier=debci\
	slapd.Suffix=dc=example,dc=com\
	slapd.RootDN="cn=Directory Manager"\
	slapd.RootDNPwd=Secret123

