mount("ubifs", "UBI", "system", "/system", "");
ui_print("Source: None");
ui_print("Target: None");
ui_print("Verifying current system...");
show_progress(0.100000, 0);
apply_patch_check("/system/etc/shadow", "e9d90be6d661e502a350633edcf90548b9ef2c0d", "f6267a29a821dd37089d6596d44f1c55e5a0392d") || abort("E3005: \"/system/etc/shadow\" has unexpected contents.");
apply_patch_check("/system/usr/bin/atfwd_daemon", "6fd43b3b3b7eeca9b9343b92b274c5091d53f0bf", "fdbd3f4cbdf64feaa91111b77f6bcf9e168e08fb") || abort("E3005: \"/system/usr/bin/atfwd_daemon\" has unexpected contents.");
apply_patch_check("/system/usr/bin/fibo_app_platform", "cce4f89d9c88d33a936eb6f576b8a8cd78772ac8", "79ad2744c7f94d328740f7623d27a989a218cd1f") || abort("E3005: \"/system/usr/bin/fibo_app_platform\" has unexpected contents.");
apply_patch_check("/system/var/lib/opkg/status", "425baa0d8771ce0862e2b02062685af3f42aec1d", "34375d3952c4e128cdde18d0a745ddb11d0f0a69") || abort("E3005: \"/system/var/lib/opkg/status\" has unexpected contents.");
apply_patch_space(1608220) || abort("E3006: Not enough free space on /cache to apply patches.");

# ---- radio update verification ----

ui_print("Verifying radio-update...");
apply_patch_check("/firmware/image/modem.b02", "17f9d55ae4a6c06554ef23b8bbd5764fe6acfd0b", "83472f2cb8d3ff129d93512c394fc1c41e6cb32b") || abort("E3005: \"/firmware/image/modem.b02\" has unexpected contents.");
apply_patch_check("/firmware/image/modem.b21", "e18e784753e0f5162042475685ddf9dce90f04b2", "e316723d0a4e2dcefa9f5ebcecc46da8c4062882") || abort("E3005: \"/firmware/image/modem.b21\" has unexpected contents.");
apply_patch_check("/firmware/image/modem.b23", "e4b96e0ea6657ba8e237bf13bf5b3f9a003e4b6e", "fa844f6be7024b9c3bb4a0c1429ea73083f314da") || abort("E3005: \"/firmware/image/modem.b23\" has unexpected contents.");
apply_patch_check("/firmware/image/modem.b26", "d1be019981e244c0a825249e7353e5de01168e6c", "71b7ed5a7e869d43fd14b80b276f93ea7789fc2c") || abort("E3005: \"/firmware/image/modem.b26\" has unexpected contents.");
apply_patch_check("/firmware/image/modem.b24", "68fe62eb0d24e60bf32c87bd33e1446fc041092b", "82b3c253a4718743153ae14aaf6f8e62f881651c") || abort("E3005: \"/firmware/image/modem.b24\" has unexpected contents.");
apply_patch_check("/firmware/image/modem.b20", "59330cb3fd5ac4aaee66d22a3fd5f6fc05f76c88", "9060391b154095d00e6058ebf4ac0802affa6d63") || abort("E3005: \"/firmware/image/modem.b20\" has unexpected contents.");
apply_patch_check("/firmware/image/modem.b01", "fe87a989475d6cc766c83cc67d33bad508c3d375", "0db7ea8284a364eaaee063b96b8b7ab81a02a210") || abort("E3005: \"/firmware/image/modem.b01\" has unexpected contents.");
apply_patch_check("/firmware/image/modem.mdt", "b178c0cd44f80d0f3d331a17f6df2e5d4e1c44d9", "c7efaed549a0658d2ce51f322984f610f975e2e6") || abort("E3005: \"/firmware/image/modem.mdt\" has unexpected contents.");

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

