[SCRIPT/ZIP][v1.3] Init.d enabler @ stock kernel / ALL DEVICES / NO BUSYBOX needed

Search This thread

_alexndr

Senior Member
Mar 1, 2013
2,815
17,624
Samsung Galaxy S21 Ultra
I present you universal script to enable Init.d in ALL ANDROID DEVICES (I hope...) while running the stock kernel. NO BUSYBOX needed! It is packed in easy to use ZIP flashable :cool:

EDIT: This script will NOT work with Magisk! However, notice that using Magisk you do not need init.d support at all (you can put your scripts in /magisk/.core/post-fs-data.d OR /magisk/.core/service.d, depending on your needs).

Requirements:
- a rooted Android device (SuperSU) :)
- ANY tool to flash a ZIP (custom recovery or FlashFire app)

Installation:
1. Custom recovery - open file using "Install Zip" option and confirm "Yes - install..."
2. FlashFire - open file using "Flash ZIP or OTA" option (default mount options). Tap "FLASH"

How to check:
Just check if /data/initd_test.log file exists (optionally you can check its content) :cool:

Changelog:

v1.3:

★ This version automatically detects privileges of launched sh script used to trigger init.d and if these are not sufficient to remount /system rw - all commands are automatically expanded to "/su/bin/su -c [command]" or "/system/xbin/su -c [command]" (depending on SuperSU install mode)
★ Fixed problem with "exit 0" at the end of used sh script resulting that simply added new lines never worked. This version automatically detects such case and moves "exit 0" at the end of modified file
★ SELinux context autodetection - starting from v1.3 modified file has always exact same context as original file
★ BusyBox will not be used anymore, even if exists (checking the presence removed)

v1.2:

★ Starting from this version installer performs more secure and only 100% reversible actions. Original *.sh file is never touched (just renamed to *.bak to keep its original attributes, including context). Installer will try to set to modified file as many attributes taken from original file as possible (instead of forcing "known values").
★ Added initd_remover.zip. Use it if you want to remove Init.d support (enabled by script from this thread!) and restore 100% original system files

v1.1:

