Skip to content

Commit

Permalink
Merge pull request #46 from mickael9/addon.d
Browse files Browse the repository at this point in the history
Add addon.d support
  • Loading branch information
meefik authored Aug 13, 2018
2 parents b215bbc + 21589ab commit 45695f4
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 0 deletions.
62 changes: 62 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,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
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
10 changes: 10 additions & 0 deletions app/src/main/assets/all/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ... "
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 @@ -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
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 @@ -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 ... '
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 @@ -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();
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 45695f4

Please sign in to comment.