#!/bin/sh

TARGETDIR=$1

echo ">>>$TARGETDIR<<<"

BUILD=`cat ../GfA/board/GfA/Display001/BUILD`
BUILDDATE=`date +"%Y-%m-%d %H:%M"`
BUILD=$((BUILD+1))
echo $BUILD > ../GfA/board/GfA/Display001/BUILD

chmod 600  ../GfA/board/GfA/Display001/rootfs/root/.ssh/id*
cp -a ../GfA/board/GfA/Display001/rootfs/* $TARGETDIR/
cp -v output/staging/usr/bin/locale $TARGETDIR/usr/bin/
mkdir -p $TARGETDIR/usr/share/i18n
cp -a output/staging/usr/share/i18n/* $TARGETDIR/usr/share/i18n

# Dienste auf Manuell stellen
SERVICE=S80dhcp-relay
NSERVICE=M80dhcp-relay
if [ -f $TARGETDIR/etc/init.d/$SERVICE ]
then
	rm $TARGETDIR/etc/init.d/$NSERVICE
	mv $TARGETDIR/etc/init.d/$SERVICE $TARGETDIR/etc/init.d/$NSERVICE
fi

SERVICE=S80dhcp-server
NSERVICE=M80dhcp-server
if [ -f $TARGETDIR/etc/init.d/$SERVICE ]
then
	rm $TARGETDIR/etc/init.d/$NSERVICE
	mv $TARGETDIR/etc/init.d/$SERVICE $TARGETDIR/etc/init.d/$NSERVICE
fi

SERVICE=S50postgresql
NSERVICE=M50postgresql
if [ -f $TARGETDIR/etc/init.d/$SERVICE ]
then
	rm $TARGETDIR/etc/init.d/$NSERVICE
	mv $TARGETDIR/etc/init.d/$SERVICE $TARGETDIR/etc/init.d/$NSERVICE
fi

SERVICE=S97mysqld
NSERVICE=M97mysqld
if [ -f $TARGETDIR/etc/init.d/$SERVICE ]
then
	rm $TARGETDIR/etc/init.d/$NSERVICE
	mv $TARGETDIR/etc/init.d/$SERVICE $TARGETDIR/etc/init.d/$NSERVICE
fi
#------------------------------------
#-- fonts kopieren, muss noch geändert werden dass qt mit fontconfig funktioniert
mkdir -p $TARGETDIR/usr/lib/fonts
cp $TARGETDIR/usr/share/fonts/dejavu/* $TARGETDIR/usr/lib/fonts
cp $TARGETDIR/usr/share/fonts/liberation/* $TARGETDIR/usr/lib/fonts
#------------------------------------
#-- links für EGL bibliotheken herstellen
WRKDIR=`pwd`
cd $TARGETDIR/usr/lib

rm ./libEGL.so.1
rm ./libGLESv2.so.2
ln -s libEGL.so ./libEGL.so.1
ln -s libGLESv2.so ./libGLESv2.so.2

cd $WRKDIR
#------------------------------------
echo "GfA-Display001 Rel 1.0 Build $BUILD ($BUILDDATE)" > $TARGETDIR/etc/BUILD