★ Avoids potential WiFi problems in case of Samsung S6 (and probably other Samsung's Exynos based devices running Android 6.0.1) - see post #3

v1.0:

★ Initial version

Enabler [sh script]:
Code:
#!/sbin/sh
# Init.d enabler by ALEXNDR (_alexndr @ XDA)

OUTFD=/proc/self/fd/$2

ui_print() {
    echo -n -e "ui_print $1\n" >> $OUTFD
    echo -n -e "ui_print\n" >> $OUTFD
}

set_perm() {
    chown $1.$2 $4
    chown $1:$2 $4
    chmod $3 $4
    if [ -z "$5" ] ; then
        chcon u:object_r:system_file:s0 $4
    else
        chcon u:object_r:$5:s0 $4
    fi
}

resolve_link() {
    if [ -z "$1" ] || [ ! -e $1 ] ; then return 1 ; fi
    local VAR=$1
    while [ -h "$VAR" ] ; do
        VAR=$(readlink $VAR)
    done
    echo $VAR
}

is_mounted() {
    if [ -z "$2" ] ; then
        cat /proc/mounts | grep $1 >/dev/null
    else
        cat /proc/mounts | grep $1 | grep "$2," >/dev/null
    fi
    return $?
}

ui_print " "
ui_print "=========================================="
ui_print "Init.d enabler by ALEXNDR (_alexndr @ XDA)"
ui_print "=========================================="
ui_print " "

SYSTEM=$(resolve_link $(find /dev/block/platform -type l | grep -i -m 1 "/app$")) ||
SYSTEM=$(resolve_link $(find /dev/block/platform -type l | grep -i -m 1 "/system$"))

if (! is_mounted /system) ; then mount -o rw /system ; fi
if (! is_mounted /system rw) ; then mount -o rw,remount /system ; fi
if (! is_mounted /system rw) ; then mount -t ext4 -o rw $SYSTEM /system ; fi
if (! is_mounted /system rw) ; then mount -t f2fs -o rw $SYSTEM /system ; fi
if (! is_mounted /system rw) ; then
    ui_print "Failed! Can't mount /system rw, aborting!"
    ui_print " "
    exit 1
fi

SYSLIB=/system/lib
cat /system/build.prop | grep "ro.product.cpu.abilist=" | grep "64" >/dev/null && SYSLIB=/system/lib64
cat /system/build.prop | grep "ro.product.cpu.abi=" | grep "64" >/dev/null && SYSLIB=/system/lib64

# These files are prefered to trigger init.d scripts (in following order, if exists):
# /system/etc/init.*.post_boot.sh
# /system/etc/*.post_boot.sh
# /system/etc/init.*.boot.sh
# /system/etc/*.boot.sh
#
# /system/bin/debuggerd is used if there is no suitable *.sh file in /system/etc

BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.post_boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.post_boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.boot\.sh$") ||
BOOTFILE=/system/bin/debuggerd

BOOTCON=$(ls -Z $BOOTFILE 2>/dev/null | grep "u:object_r" | cut -d: -f3)
if [ -z "$BOOTCON" ] ; then
    BOOTCON=$(LD_LIBRARY_PATH=$SYSLIB /system/bin/toolbox ls -Z $BOOTFILE 2>/dev/null | grep "u:object_r" | cut -d: -f3)
fi
if [ -z "$BOOTCON" ] ; then
    BOOTCON=$(LD_LIBRARY_PATH=$SYSLIB /system/bin/toybox ls -Z $BOOTFILE 2>/dev/null | grep "u:object_r" | cut -d: -f3)
fi
if [ -z "$BOOTCON" ] ; then
    BOOTCON=system_file
fi

cat $BOOTFILE | grep "^exit 0" >/dev/null && EXIT=true || EXIT=false

if [ -z "$(cat $BOOTFILE | grep "Init\.d")" ] ; then
    if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
        if [ ! -f /system/bin/debuggerd_real ] ; then
            mv -f $BOOTFILE /system/bin/debuggerd_real
            echo "#!/system/bin/sh" > $BOOTFILE
        else
            sed -i '/debuggerd_real/d' $BOOTFILE
        fi
    else
        mv -f $BOOTFILE "$BOOTFILE.bak"
        cp -pf "$BOOTFILE.bak" $BOOTFILE
        if ($EXIT) ; then sed -i '/^exit 0/d' $BOOTFILE ; fi
        echo "" >> $BOOTFILE
    fi
    echo "# Init.d support" >> $BOOTFILE
    echo 'SU="$(ls /su/bin/su 2>/dev/null || ls /system/xbin/su) -c"' >> $BOOTFILE
    echo 'mount -o rw,remount /system && SU="" || eval "$SU mount -o rw,remount /system"' >> $BOOTFILE
    echo 'eval "$SU chmod 777 /system/etc/init.d"' >> $BOOTFILE
    echo 'eval "$SU chmod 777 /system/etc/init.d/*"' >> $BOOTFILE
    echo 'eval "$SU mount -o ro,remount /system"' >> $BOOTFILE
    echo 'ls /system/etc/init.d/* 2>/dev/null | while read xfile ; do eval "$SU /system/bin/sh $xfile" ; done' >> $BOOTFILE
    if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
        echo '/system/bin/debuggerd_real [email protected]' >> $BOOTFILE
        set_perm 0 2000 755 $BOOTFILE $BOOTCON
    else
        if ($EXIT) ; then echo "exit 0" >> $BOOTFILE ; fi
        chcon u:object_r:$BOOTCON:s0 $BOOTFILE
    fi
    mkdir -p /system/etc/init.d
    echo "#!/system/bin/sh" > /system/etc/init.d/00test
    echo "# Init.d test" >> /system/etc/init.d/00test
    echo 'echo "Init.d is working !!!" > /data/initd_test.log' >> /system/etc/init.d/00test
    echo 'echo "excecuted on $(date +"%d-%m-%Y %r")" >> /data/initd_test.log' >> /system/etc/init.d/00test
    echo "#!/system/bin/sh" > /system/etc/init.d/99SuperSUDaemon
    echo "/system/xbin/daemonsu --auto-daemon &" >> /system/etc/init.d/99SuperSUDaemon
    set_perm 0 0 777 /system/etc/init.d
    set_perm 0 0 777 "/system/etc/init.d/*"
    ui_print "Init.d has been successfully enabled"
    ui_print "using following file run at boot:"
    ui_print " "
    ui_print "$BOOTFILE"
    ui_print " "
    ui_print "Check result in /data/initd_test.log file"
    ui_print " "
else
    ui_print "Init.d is enabled already, aborting!"
    ui_print " " # exit is not necessary
fi

umount /system

exit 0
Remover [sh script]:
Code:
#!/sbin/sh
# Init.d remover by ALEXNDR (_alexndr @ XDA)

OUTFD=/proc/self/fd/$2

ui_print() {
    echo -n -e "ui_print $1\n" >> $OUTFD
    echo -n -e "ui_print\n" >> $OUTFD
}

resolve_link() {
    if [ -z "$1" ] || [ ! -e $1 ] ; then return 1 ; fi
    local VAR=$1
    while [ -h "$VAR" ] ; do
        VAR=$(readlink $VAR)
    done
    echo $VAR
}

is_mounted() {
    if [ -z "$2" ] ; then
        cat /proc/mounts | grep $1 >/dev/null
    else
        cat /proc/mounts | grep $1 | grep "$2," >/dev/null
    fi
    return $?
}

ui_print " "
ui_print "=========================================="
ui_print "Init.d remover by ALEXNDR (_alexndr @ XDA)"
ui_print "=========================================="
ui_print " "

SYSTEM=$(resolve_link $(find /dev/block/platform -type l | grep -i -m 1 "/app$")) ||
SYSTEM=$(resolve_link $(find /dev/block/platform -type l | grep -i -m 1 "/system$"))

if (! is_mounted /system) ; then mount -o rw /system ; fi
if (! is_mounted /system rw) ; then mount -o rw,remount /system ; fi
if (! is_mounted /system rw) ; then mount -t ext4 -o rw $SYSTEM /system ; fi
if (! is_mounted /system rw) ; then mount -t f2fs -o rw $SYSTEM /system ; fi
if (! is_mounted /system rw) ; then
    ui_print "Failed! Can't mount /system rw, aborting!"
    ui_print " "
    exit 1
fi

BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.post_boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.post_boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.boot\.sh$") ||
BOOTFILE=/system/bin/debuggerd

if [ ! -z "$(cat $BOOTFILE | grep "Init\.d")" ] ; then
    if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
        if [ -f /system/bin/debuggerd_real ] ; then
            rm -f $BOOTFILE
            mv -f /system/bin/debuggerd_real $BOOTFILE
        else
            ui_print "Failed! Missing debuggerd_real file!"
            exit 1
        fi
    elif [ -f "$BOOTFILE.bak" ] ; then
        rm -f $BOOTFILE
        mv -f "$BOOTFILE.bak" $BOOTFILE
    else
        ui_print "Failed! Missing *.sh.bak file!"
        exit 1
    fi
    rm -Rf /system/etc/init.d
    ui_print "Init.d has been successfully removed :)"
else
    ui_print "Init.d by ALEXNDR has not been detected!"
fi

ui_print " "
umount /system
exit 0
NOTE:
If it does not work for your device - please post here a feedback! I will try to find a reason and tune my script


Credits: @Chainfire, @JustArchi


Hit Thanks button if you like my work. If you really appreciate my work - feel free to buy me a beer :)
 

