#!/system/bin/sh
OSCAM_SYSTEM=/system/oscam
OSCAM_DATA=/data/oscam
OSCAM_MOUNTPOINT=/data
OSCAM_MOUNTTED=`cat /proc/mounts | busybox awk '/\/data ext4/ {print $2}'`
echo "$OSCAM_MOUNTTED"


if [ -f /var/.camdisable ]; then
		sleep 7d
else
		if [ -f /var/.ottbox ]; then
				sleep 7d
		fi
		if [ ! -d $OSCAM_SYSTEM ]; then
				sleep 7d
		fi
		if [ "$OSCAM_MOUNTTED" == "$OSCAM_MOUNTPOINT" ]; then
				if [ -d $OSCAM_DATA ]; then
						cd $OSCAM_DATA
						sleep 1
						if [ -e /$OSCAM_DATA/oscamworks.exe ]; then
								echo "start oscam" > /dev/kmsg
								./oscamworks.exe > /dev/null
						else
								echo "start oscam(e)" > /dev/kmsg
								cp $OSCAM_SYSTEM/oscam8.exe $OSCAM_DATA/oscamworks.exe
								if [ ! -e $OSCAM_DATA/oscam.conf ]; then
									cp $OSCAM_SYSTEM/oscam.conf $OSCAM_DATA
								fi
								if [ ! -e $OSCAM_DATA/oscam.server ]; then
									cp $OSCAM_SYSTEM/oscam.server $OSCAM_DATA
								fi
								if [ ! -e $OSCAM_DATA/oscam.keys ]; then
									cp $OSCAM_SYSTEM/oscam.keys $OSCAM_DATA
								fi
								if [ ! -e $OSCAM_DATA/constant.cw ]; then
									cp $OSCAM_SYSTEM/constant.cw $OSCAM_DATA
								fi
								cp $OSCAM_SYSTEM/oscam.ac $OSCAM_DATA
								cp $OSCAM_SYSTEM/oscam.cacheex $OSCAM_DATA
								cp $OSCAM_SYSTEM/oscam.cert $OSCAM_DATA
								cp $OSCAM_SYSTEM/oscam.dvbapi $OSCAM_DATA
								cp $OSCAM_SYSTEM/oscam.guess $OSCAM_DATA
								cp $OSCAM_SYSTEM/oscam.ird $OSCAM_DATA
								cp $OSCAM_SYSTEM/oscam.provid $OSCAM_DATA
								cp $OSCAM_SYSTEM/oscam.services $OSCAM_DATA
								cp $OSCAM_SYSTEM/oscam.srvid $OSCAM_DATA
								cp $OSCAM_SYSTEM/oscam.tiers $OSCAM_DATA
								cp $OSCAM_SYSTEM/oscam.user $OSCAM_DATA
								cp $OSCAM_SYSTEM/oscam.whitelist $OSCAM_DATA
								chmod -R 777 $OSCAM_DATA
						fi
				fi
		fi
fi

