Remove All Ads from XDA

[TIP] Running random scripts at boot

235 posts
Thanks Meter: 39
By doublehp, Senior Member on 21st June 2014, 12:28 AM
Post Reply Email Thread
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.
The Following 2 Users Say Thank You to doublehp For This Useful Post: [ View ] Gift doublehp Ad-Free
28th September 2014, 07:35 AM |#2  
rgolnazarian's Avatar
Flag sherman oaks
Thanks Meter: 13
Hey thanks for the directions but I tried running the command mnt/sdcard/download/wp_mod.ko and I got a "failed exec format error"....
28th September 2014, 11:53 PM |#3  
OP Senior Member
Thanks Meter: 39
Originally Posted by rgolnazarian

Hey thanks for the directions but I tried running the command mnt/sdcard/download/wp_mod.ko and I got a "failed exec format error"....

This is completely unrelated and offtopic. Either your file does not have exec bit, or wrong interpreter, or stored on partition that has noexec.

Hmmm ... why is the quoted message different from the one I received by email ???

Any way, even if you are in /, "mnt/sdcard/download/wp_mod.ko" is an invalid command. A module can not be executed, it must be inserted; see tutos about it.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes