I have a script I need to run once, and only once the phone is booted.
I have attempted init.qcom.post_boot.sh, init.sec.boot.sh, debuggerd, and finally mkshrc
While my script ran with debuggerd, I found that it ran every time debuggerd ran, which is not something I need to happen... thus when I stumbled upon /system/etc/mkshrc
(the other 2 simply did not work)
What I found was, the script runs that one time, on boot... however, it also seems to run every time adb shell
runs, along with (I assume) everytime shell is fired up... which is also undersireable.
So, what can I do in /system/etc/mkshrc
to ensure my call to my script runs only the one time... at boot?
I thought about running a while
loop to check for the getprop sys.boot_completed
if it ==
1 then dump a file somewhere, and through an if
statement inside the looop to check for that file, if exists then exit, if not then run the next command...
however, everywhere I am allowed to dump that file, it persists between boots, so that next command
never runs again.
NOTE
Does not need root to do this, nor does my script need root to run (yes, I have confirmed)
CODE
BB=/system/xbin/busybox
MYPID=/mnt/sdcard/.kev-run
while [ `getprop init.svc.bootanim` == "stopped" ] ; do
# if the run file does not exist, and we are stopped
if [ ! -e $MYPID ]; then
# run the scripts, then create the run file
LOG=/mnt/sdcard/Download/kevs-scripts.log
$BB rm -f $LOG;
$BB echo "Launching Kevs Scripts" >> $LOG;
MY_SCRIPT
# write the run file so we aren't running this everytime this file runs
touch $MYPID;
sleep 1;
fi
done
# if we are still booting, delete the run file
while [ `getprop init.svc.bootanim` != "stopped" ] ; do
# we're not done booting, remove our makeshift pid file and sleep a second
$BB rm -f $MYPID;
sleep 1;
done
Seems to be off to me