FORUMS

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

2,710 posts
Thanks Meter: 16,859
 
By _alexndr, Senior Member on 29th March 2016, 08:32 PM
Post Reply Email Thread
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

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)

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
Attached Files
File Type: zip initd_remover.zip - [Click for QR Code] (1.7 KB, 8650 views)
File Type: zip initd_any_stock_v1.3.zip - [Click for QR Code] (2.4 KB, 17764 views)
The Following 59 Users Say Thank You to _alexndr For This Useful Post: [ View ] Gift _alexndr Ad-Free
1st April 2016, 12:57 PM |#3  
thereassaad's Avatar
Recognized Contributor
Flag Bierut
Thanks Meter: 9,790
 
More
@_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
The Following User Says Thank You to thereassaad For This Useful Post: [ View ] Gift thereassaad Ad-Free
1st April 2016, 08:44 PM |#4  
ROBERT CM's Avatar
Senior Member
Flag Lima
Thanks Meter: 930
 
Donate to Me
More
Quote:
Originally Posted by thereassaad

@_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

In my case work good no problem with WiFi connection on S5 MM 6.0.1
Regards
The Following User Says Thank You to ROBERT CM For This Useful Post: [ View ] Gift ROBERT CM Ad-Free
1st April 2016, 08:52 PM |#5  
_alexndr's Avatar
OP Senior Member
Thanks Meter: 16,859
 
Donate to Me
More
Quote:
Originally Posted by thereassaad

@_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
2nd April 2016, 02:36 PM |#6  
_alexndr's Avatar
OP Senior Member
Thanks Meter: 16,859
 
Donate to Me
More
Another update

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
The Following 3 Users Say Thank You to _alexndr For This Useful Post: [ View ] Gift _alexndr Ad-Free
2nd April 2016, 02:40 PM |#7  
thereassaad's Avatar
Recognized Contributor
Flag Bierut
Thanks Meter: 9,790
 
More
@_alexndr , definitely mate will give a shot , later , thanks for ur work xD ,
The Following User Says Thank You to thereassaad For This Useful Post: [ View ] Gift thereassaad Ad-Free
4th April 2016, 01:58 AM |#8  
Senior Member
Thanks Meter: 17
 
More
good work bro will test more with new update
The Following User Says Thank You to chandarakk For This Useful Post: [ View ] Gift chandarakk Ad-Free
5th April 2016, 12:15 PM |#9  
DheaApriandi's Avatar
Member
Flag Cirebon
Thanks Meter: 52
 
Donate to Me
More
Good work 😁

Sent from my A66A using XDA-Developers mobile app
9th April 2016, 02:23 PM |#10  
_alexndr's Avatar
OP Senior Member
Thanks Meter: 16,859
 
Donate to Me
More
Another update

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)
16th April 2016, 07:52 PM |#11  
Senior Member
Flag Mantes-la-Ville
Thanks Meter: 613
 
More
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.
Post Reply Subscribe to Thread

Tags
android, enable, init.d, phone, script

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes