[Android Software/Hacking General [Developers Only]] osm0sis:
Shell script is awesome.

I just took the most convoluted EDIFY script, my latest combined Nexus BootUnlocker Script zip -- which to support 3 devices had to be a nest of EDIFY ifelse logic so deep that the thought of adding support for yet another device was giving me nightmares -- and with a few tricks from good old Chainfire, turned it into a shell script with variables to make device addition a breeze, remove all the redundancies, and that works with the recovery UI if you replace the update-binary with it.

Let's compare. ;)

cwm-Nexus.BootUnlocker-EDIFY.zip/META-INF/com/google/android/updater-script:

ui_print("");
ui_print("Nexus BootUnlocker Script");
ui_print("by osm0sis @ xda-developers");
ui_print("");

ui_print("For GN, N4 and N10 bootloaders ONLY");
show_progress(1.34, 0);

ui_print("");
ui_print("Verifying device...");
run_program("/sbin/busybox", "mount", "/system");
ifelse(getprop("ro.product.device") == "maguro" || getprop("ro.build.product") == "maguro" ||
getprop("ro.product.device") == "toro" || getprop("ro.build.product") == "toro" ||
getprop("ro.product.device") == "toroplus" || getprop("ro.build.product") == "toroplus",
(ui_print("Galaxy Nexus: ", getprop("ro.product.device"));
ui_print("Bootloader: ", getprop("ro.bootloader"));
set_progress(0.4);
ui_print("");
ui_print("Checking bootloader status...");
ifelse(run_program("/sbin/sh", "-c", "test `dd ibs=1 count=1 skip=124 obs=1 if=/dev/block/platform/omap/omap_hsmmc.0/by-name/param 2> /dev/nul | /sbin/busybox od -h | /sbin/busybox head -n 1 | /sbin/busybox cut -c 13-` = '0001'") == 0,
(ui_print("Bootloader is locked.");
ui_print("");
ui_print("Unlocking...");
assert(run_program("/sbin/sh", "-c", "echo -ne '\\x00' | dd obs=1 count=1 seek=124 of=/dev/block/platform/omap/omap_hsmmc.0/by-name/param"));
),
(ifelse(run_program("/sbin/sh", "-c", "test -z `dd ibs=1 count=1 skip=124 obs=1 if=/dev/block/platform/omap/omap_hsmmc.0/by-name/param 2> /dev/nul | /sbin/busybox od -h | /sbin/busybox head -n 1 | /sbin/busybox cut -c 13-`") == 0,
(ui_print("Bootloader is unlocked.");
ui_print("");
ui_print("Locking...");
assert(run_program("/sbin/sh", "-c", "echo -ne '\\x01' | dd obs=1 count=1 seek=124 of=/dev/block/platform/omap/omap_hsmmc.0/by-name/param"));
),
(ui_print("Status does not match known values.");
ui_print("This is not the intended device or bootloader.");
ui_print("");
ui_print("Your system has not been changed.");
ui_print("");
ui_print("Script will now exit...");
ui_print("");
unmount("/system");
abort();
)
);
)
);
),
(ifelse(getprop("ro.product.device") == "mako" || getprop("ro.build.product") == "mako",
(ui_print("Nexus 4: ", getprop("ro.product.device"));
ui_print("Bootloader: ", getprop("ro.bootloader"));
set_progress(0.4);
ui_print("");
ui_print("Checking bootloader status...");
ifelse(run_program("/sbin/sh", "-c", "test -z `dd ibs=1 count=1 skip=16400 obs=1 if=/dev/block/platform/msm_sdcc.1/by-name/misc 2> /dev/nul | /sbin/busybox od -h | /sbin/busybox head -n 1 | /sbin/busybox cut -c 13-`") == 0,
(ui_print("Bootloader is locked.");
ui_print("");
ui_print("Unlocking...");
assert(run_program("/sbin/sh", "-c", "echo -ne '\\x01' | dd obs=1 count=1 seek=16400 of=/dev/block/platform/msm_sdcc.1/by-name/misc"));
),
(ifelse(run_program("/sbin/sh", "-c", "test `dd ibs=1 count=1 skip=16400 obs=1 if=/dev/block/platform/msm_sdcc.1/by-name/misc 2> /dev/nul | /sbin/busybox od -h | /sbin/busybox head -n 1 | /sbin/busybox cut -c 13-` = '0001'") == 0,
(ui_print("Bootloader is unlocked.");
ui_print("");
ui_print("Locking...");
assert(run_program("/sbin/sh", "-c", "echo -ne '\\x00' | dd obs=1 count=1 seek=16400 of=/dev/block/platform/msm_sdcc.1/by-name/misc"));
),
(ui_print("Status does not match known values.");
ui_print("This is not the intended device or bootloader.");
ui_print("");
ui_print("Your system has not been changed.");
ui_print("");
ui_print("Script will now exit...");
ui_print("");
unmount("/system");
abort();
)
);
)
);
),
(ifelse(getprop("ro.product.device") == "manta" || getprop("ro.build.product") == "manta",
(ui_print("Nexus 10: ", getprop("ro.product.device"));
ui_print("Bootloader: ", getprop("ro.bootloader"));
set_progress(0.4);
ui_print("");
ui_print("Checking bootloader status...");
ifelse(run_program("/sbin/sh", "-c", "test -z `dd ibs=1 count=1 skip=548 obs=1 if=/dev/block/platform/dw_mmc.0/by-name/param 2> /dev/nul | /sbin/busybox od -h | /sbin/busybox head -n 1 | /sbin/busybox cut -c 13-`") == 0,
(ui_print("Bootloader is locked.");
ui_print("");
ui_print("Unlocking...");
assert(run_program("/sbin/sh", "-c", "echo -ne '\\x01' | dd obs=1 count=1 seek=548 of=/dev/block/platform/dw_mmc.0/by-name/param"));
),
(ifelse(run_program("/sbin/sh", "-c", "test `dd ibs=1 count=1 skip=548 obs=1 if=/dev/block/platform/dw_mmc.0/by-name/param 2> /dev/nul | /sbin/busybox od -h | /sbin/busybox head -n 1 | /sbin/busybox cut -c 13-` = '0001'") == 0,
(ui_print("Bootloader is unlocked.");
ui_print("");
ui_print("Locking...");
assert(run_program("/sbin/sh", "-c", "echo -ne '\\x00' | dd obs=1 count=1 seek=548 of=/dev/block/platform/dw_mmc.0/by-name/param"));
),
(ui_print("Status does not match known values.");
ui_print("This is not the intended device or bootloader.");
ui_print("");
ui_print("Your system has not been changed.");
ui_print("");
ui_print("Script will now exit...");
ui_print("");
unmount("/system");
abort();
)
);
)
);
),
(ifelse(getprop("ro.product.device") == "grouper" || getprop("ro.build.product") == "grouper" ||
getprop("ro.product.device") == "tilapia" || getprop("ro.build.product") == "tilapia",
(ui_print("Nexus 7: ", getprop("ro.product.device"));
ui_print("Bootloader: ", getprop("ro.bootloader"));
ui_print("");
ui_print("Unsupported device.");
ui_print("For N7 BootUnlocker Script go to http://v.ht/N7BU");
),
(ui_print("Device: ", getprop("ro.product.device"));
ui_print("Bootloader: ", getprop("ro.bootloader"));
ui_print("");
ui_print("Unsupported device.");
)
);
set_progress(0.4);
ui_print("");
ui_print("Your system has not been changed.");
ui_print("");
ui_print("Script will now exit...");
ui_print("");
unmount("/system");
abort();
)
);
)
);
)
);
set_progress(0.9);

