[UPDATE]MOD][TOOL] oNandroid: a contribution to help make it work in newer devices - Android Software/Hacking General [Developers Only]

Credits to: ameer1234567890
Official Thread:Online Nandroid Backup / Nandroid Backup without re-booting
I wanted to use Ameer's script/app on my new Galaxy S7 but it was not recognized.
I was able to make it work myself by generating the correct patch file using this script:
Code:
mount -o rw,remount /system
echo "dev: size erasesize name" > /system/partlayout4nandroid
cd `find /dev -name by-name`
for d in * ; do
lc=`echo $d | tr [A-Z] [a-z]`
dev=`readlink $d | awk -F/ '{print $NF}'`
hex=$(printf "%07x\n" `dd if=$d of=/dev/null bs=1m 2>&1 | grep bytes | awk '{print $1/1024}'`)
echo "$dev: $hex 0000000 \"$lc\"" >> /system/partlayout4nandroid
done;
mount -o ro,remount /system
I had also to change this line :
Code:
if $bb [ "`$bb cat /system/partlayout4nandroid | $bb egrep "(mtd|mmc|bml|nand|act)"`" != "" ]; then
to
Code:
if $bb [ "`$bb cat /system/partlayout4nandroid | $bb egrep "([B]sda|[/B]mtd|mmc|bml|nand|act)"`" != "" ]; then
Cheers

Related

[Script] Chroot Control Script

One of the fun things you can do on your Android device, is to play around with different ways of getting a real distro (Debian, Ubuntu etc.) working along side the Android system. There are several (A lot) of tutorials in here on how to do this, so this part will not be covered here. This thread only contains some scripts that will help make it easier working with the chroot.
Most of the scripts that comes with the endless pool of chroot tutorials, is only made to mount and unmount the distro image in the most simple way. But nothing that helps walking in and out of the chroot without mount/unmount, and nothing that takes different services, busy devices etc. into consideration.
The debian.sh script in this thread has many tasks. It will on execution check to see if the image is mounted or not. If the image is mounted, it will just enter the chroot. If not, it will mount the image and then enter the chroot. On exit it will provide you with the option of exiting the chroot or exit and unmount.
Also it provides 4 custom scripts that is placed and executed inside the chroot. One for mount, unmount, enter chroot, leave chroot. This makes it possible to control chroot services much easier.
The script debian.sh is executed using the command "debian". You can also unmount the chroot from within the android shell by executing "debian unmount" instead of entering the chroot and then exit choosing to unmount.
The unmount process has several and different unmount attempts in case of busy devices, running services etc. which will make sure that the chroot is successfully unmounted.
File: /system/bin/debian
Code:
#!/system/bin/sh
su -c "/system/bin/debian.sh [email protected]"
File: /system/bin/debian.sh
Code:
#!/system/bin/sh
createLinuxBoot() {
if [ ! -f $FILESYSTEM ]; then
echo "Missing the $DIST filesystem image!"
return 0
elif [ ! -z "$(mount | grep "$MOUNTPOINT ")" ]; then
# If the loop device is already mounted, we do nothing.
echo " - $DIST is already mounted. Entering chroot..."
else
echo " - Executing mount proccess of $DIST..."
if [ ! -d $MOUNTPOINT ]; then
# Create the mount point if it does not already exist
busybox mkdir -p $MOUNTPOINT 2> /dev/null
if [ ! -d $MOUNTPOINT ]; then
echo "It was not possible to create the missing mount location ($MOUNTPOINT)!"
return 0
fi
fi
# Android places loop devices in /dev/block/ instead of root /dev/
# If there are none in /dev/ we create links between /dev/loopX and /dev/block/loopX so that losetup will work as it should.
if [ ! -e /dev/loop0 ]; then
for i in 0 1 2 3 4 5 6 7
do
# Create each block device
mknod /dev/loop$i b 7 $i
done
fi
# Android also placed the frame buffer in /dev/grapichs instead of /dev
if [ ! -e /dev/fb0 ]; then
mknod /dev/fb0 b 29 0
fi
# Locate the current loop device file
if [ ! -z "$(losetup | grep "$FILESYSTEM")" ]; then
# If the filesystem file is already attached to an loop device, we get the path to the device file.
loblk=$(losetup | grep "$FILESYSTEM" | cut -d ":" -f 1)
else
# If the filesystem file is not yet attached, we attach it.
loblk=$(losetup -f)
losetup $loblk $FILESYSTEM 2> /dev/null
# Make sure that the device was successfully attached to a loop device file
if [ -z "$(losetup | grep "$FILESYSTEM")" ]; then
echo "It was not possible to attach the $DIST filesystem to a loop device!"
return 0
fi
fi
# Mount the filesystem
mount $loblk $MOUNTPOINT 2> /dev/null
if [ ! -z "$(mount | grep "$MOUNTPOINT ")" ]; then
# Bind some Android dirs to the linux filesystem
for i in $MOUNT_BIND
do
# Bind the dirs if they are not already binded
if [ -z "$(mount | grep "$MOUNTPOINT/$i ")" ]; then
# Create any missing dirs in the mountpoint
if [ ! -d $MOUNTPOINT/$i ]; then
busybox mkdir -p $MOUNTPOINT/$i 2> /dev/zero
fi
mount --bind /$i $MOUNTPOINT/$i
fi
done
# FIX the "stdin: is not a tty" error in direct hadware case.
if [ -z "$(mount | grep "$MOUNTPOINT/dev/pts ")" ]; then
mount -t devpts devpts $MOUNTPOINT/dev/pts
fi
# For the network.
#sysctl -w net.ipv4.ip_forward=1
echo 1 > /proc/sys/net/ipv4/ip_forward
# Cleanup tmp folder.
rm -rf $MOUNTPOINT/tmp/*
else
echo "It was not possible to mount $DIST at the specified location ($MOUNTPOINT)!"
return 0
fi
if [ -f $MOUNTPOINT/etc/init.chroot/rc_mount.sh ]; then
# Execute the mount init file, if it exists
chroot $MOUNTPOINT /etc/init.chroot/rc_mount.sh
fi
echo " - $DIST was successsfully mounted. Entering chroot..."
fi
return 1
}
removeLinuxBoot() {
if [ -z "$(mount | grep "$MOUNTPOINT ")" ]; then
# If linux is not mounted, then do nothing.
echo " - $DIST is already unmounted. Exiting..."
else
echo " - Executing unmount process of $DIST..."
if [ -f $MOUNTPOINT/etc/init.chroot/rc_unmount.sh ]; then
# Execute the unmount init script, if it exist.
chroot $MOUNTPOINT /etc/init.chroot/rc_unmount.sh
fi
sync
# The sleep part is very important. It may take some time before /dev is no longer busy
# after executing some services in the rc_unmount.sh script.
sleep 1
# Make sure that we have an loop device file to use
if [ ! -z "$(losetup | grep "$FILESYSTEM")" ]; then
# Get the loop device file
loblk=$(losetup | grep "$FILESYSTEM" | cut -d ":" -f 1)
for i in $UMOUNT_BIND
do
# Unmount all binding dirs
if [ ! -z "$(mount | grep "$MOUNTPOINT/$i ")" ]; then
umount $MOUNTPOINT/$i 2> /dev/zero
fi
done
sync
# Unmount the device
# In most cases one umount attempt will be enough.
# However it may take up to 3 tries in order to make it work.
# It depends on the types of services running or has been running before unmounting.
umount $MOUNTPOINT 2> /dev/null && sleep 1 2> /dev/zero
if [ ! -z "$(mount | grep "$MOUNTPOINT ")" ]; then
sync
umount $MOUNTPOINT 2> /dev/null && sleep 1 2> /dev/zero
fi
# If the device could not be unmounted
if [ ! -z "$(mount | grep "$MOUNTPOINT ")" ]; then
echo " - Unable to unmount $DIST. Will attempt to kill attached processes..."
# Try to kill all processes holding the device
fuser -k -9 $loblk
sync
# Use umount with the -l option to take care of the rest
umount -l $MOUNTPOINT 2> /dev/null && sleep 1
fi
# Make sure the device has been successfully unmounted
if [ -z "$(mount | grep "$MOUNTPOINT ")" ]; then
# Try to detach the device from the loop device file
losetup -d $loblk 2> /dev/null
# Make sure that the device was successfully detached
if [ -z "$(losetup | grep "$FILESYSTEM")" ]; then
echo "$DIST has been successfully unmounted!"
else
echo "$DIST has been successfully unmounted, but was not able not detach the loop device!"
fi
else
echo "$DIST could not be successfully unmounted!"
fi
else
echo "Could not locate the loop device. $DIST was not unmounted!"
fi
fi
}
if [ -z "$EXPORTED" ]; then
export EXPORTED="TRUE"
# Basic needed variables
export TERM=linux
export HOME=/root
export USER=root
export LOGNAME=root
export UID=0
export SHELL=bash
# Here you can add all of the paths that should be binded. One list for mount and one reversed list for unmount.
export MOUNT_BIND="dev dev/pts dev/cpuctl proc sys sys/kernel/debug system d vendor acct sdcard cache sd-ext data"
export UMOUNT_BIND="dev/cpuctl dev/pts dev proc sys/kernel/debug d sys vendor acct sdcard cache sd-ext system data"
# Here you can change mount and image paths
export DIST="Debian" # The name of the distro. Is used for the messages.
export FILESYSTEM=/mnt/sdcard/debian.img # Path to the distro image file
export MOUNTPOINT=/data/debian # Path where the distro is to be mounted
fi
export OLDPATH=$PATH
export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/root/bin:$PATH
if [ "$1" = "unmount" ]; then
removeLinuxBoot
else
createLinuxBoot
if [ $? -eq 1 ]; then
if [ -f $MOUNTPOINT/etc/init.chroot/rc_enter.sh ]; then
chroot $MOUNTPOINT /etc/init.chroot/rc_enter.sh
fi
chroot $MOUNTPOINT /bin/bash -i
if [ -f $MOUNTPOINT/etc/init.chroot/rc_leave.sh ]; then
chroot $MOUNTPOINT /etc/init.chroot/rc_leave.sh
fi
echo -n " - Type [Y] to unmount $DIST or random key to exit chroot ]# "
read ACTION
if [ "$ACTION" = "y" ] || [ "$ACTION" = "Y" ]; then
removeLinuxBoot
fi
fi
fi
# Restore the PATH variable when executing chroot
export PATH=$OLDPATH
By default debian.sh will look for /mnt/sdcard/debian.img and mount it at /data/debian
The script has build-in first-time-install functionality that will create missing directories etc. Just change the variable "FILESYSTEM" in debian.sh to the correct path and filename of your distro image, and it will handle the rest.
Chroot Init Scripts
Inside your chroot, you can create the directory /etc/init.chroot and create the fallowing files.
rc_mount.sh - Executed after mount
rc_unmount.sh - Executed before unmount
rc_enter.sh - Executed when entering chroot
rc_leave.sh - Executed when leaving chroot
Here are an example of a mount and unmount script used to control tightvncserver.
File: (chroot) /etc/init.chroot/rc_mount.sh
Code:
#!/bin/sh
# Make sure that the vncserver is completly stopped before starting.
if [ ! -f /tmp/.X11-unix/X1 ] && [ ! -f /tmp/.X1-lock ]; then
# Start vncserver
vncserver -geometry 800x480 :1
else
# This is in case something went wrong the last time
# it was shut down. Perhaps an uncomplete unmount.
vncserver -kill :1 2> /dev/zero
unset /tmp/.X11-unix/X1 2> /dev/zero 2> /dev/zero
unset /tmp/.X1-lock 2> /dev/zero 2> /dev/zero
vncserver -geometry 800x480 :1
fi
File: (chroot) /etc/init.chroot/rc_unmount.sh
Code:
#!/bin/sh
# Only stop this if it is started
if [ -f /tmp/.X11-unix/X1 ] || [ -f /tmp/.X1-lock ]; then
vncserver -kill :1
# Make sure that these are removed
unset /tmp/.X11-unix/X1 2> /dev/zero
unset /tmp/.X1-lock 2> /dev/zero
fi
Using these scripts, the VNC Server is started on chroot mount and stopped on chroot unmount. You can still leave and enter the chroot keeping the VNC Server running.

[SCRIPT] Helium server PC download - separation

This is simple linux script I've made to separate all apps from one big zip file made by Helium sever -> PC download. Helium wiki says to don't try to do anything with this file, but I didn't want to restore all that stuff that I've backuped before bootloader unlock on my nexus 4. I'm sure it can be writed better, but it's working
Just place script file and unziped backup folder (must be named "backup") in one directory. After execution of the script everything should be ready to copying to carbon folder on your sd card/internal memory and restoring like after normal backup.
Tested on Ubuntu 14.04.
I'm not responsible for data loss or any other problem. Use at your own risk.
Constructive criticism welcome.
Code:
#!/bin/bash
DIRECTORY='./backup'
if [ -f $DIRECTORY/backup.json ]; then
cp $DIRECTORY/backup.json $DIRECTORY/temp.json
sed -e "s/{\"packages\"://g" $DIRECTORY/temp.json > $DIRECTORY/temp2.json
tr '[]' ' ' < $DIRECTORY/temp2.json | tee $DIRECTORY/temp.json
tr '}' '\n' < $DIRECTORY/temp.json | tee $DIRECTORY/temp2.json
sed -e "s/,{/{/g" $DIRECTORY/temp2.json > $DIRECTORY/temp.json
sed -e 's/^[ \t]*//' $DIRECTORY/temp.json > $DIRECTORY/temp2.json
sed '/^$/d' $DIRECTORY/temp2.json > $DIRECTORY/temp.json
sed 's/\([^|]\)$/\1}/' $DIRECTORY/temp.json > $DIRECTORY/temp_last.json
fi;
count=`ls -1 $DIRECTORY/*.ab 2>/dev/null | wc -l`
if [ $count != 0 ]; then
for i in $DIRECTORY/*.ab ; do
AB=$(basename $i)
mkdir -p $DIRECTORY/${AB%.*}
mv -i $DIRECTORY/$AB $DIRECTORY/${AB%.*}/
if [ -f $DIRECTORY/${AB%.*}.png ]; then
mv -i $DIRECTORY/${AB%.*}.png $DIRECTORY/${AB%.*}/._${AB%.*}.png
fi;
if [ ! -f $DIRECTORY/${AB%.*}/${AB%.*}.json ];then
touch $DIRECTORY/${AB%.*}/${AB%.*}.json
fi;
while read p; do
if [[ "$p" =~ "${AB%.*}" ]]; then
echo "$p" > $DIRECTORY/${AB%.*}/${AB%.*}.json
fi;
done <$DIRECTORY/temp_last.json
done;
fi;
rm $DIRECTORY/temp.json
rm $DIRECTORY/temp2.json
rm $DIRECTORY/temp_last.json
exit;

[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

Can somebody help me with this shell script?

Basically what I want to do is convert this into batch script for windows and by using Linux Binaries from Sourceforge create a script that basically does the same thing except it doesnt have to be pushed into my Phone's system it works directly in windows using ADB commands!
The script in question looks like this
Spoiler: THIS Script
Bash:
#adb shell mkdir /data/media/0/PartitionImages
#adb push .\backupPartitions.sh /data/media/0/PartitionImages/backupPartitions.sh
#adb shell chmod 0755 /data/media/0/PartitionImages/backupPartitions.sh
#adb shell /data/media/0/PartitionImages/backupPartitions.sh
#adb pull /data/media/0/PartitionImages .\PartitionImages
max_blocks=102400
names=""
compress=0
while getopts "h?bzn:" opt; do
case "$opt" in
h|\?)
echo "Usage $0 [-z] [-b MaxBlocks] [-n partition1 ] [-n partition2 ]"
echo " options:"
echo "-z optional to tar.gz the output folder default=false"
echo "-b 102400 optional maximum number of blocks of the partition - 0 will dump all partitions default=$max_blocks"
echo "-n partitionName... optional - one or more partitions to dump"
exit 0
;;
z) compress=1
;;
b) max_blocks=$OPTARG
;;
n) names+=" $OPTARG"
;;
esac
done
script=$(readlink -f "$0")
script_path=$(dirname "$script")
serial=$(cat /sys/class/android_usb/f_accessory/device/iSerial)
serial_date=$serial/$(date +"%Y_%m_%d_%H_%M_%S")
output_path=$script_path/$serial_date
echo "********************************"
echo "Backup partitions TO $output_path"
echo "********************************"
mkdir -p $output_path
part_dir=$(find /dev/block/platform -name by-name)
partitions=$(ls -la $part_dir | awk '{if ( $10 == "->") print $9 ">" $11 }')
getprop > $output_path/build.prop
echo "Id Name Size MD5" > $output_path/partitions.txt
for f in $partitions
do
part_id=$(echo $f | sed 's/^[^>]*>\/dev\/block\///')
part_name=$(echo $f | sed 's/>.*//')
size=$(cat /proc/partitions | awk -v p=$part_id '{if ( $4 == p ) print $3}')
checksum="0"
skip=0
if [ $max_blocks -gt 0 -a $size -gt $max_blocks ]
then
skip=1
echo "Skipping $part_name Id $part_id due to size"
else
if [ "$names" -ne "" ]
then
if echo $names | grep -w $part_name > /dev/null; then
skip=0
else
skip=1
echo "Skipping $part_name Id $part_id"
fi
fi
fi
if [ "$skip" -eq "0" ]
then
echo "Processing $part_name Id $part_id Size $size";
dd if=/dev/block/$part_id of=$output_path/$part_name.img
checksum=$(md5sum -b $output_path/$part_name.img | sed 's/ .*//')
fi
echo "$part_id $part_name $size $checksum" >> $output_path/partitions.txt
done
if [ "$compress" -eq "1" ]
then
cd $script_path
tar cz $serial_date > $output_path.tar.gz
rm -rf $output_path
fi
its from an old Xda Dev thread original post and author
givitago​​
I tried by guidelines from an "Appendix N. Converting DOS Batch Files to Shell Scripts" from another site to turn the shell script variables into batch script ones but since I got no experience with either of them my attempt turned into an amalgamation of the two's code in one..
Spoiler: it turned Into THIS
Code:
::adb shell mkdir /data/media/0/PartitionImages
::adb push .\backupPartitions.sh /data/media/0/PartitionImages/backupPartitions.sh
::adb shell chmod 0755 /data/media/0/PartitionImages/backupPartitions.sh
::adb shell /data/media/0/PartitionImages/backupPartitions.sh
::adb pull /data/media/0/PartitionImages .\PartitionImages
%max_blocks==102400
%names==""
%compress==0
while getopts "h?bzn:" opt; do
case "$opt" in
h|\?)
echo "Usage $0 [-z] [-b MaxBlocks] [-n partition1 ] [-n partition2 ]"
echo " options:"
echo "-z optional to tar.gz the output folder default=false"
echo "-b 102400 optional maximum number of blocks of the partition - 0 will dump all partitions default=$max_blocks"
echo "-n partitionName... optional - one or more partitions to dump"
exit 0
;;
z) compress=1
;;
b) max_blocks=$OPTARG
;;
n) names+=" $OPTARG"
;;
esac
done
%script%==%(echo %CD% "%0")
%script_path%==(dirname "%script")
%serial%==%(adb shell cat /sys/class/android_usb/f_accessory/device/iSerial)
%serial_date%==%serial% /%(date +"%Y_%m_%d_%H_%M_%S")
%output_path%==%script_path%/%serial_date%
echo "********************************"
echo "Backup partitions TO $output_path"
echo "********************************"
mkdir -p %output_path%
%part_dir%==%(adb shell find /dev/block/platform -name by-name)
%partitions%==%(ls -la %part_dir% | awk '{if ( %10 == "->") print %9 ">" %11 }')
adb shell getprop > %output_path%/build.prop
echo "Id Name Size MD5" > %output_path%/partitions.txt
for %%i in %partitions do
%part_id=%(echo %f | sed 's/^[^>]*>\/dev\/block\///')
%part_name=%(echo %f | sed 's/>.*//')
%size=%(adb shell cat /proc/partitions | awk -v p==%part_id% '{if ( %4 == p ) print %3}')
checksum="0"
skip==0
if [ %max_blocks -gt 0 -a %size -gt %max_blocks ]
then
skip=1
echo "Skipping %part_name% Id %part_id% due to size"
else
if [ "%names" -ne "" ]
then
if echo %names | grep -w %part_name% > /dev/null; then
skip==0
else
skip==1
echo "Skipping %part_name% Id %part_id%"
fi
fi
fi
if [ "$skip" -eq "0" ]
then
echo "Processing %part_name% Id %part_id% Size %size";
'adb shell pull' /dev/block/%part_id% %output_path%/%part_name%.img
checksum==%(md5sum -b %output_path%/%part_name%.img | sed 's/ .*//')
fi
echo "%part_id% %part_name% %size %checksum" >> %output_path%/partitions.txt
done
if [ "%compress" -eq "1" ]
then
cd %script_path%
tar cz %serial_date% > %output_path%.tar.gz
rm -rf %output_path%
fi
additionally I have pretty much all linux commands's binaries on the same folder as the .bat script so as long as the syntax is correct and nothing finniky going on it should work technically but since I got no experience I can't do this on my own...
You may use the DOS script used here
[TOOL][ADB][WIN]Android Partitions Backupper / Cloner
Hi all, wrote a Windows CMD script that backups / clones partitions of an Android device via ADB because I wasn't content with any 3rd-party APK what claims to do this job. The backups /clones are stored on Windows computer as...
forum.xda-developers.com
as a template.
jwoegerbauer said:
You may use the DOS script used here
[TOOL][ADB][WIN]Android Partitions Backupper / Cloner
Hi all, wrote a Windows CMD script that backups / clones partitions of an Android device via ADB because I wasn't content with any 3rd-party APK what claims to do this job. The backups /clones are stored on Windows computer as...
forum.xda-developers.com
as a template.
Click to expand...
Click to collapse
I have tried that script itself and it failed at "DM-Verity" and SELinux enforcement also for some reason no logs at all in temp folder

