ui_print(" ");
ui_print("==================================================");
ui_print("EX Control - USB setup");
ui_print("Official EX Control file, free from the EX Control website.");
ui_print("==================================================");
ui_print(concat("Unit: ", getprop("ro.product.device"), "    SW: ", getprop("ro.bicv.os.version")));
ui_print(concat("Build: ", getprop("ro.build.version.incremental")));
ui_print("==================================================");
getprop("ro.product.device") == "IHU629G" || abort("Wrong head unit - this file is for IHU629G only. Nothing was changed.");
ui_print("Preparing the head unit for EX Control...");
set_progress(0.200000);
mount("ext4", "EMMC", "/dev/block/platform/bootdevice/by-name/system", "/system");
mount("ext4", "EMMC", "/dev/block/platform/bootdevice/by-name/userdata", "/data");
ui_print(ifelse(is_mounted("/system"), "[OK] /system mounted", "[!!] /system NOT mounted"));
ui_print(ifelse(is_mounted("/data"), "[OK] /data mounted", "[!!] /data NOT mounted"));
is_mounted("/system") || abort("/system could not be mounted. Nothing was changed.");
is_mounted("/data") || abort("/data could not be mounted. Nothing was changed.");
run_program("/system/bin/sh", "-c", "f=/data/property/persistent_properties; st=/tmp/adb_enable.status; REC='\\012\\034\\012\\024persist.adb.tcp.port\\022\\0045555'; NEEDLE='\\024persist.adb.tcp.port\\022\\0045555'; before=0; [ -f \"$f\" ] && before=$(wc -c < \"$f\" | tr -d ' '); if [ ! -f \"$f\" ]; then if printf \"$REC\" > \"$f\"; then chmod 600 \"$f\"; out=created; else out=error_write; fi; elif grep -aqF \"$(printf \"$NEEDLE\")\" \"$f\"; then out=already; else if printf \"$REC\" >> \"$f\"; then out=added; else out=error_write; fi; fi; restorecon \"$f\" 2>/dev/null || :; after=0; [ -f \"$f\" ] && after=$(wc -c < \"$f\" | tr -d ' '); grep -aqF \"$(printf \"$NEEDLE\")\" \"$f\" || out=error_verify; printf 'status=%s (%s -> %s bytes)\\n' \"$out\" \"$before\" \"$after\" > \"$st\"");
set_progress(1.000000);
ui_print("---");
ui_print(concat("Result: ", file_getprop("/tmp/adb_enable.status", "status")));
ui_print(ifelse(is_substring("already", file_getprop("/tmp/adb_enable.status", "status")), "[OK] Head unit was already prepared.", ifelse(is_substring("error", file_getprop("/tmp/adb_enable.status", "status")), "[!!] ERROR - the head unit was NOT prepared.", "[OK] Head unit prepared.")));
ui_print("---");
ui_print("Copying the EX Control installer...");
ifelse(package_extract_file("exdrop/base.apk", "/tmp/exdrop.apk") && package_extract_file("exdrop/apk-drop.sh", "/tmp/apk-drop.sh"), run_program("/system/bin/sh", "/tmp/apk-drop.sh", "com.ex.installer", "system"), ui_print("[!!] could not extract the installer"));
ui_print(ifelse(is_substring("placed", file_getprop("/tmp/apk_drop.status", "status")) || is_substring("replaced", file_getprop("/tmp/apk_drop.status", "status")), "[OK] Installer copied.", ifelse(is_substring("skipped", file_getprop("/tmp/apk_drop.status", "status")), "[OK] Installer already in place.", concat("[!!] Installer NOT copied: ", file_getprop("/tmp/apk_drop.status", "status")))));
ui_print("---");
ui_print("KEEP THE USB DRIVE PLUGGED IN.");
ui_print("After the restart, EX Control installs by itself");
ui_print("from the drive within about a minute.");
ui_print("---");
ui_print("'Installation aborted' below is NORMAL.");
ui_print("Nothing was erased. This is expected.");
ui_print("---");
ui_print("Hold the LEFT (previous track) steering wheel button");
ui_print("for about 20 seconds to restart.");
ui_print("==================================================");
abort("Done - intentional stop, nothing erased");
