assert(getprop("ro.product.device") == "mb886" || getprop("ro.build.product") == "mb886" || getprop("ro.product.device") == "qinara" || getprop("ro.build.product") == "qinara" || abort("This package is for device: mb886,qinara; this device is " + getprop("ro.product.device") + "."););
ui_print("Target: motorola/MB886_att/qinara:4.1.1/9.8.0Q-97_MB886_FFW-20/27:user/release-keys");
ifelse(is_mounted("/system"), unmount("/system"));
assert(getprop("ro.boot.secure_hardware") == "" || abort("This package is for devices with 4.1 bootloader"););
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);
mount("ext4", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/system", "/system", "");
run_program("/tmp/install/bin/backuptool.sh", "backup");
unmount("/system");
if is_mounted("/data") then
package_extract_file("META-INF/org/lineageos/releasekey", "/tmp/releasekey");
run_program("/tmp/install/bin/otasigcheck.sh") != "31744" || abort("Can't install this package on top of incompatible data. Please try another package or run a factory reset");
else
mount("f2fs", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/userdata", "/data", "");
package_extract_file("META-INF/org/lineageos/releasekey", "/tmp/releasekey");
run_program("/tmp/install/bin/otasigcheck.sh") != "31744" || abort("Can't install this package on top of incompatible data. Please try another package or run a factory reset");
unmount("/data");
endif;
show_progress(0.750000, 0);
ui_print("Patching system image unconditionally...");
block_image_update("/dev/block/platform/msm_sdcc.1/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/platform/msm_sdcc.1/by-name/system", "40,0,32770,32849,32851,33341,65535,65536,65538,66028,94037,98304,98306,98385,98387,98877,131071,131072,131074,163840,163842,163921,163923,164413,196607,196608,196610,229376,229378,229457,229459,229949,262143,262144,262146,294912,294914,294993,294995,295485,313407") == "42a7eddb85b222df218a0b27689a355506dcf436" then
if range_sha1("/dev/block/platform/msm_sdcc.1/by-name/system", "48,32770,32849,32851,33341,65535,65536,65538,66028,94037,94549,97792,98304,98306,98385,98387,98877,131071,131072,131074,131586,163328,163840,163842,163921,163923,164413,196607,196608,196610,197122,228864,229376,229378,229457,229459,229949,262143,262144,262146,262658,294400,294912,294914,294993,294995,295485,313407,313408") == "ca05b664c060f6de928d273b9e1b3d79c6ab1ec8" then
ui_print("Verified the updated system image.");
else
  abort("system partition has unexpected non-zero contents after OTA update");
endif;
else
  abort("system partition has unexpected contents after OTA update");
endif;
show_progress(0.020000, 10);
mount("ext4", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/system", "/system", "");
run_program("/tmp/install/bin/backuptool.sh", "restore");
if (run_program("test", "-f", "/system/addon.d/51-addonsu.sh") == "0" && run_program("test", "-f", "/system/xbin/su") == "0") then
package_extract_file("extra/su", "/system/xbin/su");
set_metadata("/system/xbin/su", "uid", 0, "gid", 2000, "mode", 0755, "selabel", "u:object_r:su_exec:s0");
symlink("/system/xbin/su", "/system/bin/su");
endif;
unmount("/system");
show_progress(0.050000, 5);
package_extract_file("boot.img", "/dev/block/platform/msm_sdcc.1/by-name/boot");
show_progress(0.200000, 10);