Attachments

  • initd_remover.zip
    1.7 KB · Views: 9,164
  • initd_any_stock_v1.3.zip
    2.4 KB · Views: 18,813
Last edited:

_alexndr

Senior Member
Mar 1, 2013
2,815
17,624
Samsung Galaxy S21 Ultra
@_alexndr mate today i tried ur init.d enabled but on my s6 mm 6.0.1 its bricked my wifi as after flashing ur script i can't get wifi connected any fix for MM ?? Thanks

Strange as my installer in case of G920F should only add to /system/etc/init.sec.boot.sh following lines:
Code:
# Init.d support
mount -o rw,remount /system
chmod 777 /system/etc/init.d
chmod 777 /system/etc/init.d/*
mount -o ro,remount /system
busybox run-parts /system/etc/init.d

or following if busybox has not been installed:
Code:
# Init.d support
mount -o rw,remount /system
chmod 777 /system/etc/init.d
chmod 777 /system/etc/init.d/*
mount -o ro,remount /system
ls /system/etc/init.d/* 2>/dev/null | while read xfile ; do $xfile ; done

Original file should be renamed to /system/etc/init.sec.boot.sh.bak, so you can just delete modified init.sec.boot.sh and then rename init.sec.boot.sh.bak -> init.sec.boot.sh to revert changes (+ delete /system/etc/init.d folder but it's just a cosmetic)

...but before you do it - it would be great if you help in further development and try if following command put in terminal emulator or adb shell will help:

Code:
su
mount -o rw,remount /system
chmod 550 /system/etc/init.sec.boot.sh
chown 0:2000 /system/etc/init.sec.boot.sh
chcon u:object_r:sec-sh_exec:s0 /system/etc/init.sec.boot.sh
mount -o ro,remount /system

...then reboot device :)


EDIT:
Anyway - #1 has been updated as I found potential permissions / SELinux context mismatch in case of Samsung's Exynos based devices running Android 6.0.1. NOTE: It will not fix broken installation already done - you need to revert changes first (as I mentioned above - by deleting init.sec.boot.sh and renaming init.sec.boot.sh.bak -> init.sec.boot.sh) and then re-flash v1.1
 
Last edited:

_alexndr

Senior Member
Mar 1, 2013
2,815
17,624
Samsung Galaxy S21 Ultra
Another update :cool:

Changelog:

v1.2:

★ Starting from this version installer performs more secure and only 100% reversible actions. Original *.sh file is never touched (just renamed to *.bak to keep its original attributes, including context). Installer will try to set to modified file as many attributes taken from original file as possible (instead of forcing "known values").
★ Added initd_remover.zip. Use it if you want to remove Init.d support (enabled by script from this thread!) and restore 100% original system files
 
Last edited:

_alexndr

Senior Member
Mar 1, 2013
2,815
17,624
Samsung Galaxy S21 Ultra
Another update :cool:

Changelog:

v1.3:

★ This version automatically detects privileges of launched sh script used to trigger init.d and if these are not sufficient to remount /system rw - all commands are automatically expanded to "/su/bin/su -c [command]" or "/system/xbin/su -c [command]" (depending on SuperSU install mode)
★ Fixed problem with "exit 0" at the end of used sh script resulting that simply added new lines never worked. This version automatically detects such case and moves "exit 0" at the end of modified file
★ SELinux context autodetection - starting from v1.3 modified file has always exact same context as original file
★ BusyBox will not be used anymore, even if exists (checking the presence removed)
 
Last edited:

WILMANS2M

Senior Member
Aug 6, 2009
3,061
584
Mantes-la-Ville
Huawei P10
First of all really thank you for this script which works very well...except if included in the installation script.

The initd.sh is this

I use this command in the updater-script:

ui_print("@ Add init.d support");
package_extract_file("tools/initd.sh", "/tmp/initd.sh");
set_perm(0, 0, 0777, "/tmp/initd.sh");
run_program("/tmp/initd.sh");
delete("/tmp/initd.sh");
ui_print("--> Init.d Installed");

But not working. Got this error in recovery log
run_program: execv failed: No such file or directory
run_program: child exited with status 1

Any advice or a proper .sh script please ?

Thanks very much.
 

_alexndr

Senior Member
Mar 1, 2013
2,815
17,624
Samsung Galaxy S21 Ultra
First of all really thank you for this script which works very well...except if included in the installation script.

The initd.sh is this

I use this command in the updater-script:

ui_print("@ Add init.d support");
package_extract_file("tools/initd.sh", "/tmp/initd.sh");
set_perm(0, 0, 0777, "/tmp/initd.sh");
run_program("/tmp/initd.sh");
delete("/tmp/initd.sh");
ui_print("--> Init.d Installed");

But not working. Got this error in recovery log
run_program: execv failed: No such file or directory
run_program: child exited with status 1

Any advice or a proper .sh script please ?

Thanks very much.

My script (as it is in post #1) is designed to be standalone installer. If you want to enable init.d by a sh script called from the updater-script - please try as follow:

Code:
#!/sbin/sh
# Init.d enabler by ALEXNDR (_alexndr @ XDA)

set_perm() {
    chown $1.$2 $4
    chown $1:$2 $4
    chmod $3 $4
    if [ -z "$5" ] ; then
        chcon u:object_r:system_file:s0 $4
    else
        chcon u:object_r:$5:s0 $4
    fi
}

# These files are prefered to trigger init.d scripts (in following order, if exists):
# /system/etc/init.*.post_boot.sh
# /system/etc/*.post_boot.sh
# /system/etc/init.*.boot.sh
# /system/etc/*.boot.sh
#
# /system/bin/debuggerd is used if there is no suitable *.sh file in /system/etc

BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.post_boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.post_boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.boot\.sh$") ||
BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.boot\.sh$") ||
BOOTFILE=/system/bin/debuggerd

BOOTCON=$(ls -Z $BOOTFILE 2>/dev/null | grep "u:object_r" | cut -d: -f3)
if [ -z "$BOOTCON" ] ; then
    BOOTCON=system_file
fi

cat $BOOTFILE | grep "^exit 0" >/dev/null && EXIT=true || EXIT=false

if [ -z "$(cat $BOOTFILE | grep "[Ii]nit\.d")" ] ; then
    if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
        if [ ! -f /system/bin/debuggerd_real ] ; then
            mv -f $BOOTFILE /system/bin/debuggerd_real
            echo "#!/system/bin/sh" > $BOOTFILE
        else
            sed -i '/debuggerd_real/d' $BOOTFILE
        fi
    else
        mv -f $BOOTFILE "$BOOTFILE.bak"
        cp -pf "$BOOTFILE.bak" $BOOTFILE
        if ($EXIT) ; then sed -i '/^exit 0/d' $BOOTFILE ; fi
        echo "" >> $BOOTFILE
    fi
    echo "# Init.d support" >> $BOOTFILE
    echo 'SU="$(ls /su/bin/su 2>/dev/null || ls /system/xbin/su) -c"' >> $BOOTFILE
    echo 'mount -o rw,remount /system && SU="" || eval "$SU mount -o rw,remount /system"' >> $BOOTFILE
    echo 'eval "$SU chmod 777 /system/etc/init.d"' >> $BOOTFILE
    echo 'eval "$SU chmod 777 /system/etc/init.d/*"' >> $BOOTFILE
    echo 'eval "$SU mount -o ro,remount /system"' >> $BOOTFILE
    echo 'ls /system/etc/init.d/* 2>/dev/null | while read xfile ; do eval "$SU /system/bin/sh $xfile" ; done' >> $BOOTFILE
    if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
        echo '/system/bin/debuggerd_real [email protected]' >> $BOOTFILE
        set_perm 0 2000 755 $BOOTFILE $BOOTCON
    else
        if ($EXIT) ; then echo "exit 0" >> $BOOTFILE ; fi
        chcon u:object_r:$BOOTCON:s0 $BOOTFILE
    fi
    mkdir -p /system/etc/init.d
    echo "#!/system/bin/sh" > /system/etc/init.d/00test
    echo "# Init.d test" >> /system/etc/init.d/00test
    echo 'echo "Init.d is working !!!" > /data/initd_test.log' >> /system/etc/init.d/00test
    echo 'echo "excecuted on $(date +"%d-%m-%Y %r")" >> /data/initd_test.log' >> /system/etc/init.d/00test
    echo "#!/system/bin/sh" > /system/etc/init.d/99SuperSUDaemon
    echo "/system/xbin/daemonsu --auto-daemon &" >> /system/etc/init.d/99SuperSUDaemon
    set_perm 0 0 777 /system/etc/init.d
    set_perm 0 0 777 "/system/etc/init.d/*"
fi

exit 0
 
Last edited:
  • Like
Reactions: pani690

WILMANS2M

Senior Member
Aug 6, 2009
3,061
584
Mantes-la-Ville
Huawei P10
i tried something different. I keep your original zip file, and put it in tools/initd folder in my custom rom
Then i added this in the updater script:

ui_print("@ Add init.d support");
package_extract_dir("tools/initd", "/tmp/initd");
run_program("/sbin/busybox", "unzip", "/tmp/initd/initd.any.stock.1.3.zip", "META-INF/com/google/android/*", "-d", "/tmp/initd");
run_program("/sbin/busybox", "sh", "/tmp/initd/META-INF/com/google/android/update-binary", "dummy", "1", "/tmp/initd/initd.any.stock.1.3.zip");
ui_print("--> Init.d Installed");

IT WORKS with this :)

Thanks ;)
 
Last edited:

Has.007

Senior Member
Sep 13, 2015
1,091
4,370
Curepipe
Hey, Firstly thanks for all your work!
I've not tried this yet but I'm working on stock based ROM nd I want to enable to init.d support in it.
I've used the SuperR's Kitchen to enable the init.d support in the kernel nd I could find the script in the kernel too. Not sure if it'll work or not as I haven't tested in yet. So I hope you can tell me if I need to enable this way too or not,
Thanks.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 59
    I present you universal script to enable Init.d in ALL ANDROID DEVICES (I hope...) while running the stock kernel. NO BUSYBOX needed! It is packed in easy to use ZIP flashable :cool:

    EDIT: This script will NOT work with Magisk! However, notice that using Magisk you do not need init.d support at all (you can put your scripts in /magisk/.core/post-fs-data.d OR /magisk/.core/service.d, depending on your needs).

    Requirements:
    - a rooted Android device (SuperSU) :)
    - ANY tool to flash a ZIP (custom recovery or FlashFire app)

    Installation:
    1. Custom recovery - open file using "Install Zip" option and confirm "Yes - install..."
    2. FlashFire - open file using "Flash ZIP or OTA" option (default mount options). Tap "FLASH"

    How to check:
    Just check if /data/initd_test.log file exists (optionally you can check its content) :cool:

    Changelog:

    v1.3:

    ★ This version automatically detects privileges of launched sh script used to trigger init.d and if these are not sufficient to remount /system rw - all commands are automatically expanded to "/su/bin/su -c [command]" or "/system/xbin/su -c [command]" (depending on SuperSU install mode)
    ★ Fixed problem with "exit 0" at the end of used sh script resulting that simply added new lines never worked. This version automatically detects such case and moves "exit 0" at the end of modified file
    ★ SELinux context autodetection - starting from v1.3 modified file has always exact same context as original file
    ★ BusyBox will not be used anymore, even if exists (checking the presence removed)

    v1.2:

    ★ Starting from this version installer performs more secure and only 100% reversible actions. Original *.sh file is never touched (just renamed to *.bak to keep its original attributes, including context). Installer will try to set to modified file as many attributes taken from original file as possible (instead of forcing "known values").
    ★ Added initd_remover.zip. Use it if you want to remove Init.d support (enabled by script from this thread!) and restore 100% original system files

    v1.1:

    ★ Avoids potential WiFi problems in case of Samsung S6 (and probably other Samsung's Exynos based devices running Android 6.0.1) - see post #3

    v1.0:

    ★ Initial version

    Enabler [sh script]:
    Code:
    #!/sbin/sh
    # Init.d enabler by ALEXNDR (_alexndr @ XDA)
    
    OUTFD=/proc/self/fd/$2
    
    ui_print() {
        echo -n -e "ui_print $1\n" >> $OUTFD
        echo -n -e "ui_print\n" >> $OUTFD
    }
    
    set_perm() {
        chown $1.$2 $4
        chown $1:$2 $4
        chmod $3 $4
        if [ -z "$5" ] ; then
            chcon u:object_r:system_file:s0 $4
        else
            chcon u:object_r:$5:s0 $4
        fi
    }
    
    resolve_link() {
        if [ -z "$1" ] || [ ! -e $1 ] ; then return 1 ; fi
        local VAR=$1
        while [ -h "$VAR" ] ; do
            VAR=$(readlink $VAR)
        done
        echo $VAR
    }
    
    is_mounted() {
        if [ -z "$2" ] ; then
            cat /proc/mounts | grep $1 >/dev/null
        else
            cat /proc/mounts | grep $1 | grep "$2," >/dev/null
        fi
        return $?
    }
    
    ui_print " "
    ui_print "=========================================="
    ui_print "Init.d enabler by ALEXNDR (_alexndr @ XDA)"
    ui_print "=========================================="
    ui_print " "
    
    SYSTEM=$(resolve_link $(find /dev/block/platform -type l | grep -i -m 1 "/app$")) ||
    SYSTEM=$(resolve_link $(find /dev/block/platform -type l | grep -i -m 1 "/system$"))
    
    if (! is_mounted /system) ; then mount -o rw /system ; fi
    if (! is_mounted /system rw) ; then mount -o rw,remount /system ; fi
    if (! is_mounted /system rw) ; then mount -t ext4 -o rw $SYSTEM /system ; fi
    if (! is_mounted /system rw) ; then mount -t f2fs -o rw $SYSTEM /system ; fi
    if (! is_mounted /system rw) ; then
        ui_print "Failed! Can't mount /system rw, aborting!"
        ui_print " "
        exit 1
    fi
    
    SYSLIB=/system/lib
    cat /system/build.prop | grep "ro.product.cpu.abilist=" | grep "64" >/dev/null && SYSLIB=/system/lib64
    cat /system/build.prop | grep "ro.product.cpu.abi=" | grep "64" >/dev/null && SYSLIB=/system/lib64
    
    # These files are prefered to trigger init.d scripts (in following order, if exists):
    # /system/etc/init.*.post_boot.sh
    # /system/etc/*.post_boot.sh
    # /system/etc/init.*.boot.sh
    # /system/etc/*.boot.sh
    #
    # /system/bin/debuggerd is used if there is no suitable *.sh file in /system/etc
    
    BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.post_boot\.sh$") ||
    BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.post_boot\.sh$") ||
    BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.boot\.sh$") ||
    BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.boot\.sh$") ||
    BOOTFILE=/system/bin/debuggerd
    
    BOOTCON=$(ls -Z $BOOTFILE 2>/dev/null | grep "u:object_r" | cut -d: -f3)
    if [ -z "$BOOTCON" ] ; then
        BOOTCON=$(LD_LIBRARY_PATH=$SYSLIB /system/bin/toolbox ls -Z $BOOTFILE 2>/dev/null | grep "u:object_r" | cut -d: -f3)
    fi
    if [ -z "$BOOTCON" ] ; then
        BOOTCON=$(LD_LIBRARY_PATH=$SYSLIB /system/bin/toybox ls -Z $BOOTFILE 2>/dev/null | grep "u:object_r" | cut -d: -f3)
    fi
    if [ -z "$BOOTCON" ] ; then
        BOOTCON=system_file
    fi
    
    cat $BOOTFILE | grep "^exit 0" >/dev/null && EXIT=true || EXIT=false
    
    if [ -z "$(cat $BOOTFILE | grep "Init\.d")" ] ; then
        if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
            if [ ! -f /system/bin/debuggerd_real ] ; then
                mv -f $BOOTFILE /system/bin/debuggerd_real
                echo "#!/system/bin/sh" > $BOOTFILE
            else
                sed -i '/debuggerd_real/d' $BOOTFILE
            fi
        else
            mv -f $BOOTFILE "$BOOTFILE.bak"
            cp -pf "$BOOTFILE.bak" $BOOTFILE
            if ($EXIT) ; then sed -i '/^exit 0/d' $BOOTFILE ; fi
            echo "" >> $BOOTFILE
        fi
        echo "# Init.d support" >> $BOOTFILE
        echo 'SU="$(ls /su/bin/su 2>/dev/null || ls /system/xbin/su) -c"' >> $BOOTFILE
        echo 'mount -o rw,remount /system && SU="" || eval "$SU mount -o rw,remount /system"' >> $BOOTFILE
        echo 'eval "$SU chmod 777 /system/etc/init.d"' >> $BOOTFILE
        echo 'eval "$SU chmod 777 /system/etc/init.d/*"' >> $BOOTFILE
        echo 'eval "$SU mount -o ro,remount /system"' >> $BOOTFILE
        echo 'ls /system/etc/init.d/* 2>/dev/null | while read xfile ; do eval "$SU /system/bin/sh $xfile" ; done' >> $BOOTFILE
        if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
            echo '/system/bin/debuggerd_real [email protected]' >> $BOOTFILE
            set_perm 0 2000 755 $BOOTFILE $BOOTCON
        else
            if ($EXIT) ; then echo "exit 0" >> $BOOTFILE ; fi
            chcon u:object_r:$BOOTCON:s0 $BOOTFILE
        fi
        mkdir -p /system/etc/init.d
        echo "#!/system/bin/sh" > /system/etc/init.d/00test
        echo "# Init.d test" >> /system/etc/init.d/00test
        echo 'echo "Init.d is working !!!" > /data/initd_test.log' >> /system/etc/init.d/00test
        echo 'echo "excecuted on $(date +"%d-%m-%Y %r")" >> /data/initd_test.log' >> /system/etc/init.d/00test
        echo "#!/system/bin/sh" > /system/etc/init.d/99SuperSUDaemon
        echo "/system/xbin/daemonsu --auto-daemon &" >> /system/etc/init.d/99SuperSUDaemon
        set_perm 0 0 777 /system/etc/init.d
        set_perm 0 0 777 "/system/etc/init.d/*"
        ui_print "Init.d has been successfully enabled"
        ui_print "using following file run at boot:"
        ui_print " "
        ui_print "$BOOTFILE"
        ui_print " "
        ui_print "Check result in /data/initd_test.log file"
        ui_print " "
    else
        ui_print "Init.d is enabled already, aborting!"
        ui_print " " # exit is not necessary
    fi
    
    umount /system
    
    exit 0
    Remover [sh script]:
    Code:
    #!/sbin/sh
    # Init.d remover by ALEXNDR (_alexndr @ XDA)
    
    OUTFD=/proc/self/fd/$2
    
    ui_print() {
        echo -n -e "ui_print $1\n" >> $OUTFD
        echo -n -e "ui_print\n" >> $OUTFD
    }
    
    resolve_link() {
        if [ -z "$1" ] || [ ! -e $1 ] ; then return 1 ; fi
        local VAR=$1
        while [ -h "$VAR" ] ; do
            VAR=$(readlink $VAR)
        done
        echo $VAR
    }
    
    is_mounted() {
        if [ -z "$2" ] ; then
            cat /proc/mounts | grep $1 >/dev/null
        else
            cat /proc/mounts | grep $1 | grep "$2," >/dev/null
        fi
        return $?
    }
    
    ui_print " "
    ui_print "=========================================="
    ui_print "Init.d remover by ALEXNDR (_alexndr @ XDA)"
    ui_print "=========================================="
    ui_print " "
    
    SYSTEM=$(resolve_link $(find /dev/block/platform -type l | grep -i -m 1 "/app$")) ||
    SYSTEM=$(resolve_link $(find /dev/block/platform -type l | grep -i -m 1 "/system$"))
    
    if (! is_mounted /system) ; then mount -o rw /system ; fi
    if (! is_mounted /system rw) ; then mount -o rw,remount /system ; fi
    if (! is_mounted /system rw) ; then mount -t ext4 -o rw $SYSTEM /system ; fi
    if (! is_mounted /system rw) ; then mount -t f2fs -o rw $SYSTEM /system ; fi
    if (! is_mounted /system rw) ; then
        ui_print "Failed! Can't mount /system rw, aborting!"
        ui_print " "
        exit 1
    fi
    
    BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.post_boot\.sh$") ||
    BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.post_boot\.sh$") ||
    BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.boot\.sh$") ||
    BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.boot\.sh$") ||
    BOOTFILE=/system/bin/debuggerd
    
    if [ ! -z "$(cat $BOOTFILE | grep "Init\.d")" ] ; then
        if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
            if [ -f /system/bin/debuggerd_real ] ; then
                rm -f $BOOTFILE
                mv -f /system/bin/debuggerd_real $BOOTFILE
            else
                ui_print "Failed! Missing debuggerd_real file!"
                exit 1
            fi
        elif [ -f "$BOOTFILE.bak" ] ; then
            rm -f $BOOTFILE
            mv -f "$BOOTFILE.bak" $BOOTFILE
        else
            ui_print "Failed! Missing *.sh.bak file!"
            exit 1
        fi
        rm -Rf /system/etc/init.d
        ui_print "Init.d has been successfully removed :)"
    else
        ui_print "Init.d by ALEXNDR has not been detected!"
    fi
    
    ui_print " "
    umount /system
    exit 0
    NOTE:
    If it does not work for your device - please post here a feedback! I will try to find a reason and tune my script


    Credits: @Chainfire, @JustArchi


    Hit Thanks button if you like my work. If you really appreciate my work - feel free to buy me a beer :)
    3
    Another update :cool:

    Changelog:

    v1.2:

    ★ Starting from this version installer performs more secure and only 100% reversible actions. Original *.sh file is never touched (just renamed to *.bak to keep its original attributes, including context). Installer will try to set to modified file as many attributes taken from original file as possible (instead of forcing "known values").
    ★ Added initd_remover.zip. Use it if you want to remove Init.d support (enabled by script from this thread!) and restore 100% original system files
    3
    i tried something different. I keep your original zip file, and put it in tools/initd folder in my custom rom
    Then i added this in the updater script:

    ui_print("@ Add init.d support");
    package_extract_dir("tools/initd", "/tmp/initd");
    run_program("/sbin/busybox", "unzip", "/tmp/initd/initd.any.stock.1.3.zip", "META-INF/com/google/android/*", "-d", "/tmp/initd");
    run_program("/sbin/busybox", "sh", "/tmp/initd/META-INF/com/google/android/update-binary", "dummy", "1", "/tmp/initd/initd.any.stock.1.3.zip");
    ui_print("--> Init.d Installed");

    IT WORKS with this :)

    Thanks ;)
    2
    Hey, Firstly thanks for all your work!
    I've not tried this yet but I'm working on stock based ROM nd I want to enable to init.d support in it.
    I've used the SuperR's Kitchen to enable the init.d support in the kernel nd I could find the script in the kernel too. Not sure if it'll work or not as I haven't tested in yet. So I hope you can tell me if I need to enable this way too or not,
    Thanks.
    1
    Great Work..
    Thanks :D
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone