Search code examples
androidandroid-emulatorbootandroid-buildrootfs

Copy a shell script to android out folder and execute it during boot


I have a shell script which I need to copy to anywhere in out folder during Android build process so that it appears somewhere in Android RootFS. Now, once it is copied after Android build process and becomes part of Android RootFS, I want to execute the shell script during boot time.

How can I do it?


Solution

  • Well, I created a root folder in AOSP or anywhere, then created Android.mk and copied the script to be copied to out folder. Added below comments in Android.mk

    $(shell cp -rf $(LOCAL_PATH)/myscript.sh `pwd`/$(TARGET_OUT)/path/to/folder/)
    

    Now to make it run during Android boot, I added below code in last of init.goldfish.rc:

    service myscript_start /system/bin/busybox ash /system/path/to/folder/myscript.sh
        class main
        oneshot
    

    Also, I added below line under # start essential services section of init.goldfish.rc

    start myscript_start
    

    That way my script was copied to desired location of out folder and also got called during android boot time.

    I wonder if there is any better way to do that. I would like to know if anyone has suggestions.