unmount("/system");
ui_print("Done!");
set_progress(1.34);

144 lines, 6741 bytes.

And... :D

cwm-Nexus.BootUnlocker.zip/META-INF/com/google/android/update-binary:

#!/sbin/sh
# Nexus BootUnlocker Script: Recovery Flashable Zip
# osm0sis @ xda-developers

OUTFD=$2;
ui_print() {
echo -ne "ui_print $1\n" > /proc/self/fd/$OUTFD;
echo -ne "ui_print\n" > /proc/self/fd/$OUTFD;
}
show_progress() { echo "progress $1 $2" > /proc/self/fd/$OUTFD; }
set_progress() { echo "set_progress $1" > /proc/self/fd/$OUTFD; }
abort() {
ui_print " ";
ui_print "Your system has not been changed.";
ui_print " ";
ui_print "Script will now exit...";
ui_print " ";
umount /system;
exit 1;
}

ui_print " ";
ui_print "Nexus BootUnlocker Script";
ui_print "by osm0sis @ xda-developers";
ui_print " ";
ui_print "For GN, N4 and N10 bootloaders ONLY";
show_progress 1.34 0;

ui_print " ";
ui_print "Verifying device...";
/sbin/busybox mount /system;
set_progress 0.2;
device=`getprop ro.product.device`;
bootloader=`getprop ro.bootloader`;
if [ $device == "maguro" -o $device == "toro" -o $device == "toroplus" ]; then
ui_print "Galaxy Nexus: $device";
block=/dev/block/platform/omap/omap_hsmmc.0/by-name/param;
offset=124;
locked=01;
unlocked=00;
elif [ $device == "mako" ]; then
ui_print "Nexus 4: $device";
block=/dev/block/platform/msm_sdcc.1/by-name/misc;
offset=16400;
locked=00;
unlocked=01;
elif [ $device == "manta" ]; then
ui_print "Nexus 10: $device";
block=/dev/block/platform/dw_mmc.0/by-name/param;
offset=548;
locked=00;
unlocked=01;
else
test -z $device && device=unknown;
test -z $bootloader && bootloader=unknown;
test $device == "grouper" -o $device == "tilapia" && ui_print "Nexus 7 (2012): $device" || ui_print "Device: $device";
ui_print "Bootloader: $bootloader";
ui_print " ";
ui_print "Unsupported device.";
test $device == "grouper" -o $device == "tilapia" && ui_print "For N7'12 BootUnlocker Script go to http://v.ht/N7BU";
abort;
fi;
ui_print "Bootloader: $bootloader";
set_progress 0.4;

