#!/bin/bash

export DIST=$1
export ARCH=$2
export ISO_NAME=$3

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

mkdir -pv ${WORK_DIR}/deepin-cd/deepin/${DEBVERSION}/${CODENAME}/
cat > ${WORK_DIR}/deepin-cd/deepin/${DEBVERSION}/${CODENAME}/CONF.sh << EOF

if [ "\$DEBIAN_CD_CONF_SOURCED" = true ]; then
	return 0
fi

unset NONFREE           || true
unset CONTRIB           || true
unset EXTRANONFREE      || true
unset LOCAL             || true
unset LOCALDEBS         || true
unset SECURITY          || true
unset PROPOSED_UPDATES  || true
unset BOOTDIR           || true
unset SYMLINK           || true
unset COPYLINK          || true
unset MKISOFS           || true
unset MKISOFS_OPTS      || true
unset ISOLINUX          || true
unset EXCLUDE           || true
unset NORECOMMENDS      || true
unset NOSUGGESTS        || true
unset IMAGESUMS         || true
unset JIGDOTEMPLATEURL  || true
unset JIGDOFALLBACKURLS || true
unset JIGDOINCLUDEURLS  || true
unset JIGDOSCRIPT       || true
unset JIGDO_OPTS        || true
unset PUBLISH_URL       || true
unset PUBLISH_PATH      || true
unset UDEB_INCLUDE      || true
unset UDEB_EXCLUDE      || true
unset BASE_INCLUDE      || true
unset BASE_EXCLUDE      || true
unset INSTALLER_CD      || true
unset MAXCDS            || true
unset MAXISOS           || true
unset MAXJIGDOS         || true
unset SPLASHPNG         || true
unset OMIT_MANUAL       || true
unset OMIT_RELEASE_NOTES || true
unset OMIT_DOC_TOOLS     || true
unset OUTFILE            || true
unset MAX_PKG_SIZE       || true
unset DEBOOTSTRAP_OPTS   || true
unset ARCHIVE_KEYRING_PACKAGE || true
unset ARCHIVE_KEYRING_FILE    || true

export BASEDIR=${WORK_DIR}/deepin-cd

export CDNAME=${CDNAME}

export CODENAME=${CODENAME}

if [ -z "\$DI_CODENAME" ]; then
	export DI_CODENAME=${DI_CODENAME}
fi

export DEBVERSION=${DEBVERSION}

export OFFICIAL=${OFFICIAL}

if [ -z "\$ARCHES" ]; then
	CPU=`dpkg-architecture -qDEB_HOST_ARCH_CPU 2>/dev/null || true`
	if [ -z "\$CPU" ]; then
		CPU=`dpkg-architecture -qDEB_HOST_ARCH`
	fi
	KERNEL=`dpkg-architecture -qDEB_HOST_ARCH_OS 2>/dev/null || true`
	if [ -z "\$KERNEL" ]; then
		KERNEL=linux
	fi
	if [ \$KERNEL = linux ] ; then
		ARCHES=\$CPU
	else
		ARCHES="\$KERNEL-\$CPU"
	fi
	export ARCHES
fi

export MIRROR=${LOCAL_MIRROR}
export TDIR=\$BASEDIR/build/$DEBVERSION
export OUT=\$BASEDIR/output/$DEBVERSION
export APTTMP=\$TDIR/apt
export SPLASHPNG="${WORK_DIR}/deepin-cd/deepin/${DEBVERSION}/${CODENAME}/splash.png"
export COPYLINK=1
export NONFREE=1
export CONTRIB=1
export FORCE_FIRMWARE=1

export i386_MKISOFS="xorriso"
export i386_MKISOFS_OPTS="-as mkisofs -r -checksum_algorithm_iso md5,sha1,sha256,sha512"
export amd64_MKISOFS="xorriso"
export amd64_MKISOFS_OPTS="-as mkisofs -r -checksum_algorithm_iso md5,sha1,sha256,sha512"

export ISOLINUX=1

export VERBOSE_MAKE=1

ATTEMPT_FALLBACK=yes

export IMAGESUMS=1

export MAXISOS=1
export MAXJIGDOS=0
export DESKTOP=mate
export MAXCDS=1
export OMIT_MANUAL=1
export OMIT_RELEASE_NOTES=1
export OMIT_DOC_TOOLS=1

case "\$OFFICIAL" in
    "Official")
	export OFFICIAL_VAL=2
	;;
    "Official Beta")
	export OFFICIAL_VAL=1
	;;
    *)
	export OFFICIAL_VAL=0
	;;
esac

export OUTFILE=${OUTFILE}
EOF
