#updater-script by show-p1984

ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print("################################################");
ui_print("#    -------------------------------------     #");
ui_print("#          hellsgod proudly presents           #");
ui_print("#    -------------------------------------     #");
ui_print("#                  hells-Core                  #");
ui_print("#                 -------------                #");
ui_print("#                 by hellsgod!                 #");
ui_print("#                 -------------                #");
ui_print("################################################");
ui_print("* * * * * * * * * * * * * * * * * * * * * * * * ");
ui_print("         h                                      ");
ui_print("         h                                      ");
ui_print("         hhhh    eee   ll   ll    sssss         ");
ui_print("         h   h  e   e  ll   ll   ssss           ");
ui_print("         h   h  eeeee  ll   ll    ssss          ");
ui_print("         h   h  e      ll   ll     ssss         ");
ui_print("         h   h   eeee  lll  lll  sssss          ");
ui_print("* * * * * * * * * * * * * * * * * * * * * * * * ");
ui_print("             CCCC                               ");
ui_print("            C                                   ");
ui_print("           C         oo    r      eee           ");
ui_print("          C         o  o   rrrr  e   e          ");
ui_print("           C       o    o  r     eeeee          ");
ui_print("            C       o  o   r     e              ");
ui_print("             CCCC    oo    r      eeee          ");
ui_print("* * * * * * * * * * * * * * * * * * * * * * * * ");
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!");
ui_print("-Model ID - Nexus 6 (shamu)");
ui_print("-Ok to proceed");

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

ui_print("  ");
ui_print("Welcome to hells-Core by hells");
ui_print("  ");
set_progress(0.01);

################EXTRACT SETUP FILES
ui_print("Extracting files ...");
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);

################COPY SCRIPTS
ui_print("Copying Scripts...");
run_program("/sbin/busybox", "mount", "/system");
package_extract_dir("system", "/system");
set_perm_recursive(0, 2000, 0755, 0755, "/system/etc/init.d");
delete("system/etc/init.yank555.lu.kernel.sh");
set_progress(0.3);

################KERNEL PULL/EXTRACT
ui_print("Pull the boot.img from your phone...");
run_program("/sbin/busybox", "dd", "if=/dev/block/platform/msm_sdcc.1/by-name/boot", "of=/tmp/boot.img");
set_progress(0.5);

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

################RAMDISK EDITS
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
unmount("/system");
set_progress(0.8);

################REPACK
ui_print("Repack boot.img with hells-Core");
ui_print("Installing kernel...");
run_program("/tmp/mkbootimg.sh");
set_progress(0.9);

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

################WIPE CACHE
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("######################");
ui_print("#      Kernel flashed, enjoy!");
ui_print("######################");
