Prompt [TIP] Running random scripts at boot

HTC One M8.

I have done HTCdev with
then rooted

Then did S-OFF with

Then, to be able to write to /system, you need more steps. From recovery, it works easily. From live running system, the default stock ROM has a write protection. This WP can be removed easily by loading a kernel module:
insmod /mnt/sdcard/Download/wp_mod_m8.ko
mount -o remount,rw /system
Now, I want to run random scripts.

First, check if the stock ROM has the same issue as my previous phone:

root@htc_m8:/ # echo $PATH
root@htc_m8:/ # ls -l /system/sbin
/system/sbin: No such file or directory
1|root@htc_m8:/ #
That's exactly what we need: a folder that is in PATH, that does not exist, and should exist somewhere we can create it. So:

insmod /mnt/sdcard/Download/wp_mod_m8.ko
mount -o remount,rw /system
mkdir /data/local/bin
ln -s /data/local/bin/ /system/sbin
Then, create two small scripts in there: do vi /system/sbin/vibrate , then i to enter insert mode, paste this code, esc, :x ... or use any other editor if you want:
[ "$i" = "" ] && i=400

# default value for voltage_level at boot is 3100 mV.
[ $i -gt 0 ] 2>/dev/null || {
        echo "Invalid argument '$i'; should be a number below 9999 ms."
        exit 1
[ $i -gt 9999 ] && {
        echo "Invalid argument '$i'; should be below 9999 ms."
        exit 1

[ "$2" != "" ] && {
[ $2 -ge $vmin ] 2>/dev/null || {
        echo "Invalid argument '$2'; should be a number between $vmin and ${v} mV."
        exit 1
[ $2 -gt $v ] && {
        echo "Invalid argument '$2'; should be below ${v} mV."
        exit 1

[ "$i" = "" ] && { echo "Provide argument: time in ms." ; exit 1 ; }
[ "$2" = "" ] && {
        echo "Voltage not provided. Using default $v mV."
        } || {
         echo "Using voltage argument $v mV."
echo $v > /sys/devices/virtual/timed_output/vibrator/voltage_level
echo "$i" > /sys/devices/virtual/timed_output/vibrator/enable
It was an old code for HTC Sensation; voltage does not work anymore, but duration does.

A shorter script for flash, and create the init script:

echo "echo 255 > /sys/class/leds/flashlight/brightness" > /system/sbin/flashlight
echo "#!/system/bin/sh

# /system/etc/

/system/sbin/flashlight" > /data/local/bin/rc.init
chmod 755 /system/sbin/flashlight
chmod 755 /system/sbin/vibrate
chmod 755 /data/local/bin/rc.init
Now, the tricky part: make the init script run at boot. Edit /system/etc/ , and below the comment, insert this line:

/data/local/bin/rc.init &
Reboot, enjoy Your phone flashes and vibrates at boot. As is, this is almost useless. But, now you can create system scripts, and run them at boot ... you can do pretty much anything you do on a classic Linux machine.

Because scripts are put in a folder which is in the default system $PATH, all apps or widgets can run those scripts. This vibrate script can be called for example from a Tasker or ScriptManager widget.

I love vibrate, because it's a small noise; I tail it to any command that is likely to take more than 1mn to run. Having a ScriptManager widget running it also helps me check the system load. If phone seems slow, and vibration does not happen at once, then the phone has big load, and I shall wait for things to settle.

/system/etc/ was not a random choice. To understand why: open / , and now, search a script that is run ... at boot ... with user root ... and that lays in /system. Many scripts are run as user, or stored outside /system.

Now, it's up to you to create scripts that are usefull to you.
HTC One M8, unpacked 2014-06-19 at 4PM; HTCDEV + SuperSU + S-Off + hone made random scripts at boot 2014-06-20 at 11:30PM .

HTC Sensation received July 27th 2011 (First HTC). Cracked Fre3vo 28th. Craked S-OFF via Revolutionary 30th with success on first attempt. LeeDrOiD 1.2.