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", "4cf16208c77edf0e2955e711ec79cf7c760cf6ab", "fd065145d017428efc029b8e4db806bf33b62561") || abort("E3005: \"/system/etc/shadow\" has unexpected contents.");
apply_patch_check("/system/usr/bin/atfwd_daemon", "a20261bf21d59a9a05b6023af39687abf6b7f478", "8ef42dd5d2b4cf08d2803fe40ae23a015076aff1") || abort("E3005: \"/system/usr/bin/atfwd_daemon\" has unexpected contents.");
apply_patch_check("/system/var/lib/opkg/status", "4625db9796a52118534b5773912261ca224b76f3", "519d6635b862c01544564dfdf0f147528b188e5a") || abort("E3005: \"/system/var/lib/opkg/status\" has unexpected contents.");
apply_patch_space(102700) || 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.b20", "890cc1a35903e4ae1da9adf9a345eec614733198", "57efb56b2455564bddec8425d1d115b836e53d6d") || abort("E3005: \"/firmware/image/modem.b20\" has unexpected contents.");
apply_patch_check("/firmware/image/modem.mdt", "86ea0c00e9c1f5c178400b0b2039841aeb29f1cf", "4cc06d6a1155ca0d472c0911e1967d416916ed17") || abort("E3005: \"/firmware/image/modem.mdt\" has unexpected contents.");
apply_patch_check("/firmware/image/modem.b23", "44210fe541d3d6591941088f6fe2d41ab4312953", "e870784d873d84d58c32aa6cb4c0b29d429a7c0e") || abort("E3005: \"/firmware/image/modem.b23\" has unexpected contents.");
apply_patch_check("/firmware/image/modem.b01", "42e44ab22b3e87d7cecbe246422f0e4b82583ac7", "cc76896d1e8373d2961e1d887c9271751e5fd7a2") || abort("E3005: \"/firmware/image/modem.b01\" 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", "-",
            4cf16208c77edf0e2955e711ec79cf7c760cf6ab, 1205,
            fd065145d017428efc029b8e4db806bf33b62561,
            package_extract_file("patch/system/etc/shadow.p")) ||
    abort("E3008: Failed to apply patch to /system/etc/shadow");
set_progress(0.006053);
apply_patch("/system/usr/bin/atfwd_daemon", "-",
            a20261bf21d59a9a05b6023af39687abf6b7f478, 102700,
            8ef42dd5d2b4cf08d2803fe40ae23a015076aff1,
            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.521928);
apply_patch("/system/var/lib/opkg/status", "-",
            4625db9796a52118534b5773912261ca224b76f3, 95173,
            519d6635b862c01544564dfdf0f147528b188e5a,
            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.999995);
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/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.b20", "-",
            890cc1a35903e4ae1da9adf9a345eec614733198, 17208808,
            57efb56b2455564bddec8425d1d115b836e53d6d,
            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.mdt", "-",
            86ea0c00e9c1f5c178400b0b2039841aeb29f1cf, 8788,
            4cc06d6a1155ca0d472c0911e1967d416916ed17,
            package_extract_file("patch/firmware-update/modem.mdt.p")) ||
    abort("E3008: Failed to apply patch to /firmware/image/modem.mdt");
apply_patch("/firmware/image/modem.b23", "-",
            44210fe541d3d6591941088f6fe2d41ab4312953, 85120,
            e870784d873d84d58c32aa6cb4c0b29d429a7c0e,
            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.b01", "-",
            42e44ab22b3e87d7cecbe246422f0e4b82583ac7, 7808,
            cc76896d1e8373d2961e1d887c9271751e5fd7a2,
            package_extract_file("patch/firmware-update/modem.b01.p")) ||
    abort("E3008: Failed to apply patch to /firmware/image/modem.b01");
ui_print("Patching remaining system files...");
set_metadata("/system/build.prop", "uid", 0, "gid", 0, "mode", 0644, "capabilities", 0x0);
unmount("/system");
