Launch a script at boot

Hi there,

Do you know how to launch a script at boot on Android Nougat?

I used to create a userinit.sh script in /data/local on other boards but it doesn’t work for the Khadas VIM.
I’ve also tried to put my script in /etc/init.d but it didn’t work as well.

Peace

Are you a developer? Can you build your rom?
You need to modify the source code and execute the shell script.
What’s the function of your script ‘userinit.sh’?

Hi

Yes I am. My userinit.sh launches an executable from /data/local.

Here is its content:

#!/system/bin/sh
/data/local/myExecutable

I’ve gave the file all permissions.

chmod 0777 /data/local/myExecutable

You can follow below steps to have a try
###Steps###
1.Modify the file device/khadas/kvim/init.amlogic.board.rc

@@ -43,3 +43,8 @@ service tee_supplicant /system/bin/tee-supplicant
                oneshot
                seclabel u:r:tee:s0
 
+service myExecutable /system/bin/myExecutable
+        class main
+        user_root
+        group root
+        oneshot

2.Modify the file ‘device/khadas/kvim/device.mk’

@@ -37,6 +37,10 @@ PRODUCT_COPY_FILES += \
     device/khadas/kvim/files/mesondisplay.cfg:system/etc/mesondisplay.cfg \
     frameworks/native/data/etc/android.hardware.hdmi.cec.xml:system/etc/permissions/android.hardware.
 
+PRODUCT_COPY_FILES += \
+    device/khadas/kvim/file/myExecutable:system/bin/myExecutable
+

3.Copy the file ‘myExecutable’ to the path ‘device/khadas/kvim/file/’

4.Rebuild your rom

About how to add support for the script in the path ‘system/etc/init.d/’ , You can follow below method to test by adb command.

$ adb root
$ adb remount
$ adb push userinit.sh /system/etc/init.d/userinit
$ adb shell vi /system/bin/preinstall.sh
$ adb sync 
$ adb reboot

Notice:

  1. The file ‘userinit.sh’ must be renamed as ‘userinit’

  2. Modify the file ‘system/bin/preinstall.sh’

@@ -3,6 +3,7 @@
 MARK=/data/local/symbol_thirdpart_apks_installed
 PKGS=/system/preinstall/
 
+busybox run-parts /system/etc/init.d/
 if [ ! -e $MARK ]; then
 echo "booting the first time, so pre-install some APKs."
1 Like

In a Amlogic Tx3 tv-box, it works!!

Hiii @Terry

I am creating my own service for VIM3. Will I have to create .te file in sepolicy??
Or these three steps are enough??

I have done it.
Though I had to made few changes apart from those three steps suggested by Terry.

@Parth_Prajapati

Hi
I also use VIM3.
Does the sepolicy folder need to modify ?
ex : *.te
path : \device\khadas\common\sepolicy

Yes, You have to modify sepolicy folder.