getprop("ro.product.device") == "ursa" || abort("E3004: This package is for \"ursa\" devices; this is a \"" + getprop("ro.product.device") + "\".");
ui_print("Source: Xiaomi/ursa/ursa:10/QKQ1.190828.002/V12.5.1.0.QEHCNXM:user/release-keys");
ui_print("Target: Xiaomi/ursa/ursa:10/QKQ1.190828.002/V12.5.3.0.QEHCNXM:user/release-keys");
ui_print("Verifying current system...");
getprop("ro.build.fingerprint") == "Xiaomi/ursa/ursa:10/QKQ1.190828.002/V12.5.1.0.QEHCNXM:user/release-keys" ||
    getprop("ro.build.fingerprint") == "Xiaomi/ursa/ursa:10/QKQ1.190828.002/V12.5.3.0.QEHCNXM:user/release-keys" ||
    abort("E3001: Package expects build fingerprint of Xiaomi/ursa/ursa:10/QKQ1.190828.002/V12.5.1.0.QEHCNXM:user/release-keys or Xiaomi/ursa/ursa:10/QKQ1.190828.002/V12.5.3.0.QEHCNXM:user/release-keys; this device has " + getprop("ro.build.fingerprint") + ".");
show_progress(0.100000, 10);
patch_partition_check("EMMC:/dev/block/bootdevice/by-name/boot:45303114:41e095446978727fb9a1213a3d1e410dd06744de",
                      "EMMC:/dev/block/bootdevice/by-name/boot:45303114:95a1d99756f414dd2a6290afaa4ca34f6417c292") ||
    abort("E3005: \"EMMC:/dev/block/bootdevice/by-name/boot:45303114:41e095446978727fb9a1213a3d1e410dd06744de\" or \"EMMC:/dev/block/bootdevice/by-name/boot:45303114:95a1d99756f414dd2a6290afaa4ca34f6417c292\" has unexpected contents.");
