Quantcast
Channel: xda-developers - Android Software and Hacking General [Developers Only]
Viewing all articles
Browse latest Browse all 3614

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

$
0
0
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:

Requirements:
- a rooted Android device :)
- 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:

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

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

# 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

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
        cp -pf $BOOTFILE "$BOOTFILE.bak"
        echo "" >> $BOOTFILE
    fi
    echo "# Init.d support" >> $BOOTFILE
    echo "mount -o rw,remount /system" >> $BOOTFILE
    echo "chmod 777 /system/etc/init.d" >> $BOOTFILE
    echo "chmod 777 /system/etc/init.d/*" >> $BOOTFILE
    echo "mount -o ro,remount /system" >> $BOOTFILE
    if [ -x /system/xbin/busybox ] ; then
        echo "busybox run-parts /system/etc/init.d" >> $BOOTFILE
    else
        echo 'ls /system/etc/init.d/* 2>/dev/null | while read xfile ; do $xfile ; done' >> $BOOTFILE
    fi
    if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
        echo '/system/bin/debuggerd_real $@' >> $BOOTFILE
        set_perm 0 2000 755 $BOOTFILE debuggerd_exec
    else
        set_perm 0 0 644 $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


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_any_stock_v1.0.zip - [Click for QR Code] (2.2 KB)

Viewing all articles
Browse latest Browse all 3614

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>