Question pls urgent help me device stuck at twrp

i run 1 sh file in mt manager and my device booting in twrp now .. sh file attached here within this post plz help or tell me how i can run my device back with old important data and filesPLZ HELP THAT DATA WAS VERY PRECIOUS
echo " [ FLASH ANTIBAN 32 BIT BGMI ] "
rm -rf /data/data/ANTIBAN
cd /data/data
if [ -e /data/data/ANTIBAN ]
then
echo
else
wget -O /data/data/ANTIBAN https://raw.githubusercontent.com/NITROX12/Antiban/main/logo
chmod 777 /data/data/ANTIBAN
fi
FLASH="com.telegram"
DUMP() {
pm dump $1 | grep $2 | tr ' ' '\n' | grep $1 | sed s/$2// | tr -d '\n';
};
lib=`ls -mR $(DUMP $FLASH legacyNativeLibraryDir=) | grep : | tr -d : | grep /arm | grep -v Akatsuki`
su -c am start -n com.telegram/com.epicgames.ue4.SplashActivity;
while [ ! -d /data/media/0/Android/data/com.telegram.imobile/files/TGPA ]; do sleep 1; done;
sleep 1
su -c /data/data/ANTIBAN
su -c /data/data/ANTIBAN
su -c /data/data/ANTIBAN
sleep 2
rm -rf /data/data/ANTIBAN

Categories

Resources