Post Reply

[TIP] Running random scripts at boot

OP doublehp

20th June 2014, 11:28 PM   |  #1  
OP Senior Member
Thanks Meter: 35
 
215 posts
Join Date:Joined: Jul 2009
HTC One M8.

I have done HTCdev with http://htc-one.wonderhowto.com/how-t...ne-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://forum.xda-developers.com/show....php?t=2701816
then:
Code:
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:

Code:
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:

Code:
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:
Code:
#!/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:

Code:
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:

Code:
/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.
The Following 2 Users Say Thank You to doublehp For This Useful Post: [ View ]
28th September 2014, 06:35 AM   |  #2  
rgolnazarian's Avatar
Member
Thanks Meter: 4
 
48 posts
Join Date:Joined: Oct 2012
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, 10:53 PM   |  #3  
OP Senior Member
Thanks Meter: 35
 
215 posts
Join Date:Joined: Jul 2009
Quote:
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
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in One (M8) Q&A, Help & Troubleshooting by ThreadRank