#!/bin/sh -e
echo "===========================================>"
echo "============== $TARGET_DIR ==============>"
echo "===========================================>"

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

#---Dienste auf manuell stellen
SERVICE=S97mysqld
NSERVICE=M97mysqld
if [ -f $TARGET_DIR/etc/init.d/$SERVICE ]
then
	if [ -f $TARGET_DIR/etc/init.d/$NSERVICE ]
	then
        	rm $TARGET_DIR/etc/init.d/$NSERVICE
	fi
        mv $TARGET_DIR/etc/init.d/$SERVICE $TARGET_DIR/etc/init.d/$NSERVICE
fi

SERVICE=S60openvpn
NSERVICE=M60openvpn
if [ -f $TARGET_DIR/etc/init.d/$SERVICE ]
then
	if [ -f $TARGET_DIR/etc/init.d/$NSERVICE ]
	then
        	rm $TARGET_DIR/etc/init.d/$NSERVICE
	fi
        mv $TARGET_DIR/etc/init.d/$SERVICE $TARGET_DIR/etc/init.d/$NSERVICE
fi



SERVICE=S99Display_GSM
NSERVICE=M99Display_GSM
if [ -f $TARGET_DIR/etc/init.d/$SERVICE ]
then
	if [ -f $TARGET_DIR/etc/init.d/$NSERVICE ]
	then
        	rm $TARGET_DIR/etc/init.d/$NSERVICE
	fi
        mv $TARGET_DIR/etc/init.d/$SERVICE $TARGET_DIR/etc/init.d/$NSERVICE
fi



#---sshd background start
SERVICE=S50sshd
NSERVICE=S50sshd.detach
if [ -f $TARGET_DIR/etc/init.d/$SERVICE ]
then
	if [ -f $TARGET_DIR/etc/init.d/$NSERVICE ]
	then
        	rm $TARGET_DIR/etc/init.d/$NSERVICE
	fi
        mv $TARGET_DIR/etc/init.d/$SERVICE $TARGET_DIR/etc/init.d/$NSERVICE
fi

#------- remove modules -----
TOREMOVE=lib/modules/4.19.94-rt39/kernel/drivers/net/usb/cdc_ether.ko

if [ -f "$TARGET_DIR/$TOREMOVE" ]
then 
	rm "$TARGET_DIR/$TOREMOVE"
fi	

echo "=========="
sudo chown 0:10 $TARGET_DIR/home/Administrator/startapp.sh

#----------------------------
echo "$BUILD ($BUILDDATE)" > $TARGET_DIR/etc/BUILD