
# Script Version: 0.9

show_progress(0.999999, 99);

if getprop("ext.edition") == "ng" then

ui_print(" ");
ui_print("-Installing Cool Sense");
ui_print("-Recommended Partition Layout");
ui_print("-Fat32+Ext4");

ui_print(" ");
ui_print("-Installing DATA Partition...");
unmount("/data");
mount("MTD","userdata","/data");
delete_recursive("/data/dalvik-cache");
package_extract_dir("data", "/data");
set_perm_recursive(1000, 1000, 0771, 0644, "/data/app");
set_perm_recursive(1000, 1000, 0771, 0644, "/data/local");

ui_print(" ");
ui_print("-Installing SYSTEM Partition...");
unmount("/system");
format("MTD", "system");
mount("MTD", "system", "/system");
package_extract_dir("system", "/system");

if getprop("ext.edition") == "ng" then
ui_print(" ");
ui_print("-Press |Yes| To Install GSM Version");
ui_print("-Press |No| To Install CDMA Version");
ui_print("4ext: show_yesno");
run_program("/sbin/sleep", "2");
endif;
if getprop("ext.confirm") == "yes" then

ui_print(" ");
ui_print("-Installing GSM Version...");

else

ui_print(" ");
ui_print("-Installing CDMA Version...");

delete("/system/etc/permissions/android.hardware.telephony.gsm.xml");
delete("/system/build.prop");
package_extract_dir("cdma", "/system");

endif;
 
if getprop("ext.edition") == "ng" then
ui_print(" ");
ui_print("-Press |Yes| To Install *Ckpv5* Primo Theme");
ui_print("-Press |No| To Continue ICS Theme Option");
ui_print("4ext: show_yesno");
run_program("/sbin/sleep", "2");
endif;
if getprop("ext.confirm") == "yes" then

ui_print(" ");
ui_print("-Installing Primo Theme...");
package_extract_dir("primo", "/system");
package_extract_dir("primob", "/data/local");
delete("/data/local/boot.mp3");

else

if getprop("ext.edition") == "ng" then
ui_print(" ");
ui_print("-Press |Yes| To Install ICS Theme");
ui_print("-Press |No| To Continue With Stock Theme");
ui_print("4ext: show_yesno");
run_program("/sbin/sleep", "2");
endif;
if getprop("ext.confirm") == "yes" then

ui_print(" ");
ui_print("-Installing ICS Theme...");
package_extract_dir("ics", "/system");
package_extract_dir("icsb", "/data/local");
delete("/data/local/boot.mp3");

endif;

endif;

ui_print("4ext: disable_scrn_update");

ui_print(" ");
ui_print("-Setting Up SYSTEM Permissions...");

symlink("/data/hosts","/system/etc/hosts");

set_perm_recursive(0, 0, 0755, 0644, "/system");
set_perm_recursive(0, 2000, 0755, 0755, "/system/bin");
set_perm_recursive(0, 2000, 0755, 0755, "/system/xbin");
set_perm_recursive(1002, 1002, 0755, 0440, "/system/etc/bluz");
set_perm(0, 3003, 0755, "/system/bin/ip");
set_perm(0, 3003, 0755, "/system/bin/ipd");
set_perm(0, 3003, 02755, "/system/bin/netcfg");
set_perm(0, 3003, 06755, "/system/bin/netd");
set_perm(0, 3004, 02755, "/system/bin/ping");
set_perm(0, 2000, 06755, "/system/bin/run-as");
set_perm_recursive(1002, 1002, 0755, 0440, "/system/etc/bluetooth");
set_perm(0, 0, 0755, "/system/etc/bluetooth");
set_perm(1000, 1000, 0640, "/system/etc/bluetooth/auto_pairing.conf");
set_perm(3002, 3002, 0444, "/system/etc/bluetooth/blacklist.conf");
set_perm(1002, 1002, 0440, "/system/etc/dbus.conf");
set_perm(1014, 2000, 0550, "/system/etc/dhcpcd/dhcpcd-run-hooks");
set_perm(0, 2000, 0550, "/system/etc/init.goldfish.sh");
set_perm_recursive(0, 0, 0755, 0555, "/system/etc/ppp");
set_perm(0, 0, 04755, "/system/bin/sysro");
set_perm(0, 0, 04755, "/system/bin/sysrw");
symlink("/system/xbin/busybox","/system/xbin/bb/ifconfig");
symlink("/system/xbin/busybox","/system/xbin/bb/route");
set_perm(0, 0, 04755, "/system/xbin/openvpn");
set_perm(0, 0, 04755, "/system/etc/ppp/ip-up-vpn");
set_perm(0, 0, 04755, "/system/xbin/dropbear");
set_perm(0, 0, 04755, "/system/xbin/flash_image");
symlink("dropbear","/system/xbin/dropbearkey");
set_perm_recursive(0, 2000, 0755, 0755, "/system/etc/init.d");

ui_print(" ");
ui_print("-Installing Toolbox & Busybox...");

symlink("toolbox", "/system/bin/chownto", "/system/bin/getevent", "/system/bin/getprop", "/system/bin/ifconfig", "/system/bin/iftop", "/system/bin/ioctl", "/system/bin/log", "/system/bin/nandread", "/system/bin/newfs_msdos", "/system/bin/notify", "/system/bin/schedtop", "/system/bin/sendevent", "/system/bin/setprop", "/system/bin/smd", "/system/bin/start", "/system/bin/stop",	"/system/bin/vmstat", "/system/bin/watchprops", "/system/bin/wipe", "/system/bin/top");

set_perm(0, 1000, 0755, "/system/xbin/busybox");
run_program("/sbin/sh","-c",
concat("( cd /system/xbin ; ",
" ./busybox --install -s /system/xbin )"));

delete_recursive("/data/data/com.noshufou.android.su");
set_perm(0, 0, 06755, "/system/bin/su");
delete("/system/xbin/su");
symlink("/system/bin/su","/system/xbin/su");

package_extract_dir("sdcard", "/sdcard");

ui_print(" ");
ui_print("-Installing Boot Partition...");
unmount("/boot");
format("MTD", "boot");
package_extract_file("boot.img","/tmp/boot.img");
write_raw_image("/tmp/boot.img", "boot");
delete("/tmp/boot.img");

assert(package_extract_file("boot.img", "/tmp/boot.img"),
       write_raw_image("/tmp/boot.img", "boot"),
       delete("/tmp/boot.img"));

ui_print(" ");
ui_print("-Installation Completed...");
ui_print("-Reboot and Enjoy...");

unmount("/system");
unmount("/data");

else

ui_print(" ");
ui_print("-Flashing 4EXT Touch Recovery...");
ui_print("-So You Can Use |Yes| and |No| Options.");

package_extract_file("recovery.img","/tmp/recovery.img");
write_raw_image("/tmp/recovery.img", "recovery");
delete("/tmp/recovery.img");

ui_print(" ");
ui_print("-Flashing Completed...");
ui_print("-Rebooting To Recovery.");
ui_print("-Plz ReFlash CoolRom.zip.");

run_program("/sbin/sleep", "15");
run_program("/sbin/reboot", "recovery");

endif;

show_progress(0.000000, 0);
