Skip to content

Commit

Permalink
Add addon.d support
Browse files Browse the repository at this point in the history
This makes busybox persist on OTA updates if the ROM supports it.
  • Loading branch information
mickael9 committed Oct 18, 2017
1 parent 8a8c505 commit 89b401f
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 0 deletions.
60 changes: 60 additions & 0 deletions app/src/main/assets/all/scripts/addon.d.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/sbin/sh
#
# /system/addon.d/99-busybox.sh
# Backup and restore busybox
#

. /tmp/backuptool.functions

do_action() {
action="$1"
bb_install=$(cat "$2")
bb="$bb_install/busybox"

[ -z "$bb_install" ] && exit 1

if [ "$action" = "backup" ]; then
local_bb="$bb"
[ ! -f "$local_bb" ] && exit 1
backup_file "$bb"
echo "$bb_install" > /tmp/busybox-install-dir
elif [ "$action" = "restore" ]; then
local_bb="$C/$bb"
[ ! -f "$local_bb" ] && exit 1
restore_file "$bb"
fi

"$local_bb" --list | while read applet; do
file="$bb_install/$applet"

if [ "$action" = "backup" ]; then
link=$(readlink -f "$file")
[ -f "$file" -a "$link" = "$bb" ] && backup_file "$file"
elif [ "$action" = "restore" ]; then
[ -f "$C/$file" ] && restore_file "$file"
fi
done
}

case "$1" in
backup)
do_action backup "$S/addon.d/busybox-install-dir"
;;

restore)
do_action restore "/tmp/busybox-install-dir"
;;

pre-backup)
# Stub
;;
post-backup)
# Stub
;;
pre-restore)
# Stub
;;
post-restore)
# Stub
;;
esac
18 changes: 18 additions & 0 deletions app/src/main/assets/all/scripts/info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ busybox printf "* /data: $DATA_FREE\n"
SYSTEM_FREE=$(busybox df -Ph /system | busybox grep -v ^Filesystem | busybox awk '{print $4}')
busybox printf "* /system: $SYSTEM_FREE\n"

busybox printf "\naddon.d support:\n"
if busybox test -d /system/addon.d
then
busybox printf "* available\n"
else
busybox printf "* unavailable\n"
fi

busybox printf "\nLatest BusyBox:\n"
BB_BIN=$(busybox which busybox)
BB_VERSION=$(busybox | busybox head -1 | busybox awk '{print $2}')
Expand Down Expand Up @@ -53,6 +61,16 @@ then
busybox printf "* size: $BB_SIZE bytes\n"
BB_MD5=$(busybox md5sum $BB_BIN | busybox awk '{print $1}')
busybox printf "* md5: $BB_MD5\n"

if test -d /system/addon.d
then
if test -f /system/addon.d/99-busybox.sh
then
busybox printf "* addon.d script: found\n"
else
busybox printf "* addon.d script: not found\n"
fi
fi
else
busybox printf "* not installed\n"
fi
16 changes: 16 additions & 0 deletions app/src/main/assets/all/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ if busybox test -e "$INSTALL_DIR/busybox"
then
busybox rm "$INSTALL_DIR/busybox"
fi

if busybox test "$SYSTEM_REMOUNT" -ne 0 -a -d /system/addon.d
then
busybox cp "$ENV_DIR/scripts/addon.d.sh" /system/addon.d/99-busybox.sh
echo "$INSTALL_DIR" > /system/addon.d/busybox-install-dir
fi

busybox cp $BB_BIN $INSTALL_DIR/busybox
if busybox test $? -eq 0
then
Expand All @@ -32,8 +39,17 @@ else
fi

busybox printf "Setting permissions ... "

if busybox test "$SYSTEM_REMOUNT" -ne 0 -a -d /system/addon.d
then
busybox chown 0:0 /system/addon.d/99-busybox.sh
busybox chmod 755 /system/addon.d/99-busybox.sh
busybox chmod 644 /system/addon.d/busybox-install-dir
fi

busybox chown 0:0 $INSTALL_DIR/busybox
busybox chmod 755 $INSTALL_DIR/busybox

if busybox test $? -eq 0
then
busybox printf "done\n"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/assets/all/scripts/recovery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ ui_print "Installing BusyBox to $INSTALL_DIR..."
cp busybox $INSTALL_DIR
chmod 755 $INSTALL_DIR/busybox
$INSTALL_DIR/busybox --install -s $INSTALL_DIR
if [ -d /system/addon.d ]; then
cp addon.d.sh /system/addon.d/99-busybox.sh
chmod 755 /system/addon.d/99-busybox.sh
echo "$INSTALL_DIR" > /system/addon.d/busybox-install-dir
chmod 644 /system/addon.d/busybox-install-dir
fi
ui_print "Unmounting /system part..."
umount /system
exit 0
15 changes: 15 additions & 0 deletions app/src/main/assets/all/scripts/remove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ else
busybox printf "... path not found.\n"
fi

busybox printf "Removing addon.d script: \n"
if busybox test -e /system/addon.d/99-busybox.sh
then
busybox rm /system/addon.d/busybox-install-dir
busybox rm /system/addon.d/99-busybox.sh
if busybox test $? -eq 0
then
busybox printf "done\n"
else
busybox printf "fail\n"
fi
else
busybox printf "not found\n"
fi

if busybox test "$SYSTEM_REMOUNT" -ne 0
then
busybox printf 'Remounting /system to ro ... '
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/ru/meefik/busybox/EnvUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ static boolean makeZipArchive(Context c, String archiveName) {
File updateBinary = new File(PrefStore.getEnvDir(c) + "/scripts/recovery.sh");
zip.putNextEntry(new ZipEntry("META-INF/com/google/android/update-binary"));
addFileToZip(updateBinary, zip);
File addondBinary = new File(PrefStore.getEnvDir(c) + "/scripts/addon.d.sh");
zip.putNextEntry(new ZipEntry("addon.d.sh"));
addFileToZip(addondBinary, zip);

result = true;
} catch (IOException e) {
e.printStackTrace();
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/ru/meefik/busybox/ExecScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ private void install() {
if (!EnvUtils.isRooted(context)) return;
String envDir = PrefStore.getEnvDir(context);
List<String> params = new ArrayList<>();
params.add("ENV_DIR=" + envDir);
params.add("INSTALL_DIR=" + PrefStore.getInstallDir(context));
params.add("INSTALL_APPLETS=" + PrefStore.isInstallApplets(context));
params.add("REPLACE_APPLETS=" + PrefStore.isReplaceApplets(context));
Expand Down

0 comments on commit 89b401f

Please sign in to comment.