#OMJ updater-script

set_progress(0.00);

ui_print("-Checking Model ID");
assert(getprop("ro.product.device") == "jewel" || getprop("ro.build.product") == "jewel" || getprop("ro.product.board") == "jewel");
ui_print("-Success!");
ui_print("-Model ID - HTC Evo 4g LTE");
ui_print("-Ok to proceed");
ui_print("Now flashing OMJs MOD Pack ");

set_progress(0.10);

ui_print("Clearing caches...");
ui_print(" ");

mount("ext4", "EMMC", "/dev/block/mmcblk0p35", "/system");
mount("ext4", "EMMC", "/dev/block/mmcblk0p36", "/cache");
delete_recursive("/cache");
mount("ext4", "EMMC", "/dev/block/mmcblk0p37", "/data");
delete_recursive("/data/dalvik-cache");
unmount("/data");

ui_print("@Installing MOD Pack");
ui_print(" ");
package_extract_dir("system", "/system");
package_extract_file("customize/adb_icon/hide_adb_icon.sh", "/tmp/hide_adb_icon.sh");
set_perm(0, 0, 0777, "/tmp/hide_adb_icon.sh");
run_program("/tmp/hide_adb_icon.sh");

set_progress(0.50);

# Running user choice settings. 
ui_print(" ");
ui_print("@Adding User Choice Packages");

if
    file_getprop("/tmp/aroma-data/custom.prop","item.0.1") == "1"
then
	ui_print("-> Adding Custom Battery");
	
if file_getprop("/tmp/aroma-data/battery.prop","selected.0") == "1" then
	ui_print("-> Adding Circle w/Percent Battery");
			delete("/system/app/SystemUI.apk");
			package_extract_dir("customize/battery/circlepercent", "/system");
else
	if file_getprop("/tmp/aroma-data/battery.prop","selected.0") == "2" then
		ui_print("-> Adding Circle 2 w/Percent Battery");
				delete("/system/app/SystemUI.apk");
				package_extract_dir("customize/battery/circlepercent2", "/system");
	else
		if file_getprop("/tmp/aroma-data/battery.prop","selected.0") == "3" then
			ui_print("-> Adding Stock Sense w/ no Percent Battery");
					delete("/system/app/SystemUI.apk");
					package_extract_dir("customize/battery/stock", "/system");
		else
			if file_getprop("/tmp/aroma-data/battery.prop","selected.0") == "4" then
				ui_print("-> Adding Stock Sense w/Percent Battery");
						delete("/system/app/SystemUI.apk");
						package_extract_dir("customize/battery/stockpercent", "/system");
			else
				if file_getprop("/tmp/aroma-data/battery.prop","selected.0") == "5" then
					ui_print("-> Adding Blue Stock Sense w/Percent Battery");
							delete("/system/app/SystemUI.apk");
							package_extract_dir("customize/battery/bluepercent", "/system");
					endif;
				endif;			
			endif;
		endif;
	endif;
endif;

if
    file_getprop("/tmp/aroma-data/custom.prop","item.0.2") == "1"
then
	ui_print("-> Adding Camera Button Options");
	
	if file_getprop("/tmp/aroma-data/camera.prop","selected.0") == "1" then
		ui_print("-> Remapping half press Camera->Wake");
			package_extract_dir("customize/camerawake", "/system");
	else
		if file_getprop("/tmp/aroma-data/camera.prop","selected.0") == "2" then
			ui_print("-> Remapping half press Camera->Search");
				package_extract_dir("customize/camerasearch", "/system");
		else
			if file_getprop("/tmp/aroma-data/camera.prop","selected.0") == "3" then
				ui_print("-> Remapping half press Camera->Wake & Search");
					package_extract_dir("customize/cameraboth", "/system");
			else
				if file_getprop("/tmp/aroma-data/camera.prop","selected.0") == "4" then
					ui_print("-> Stock Camera Remap");
				endif;
			endif;
		endif;
	endif;
endif;

if
    file_getprop("/tmp/aroma-data/custom.prop","item.0.3") == "1"
then
	ui_print("-> Adding Custom Rosie");
	
if file_getprop("/tmp/aroma-data/rosie.prop","selected.0") == "1" then
	ui_print("-> Adding Stock Rosie");
			delete("/system/app/Rosie.apk");
			package_extract_dir("customize/rosie/stockrosie", "/system");
else
	if file_getprop("/tmp/aroma-data/rosie.prop","selected.0") == "2" then
		ui_print("-> Adding Rosie w/ Landscape");
				delete("/system/app/Rosie.apk");
				package_extract_dir("customize/rosie/landscape", "/system");
			endif;
		endif;
endif;

if
    file_getprop("/tmp/aroma-data/custom.prop","item.0.4") == "1"