ui_print("Removing unneeded files...");
delete("/system/recovery.img", "/system/etc/version",
       "/system/etc/timestamp",
       "/system/build.prop");
show_progress(0.800000, 0);
ui_print("Patching system files...");
apply_patch("/system/etc/shadow", "-",
            e9d90be6d661e502a350633edcf90548b9ef2c0d, 1205,
            f6267a29a821dd37089d6596d44f1c55e5a0392d,
            package_extract_file("patch/system/etc/shadow.p")) ||
    abort("E3008: Failed to apply patch to /system/etc/shadow");
set_progress(0.000663);
apply_patch("/system/usr/bin/atfwd_daemon", "-",
            6fd43b3b3b7eeca9b9343b92b274c5091d53f0bf, 112596,
            fdbd3f4cbdf64feaa91111b77f6bcf9e168e08fb,
            package_extract_file("patch/system/usr/bin/atfwd_daemon.p")) ||
    abort("E3008: Failed to apply patch to /system/usr/bin/atfwd_daemon");
set_progress(0.062608);
apply_patch("/system/usr/bin/fibo_app_platform", "-",
            cce4f89d9c88d33a936eb6f576b8a8cd78772ac8, 1608220,
            79ad2744c7f94d328740f7623d27a989a218cd1f,
            package_extract_file("patch/system/usr/bin/fibo_app_platform.p")) ||
    abort("E3008: Failed to apply patch to /system/usr/bin/fibo_app_platform");
set_progress(0.947374);
apply_patch("/system/var/lib/opkg/status", "-",
            425baa0d8771ce0862e2b02062685af3f42aec1d, 95657,
            34375d3952c4e128cdde18d0a745ddb11d0f0a69,
            package_extract_file("patch/system/var/lib/opkg/status.p")) ||
    abort("E3008: Failed to apply patch to /system/var/lib/opkg/status");
set_progress(0.999999);
show_progress(0.100000, 10);
ui_print("Unpacking new system files...");
package_extract_dir("system", "/system");
ui_print("Symlinks and permissions...");
set_metadata("/system", "uid", 0, "gid", 0, "mode", 0755, "capabilities", 0x0, "selabel", "system_u:object_r:root_t:s0");
set_metadata("/system/build.prop", "uid", 0, "gid", 0, "mode", 0644, "capabilities", 0x0, "selabel", "system_u:object_r:leprop_system_data_t:s15:c0.c1023");
set_metadata("/system/etc", "uid", 0, "gid", 0, "mode", 0755, "capabilities", 0x0, "selabel", "system_u:object_r:etc_t:s0");
set_metadata("/system/etc/shadow", "uid", 0, "gid", 0, "mode", 0400, "capabilities", 0x0, "selabel", "system_u:object_r:shadow_t:s0");
set_metadata("/system/etc/timestamp", "uid", 0, "gid", 0, "mode", 0644, "capabilities", 0x0, "selabel", "system_u:object_r:etc_t:s0");
set_metadata("/system/etc/version", "uid", 0, "gid", 0, "mode", 0644, "capabilities", 0x0, "selabel", "system_u:object_r:etc_t:s0");
set_metadata("/system/usr", "uid", 0, "gid", 0, "mode", 0755, "capabilities", 0x0, "selabel", "system_u:object_r:usr_t:s0");
set_metadata("/system/usr/bin", "uid", 0, "gid", 0, "mode", 0755, "capabilities", 0x0, "selabel", "system_u:object_r:bin_t:s0");
set_metadata("/system/usr/bin/atfwd_daemon", "uid", 0, "gid", 0, "mode", 0755, "capabilities", 0x0, "selabel", "system_u:object_r:atfwd_exec_t:s0");
set_metadata("/system/usr/bin/fibo_app_platform", "uid", 0, "gid", 0, "mode", 0755, "capabilities", 0x0, "selabel", "system_u:object_r:fibo_app_platform_exec_t:s0");
set_metadata("/system/var", "uid", 0, "gid", 0, "mode", 0755, "capabilities", 0x0, "selabel", "system_u:object_r:var_t:s0");
set_metadata("/system/var/lib", "uid", 0, "gid", 0, "mode", 0755, "capabilities", 0x0, "selabel", "system_u:object_r:var_lib_t:s0");
set_metadata("/system/var/lib/opkg", "uid", 0, "gid", 0, "mode", 0755, "capabilities", 0x0, "selabel", "system_u:object_r:var_lib_t:s0");
set_metadata("/system/var/lib/opkg/status", "uid", 0, "gid", 0, "mode", 0644, "capabilities", 0x0, "selabel", "system_u:object_r:var_lib_t:s0");

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

ui_print("Patching firmware images...");
apply_patch("/firmware/image/modem.b02", "-",
            17f9d55ae4a6c06554ef23b8bbd5764fe6acfd0b, 10544,
            83472f2cb8d3ff129d93512c394fc1c41e6cb32b,
            package_extract_file("patch/firmware-update/modem.b02.p")) ||
    abort("E3008: Failed to apply patch to /firmware/image/modem.b02");
apply_patch("/firmware/image/modem.b21", "-",
            e18e784753e0f5162042475685ddf9dce90f04b2, 10133278,
            e316723d0a4e2dcefa9f5ebcecc46da8c4062882,
            package_extract_file("patch/firmware-update/modem.b21.p")) ||
    abort("E3008: Failed to apply patch to /firmware/image/modem.b21");
apply_patch("/firmware/image/modem.b23", "-",
            e4b96e0ea6657ba8e237bf13bf5b3f9a003e4b6e, 89664,
            fa844f6be7024b9c3bb4a0c1429ea73083f314da,
            package_extract_file("patch/firmware-update/modem.b23.p")) ||
    abort("E3008: Failed to apply patch to /firmware/image/modem.b23");
apply_patch("/firmware/image/modem.b26", "-",
            d1be019981e244c0a825249e7353e5de01168e6c, 65536,
            71b7ed5a7e869d43fd14b80b276f93ea7789fc2c,
            package_extract_file("patch/firmware-update/modem.b26.p")) ||
    abort("E3008: Failed to apply patch to /firmware/image/modem.b26");
apply_patch("/firmware/image/modem.b24", "-",
            68fe62eb0d24e60bf32c87bd33e1446fc041092b, 40656960,
            82b3c253a4718743153ae14aaf6f8e62f881651c,
            package_extract_file("patch/firmware-update/modem.b24.p")) ||
    abort("E3008: Failed to apply patch to /firmware/image/modem.b24");
apply_patch("/firmware/image/modem.b20", "-",
            59330cb3fd5ac4aaee66d22a3fd5f6fc05f76c88, 14405288,
            9060391b154095d00e6058ebf4ac0802affa6d63,
            package_extract_file("patch/firmware-update/modem.b20.p")) ||
    abort("E3008: Failed to apply patch to /firmware/image/modem.b20");
apply_patch("/firmware/image/modem.b01", "-",
            fe87a989475d6cc766c83cc67d33bad508c3d375, 7808,
            0db7ea8284a364eaaee063b96b8b7ab81a02a210,
            package_extract_file("patch/firmware-update/modem.b01.p")) ||
    abort("E3008: Failed to apply patch to /firmware/image/modem.b01");
apply_patch("/firmware/image/modem.mdt", "-",
            b178c0cd44f80d0f3d331a17f6df2e5d4e1c44d9, 8788,
            c7efaed549a0658d2ce51f322984f610f975e2e6,
            package_extract_file("patch/firmware-update/modem.mdt.p")) ||
    abort("E3008: Failed to apply patch to /firmware/image/modem.mdt");
ui_print("Patching remaining system files...");
set_metadata("/system/build.prop", "uid", 0, "gid", 0, "mode", 0644, "capabilities", 0x0);
unmount("/system");
