getprop("ro.product.device") == "montoya" || abort("This package is for \"montoya\" devices; this is a \"" + getprop("ro.product.device") + "\".");
ui_print("Verifying current system...");
getprop("ro.build.fingerprint") == "Amazon/montoya:5.1/LMY47O/54.5.3.6_user_536116920:user/release-keys" ||
    getprop("ro.build.fingerprint") == "Amazon/montoya:5.1/LMY47O/54.5.3.7_user_537174420:user/release-keys" ||
    abort("Package expects build fingerprint of Amazon/montoya:5.1/LMY47O/54.5.3.6_user_536116920:user/release-keys or Amazon/montoya:5.1/LMY47O/54.5.3.7_user_537174420:user/release-keys; this device has " + getprop("ro.build.fingerprint") + ".");
apply_patch_check("EMMC:/dev/block/platform/sdhci.1/by-name/boot:4645120:61ccbe5bf65744c690e0759cc0c83af8fcb717bd:4645120:69270bc823375c9d08e371d2074f93b982cbee88") || abort("\"EMMC:/dev/block/platform/sdhci.1/by-name/boot:4645120:61ccbe5bf65744c690e0759cc0c83af8fcb717bd:4645120:69270bc823375c9d08e371d2074f93b982cbee88\" has unexpected contents.");
if (range_sha1("/dev/block/platform/sdhci.1/by-name/system", "30,0,32767,32768,32770,32825,32827,33277,65535,65536,65538,65988,68756,98304,98306,98361,98363,98813,131071,131072,131074,163840,163842,163897,163899,164349,196607,196608,196610,197060,201215") == "a9c680c70a53be65a08b16ce330839c97e2ab921" || block_image_verify("/dev/block/platform/sdhci.1/by-name/system", package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat")) then
ui_print("Verified system image...");
else
(range_sha1("/dev/block/platform/sdhci.1/by-name/system", "2,0,1") == "54fe8fc3f0e8c43b43965833120c439d0a9d93c5") || abort("/dev/block/platform/sdhci.1/by-name/system has been remounted R/W; reflash device to reenable OTA updates");
abort("system partition has unexpected contents");
endif;

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

ui_print("Patching system image after verification.");
show_progress(0.900000, 0);
block_image_update("/dev/block/platform/sdhci.1/by-name/system", package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat");
ui_print("Patching boot image...");
show_progress(0.100000, 10);
apply_patch("EMMC:/dev/block/platform/sdhci.1/by-name/boot:4645120:61ccbe5bf65744c690e0759cc0c83af8fcb717bd:4645120:69270bc823375c9d08e371d2074f93b982cbee88",
            "-", 69270bc823375c9d08e371d2074f93b982cbee88, 4645120,
            61ccbe5bf65744c690e0759cc0c83af8fcb717bd, package_extract_file("patch/boot.img.p"));
package_extract_file("images/vc-firmware.img.signed", "/dev/block/platform/sdhci.1/by-name/vc-firmware");
package_extract_file("META-INF/com/amazon/android/target.blocklist", "/cache/recovery/last_blocklist");
set_metadata("/cache/recovery/last_blocklist", "uid", 0, "gid", 0, "mode", 0444, "capabilities", 0x0);
set_progress(1.000000);
