[Completed] [Q] I wrote a script for init.d , but its not running properly on boot. - XDA Assist

I wrote a script for init.d , but its not running properly on boot.
Code:
#!/system/bin/sh
# init.d (startup scripts) permission fixer.
mount -o remount,rw -t auto /system
chown -R 0.0 /system/etc/init.d
chown -R 0:0 /system/etc/init.d
chmod -R 777 /system/etc/init.d
chcon u:object_r:system_file:s0 /system/etc/init.d
chcon u:object_r:system_file:s0 /system/etc/init.d/*
echo "Init.d is working !!!" > /data/Test.log
echo "excecuted on \$(date +"%d-%m-%Y %r" )" >> /data/Test.log
echo "Init.d is working !!!" > /sdcard/Test.log
echo "excecuted on \$(date +"%d-%m-%Y %r" )" >> /sdcard/Test.log
mount -o remount,ro -t auto /system
The problem is that
Code:
echo "Init.d is working !!!" > /sdcard/Test.log
echo "excecuted on \$(date +"%d-%m-%Y %r" )" >> /sdcard/Test.log
Its not creats the "Test.log" output file in "sdcard" .
I don't know why its not creats the "Test.log" output file in "/sdcard/Test.log" is there any wrong with scripts or some thing I've missed.??

Hi there,
I'm sorry, but XDA Assist is not a "helpdesk" providing technical assistance but more to point you in the correct direction with your problem.
So, you already opened a new thread here: [GUIDE/TIPS] Android Linux Shell Scripting. , please wait there an answer or open a new one in the general forum dedicated for questions and answers here:
> General discussion > Questions and Answers
Good luck

Related

[GUIDE] Add init.d scripts support for padfone/padfone 2

First of all, if you don't know what does init.d means then you probably won't need this and I'm not responsible if your padfone explodes when running this . Seriously this is almost completely sure but your device, your responsibility.
Credits:
I gathered information from this thread from DooMLoRD http://forum.xda-developers.com/showthread.php?t=1236446 as well as from others in this forum, but i believe he was the first.
Pre-requisites:
A rooted padfone, busybox and a command-line (adb, terminal, ...)
Explanation:
We are going to use the install-recovery.sh script that recreates the recovery partition (if it has been modified) while the device boots.
The way it works is simple:
- the boot process calls install-recovery.sh while executing init.rc
- the install-recovery.sh calls sysinit script
- the sysinit script runs /system/etc/init.d/* in order
Issues:
I found that the script is called in an early state where the date is still not set (is said Jan 28 1970!!!) and only a few fs are mounted:
/system, /data, /persist, /cache
so no sdcard, no Removable ...
Howto:
you can either copy the following text to a file in your device or download the attached file and in a terminal run:
$su
#cd to the directory where the script was stored
#sh ./enable_initd.sh
Code:
#!/system/bin/sh
echo ''
echo 'This script will enable init.d'
echo ''
echo 'You will need to reboot to check if it worked'
echo ''
echo 'If the script successfully enabled init.d you will'
echo 'have a file in /data/log called init.d-log.txt'
echo 'after the device is done rebooting.'
echo 'Once checked that it is working, you can delete'
echo '/system/etc/init.d/99test and /data/log/init.d-log.txt'
echo 'Remember to always set the proper permissions in your'
echo 'scripts or they will not work.'
echo ''
if [ ! -f /system/xbin/busybox -a ! -f /system/bin/busybox ]
then
echo 'no busybox found! please re-install/update your busybox'
else
# Mount system as rw in order to prepare the paths and scripts
mount -o remount,rw /system
# Create init.d dir
if [ -d '/system/etc/init.d' ]
then
chmod 755 /system/etc/init.d
else
mkdir /system/etc/init.d
chmod 755 /system/etc/init.d
fi
# Create sysinit script if needed
if [ -f /system/bin/sysinit ]
then
echo 'sysinit exists, init.d should be enabled'
chmod 755 /system/bin/sysinit
else
touch /system/bin/sysinit
echo '#!/system/bin/sh' >> /system/bin/sysinit
echo 'export PATH=/sbin:/system/sbin:/system/bin:/system/xbin' >> /system/bin/sysinit
echo '/system/bin/logwrapper busybox run-parts /system/etc/init.d' >> /system/bin/sysinit
chmod 755 /system/bin/sysinit
fi
# Create / modify install-recovery.sh
if [ -f /system/etc/install-recovery.sh ]
then
if cat /system/etc/install-recovery.sh | egrep -i "sysinit"
then
echo 'sysinit already present in install-recovery.sh, skipping this step.'
else
cp /system/etc/install-recovery.sh /system/etc/install-recovery.sh.old
echo '' >> /system/etc/install-recovery.sh
echo '#init.d scripts integration' >> /system/etc/install-recovery.sh
echo '/system/bin/sysinit' >> /system/etc/install-recovery.sh
fi
else
touch /system/etc/install-recovery.sh
echo '#!/system/bin/sh' > /system/etc/install-recovery.sh
echo '' >> /system/etc/install-recovery.sh
echo '/system/bin/sysinit' >> /system/etc/install-recovery.sh
chmod 755 /system/etc/install-recovery.sh
fi
# Create 99test script to check if init.d works
echo '#!/system/bin/sh' > /system/etc/init.d/99test
echo '' >> /system/etc/init.d/99test
echo 'date >> /data/log/init.d-log.txt' >> /system/etc/init.d/99test
echo 'echo init.d works >> /data/log/init.d-log.txt' >> /system/etc/init.d/99test
chmod 755 /system/etc/init.d/99test
# Sync and remount system
sync
mount -o remount,ro /system
#done!
echo 'job done :)'
echo 'reboot your phone and check on'
echo '/data/log/init.d-log.txt to see if it worked'
fi
Good luck!
please make new forum request for the padfone2 here
http://forum.xda-developers.com/showthread.php?t=1660354
we can't be sure that admins look here
Sendt fra min PadFone 2 med Tapatalk2
Thanks
Very Useful! Thanks for your guide.

[SCRIPT / TOOL] zro's ultimate permission fixer script v1.0

Do I need to explain what a permission fixer script is supposed to do?
It fixes all the permissions (currently only for /system) and removes some knox bloatware folders along the way.
Root and busybox is required.
---
NOTE: This is the first step for a "rom installer script".
Please let me know if you find any errors or want any folders added to the additional permission fixes.
Or if you know any enhancements too off course.
There might be some redundancy within the script, but I wanted to better be safe
---.
So here it goes (download attached below):
Copy it to wherever you like and make it runnable (chmod 755) to execute.
I just copied it to my /system/xbin folder so I just have to type "fix_permissions.sh" when I want to fix em.
(could even get rid of the ".sh" to get the fix_permission command back kind of)
Code:
#!/system/bin/sh
echo
echo zro\'s ultimate permission fixer script v1.0
echo ============================================
echo
echo Step 1: Mounting /system writable
echo ---------------------------------
mount -o rw,remount /system
# >>> STOCK PERMISSIONS >>>
echo
echo Step 2: Fixing stock permissions
echo --------------------------------
# /system
echo fixing permissions for /system
busybox chown 0.0 /system
busybox chown 0.0 /system/*
busybox chown 0.2000 /system/bin
busybox chown 0.2000 /system/vendor
busybox chown 0.2000 /system/xbin
busybox chmod 755 /system/*
find /system -type f -maxdepth 1 -exec busybox chmod 644 {} \;
# /system/app
echo fixing permissions for /system/app
busybox chown 0.0 /system/app/*
busybox chmod 644 /system/app/*
# /system/cameradata
echo fixing permissions for /system/cameradata
busybox chown -R 0.0 /system/cameradata
find /system/cameradata \( -type d -exec busybox chmod 755 {} + \) -o \( -type f -exec busybox chmod 644 {} + \)
# /system/bin
echo fixing permissions for /system/bin
busybox chmod 755 /system/bin/*
busybox chown 0.2000 /system/bin/*
busybox chown -h 0.2000 /system/bin/*
busybox chown 0.0 /system/bin/log /system/bin/ping /system/bin/sysinit
busybox chmod 777 /system/bin/log
busybox chown 0.3003 /system/bin/netcfg
busybox chmod 2750 /system/bin/netcfg
busybox chmod 750 /system/bin/run-as
busybox chown 0.0 /system/bin/su
busybox chmod 6755 /system/bin/su
busybox chown 0.0 /system/bin/daemonsu
busybox chmod 6755 /system/bin/daemonsu
# /system/containers - Knox Bloatware (will be removed)
echo fixing permissions for /system/containers - Knox Bloatware - will be removed
rm -r /system/containers
# /system/csc
echo fixing permissions for /system/csc
busybox chown -R 0.0 /system/csc
find /system/csc \( -type d -exec busybox chmod 755 {} + \) -o \( -type f -exec busybox chmod 644 {} + \)
# /system/etc
echo fixing permissions for /system/etc
busybox chown -R 0.0 /system/etc
find /system/etc \( -type d -exec busybox chmod 755 {} + \) -o \( -type f -exec busybox chmod 644 {} + \)
busybox chown 0.2000 /system/etc/init.goldfish.sh
busybox chmod 550 /system/etc/init.goldfish.sh
busybox chmod 664 /system/etc/boot_fixup
busybox chown 1014.2000 /system/etc/dhcpcd/dhcpcd-run-hooks
busybox chmod 550 /system/etc/dhcpcd/dhcpcd-run-hooks
busybox chmod 755 /system/etc/init.d/*
busybox chmod 6755 /system/etc/install-recovery.sh
# /system/finder_cp
echo fixing permissions for /system/finder_cp
busybox chown 0.0 /system/finder_cp/*
busybox chmod 644 /system/finder_cp/*
# /system/fonts
echo fixing permissions for /system/fonts
busybox chown 0.0 /system/fonts/*
busybox chmod 644 /system/fonts/*
# /system/framework
echo fixing permissions for /system/framework
busybox chown 0.0 /system/framework/*
busybox chmod 644 /system/framework/*
# /system/lib
echo fixing permissions for /system/lib
busybox chown -R 0:0 /system/lib
find /system/lib \( -type d -exec busybox chmod 755 {} + \) -o \( -type f -exec busybox chmod 644 {} + \)
# /system/media
echo fixing permissions for /system/media
busybox chown -R 0:0 /system/media
find /system/media \( -type d -exec busybox chmod 755 {} + \) -o \( -type f -exec busybox chmod 644 {} + \)
# /system/preloadedkiosk - Bloatware (will be removed)
echo fixing permissions for /system/preloadedkiosk - Bloatware - will be removed
rm -r /system/preloadedkiosk
# /system/preloadedsso - Knox Bloatware (will be removed)
echo fixing permissions for /system/preloadedsso - Knox Bloatware - will be removed
rm -r /system/preloadedsso
# /system/sipdb
echo fixing permissions for /system/sipdb
busybox chown 0.0 /system/sipdb/*
busybox chmod 655 /system/sipdb/*
# /system/tts
echo fixing permissions for /system/tts
busybox chown -R 0:0 /system/tts
find /system/tts \( -type d -exec busybox chmod 755 {} + \) -o \( -type f -exec busybox chmod 644 {} + \)
# /system/usr
echo fixing permissions for /system/usr
busybox chown -R 0:0 /system/usr
find /system/usr \( -type d -exec busybox chmod 755 {} + \) -o \( -type f -exec busybox chmod 644 {} + \)
# /system/vendor
echo fixing permissions for /system/vendor
find /system/vendor \( -type d -exec busybox chown 0.2000 {} + \) -o \( -type f -exec busybox chown 0.0 {} + \)
find /system/vendor \( -type d -exec busybox chmod 755 {} + \) -o \( -type f -exec busybox chmod 644 {} + \)
# /system/voicebargeindata
echo fixing permissions for /system/voicebargeindata
busybox chown -R 0:0 /system/voicebargeindata
find /system/voicebargeindata \( -type d -exec busybox chmod 755 {} + \) -o \( -type f -exec busybox chmod 644 {} + \)
# /system/vold
echo fixing permissions for /system/vold
busybox chown 0.0 /system/vold/*
busybox chmod 644 /system/vold/*
# /system/wakeupdata
echo fixing permissions for /system/wakeupdata
busybox chown -R 0:0 /system/wakeupdata
find /system/wakeupdata \( -type d -exec busybox chmod 755 {} + \) -o \( -type f -exec busybox chmod 644 {} + \)
# /system/wallpaper
echo fixing permissions for /system/wallpaper
busybox chown 0.0 /system/wallpaper/*
busybox chmod 644 /system/wallpaper/*
# /system/xbin
echo fixing permissions for /system/xbin
busybox chmod 755 /system/xbin/*
busybox chown 0.2000 /system/xbin/*
busybox chown -h 0.2000 /system/xbin/*
busybox chown 0.0 /system/xbin/su
busybox chmod 6755 /system/xbin/su
busybox chown 0.0 /system/xbin/daemonsu
busybox chmod 6755 /system/xbin/daemonsu
# <<< STOCK PERMISSIONS END <<<
# ==============================
# >>> ADDITIONAL PERMISSIONS >>>
echo
echo Step 3: Fixing additional permissions
echo -------------------------------------
# /system/photoreader
echo fixing permissions for /system/photoreader
busybox chown -R 0.2000 /system/photoreader/*
find /system/photoreader/ \( -type d -exec busybox chmod 755 {} + \) -o \( -type f -exec busybox chmod 644 {} + \)
# <<< ADDITIONAL PERMISSIONS END <<<
RESERVED
zroice said:
RESERVED
Click to expand...
Click to collapse
Thanks for this, just what is was needing on my N3...
The thing is, I cannot boot the system... can you help me to run it on CWM recovery? Maybe converting it into a 'flashable script'?
this stuff is old - the kn0x0ut toolbox includes the current version of the fix permission script.
This should also work over adb on recovery. But you need some adb skills.
zroice said:
...
There might be some redundancy within the script, but I wanted to better be safe
...
Click to expand...
Click to collapse
I wonder if (for max safety) you might need to add selinux refresh stuff in some places?

[Q] I wrote a script for init.d , but its not running properly on boot.

I wrote a script for init.d , but its not running properly on boot.
Code:
#!/system/bin/sh
# init.d (startup scripts) permission fixer.
mount -o remount,rw -t auto /system
chown -R 0.0 /system/etc/init.d
chown -R 0:0 /system/etc/init.d
chmod -R 777 /system/etc/init.d
chcon u:object_r:system_file:s0 /system/etc/init.d
chcon u:object_r:system_file:s0 /system/etc/init.d/*
echo "Init.d is working !!!" > /data/Test.log
echo "excecuted on \$(date +"%d-%m-%Y %r" )" >> /data/Test.log
echo "Init.d is working !!!" > /sdcard/Test.log
echo "excecuted on \$(date +"%d-%m-%Y %r" )" >> /sdcard/Test.log
mount -o remount,ro -t auto /system
The problem is that
Code:
echo "Init.d is working !!!" > /sdcard/Test.log
echo "excecuted on \$(date +"%d-%m-%Y %r" )" >> /sdcard/Test.log
Its not creats the "Test.log" output file in "sdcard" .
I don't know why its not creats the "Test.log" output file in "/sdcard/Test.log" is there any wrong with scripts or some thing I've missed.??

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

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
Great Work..
Thanks
@_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
thereassaad said:
@_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
Click to expand...
Click to collapse
In my case work good no problem with WiFi connection on S5 MM 6.0.1
Regards
thereassaad said:
@_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
Click to expand...
Click to collapse
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
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
@_alexndr , definitely mate will give a shot , later , thanks for ur work xD ,
good work bro will test more with new update
Good work ?
Sent from my A66A using XDA-Developers mobile app
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)
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.
WILMANS2M said:
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.
Click to expand...
Click to collapse
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
Thanks for the answer. Will try it asap and give you feedback.
Envoyé de mon GT-I9505 en utilisant Tapatalk
hello @_alexndr
So tried again with the sh modified script, but same thing. Same error and no initd installed unfortunately
If you have any other advice, i really thank you in advance.
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
great job
You sir are an animal. This script is intelligently designed
Deleted
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.
@_alexndr
Thanks a lot
Confirmed Working on Samsung Galaxy S5 G900H
OS: Stock Deodexed Marshmallow 6.0.1 with GreenApple Kernal

[Tweak][Guide] Init.d Tweaks

Init.d Tweaks
(Needs ROM (Kernel) With init.d Access And Busybox, Open Empty File In Text Editor (Notepad ++ Or Similar), Insert Tweak You Want In Header,Save in /system/etc/init.d and name it Lomething Like 73tweaks)
1. Strict minfree handler tweak
Code:
echo "2048,3072,6144,15360,17920,20480" > /sys/module/lowmemorykiller/parameters/minfree
2. Internet speed tweaks
Code:
echo "0" > /proc/sys/net/ipv4/tcp_timestamps;
echo "1" > /proc/sys/net/ipv4/tcp_tw_reuse;
echo "1" > /proc/sys/net/ipv4/tcp_sack;
echo "1" > /proc/sys/net/ipv4/tcp_tw_recycle;
echo "1" > /proc/sys/net/ipv4/tcp_window_scaling;
echo "5" > /proc/sys/net/ipv4/tcp_keepalive_probes;
echo "30" > /proc/sys/net/ipv4/tcp_keepalive_intvl;
echo "30" > /proc/sys/net/ipv4/tcp_fin_timeout;
echo "404480" > /proc/sys/net/core/wmem_max;
echo "404480" > /proc/sys/net/core/rmem_max;
echo "256960" > /proc/sys/net/core/rmem_default;
echo "256960" > /proc/sys/net/core/wmem_default;
echo "4096,16384,404480" > /proc/sys/net/ipv4/tcp_wmem;
echo "4096,87380,404480" > /proc/sys/net/ipv4/tcp_rmem;
3. Vm management tweaks
Code:
echo "4096" > /proc/sys/vm/min_free_kbytes
echo "0" > /proc/sys/vm/oom_kill_allocating_task;
echo "0" > /proc/sys/vm/panic_on_oom;
echo "0" > /proc/sys/vm/laptop_mode;
echo "0" > /proc/sys/vm/swappiness
echo "50" > /proc/sys/vm/vfs_cache_pressure
echo "90" > /proc/sys/vm/dirty_ratio
echo "70" > /proc/sys/vm/dirty_background_ratio
4. Misc kernel tweaks
Code:
echo "8" > /proc/sys/vm/page-cluster;
echo "64000" > /proc/sys/kernel/msgmni;
echo "64000" > /proc/sys/kernel/msgmax;
echo "10" > /proc/sys/fs/lease-break-time;
echo "500,512000,64,2048" > /proc/sys/kernel/sem;
5. Battery tweaks
Code:
echo "500" > /proc/sys/vm/dirty_expire_centisecs
echo "1000" > /proc/sys/vm/dirty_writeback_centisecs
6. EXT4 tweaks (greatly increase I/O)
(needs /system, /cache, /data partitions formatted to EXT4)
a) removes journalism
Code:
tune2fs -o journal_data_writeback /block/path/to/system
tune2fs -O ^has_journal /block/path/to/system
tune2fs -o journal_data_writeback /block/path/to/cache
tune2fs -O ^has_journal /block/path/to/cache
tune2fs -o journal_data_writeback /block/path/to/data
tune2fs -O ^has_journal /block/path/to/data
b) perfect mount options
Code:
busybox mount -o remount,noatime,noauto_da_alloc,nodiratime,barrier=0,nobh /system
busybox mount -o remount,noatime,noauto_da_alloc,nosuid,nodev,nodiratime,barrier=0,nobh /data
busybox mount -o remount,noatime,noauto_da_alloc,nosuid,nodev,nodiratime,barrier=0,nobh /cache
7. Flags blocks as non-rotational and increases cache size
Code:
LOOP=`ls -d /sys/block/loop*`;
RAM=`ls -d /sys/block/ram*`;
MMC=`ls -d /sys/block/mmc*`;
for j in $LOOP $RAM
do
echo "0" > $j/queue/rotational;
echo "2048" > $j/queue/read_ahead_kb;
done
8. microSD card speed tweak
Code:
echo "2048" > /sys/devices/virtual/bdi/179:0/read_ahead_kb;
9. Defrags database files
Code:
for i in \
`find /data -iname "*.db"`
do \
sqlite3 $i 'VACUUM;';
done
9. Remove logger
Code:
rm /dev/log/main
10. Ondemand governor tweaks
Code:
SAMPLING_RATE=$(busybox expr `cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_transition_latency` \* 750 / 1000)
echo 95 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
echo $SAMPLING_RATE > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate
11. Auto change governor and I/O Scheduler
a) I/O Scheduler (Best: MTD devices - VR; EMMC devices - SIO) - needs kernel with these
Code:
echo "vr" > /sys/block/mmcblk0/queue/scheduler
or
Code:
echo "sio" > /sys/block/mmcblk0/queue/scheduler
b) Governor (Best: Minmax > SavagedZen > Smoothass > Smartass > Interactive) - needs kernel with these
Code:
echo "governor-name-here" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
12. Move dalvik-cache to cache partition (if it's big enough) to free up data partition space
Code:
CACHESIZE=$(df -k /cache | tail -n1 | tr -s ' ' | cut -d ' ' -f2)
if [ $CACHESIZE -gt 80000 ]
then
echo "Large cache detected, moving dalvik-cache to /cache"
if [ ! -d /cache/dalvik-cache ]
then
busybox rm -rf /cache/dalvik-cache /data/dalvik-cache
mkdir /cache/dalvik-cache /data/dalvik-cache
fi
busybox chown 1000:1000 /cache/dalvik-cache
busybox chmod 0771 /cache/dalvik-cache
# bind mount dalvik-cache so we can still boot without the sdcard
busybox mount -o bind /cache/dalvik-cache /data/dalvik-cache
busybox chown 1000:1000 /data/dalvik-cache
busybox chmod 0771 /data/dalvik-cache
else
echo "Small cache detected, dalvik-cache will remain on /data"
fi
13. Disable normalize sleeper
Code:
mount -t debugfs none /sys/kernel/debug
echo NO_NORMALIZED_SLEEPER > /sys/kernel/debug/sched_features
14. GPS.conf
(create or edit your /system/etc/gps.conf with a text editor)
a) European NTP server (replace for america or asia in your case)
Code:
NTP_SERVER=europe.pool.ntp.org
XTRA_SERVER_1=http://xtra1.gpsonextra.net/xtra.bin
XTRA_SERVER_2=http://xtra2.gpsonextra.net/xtra.bin
XTRA_SERVER_3=http://xtra3.gpsonextra.net/xtra.bin
b) SE supl for A-GPS (better than Nokia's or Google's)
Code:
SUPL_HOST=supl.sonyericsson.com
SUPL_PORT=7275
Warning: Using these tweaks may brick your device. Use it with caution.
:good::good::good:
How can I know that my ROM / kernel support Init.d or not??
AK205 said:
How can I know that my ROM / kernel support Init.d or not??
Click to expand...
Click to collapse
Install Universal Init.d from Play Store and follow in-app instructions. Init.d support will be enabled on your device. Your device must be rooted first.
Build.prop tweaks by @bravonova
bravonova said:
Install Universal Init.d from Play Store and follow in-app instructions. Init.d support will be enabled on your device. Your device must be rooted first.
Click to expand...
Click to collapse
I make and init.d script and i copy your custom values to my init.d script. However, on net speed tweaks, the tcp_rmem and tcp_wmem didn't change the value at all even i edited it. Any help?
Should it be in text file or script file?
So we create a different text document containing each code for each tweak?? Not all In one document in the init.d folder??
Nice write up, bro. Thanks. Will have to try.
Guys so why aren't these enhancing tweaks and buildprop tweaks already available in our phones? Why aren't our phones optimized?
Tweaks good for one person or situation are not necessarily optimal for every case in general .
Medyredy said:
Guys so why aren't these enhancing tweaks and buildprop tweaks already available in our phones? Why aren't our phones optimized?
Click to expand...
Click to collapse
Can you help please?
Hello, I'm a newbie here. I wish to overclock my stock kernal, So it can be done through tweak? or I have to compile new overclock kernal from stock kernal source? Their's already a overclocked kernal for my device but its for cm11 and i want to use it on 4.1.2 JB stock ROM. Is their any simple way out?
Your help will be appreciated. Thanks .
use cm11 for s7392 or try
cm12 new developed
or stock i did give it to you before
choice is yours.......
i no longer have this device
rony raj said:
use cm11 for s7392 or try
cm12 new developed
or stock i did give it to you before
choice is yours.......
i no longer have this device
Click to expand...
Click to collapse
Thanks for suggesting new Cm12 kernal.
As of cm11, X264 encoding is important for me, plus their were some other minor bugs in that build. Though i agree its the best build compiled rom for Trend.
I will myself start some project after June~July.
What happened to your device though? You are among the few members who are guiding peoples on threads related to this device and i really appreciate it.

Categories

Resources