assert(getprop("ro.product.device") == "sagit" || getprop("ro.build.product") == "sagit" || abort("E3004: This package is for device: sagit; this device is " + getprop("ro.product.device") + "."););
assert(xiaomi.verify_trustzone("TZ.BF.4.0.6-00178") == "1" || abort("Error: This package requires MIUI firmware version 9.5.16 or newer. Please upgrade firmware and retry!"););
ui_print("Target: Xiaomi/sagit/sagit:8.0.0/OPR1.170623.027/V9.2.3.0.OCAMIEK:user/release-keys");
package_extract_dir("install", "/tmp/install");
set_metadata_recursive("/tmp/install", "uid", 0, "gid", 0, "dmode", 0755, "fmode", 0644);
set_metadata_recursive("/tmp/install/bin", "uid", 0, "gid", 0, "dmode", 0755, "fmode", 0755);
run_program("/tmp/install/bin/system-mount.sh", "check", "/dev/block/bootdevice/by-name/system");
run_program("/tmp/install/bin/system-mount.sh", "backup", "/dev/block/bootdevice/by-name/system");
show_progress(0.650000, 0);
ui_print("Patching system image unconditionally...");
block_image_update("/dev/block/bootdevice/by-name/system", package_extract_file("system.transfer.list"), "system.new.dat.br", "system.patch.dat") ||
  abort("E1001: Failed to update system image.");
ui_print("Patching vendor image unconditionally...");
show_progress(0.100000, 0);
block_image_update("/dev/block/bootdevice/by-name/cust", package_extract_file("vendor.transfer.list"), "vendor.new.dat.br", "vendor.patch.dat") ||
  abort("E2001: Failed to update vendor image.");
show_progress(0.020000, 10);
run_program("/tmp/install/bin/system-mount.sh", "restore", "/dev/block/bootdevice/by-name/system");
show_progress(0.050000, 5);
package_extract_file("boot.img", "/dev/block/bootdevice/by-name/boot");
show_progress(0.200000, 10);
set_progress(1.000000);
