From cf58545a4557e72f1af69bc696b5f2ebf7b7dcc9 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 4 Jul 2018 17:15:26 +0800 Subject: [PATCH] Move shell code into scripts --- .../magisk/asyncs/InstallMagisk.java | 40 +++++++------------ src/full/res/raw/utils.sh | 19 +++++++++ 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java b/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java index 9d05d950d..130a71c02 100644 --- a/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java +++ b/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java @@ -104,7 +104,7 @@ public class InstallMagisk extends ParallelTask { } private boolean dumpBoot() { - console.add("- Copying boot image to " + mBoot); + console.add("- Copying image locally"); // Copy boot image to local try (InputStream in = mm.getContentResolver().openInputStream(bootUri); OutputStream out = new FileOutputStream(mBoot) @@ -197,31 +197,28 @@ public class InstallMagisk extends ParallelTask { ShellUtils.pump(in, out); out.close(); } + Shell.Sync.su("rm -f " + patched); console.add(""); - console.add("*********************************"); - console.add(" Patched Boot Image is placed in "); + console.add("****************************"); + console.add(" Patched image is placed in "); console.add(" " + dest + " "); - console.add("*********************************"); + console.add("****************************"); break; case SECOND_SLOT_MODE: case DIRECT_MODE: - String binPath = mm.remoteMagiskVersionCode >= Const.MAGISK_VER.HIDDEN_PATH ? - "/data/adb/magisk" : "/data/magisk"; - Shell.Sync.su(console, logs, - Utils.fmt("flash_boot_image %s %s; rm -f %s", patched, mBoot, patched), - Utils.fmt("rm -rf %s/*; mkdir -p %s; chmod 700 /data/adb", binPath, binPath), - Utils.fmt("cp -af %s/* %s; rm -rf %s", installDir, binPath, installDir), - mm.keepVerity ? "" : "patch_dtbo_image"); + Shell.Sync.sh(console, logs, + Utils.fmt("direct_install %s %s %s", patched, mBoot, installDir)); + if (!mm.keepVerity) + Shell.Sync.sh(console, logs, "find_dtbo_image", "patch_dtbo_image"); break; } - Shell.Sync.su("rm -f " + patched); } @Override protected Boolean doInBackground(Void... voids) { if (mode == FIX_ENV_MODE) { installDir = new File("/data/adb/magisk"); - Shell.Sync.sh("rm -rf " + installDir + "/*"); + Shell.Sync.sh("rm -rf /data/adb/magisk/*"); } else { installDir = new File( (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? @@ -239,11 +236,11 @@ public class InstallMagisk extends ParallelTask { return false; break; case DIRECT_MODE: - console.add("- Detecting ramdisk/boot image"); + console.add("- Detecting target image"); mBoot = ShellUtils.fastCmd("find_boot_image", "echo \"$BOOTIMAGE\""); break; case SECOND_SLOT_MODE: - console.add("- Detecting ramdisk/boot image"); + console.add("- Detecting target image"); char slot[] = ShellUtils.fastCmd("echo $SLOT").toCharArray(); if (slot[1] == 'a') slot[1] = 'b'; else slot[1] = 'a'; @@ -253,11 +250,11 @@ public class InstallMagisk extends ParallelTask { break; } if (mBoot == null) { - console.add("- Unable to detect ramdisk/boot image"); + console.add("! Unable to detect target image"); return false; } - console.add("- Use ramdisk/boot image: " + mBoot); + console.add("- Target image: " + mBoot); List abis = Arrays.asList(Build.SUPPORTED_ABIS); String arch; @@ -278,14 +275,7 @@ public class InstallMagisk extends ParallelTask { try { extractFiles(arch); if (mode == FIX_ENV_MODE) { - Shell.Sync.sh( - "cd " + installDir, - "sh update-binary extract", - "rm -f update-binary magisk.apk", - "cd /", - "rm -rf /sbin/.core/busybox/*", - "/sbin/.core/mirror/bin/busybox --install -s /sbin/.core/busybox" - ); + Shell.Sync.sh("fix_env"); } else { File patched = patchBoot(); if (patched == null) diff --git a/src/full/res/raw/utils.sh b/src/full/res/raw/utils.sh index 337ac20f6..a0decfb74 100644 --- a/src/full/res/raw/utils.sh +++ b/src/full/res/raw/utils.sh @@ -44,6 +44,25 @@ env_check() { return 0 } +fix_env() { + cd /data/adb/magisk + sh update-binary extract + rm -f update-binary magisk.apk + cd / + rm -rf /sbin/.core/busybox/* + /sbin/.core/mirror/bin/busybox --install -s /sbin/.core/busybox +} + +direct_install() { + flash_boot_image $1 $2 + rm -f $1 + rm -rf /data/adb/magisk/* 2>/dev/null + mkdir -p /data/adb/magisk 2>/dev/null + chmod 700 /data/adb + cp -f $3/* /data/adb/magisk + rm -rf $3 +} + mm_patch_dtbo() { if $KEEPVERITY; then echo false