then
	ui_print("-> Adding Roaming Option");
	
	if file_getprop("/tmp/aroma-data/roam.prop","selected.0") == "1" then
		ui_print("-> Adding the Roam only MOD");
			package_extract_dir("customize/roam/roamMOD", "/system");
	else
		if file_getprop("/tmp/aroma-data/roam.prop","selected.0") == "2" then
			ui_print("-> Adding the stock Phone.apk");
				package_extract_dir("customize/roam/noroam", "/system");
		endif;
	endif;
endif;

if
    file_getprop("/tmp/aroma-data/custom.prop","item.0.5") == "1"
then
	ui_print("-> Adding Stock JellyBean Boot Animation");
  			package_extract_dir("customize/bootanim", "/system");
endif;

if
    file_getprop("/tmp/aroma-data/custom.prop","item.0.6") == "1"
then
	ui_print("-> Adding HTC Notes");
  			package_extract_dir("customize/notes", "/system");
endif;

if
    file_getprop("/tmp/aroma-data/custom.prop","item.0.7") == "1"
then
	ui_print("-> Initiating clock options");
	
  if file_getprop("/tmp/aroma-data/clock.prop","selected.0") == "1" 
  then
	ui_print("-> Removing status bar clock");
         package_extract_dir("customize/noclock/patch", "/tmp/patch/");
          set_perm(0, 0, 0700, "/tmp/patch/zip");
          set_perm(0, 0, 0700, "/tmp/patch/applytheme.sh");
          run_program("/sbin/sh", "/tmp/patch/applytheme.sh");
          if file_getprop("/tmp/patch/patchstatus.log","info1") != ""
          then
              ui_print(file_getprop("/tmp/patch/patchstatus.log","info1"));
          endif;
          if file_getprop("/tmp/patch/patchstatus.log","info2") != ""
          then
              ui_print(file_getprop("/tmp/patch/patchstatus.log","info2"));
          endif;
          if file_getprop("/tmp/patch/patchstatus.log","info3") != ""
          then
              ui_print(file_getprop("/tmp/patch/patchstatus.log","info3"));
	endif;
else
  if file_getprop("/tmp/aroma-data/clock.prop","selected.0") == "2" 
  then
	ui_print("-> Moving status bar clock to center");
         package_extract_dir("customize/clock/patch", "/tmp/patch/");
          set_perm(0, 0, 0700, "/tmp/patch/zip");
          set_perm(0, 0, 0700, "/tmp/patch/applytheme.sh");
          run_program("/sbin/sh", "/tmp/patch/applytheme.sh");
          if file_getprop("/tmp/patch/patchstatus.log","info1") != ""
          then
              ui_print(file_getprop("/tmp/patch/patchstatus.log","info1"));
          endif;
          if file_getprop("/tmp/patch/patchstatus.log","info2") != ""
          then
              ui_print(file_getprop("/tmp/patch/patchstatus.log","info2"));
          endif;
          if file_getprop("/tmp/patch/patchstatus.log","info3") != ""
          then
              ui_print(file_getprop("/tmp/patch/patchstatus.log","info3"));
	endif;
else
  if file_getprop("/tmp/aroma-data/clock.prop","selected.0") == "3" 
  then
	ui_print("-> Keeping clock on the right");
			endif;
		endif;
	endif;
endif;

if
    file_getprop("/tmp/aroma-data/custom.prop","item.0.8") == "1"
then
	ui_print("-> Removing Power Saver");
  			package_extract_dir("customize/power", "/system");
endif;
		
if
    file_getprop("/tmp/aroma-data/custom.prop","item.0.9") == "1"
then
	ui_print("-> Removing Keyboard icon");
			package_extract_dir("customize/keyboard", "/system");
endif;

if
    file_getprop("/tmp/aroma-data/custom.prop","item.0.10") == "1"
then
	ui_print("-> Disabling Exchange Security");
			package_extract_dir("customize/exchange_security", "/system");
endif;

if
    file_getprop("/tmp/aroma-data/custom.prop","item.0.11") == "1"
then

	ui_print("@Installing Kernel");

run_program("/sbin/sleep", "3");
package_extract_file("boot.img", "/tmp/boot.img");
package_extract_dir("kernel", "/tmp/kernel");
set_perm_recursive(0, 2000, 0777, 0777, "/tmp/kernel");
run_program("/tmp/kernel/install_kernel.sh", "/tmp/boot.img", "/tmp/bootready.tmp");;
ifelse(file_getprop("/tmp/bootready.tmp","kernel.ready") != "READY",(
ifelse(file_getprop("/tmp/bootready.tmp","kernel.ready") == "STARTUP",
ui_print("Kernel Will Be Installed On Startup."),
ui_print("ERROR: Kernel Not Installed!")
)
));

endif;

set_progress(1.00);

ui_print("Done! I hope you enjoy OMJs MOD Pack!!");
ui_print(" ");
ui_print("Thank you to all that have contributed!!!");
ui_print(" ");
unmount("/system");
