mount("ext4", "EMMC", "/dev/block/bootdevice/by-name/oem", "/oem", "max_batch_time=0,commit=1,data=ordered,barrier=1,errors=panic,nodelalloc");
file_getprop("/oem/oem.prop", "ro.product.name") == "athene_amz" || abort("This package expects the value \"athene_amz\" for \"ro.product.name\" on the OEM partition; this has value \"" + file_getprop("/oem/oem.prop", "ro.product.name") + "\".");
ui_print("Source: motorola/athene_amz/athene:6.0.1/MPJ24.139-48/48:user/release-keys");
ui_print("Target: motorola/athene_amz/athene:6.0.1/MPJ24.139-49/49:user/release-keys");
ui_print("Verifying current system...");
show_progress(0.100000,0);
getprop("ro.build.thumbprint") == "6.0.1/MPJ24.139-49/49:user/release-keys" ||
    getprop("ro.build.thumbprint") == "6.0.1/MPJ24.139-48/48:user/release-keys" ||
    abort("Package expects build thumbprint of 6.0.1/MPJ24.139-49/49:user/release-keys or 6.0.1/MPJ24.139-48/48:user/release-keys; this device has " + getprop("ro.build.thumbprint") + ".");
apply_patch_check("EMMC:/dev/block/bootdevice/by-name/boot:16777216:339556bd4aa05552c88cbe1daf4d43b1b0fc9979:16777216:86ffa9576ba168ac326e4ebf4de08610e921c864") || abort("\"EMMC:/dev/block/bootdevice/by-name/boot:16777216:339556bd4aa05552c88cbe1daf4d43b1b0fc9979:16777216:86ffa9576ba168ac326e4ebf4de08610e921c864\" has unexpected contents.");
mount("ext4", "EMMC", "/dev/block/bootdevice/by-name/oem", "/oem", "");
apply_patch_check("/oem/oem.prop", "8384beebf858f743155a08114d619a3773f20db2", "534c92b39f974f5e0b51122f51ed58294cfa9131") || abort("\"/oem/oem.prop\" has unexpected contents.");
apply_patch_space(16777216) || abort("Not enough free space on /cache to apply patches.");
if (range_sha1("/dev/block/bootdevice/by-name/system", "2,1,655320") == "80ba985b4e0bec924297dd1a9a2d3d3da2de68e8" || block_image_verify("/dev/block/bootdevice/by-name/system", package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat")) then
ui_print("Verified system image...");
else
print_superblock_info("/dev/block/bootdevice/by-name/system");
abort("system partition has unexpected contents");
endif;

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

ui_print("Patching system image after verification.");
show_progress(0.400000,0);
assert(block_image_update("/dev/block/bootdevice/by-name/system", package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat"));
ui_print("Verifying the updated system image...");
if range_sha1("/dev/block/bootdevice/by-name/system", "2,0,655320") == "55e30340f58cd63ba51e62f8d42a99a35a434074" then
ui_print("Verified the updated system image.");
else
  abort("system partition has unexpected contents after OTA update");
endif;
ui_print("Patching boot image...");
assert(apply_patch("EMMC:/dev/block/bootdevice/by-name/boot:16777216:339556bd4aa05552c88cbe1daf4d43b1b0fc9979:16777216:86ffa9576ba168ac326e4ebf4de08610e921c864",
       "-", 86ffa9576ba168ac326e4ebf4de08610e921c864, 16777216,
       339556bd4aa05552c88cbe1daf4d43b1b0fc9979, package_extract_file("patch/boot.img.p")));
ui_print("Removing unneeded files from oem...");
ui_print("Patching oem files...");
assert(apply_patch("/oem/oem.prop", "-",
       534c92b39f974f5e0b51122f51ed58294cfa9131, 175,
       8384beebf858f743155a08114d619a3773f20db2, package_extract_file("patch/oem/oem.prop.p")));
ui_print("Symlinks and permissions in oem ...");
ui_print("updating rpm ...");
assert(package_extract_file("rpm.mbn", "/tmp/rpm.mbn"),
	   apply_raw_image("/tmp/rpm.mbn", "rpm"),
	   delete("/tmp/rpm.mbn"));
show_progress(0.100000,0);
assert(set_backup_flag());
ui_print("updating tz ...");
assert(package_extract_file("tz.mbn", "/tmp/tz.mbn"),
	   apply_raw_image("/tmp/tz.mbn", "tz"),
	   delete("/tmp/tz.mbn"));
show_progress(0.080000,0);
ui_print("updating hyp ...");
assert(package_extract_file("hyp.mbn", "/tmp/hyp.mbn"),
	   apply_raw_image("/tmp/hyp.mbn", "hyp"),
	   delete("/tmp/hyp.mbn"));
show_progress(0.080000,0);
ui_print("updating fsg ...");
assert(package_extract_file("fsg.mbn", "/tmp/fsg.mbn"),
	   apply_raw_image("/tmp/fsg.mbn", "fsg"),
	   delete("/tmp/fsg.mbn"));
show_progress(0.080000,0);
ui_print("Erasing modemst1 ...");
assert(format("raw", "EMMC", "/dev/block/bootdevice/by-name/modemst1", "0", "/modemst1"));
ui_print("Erasing modemst2 ...");
assert(format("raw", "EMMC", "/dev/block/bootdevice/by-name/modemst2", "0", "/modemst2"));
ui_print("Updating gpt.bin...");
assert(package_extract_file("gpt.bin", "/tmp/gpt.bin"),
                            motorola.update_gpt("/tmp/gpt.bin"),
                            delete("/tmp/gpt.bin"));
show_progress(0.080000,0);
(is_hardware_secured() == "t") || (ui_print("Validating gpt") && (assert(motorola.gpt_validate(32768,"d7264f1265129ac594ebbe35be4c31bf2b031695"))));
ui_print("Erasing DDR..");
assert(format("raw", "EMMC", "/dev/block/bootdevice/by-name/DDR", "0", "/ddr"));
ui_print("Erased DDR successfully..");
show_progress(0.080000,0);
set_progress(1.000000);
unmount("/oem");
