#!/bin/bash

set -x

if [ -e "/usr/lib/isobuilder/CONF.sh" ];then
	source /usr/lib/isobuilder/CONF.sh
elif [ -e "./CONF.sh" ];then
	source ./CONF.sh
else
	echo "CONF.sh is not exist"
	exit 0
fi

case ${ISO_TYPE} in 
	cd)
		export DISKTYPE="CD"
		export TASK="Deepin-CD"
	;;
	dvd)
		export DISKTYPE="DVD"
		export TASK="Deepin-DVD"
	;;
	*) 
		echo "unkownn options"
		exit 0
	;;
esac
	

mkdir -pv ${WORK_DIR}/deepin-cd/deepin/${DEBVERSION}/${CODENAME}

cat > ${WORK_DIR}/deepin-cd/deepin/${DEBVERSION}/${CODENAME}/build.sh << EOF
#!/bin/bash
set -x

export DISKINFO_DISTRO=${DISKINFO_DISTRO}

#BASEDIR=\$(dirname \$(dirname \$(dirname \$(dirname \$(readlink -f \$(which \$0))))))

BASEDIR=${WORK_DIR}/deepin-cd
pushd ${WORK_DIR}/deepin-cd

export CF=\$BASEDIR/deepin/${DEBVERSION}/${DIST}/CONF.sh
. \$CF
export DEBIAN_CD_CONF_SOURCED=true
export DI_DIR=${DI_DIR}

ARCHES=${ARCH}

export DISKTYPE=${DISKTYPE}
export TASK=${TASK}

./build.sh \$ARCHES
EOF
