fastboot $* getvar product 2>&1 | grep -E "^product: *selene$|^product: *eos$"
if [ $? -ne 0 ] ; then echo "error : Missmatching image and device"; exit 1; fi

if [ -e $(dirname $0)/images/anti_version.txt ]; then
CURRENT_ANTI_VER=`cat $(dirname $0)/images/anti_version.txt`
fi
if [ -z "$CURRENT_ANTI_VER" ]; then CURRENT_ANTI_VER=0; fi
ver=`fastboot $* getvar anti 2>&1 | grep -oP "anti: \K[0-9]+"`
if [ -z "$ver" ]; then ver=0; fi
if [ $ver -gt $CURRENT_ANTI_VER ]; then echo "Current device antirollback version is greater than this pakcage"; exit 1; fi

fastboot $* erase boot
if [ $? -ne 0 ] ; then echo "Erase boot error"; exit 1; fi
fastboot $* flash preloader_a `dirname $0`/images/preloader_selene.bin
if [ $? -ne 0 ] ; then echo "Flash preloader_a error"; exit 1; fi
fastboot $* flash lk_a `dirname $0`/images/lk.img
if [ $? -ne 0 ] ; then echo "Flash lk_a error"; exit 1; fi
#fastboot $* flash efuse `dirname $0`/images/efuse.img
#if [ $? -ne 0 ] ; then echo "Flash efuse error"; exit 1; fi
fastboot $* flash logo_a `dirname $0`/images/logo.bin
if [ $? -ne 0 ] ; then echo "Flash logo_a error"; exit 1; fi
fastboot $* flash tee_a `dirname $0`/images/tee.img
if [ $? -ne 0 ] ; then echo "Flash tee_a error"; exit 1; fi
fastboot $* flash scp_a `dirname $0`/images/scp.img
if [ $? -ne 0 ] ; then echo "Flash scp_a error"; exit 1; fi
fastboot $* flash sspm_a `dirname $0`/images/sspm.img
if [ $? -ne 0 ] ; then echo "Flash sspm_a error"; exit 1; fi
fastboot $* flash super `dirname $0`/images/super.img
if [ $? -ne 0 ] ; then echo "Flash super error"; exit 1; fi
fastboot $* flash rescue `dirname $0`/images/rescue.img
if [ $? -ne 0 ] ; then echo "Flash rescue error"; exit 1; fi
fastboot $* flash dtbo_a `dirname $0`/images/dtbo.img
if [ $? -ne 0 ] ; then echo "Flash dtbo_a error"; exit 1; fi
fastboot $* flash vbmeta_a `dirname $0`/images/vbmeta.img
if [ $? -ne 0 ] ; then echo "Flash vbmeta_a error"; exit 1; fi
fastboot $* flash spmfw_a `dirname $0`/images/spmfw.img
if [ $? -ne 0 ] ; then echo "Flash spmfw_a error"; exit 1; fi
fastboot $* flash md1img_a `dirname $0`/images/md1img.img
if [ $? -ne 0 ] ; then echo "Flash md1img_a error"; exit 1; fi
fastboot $* flash vbmeta_system_a `dirname $0`/images/vbmeta_system.img
if [ $? -ne 0 ] ; then echo "Flash vbmeta_system_a error"; exit 1; fi
fastboot $* flash vbmeta_vendor_a `dirname $0`/images/vbmeta_vendor.img
if [ $? -ne 0 ] ; then echo "Flash vbmeta_vendor_a error"; exit 1; fi
fastboot $* flash cust `dirname $0`/images/cust.img
if [ $? -ne 0 ] ; then echo "Flash cust error"; exit 1; fi
fastboot $* flash userdata `dirname $0`/images/userdata.img
if [ $? -ne 0 ] ; then echo "Flash userdata error"; exit 1; fi
fastboot $* flash boot_a `dirname $0`/images/boot.img
if [ $? -ne 0 ] ; then echo "Flash boot_a error"; exit 1; fi
fastboot $* erase misc
if [ $? -ne 0 ] ; then echo "Erase misc error"; exit 1; fi
fastboot $* erase metadata
if [ $? -ne 0 ] ; then echo "Erase metadata error"; exit 1; fi
fastboot $* erase md_udc
if [ $? -ne 0 ] ; then echo "Erase md_udc error"; exit 1; fi
fastboot $* oem cdms
fastboot $* reboot
if [ $? -ne 0 ] ; then echo "Reboot error"; exit 1; fi
