#!/bin/sh

BASEDIR=$(dirname $0)
cd $BASEDIR

chmod +x files/adb.mac
chmod +x files/fastboot.mac

ADBBINARY="adb.mac"
FASTBOOTBINARY="fastboot.mac"

cd ./files

echo 
echo
echo Connect your ZenFone 6 with your computer and prepare to UN-ROOT
echo
echo !!! DO NOT DISCONNECT USB CABLE WHILE ROOTING !!!
echo
echo
./${ADBBINARY} wait-for-devices
./${ADBBINARY} reboot bootloader
sleep 20

echo
echo
echo Unlocking bootloader ..
echo
echo
./${FASTBOOTBINARY} flash dnx dnx_fwr_ctp_a600cg.bin
./${FASTBOOTBINARY} flash ifwi ifwi_ctp_a600cg_unlock.bin
./${FASTBOOTBINARY} reboot-bootloader
sleep 20

echo
echo
echo Flash recovery with ROOT process and do the dirty job
echo The phone will be rebooted twice, please be patient ..
echo
echo
./${FASTBOOTBINARY} flash recovery recovery-unroot.img
sleep 5
./${FASTBOOTBINARY} flash update dummy.zip

./${ADBBINARY} wait-for-devices
./${ADBBINARY} reboot bootloader
sleep 20

echo
echo
echo Flash official recovery and re-lock bootloader for future OTA upgrade
echo
echo
./${FASTBOOTBINARY} flash recovery recovery-zenfone6.img
sleep 5
./${FASTBOOTBINARY} flash dnx dnx_fwr_ctp_a600cg.bin
./${FASTBOOTBINARY} flash ifwi ifwi_ctp_a600cg.bin

echo
echo
echo "All done, your ZenFone 6 is UN-ROOT :)"
echo "by shakalaca (http://23pin.logdown.com)"
echo
echo
./${FASTBOOTBINARY} reboot
