Launch a script at boot


#1

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


#2

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’?


#3

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


#4

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


#5

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."

Would I change a startup service in init.rc?
#6

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