ADB_CMD=/home/fvalverd/Android/android-sdk-linux_x86/platform-tools/adb

echo "---------------------------------------------------------------"
echo "	              Easy rooting toolkit (v1.0)"
echo "	                  UNROOTING SCRIPT"
echo "                 created by DooMLoRD"
echo "  based heavily on FlashTool scripts (by Bin4ry and Androxyde)"
echo "   Credits go to all those involved in making this possible!"
echo "---------------------------------------------------------------"
echo " [*] This script will:"
echo "     (1) unroot ur device using special script"
echo "     (2) remove Busybox and assocaited symlinks"
echo "     (3) remove SU files and assocaiated data"
echo " [*] Before u begin:"
echo "     (1) make sure u have installed adb drivers for ur device"
echo "     (2) enable \"USB DEBUGGING\""
echo "           from (Menu\Settings\Applications\Development)"
echo "     (3) enable \"UNKNOWN SOURCES\""
echo "           from (Menu\Settings\Applications)"
echo "     (4) [OPTIONAL] increase screen timeout to 10 minutes"
echo "     (5) connect USB cable to PHONE and then connect to PC"
echo "     (6) skip \"PC Companion Software\" prompt on device"
echo "---------------------------------------------------------------"

echo ""
echo "CONFIRM ALL THE ABOVE THEN"
echo "---------------------------------------------------------------"
echo "MAKE SURE THAT THE SCREEN IS UNLOCKED"
echo "and if you get Superuser prompts ACCEPT/ALLOW THEM" 
echo "ELSE THIS WILL NOT WORK"
echo "---------------------------------------------------------------"

echo ""
read -p "Press [Enter] AFTER TO CONFIRM ALL THE ABOVE..."

echo ""
echo "--- STARTING ----"
echo "--- WAITING FOR DEVICE"
$ADB_CMD wait-for-device


echo "--- TESTING FOR SU PERMISSIONS"
echo "MAKE SURE THAT THE SCREEN IS UNLOCKED"
echo "and if you get Superuser prompts ACCEPT/ALLOW THEM"
echo "ELSE THIS WILL NOT WORK"
$ADB_CMD shell "su -c 'echo --- Superuser check successful'"

echo ""
echo "--- cleaning"
$ADB_CMD shell "cd /data/local/tmp/; rm *"
echo "--- pushing busybox"
$ADB_CMD push ./files/busybox "/data/local/tmp/."
echo "  --- correcting permissions"
$ADB_CMD shell "chmod 755 /data/local/tmp/busybox"
echo "  --- remounting /system"
echo "MAKE SURE THAT THE SCREEN IS UNLOCKED"
echo "and if you get Superuser prompts ACCEPT/ALLOW THEM"
echo "ELSE THIS WILL NOT WORK"
$ADB_CMD shell "su -c '/data/local/tmp/busybox mount -o remount,rw /system'"

# unroot
echo "--- pushing unroot script"
$ADB_CMD push ./files/unroot "/data/local/tmp/."
echo "  --- correcting permissions"
$ADB_CMD shell "chmod 777 /data/local/tmp/unroot"
echo "  --- executing unroot"
$ADB_CMD shell "su -c '/data/local/tmp/unroot'"

echo ""
echo "--- cleaning /data/local/tmp/"
$ADB_CMD shell "cd /data/local/tmp/; rm *"
echo "--- rebooting"
$ADB_CMD reboot
echo "ALL DONE!!!"