[Sony Cross-Device General] mionica:
v2.3

Version 2.3 is up and attched to post #123.

I've improved the busybox installer massively; it now:

searches for busybox in /system/xbin, /system/.XZDualRecovery, /system/bin, /system/sbin and picks the first one that can run in recovery (yes, that's actually checked); if, and only if, none is found, the included one is used

that busybox is copied to /system/xbin (unless, of course, it was found in /system/xbin)

/system/xbin cleanup: all the existing busybox applets that are not supported by /system/xbin/busybox are removed;

all the supported applets that point to anything except /system/xbin/busybox are replaced with applets pointing to /system/xbin/busybox

busybox and all busybox applets are completely removed from /system/bin and /system/sbin

This way, everybody can enjoy a fully working busybox without any missing applets, and without risking to completely damage their setup.

Additionally, the busybox install/update log is saved to the external sdcard; it should look like

Sony D6633, firmware 23.1.1.E.0.1, Android 5.0.2
Fri Apr 24 16:19:48 BST 2015
----------------------------

loooking for busybox...
> found as /system/xbin/busybox

removing unsupported applets...
> 0 unsupported applets removed

(re)creating supported applets where needed...
> 0 applets (re)created

removing busybox and any applets from /system/bin...
> 0 wrongly placed applets removed

removing busybox and any applets from /system/sbin...
> 0 wrongly placed applets removed

All done.

- except with ****loads of applets listed at the "(re)creating supported applets where needed" if this was a clean busybox install.

Here's the install script for peer review:

#! /sbin/sh

LOGFILE=/tmp/install_busybox.log
log() {
echo "$*" >> ${LOGFILE}
}

mygp() {
cat /system/build.prop | grep $1 | sed 's,^[^=]*=,,'
}

#print a nice debug header
log "$(mygp ro.product.manufacturer) $(mygp ro.product.model), firmware $(mygp ro.build.id), Android $(mygp ro.build.version.release)"
log "$(date)"
log "----------------------------"
log " "

# lookup a suitable busybox
log "loooking for busybox..."
for dir in /system/xbin /system/.XZDualRecovery /system/bin /system/sbin /tmp
do
if test -x $dir/busybox
then
# check that we can actually run it from recovery :)
if $dir/busybox --list 2>&1 > /dev/null
then
BUSYBOX=$dir/busybox
log "> found as $dir/busybox"
break
# mention those we did find, but which don't work in recovery
else
log "> ignoring $dir/busybox, which doesn't work in recovery"
fi
fi
done
log " "

# if the one in /system/xbin doesn't exist, or if it doesn't work in recovery
if test "$BUSYBOX" != "/system/xbin/busybox"
then
log "installing $BUSYBOX to /system/xbin..."
# create the xbin folder, if need be
log ". mkdir -p /system/xbin"
mkdir -p /system/xbin 2>&1 >> ${LOGFILE}
log ". chmod 755 /system/xbin"
chmod 755 /system/xbin 2>&1 >> ${LOGFILE}
log ". chown 0.0 /system/xbin"
chown 0.0 /system/xbin 2>&1 >> ${LOGFILE}
log ". chcon u:object_r:system_file:s0 /system/xbin"
chcon u:object_r:system_file:s0 /system/xbin 2>&1 >> ${LOGFILE}
# copy busybox
log ". cp $BUSYBOX /system/xbin/"
cp $BUSYBOX /system/xbin/ 2>&1 >> ${LOGFILE}
log ". chmod 755 /system/xbin/busybox"
chmod 755 /system/xbin/busybox 2>&1 >> ${LOGFILE}
log ". chown 0.0 /system/xbin/busybox"
chown 0.0 /system/xbin/busybox 2>&1 >> ${LOGFILE}
log ". chcon u:object_r:system_file:s0 /system/xbin/busybox"
chcon u:object_r:system_file:s0 /system/xbin/busybox 2>&1 >> ${LOGFILE}
BUSYBOX=/system/xbin/busybox
log " "
fi

# get rid of the already existing applets which are no longer supported
log "removing unsupported applets..."
N=0
# foreach applet installed in /system/xbin
for applet in $(ls -l /system/xbin | grep -E ' -> [^ ]*busybox$' | grep -Ev '^su$' | awk '{print $9}')
do
aexp="$(echo -n $applet|sed 's,\[,\\\[,g')"
# check if $applet is supported by the busybox in /system/xbin
if test -z $(/system/xbin/busybox --list | grep -E "^$aexp$" 2> /dev/null)
then
test $(( $N % 5 )) -eq 0 && echo -n " " >> ${LOGFILE}
# existing but not currently supported -> remove
echo -n "$applet " >> ${LOGFILE}
rm -f /system/xbin/$applet
N=$(( $N + 1 ))
test "$(( $N % 5 ))" -eq 0 && log " "
fi
done
test $(( $N % 5 )) -ne 0 && log " "
log "> $N unsupported applets removed"
log " "

# create applets for the existing busybox
log " "
log "(re)creating supported applets where needed..."
N=0
# foreach applet supported by /system/xbin/busybox
for applet in $(/system/xbin/busybox --list | grep -Ev '^su$')
do
# check if the applet points to the right busybox
target=$(ls -l /system/xbin/$applet 2>/dev/null | awk '{print $11}')
if test "z$target" != "zbusybox"
then
test $(( $N % 5 )) -eq 0 && echo -n " " >> ${LOGFILE}
# the applet either doesn't exist, or it points to the wrong busybox
# -> replace it
echo -n "$applet " >> ${LOGFILE}
rm -f /system/xbin/$applet
ln -s busybox /system/xbin/$applet
N=$(( $N + 1 ))
test $(( $N % 5 )) -eq 0 && log " "
fi
done
test $(( $N % 5 )) -ne 0 && log " "
log "> $N applets (re)created"
log " "

# remove busybox plus any applets from /system/bin and /system/sbin
for dir in /system/bin /system/sbin
do
log "removing busybox and any applets from $dir..."
N=0
# for busybox and ant applet in $dir
for applet in busybox $(ls -l $dir | grep -E ' -> [^ ]*busybox$' | grep -Ev '^su$' | awk '{print $9}')
do
# skip non-existing $dir/busybox
if test ! -e $dir/$applet
then
continue
fi
test $(( $N % 5 )) -eq 0 && echo -n " " >> ${LOGFILE}
echo -n "$applet " >> ${LOGFILE}
rm -f $dir/$applet
N=$(( $N + 1 ))
test $(( $N % 5 )) -eq 0 && log " "
done
test $(( $N % 5 )) -ne 0 && log " "
log "> $N wrongly placed applets removed"
log " "
done

log "All done."

# copy log to external sdcard
cp $LOGFILE /external_sd

---------- Post added at 04:43 PM ---------- Previous post was at 04:34 PM ----------

That's exactly why I said to remove the busybox installer app - the applets stay in place that way, so you get full busybox functionality without the risk of breaking your system.

Anyway, 2.3 includes a full busybox install/cleanup routine, so you can forget all about busybox; sonyfix 2.3 does everything for you.

You apply sonyfix 2.3 and forget all about busybox; I promise you that every app that needs busybox will just work. Including Titanium Backup, of which I'm a big fan actually.