apply_patch_space(45303114) || abort("E3006: Not enough free space on /cache to apply patches.");
show_progress(0.100000, 70);
if (range_sha1("/dev/block/bootdevice/by-name/system", "498,1,590,698,712,744,751,753,754,1000,1005,1007,1008,1114,1115,1599,1600,2288,2289,2291,2293,2294,2295,2310,2311,2492,2493,3664,3665,3667,3668,3672,3673,3681,3682,3683,3684,9041,9042,9044,9045,9449,9450,9452,9453,10449,10451,16390,16391,16524,16525,19294,19296,25544,25546,32768,32770,32959,32960,34683,34684,34686,34688,34747,34748,34881,34883,35113,35114,35182,35183,35192,35193,35236,35239,35707,35710,35716,35717,35722,35723,35767,35770,35781,35782,35907,35908,35911,35912,35929,37231,38841,38842,38850,38851,38856,38857,38859,38860,45433,45434,45436,45437,45524,45525,45608,45609,48508,48509,48757,48758,48904,48905,49922,49923,50297,50298,50334,50335,55954,55956,61326,61327,61679,61681,61734,61735,61741,61742,61755,61756,62378,62379,63269,63270,63532,63533,63710,63711,65536,65537,66857,66858,67916,67917,70481,70482,75966,75967,77829,77830,77902,77903,80955,80958,83141,83142,85765,85766,85941,85942,86089,86090,86242,86243,88999,89000,89012,89013,89641,89642,98304,98306,98495,98496,104111,104112,104288,104291,105314,105317,107034,107035,107084,107085,107088,107091,109138,109139,109197,109198,109219,109220,109977,109980,109997,109998,110246,110249,110415,110416,110457,110458,110966,110967,112014,112015,112085,112086,112132,112133,112459,112460,112612,112613,120781,120782,120821,120822,123446,123449,127839,127840,127845,127846,128243,128244,128944,128945,128951,128952,131072,131073,132324,132325,133869,133870,147839,147841,153427,153428,153812,153814,154339,154340,154787,154788,154792,154793,154805,154806,154810,154811,154822,154823,155198,155199,155222,155223,156563,156564,156718,156719,156808,156811,156824,156827,157723,157726,161635,161636,161902,161905,163840,163842,164031,164032,164677,164678,164899,164900,168067,168068,168080,168081,168418,168419,170162,170163,170597,170598,172345,172346,175089,175094,175743,175744,179762,179763,181195,181196,181991,181992,185232,185233,192173,192174,196608,196609,197775,197776,204985,204986,205291,205292,205304,205305,205315,205318,205319,205320,205321,205322,205324,205325,205326,205327,205379,205380,205465,205468,205471,205472,205478,205479,205502,205503,205565,205566,205569,205574,205575,205576,205577,205578,205579,205580,206374,206375,206381,206382,206935,206937,207490,207492,207493,207494,207495,207496,207497,207498,207499,207500,207501,207502,207503,207504,207505,207506,207507,207510,208970,208972,209053,209054,209056,210976,210979,210981,211239,211240,211247,211249,211737,211739,211847,211848,211878,211879,211890,211891,212157,212158,212271,212272,212288,212290,213606,213607,227300,227301,229376,229378,229567,229568,235869,235870,237934,237935,238220,238221,241571,251687,256992,257508,260104,260105,260268,260269,262144,262145,264589,275206,283087,283773,286801,286811,287841,287842,290771,294914,295103,295104,295610,298985,299290,299800,299835,300117,300131,300135,300144,300147,300157,300159,300180,300543,307991,307993,315642,315643,320045,320046,320394,320395,320710,320711,320726,320727,320754,320755,320798,320799,321475,321487,323178,327681,328187,360449,360955,393217,393723,425985,426491,458753,459259,491521,492027,524289,524795,557057,557563,589825,590331,622593,623099,655361,655867,688129,688635,720897,721403,753665,754171,773253,774155,780254,780261,780367") == "dc6164b345fdbebd1e0bcd47367eefbe024248ab" || 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
check_first_block("/dev/block/bootdevice/by-name/system");
ifelse (block_image_recover("/dev/block/bootdevice/by-name/system", "498,1,590,698,712,744,751,753,754,1000,1005,1007,1008,1114,1115,1599,1600,2288,2289,2291,2293,2294,2295,2310,2311,2492,2493,3664,3665,3667,3668,3672,3673,3681,3682,3683,3684,9041,9042,9044,9045,9449,9450,9452,9453,10449,10451,16390,16391,16524,16525,19294,19296,25544,25546,32768,32770,32959,32960,34683,34684,34686,34688,34747,34748,34881,34883,35113,35114,35182,35183,35192,35193,35236,35239,35707,35710,35716,35717,35722,35723,35767,35770,35781,35782,35907,35908,35911,35912,35929,37231,38841,38842,38850,38851,38856,38857,38859,38860,45433,45434,45436,45437,45524,45525,45608,45609,48508,48509,48757,48758,48904,48905,49922,49923,50297,50298,50334,50335,55954,55956,61326,61327,61679,61681,61734,61735,61741,61742,61755,61756,62378,62379,63269,63270,63532,63533,63710,63711,65536,65537,66857,66858,67916,67917,70481,70482,75966,75967,77829,77830,77902,77903,80955,80958,83141,83142,85765,85766,85941,85942,86089,86090,86242,86243,88999,89000,89012,89013,89641,89642,98304,98306,98495,98496,104111,104112,104288,104291,105314,105317,107034,107035,107084,107085,107088,107091,109138,109139,109197,109198,109219,109220,109977,109980,109997,109998,110246,110249,110415,110416,110457,110458,110966,110967,112014,112015,112085,112086,112132,112133,112459,112460,112612,112613,120781,120782,120821,120822,123446,123449,127839,127840,127845,127846,128243,128244,128944,128945,128951,128952,131072,131073,132324,132325,133869,133870,147839,147841,153427,153428,153812,153814,154339,154340,154787,154788,154792,154793,154805,154806,154810,154811,154822,154823,155198,155199,155222,155223,156563,156564,156718,156719,156808,156811,156824,156827,157723,157726,161635,161636,161902,161905,163840,163842,164031,164032,164677,164678,164899,164900,168067,168068,168080,168081,168418,168419,170162,170163,170597,170598,172345,172346,175089,175094,175743,175744,179762,179763,181195,181196,181991,181992,185232,185233,192173,192174,196608,196609,197775,197776,204985,204986,205291,205292,205304,205305,205315,205318,205319,205320,205321,205322,205324,205325,205326,205327,205379,205380,205465,205468,205471,205472,205478,205479,205502,205503,205565,205566,205569,205574,205575,205576,205577,205578,205579,205580,206374,206375,206381,206382,206935,206937,207490,207492,207493,207494,207495,207496,207497,207498,207499,207500,207501,207502,207503,207504,207505,207506,207507,207510,208970,208972,209053,209054,209056,210976,210979,210981,211239,211240,211247,211249,211737,211739,211847,211848,211878,211879,211890,211891,212157,212158,212271,212272,212288,212290,213606,213607,227300,227301,229376,229378,229567,229568,235869,235870,237934,237935,238220,238221,241571,251687,256992,257508,260104,260105,260268,260269,262144,262145,264589,275206,283087,283773,286801,286811,287841,287842,290771,294914,295103,295104,295610,298985,299290,299800,299835,300117,300131,300135,300144,300147,300157,300159,300180,300543,307991,307993,315642,315643,320045,320046,320394,320395,320710,320711,320726,320727,320754,320755,320798,320799,321475,321487,323178,327681,328187,360449,360955,393217,393723,425985,426491,458753,459259,491521,492027,524289,524795,557057,557563,589825,590331,622593,623099,655361,655867,688129,688635,720897,721403,753665,754171,773253,774155,780254,780261,780367") && block_image_verify("/dev/block/bootdevice/by-name/system", package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat"), ui_print("system recovered successfully."), abort("E1004: system partition fails to recover"));
endif;
if (range_sha1("/dev/block/bootdevice/by-name/vendor", "50,1,221,570,578,588,589,670,671,820,821,885,886,888,892,894,905,910,911,913,914,922,923,1365,32770,32832,32833,33338,65537,66042,98306,98368,98369,98874,131073,131578,163842,163904,163905,164410,196609,197114,229378,229440,229441,229946,242356,258044,260078,260085,260203") == "eddf7a043eeaf07b4fcc407d22dfa91c21335a7e" || block_image_verify("/dev/block/bootdevice/by-name/vendor", package_extract_file("vendor.transfer.list"), "vendor.new.dat", "vendor.patch.dat")) then
ui_print("Verified vendor image...");
else
check_first_block("/dev/block/bootdevice/by-name/vendor");
ifelse (block_image_recover("/dev/block/bootdevice/by-name/vendor", "50,1,221,570,578,588,589,670,671,820,821,885,886,888,892,894,905,910,911,913,914,922,923,1365,32770,32832,32833,33338,65537,66042,98306,98368,98369,98874,131073,131578,163842,163904,163905,164410,196609,197114,229378,229440,229441,229946,242356,258044,260078,260085,260203") && block_image_verify("/dev/block/bootdevice/by-name/vendor", package_extract_file("vendor.transfer.list"), "vendor.new.dat", "vendor.patch.dat"), ui_print("vendor recovered successfully."), abort("E2004: vendor partition fails to recover"));
endif;

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

ui_print("Patching boot image...");
show_progress(0.100000, 10);
patch_partition("EMMC:/dev/block/bootdevice/by-name/boot:45303114:41e095446978727fb9a1213a3d1e410dd06744de",
                "EMMC:/dev/block/bootdevice/by-name/boot:45303114:95a1d99756f414dd2a6290afaa4ca34f6417c292",
                package_extract_file("boot.img.p")) ||
    abort("E3008: Failed to apply patch to EMMC:/dev/block/bootdevice/by-name/boot:45303114:95a1d99756f414dd2a6290afaa4ca34f6417c292");

# ---- radio update tasks ----

ui_print("Patching firmware images...");
package_extract_file("firmware-update/abl.elf", "/dev/block/bootdevice/by-name/abl_a");
package_extract_file("firmware-update/abl.elf", "/dev/block/bootdevice/by-name/abl_b");
show_progress(0.600000, 600);
ui_print("Patching system image after verification.");
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.");
ui_print("Patching vendor image after verification.");
block_image_update("/dev/block/bootdevice/by-name/vendor", package_extract_file("vendor.transfer.list"), "vendor.new.dat", "vendor.patch.dat") ||
  abort("E2001: Failed to update vendor image.");
show_progress(0.100000, 2);

# ---- radio update tasks 2 ----

ui_print("Patching vbmeta dtbo logo binimages...");
