#updater-script by show-p1984

ui_print(" _                      ___             ");
ui_print("| |__  ___ _ _  ______ / __|___ _ _ ___ ");
ui_print("| '_ \/ -_) ' \|_ / _ \ (__/ _ \ '_/ -_)");
ui_print("|_.__/\___|_||_/__\___/\___\___/_| \___|");
ui_print("");
set_progress(0.01);

ui_print("-Checking Model ID");
assert(getprop("ro.product.device") == "shamu" || getprop("ro.build.product") == "shamu" || getprop("ro.product.board") == "shamu");
ui_print("-Success!");

ifelse(is_mounted("/system") == "/system", unmount("/system"));
ifelse(is_mounted("/cache") == "/cache", unmount("/cache"));

set_progress(0.01);

package_extract_dir("kernel", "/tmp");
set_perm(0, 0, 0777, "/tmp/edit_ramdisk.sh");
set_perm(0, 0, 0777, "/tmp/mkbootimg.sh");
set_perm(0, 0, 0777, "/tmp/mkbootimg");
set_perm(0, 0, 0777, "/tmp/unpackbootimg");
set_perm(0, 0, 0777, "/tmp/busybox");
set_progress(0.1);

run_program("/sbin/busybox", "mount", "/system");
package_extract_dir("system", "/system");
set_perm_recursive(0, 2000, 0755, 0755, "/system/etc/init.d");
set_progress(0.3);

run_program("/sbin/busybox", "dd", "if=/dev/block/platform/msm_sdcc.1/by-name/boot", "of=/tmp/boot.img");
set_progress(0.5);

run_program("/tmp/unpackbootimg", "-i", "/tmp/boot.img", "-o", "/tmp/");
set_progress(0.55);

ui_print("Fixing your ramdisk...");
ui_print("  Remove forced encryption...");
ui_print("  Disable mpdecision...");
ui_print("  Looking for busybox...");
ui_print("  adding init.d support (if not already supported)...");
run_program("/tmp/edit_ramdisk.sh");
set_progress(0.65);

unmount("/system");
set_progress(0.8);

run_program("/tmp/mkbootimg.sh");
set_progress(0.9);

run_program("/sbin/busybox", "dd", "if=/tmp/newboot.img", "of=/dev/block/platform/msm_sdcc.1/by-name/boot");
set_progress(0.95);

ui_print("Wiping /cache");
run_program("/sbin/busybox", "mount", "/cache");
delete_recursive("/cache/");
run_program("/sbin/busybox", "umount", "/cache");
set_progress(1.0);

ui_print("All Done!");