ui_print " ";
ui_print "Checking bootloader status...";
lockstate=`dd ibs=1 count=1 skip=$offset obs=1 if=$block 2> /dev/nul | /sbin/busybox od -h | /sbin/busybox head -n 1 | /sbin/busybox cut -c 15-`;
test -z $lockstate && lockstate=00;
set_progress 0.6;
if [ $lockstate == $locked ]; then
ui_print "Bootloader is locked.";
ui_print " ";
ui_print "Unlocking...";
setstate=$unlocked;
elif [ $lockstate == $unlocked ]; then
ui_print "Bootloader is unlocked.";
ui_print " ";
ui_print "Locking...";
setstate=$locked;
else
ui_print "Status does not match known values.";
ui_print "This is not the intended device or bootloader.";
abort;
fi;
set_progress 0.8;

echo -ne "\x$setstate" | dd obs=1 count=1 seek=$offset of=$block;
set_progress 1.0;

umount /system;
set_progress 1.2;
ui_print "Done!";
set_progress 1.34;
exit 0;

97 lines, 2730 bytes.

Plus since it removes the need for an actual update-binary (~221 kB+), it reduces the size of the zip from 145 kB down to 2 kB. Haha. Take that, Google. 😄

I also realized that with the old one I have uploaded, on the N10 it'll display "Nexus 4: manta" by mistake. It works correctly but that typo could be scary for some manta users. Anyway, the old can stay up for now, since I want to add support for the Nexus 7 2013 (flo/deb), if possible, before I release this one, but we need volunteers: http://xdaforums.com/showthread.php?t=1731993&page=25

If you've got an unlocked new N7 please lend a hand. :good: