[One (M8) Q&A, Help & Troubleshooting] doublehp:
HTC One M8.

I have done HTCdev with http://htc-one.wonderhowto.com/how-to/unlock-bootloader-root-your-htc-one-m8-0154444/

then rooted

Then did S-OFF with http://firewater-soff.com/instructions/

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:

http://xdaforums.com/showthread.php?t=2701816

then:

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
/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin:/vendor/bin
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:

#!/system/xbin/ash
#
i="$1"
[ "$i" = "" ] && i=400

# default value for voltage_level at boot is 3100 mV.
v=3100
vmin=1200
[ $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."
} || {
v=$2
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/init.qcom.bt.sh

/data/local/bin/vibrate
/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/init.qcom.bt.sh , 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/init.qcom.bt.sh was not a random choice. To understand why: open /init.target.rc , 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.