
# Htc Script Version: P90QCT.01.001.015

ui_print("P90QCT.01.001.015");
getprop("ro.product.device") == "htc_ocnuhl" || abort("E3004: This package is for \"htc_ocnuhl\" devices; this is a \"" + getprop("ro.product.device") + "\".");
ifelse( is_ship_bootloader(getprop("ro.bootloader")) == "t" ,
       assert(check_cid("00000000", "11111111", "22222222", "33333333",
       "44444444", "55555555", "66666666", "77777777", "88888888", "99999999",
       "EVE__001") == "t");
       );
ifelse( is_ship_bootloader(getprop("ro.bootloader")) == "t" ,
       assert(check_mid("full", "2PZC10000") == "t");,
       assert(check_mid("simple", "2PZC10000") == "t");
       );
ui_print("Source: htc/ocnuhl_00091/htc_ocnuhl:8.0.0/OPR6.170623.013/1002308.7:user/release-keys");
ui_print("Target: htc/ocnuhl_00091/htc_ocnuhl:9/PQ2A.190205.003/1088389.1:user/release-keys");
ui_print("Verifying current system...");
getprop("ro.build.fingerprint") == "htc/ocnuhl_00091/htc_ocnuhl:8.0.0/OPR6.170623.013/1002308.7:user/release-keys" ||
    getprop("ro.build.fingerprint") == "htc/ocnuhl_00091/htc_ocnuhl:9/PQ2A.190205.003/1088389.1:user/release-keys" ||
    abort("E3001: Package expects build fingerprint of htc/ocnuhl_00091/htc_ocnuhl:8.0.0/OPR6.170623.013/1002308.7:user/release-keys or htc/ocnuhl_00091/htc_ocnuhl:9/PQ2A.190205.003/1088389.1:user/release-keys; this device has " + getprop("ro.build.fingerprint") + ".");
update_has_interrupt("") == "t" || check_firmware_space("") || abort("Not enough free space on /cache.");
apply_patch_space(0) || abort("E3006: Not enough free space on /cache to apply patches.");
if (htc_range_sha1("/dev/block/bootdevice/by-name/system", "134,1,32767,32768,32770,33009,33011,33513,65535,65536,65538,66040,98302,98304,98306,98545,98547,99049,131071,131072,131074,131576,131610,163840,163842,164081,164083,164585,196607,196608,196610,197112,229375,229376,229378,229617,229619,230121,262143,262144,262146,262648,294911,294912,294914,295153,295155,295657,327679,327680,327682,328184,360447,360448,360450,360952,393215,393216,393218,393720,425983,425984,425986,426488,458751,458752,458754,459256,491519,491520,491522,492024,524287,524288,524290,524792,557055,557056,557058,557560,589822,589824,589826,590328,622590,622592,622594,623096,655358,655360,655362,655864,688126,688128,688130,688632,720894,720896,720898,721400,753662,753664,753666,754168,786430,786432,786434,786936,819198,819200,819202,819441,819443,819945,851967,851968,851970,852472,884734,884736,884738,884977,884979,885481,917502,917504,917506,918008,918800,950272,950274,950776,963667,963668,978944") == "53814d081fb9e28452728be897df11f26c451a11" || update_has_interrupt("") == "t") then
ui_print("Verified system image...");
else
if (htc_range_sha1("/dev/block/bootdevice/by-name/system", "28,0,254,269,725,8301,32770,33005,98306,98541,163842,164077,229378,229613,294914,295149,425985,427008,524300,524301,524302,531344,819202,819437,884738,884973,892985,963668,978944") == "ab0b313b01ffefd8237323f419b94ded7f45480d") then
set_tgt_total_sha1("ab0b313b01ffefd8237323f419b94ded7f45480d");
else
abort("E1000: system partition has unexpected contents");
endif;
endif;

# ---- start making changes here ----

ui_print("Patching system image after verification.");
show_progress(0.900000, 0);
if ( get_tgt_total_sha1() == "ab0b313b01ffefd8237323f419b94ded7f45480d") then
ui_print("Current system is target ROM, bypass patching system");
else
block_image_update("/dev/block/bootdevice/by-name/system", package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat") ||
  abort("E1001: Failed to update system image.");
endif;

ui_print("Verifying the updated system image...");
if htc_range_sha1("/dev/block/bootdevice/by-name/system", "28,0,254,269,725,8301,32770,33005,98306,98541,163842,164077,229378,229613,294914,295149,425985,427008,524300,524301,524302,531344,819202,819437,884738,884973,892985,963668,978944") == "ab0b313b01ffefd8237323f419b94ded7f45480d" then
if range_sha1("/dev/block/bootdevice/by-name/system", "32,254,269,725,1237,7789,8301,32770,33005,98306,98541,163842,164077,229378,229613,294914,295149,425985,427008,524300,524301,524302,524814,530832,531344,819202,819437,884738,884973,892985,893497,963156,963668") == "7a2846d821d0d0c6b17ac23b662d00c79e52b640" then
ui_print("Verified the updated system image.");
else
  abort("E1003: system partition has unexpected non-zero contents after OTA update");
endif;
else
  abort("E1002: system partition has unexpected contents after OTA update");
endif;

# Start to handle htc preload...

mount("ext4", "EMMC", "/dev/block/bootdevice/by-name/apppreload", "/preload", "");
delete("/preload/EE_Instagram_Stub.apk",
       "/preload/EE_Messenger_Stub.apk",
       "/preload/Viveport_Inst.apk");
write_firmware_image("PACKAGE:firmware.zip", "zip");
set_progress(1.000000);
unmount("/preload");
