diff --git a/app/src/main/assets/all/scripts/addon.d.sh b/app/src/main/assets/all/scripts/addon.d.sh new file mode 100644 index 0000000..f495448 --- /dev/null +++ b/app/src/main/assets/all/scripts/addon.d.sh @@ -0,0 +1,62 @@ +#!/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" + backup_file "$bb_install/ssl_helper" + echo "$bb_install" > /tmp/busybox-install-dir + elif [ "$action" = "restore" ]; then + local_bb="$C/$bb" + [ ! -f "$local_bb" ] && exit 1 + restore_file "$bb" + restore_file "$bb_install/ssl_helper" + 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 diff --git a/app/src/main/assets/all/scripts/info.sh b/app/src/main/assets/all/scripts/info.sh index 2f0b58e..08b2e77 100644 --- a/app/src/main/assets/all/scripts/info.sh +++ b/app/src/main/assets/all/scripts/info.sh @@ -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}') @@ -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 diff --git a/app/src/main/assets/all/scripts/install.sh b/app/src/main/assets/all/scripts/install.sh index b22871f..fbd2c94 100644 --- a/app/src/main/assets/all/scripts/install.sh +++ b/app/src/main/assets/all/scripts/install.sh @@ -44,6 +44,16 @@ do fi done +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 + + 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 + if busybox test "$REPLACE_APPLETS" = "true" then busybox printf "Removing old applets ... " diff --git a/app/src/main/assets/all/scripts/recovery.sh b/app/src/main/assets/all/scripts/recovery.sh index a6fb382..1b75a44 100644 --- a/app/src/main/assets/all/scripts/recovery.sh +++ b/app/src/main/assets/all/scripts/recovery.sh @@ -35,6 +35,12 @@ do chmod 755 $INSTALL_DIR/$fn done $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 diff --git a/app/src/main/assets/all/scripts/remove.sh b/app/src/main/assets/all/scripts/remove.sh index ae10052..88e2502 100644 --- a/app/src/main/assets/all/scripts/remove.sh +++ b/app/src/main/assets/all/scripts/remove.sh @@ -52,6 +52,21 @@ else busybox printf "... path not found.\n" fi +busybox printf "Removing addon.d script ... " +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 ... ' diff --git a/app/src/main/java/ru/meefik/busybox/EnvUtils.java b/app/src/main/java/ru/meefik/busybox/EnvUtils.java index f6adee9..8ed3d3e 100644 --- a/app/src/main/java/ru/meefik/busybox/EnvUtils.java +++ b/app/src/main/java/ru/meefik/busybox/EnvUtils.java @@ -413,6 +413,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(); diff --git a/app/src/main/java/ru/meefik/busybox/ExecScript.java b/app/src/main/java/ru/meefik/busybox/ExecScript.java index ebca338..6dbef5a 100644 --- a/app/src/main/java/ru/meefik/busybox/ExecScript.java +++ b/app/src/main/java/ru/meefik/busybox/ExecScript.java @@ -32,6 +32,7 @@ private void install() { if (!EnvUtils.isRooted(context)) return; String envDir = PrefStore.getEnvDir(context); List 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));