Move shell code into scripts

This commit is contained in:
topjohnwu 2018-07-04 17:15:26 +08:00
parent e86015badc
commit cf58545a45
2 changed files with 34 additions and 25 deletions

View File

@ -104,7 +104,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
} }
private boolean dumpBoot() { private boolean dumpBoot() {
console.add("- Copying boot image to " + mBoot); console.add("- Copying image locally");
// Copy boot image to local // Copy boot image to local
try (InputStream in = mm.getContentResolver().openInputStream(bootUri); try (InputStream in = mm.getContentResolver().openInputStream(bootUri);
OutputStream out = new FileOutputStream(mBoot) OutputStream out = new FileOutputStream(mBoot)
@ -197,31 +197,28 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
ShellUtils.pump(in, out); ShellUtils.pump(in, out);
out.close(); out.close();
} }
Shell.Sync.su("rm -f " + patched);
console.add(""); console.add("");
console.add("*********************************"); console.add("****************************");
console.add(" Patched Boot Image is placed in "); console.add(" Patched image is placed in ");
console.add(" " + dest + " "); console.add(" " + dest + " ");
console.add("*********************************"); console.add("****************************");
break; break;
case SECOND_SLOT_MODE: case SECOND_SLOT_MODE:
case DIRECT_MODE: case DIRECT_MODE:
String binPath = mm.remoteMagiskVersionCode >= Const.MAGISK_VER.HIDDEN_PATH ? Shell.Sync.sh(console, logs,
"/data/adb/magisk" : "/data/magisk"; Utils.fmt("direct_install %s %s %s", patched, mBoot, installDir));
Shell.Sync.su(console, logs, if (!mm.keepVerity)
Utils.fmt("flash_boot_image %s %s; rm -f %s", patched, mBoot, patched), Shell.Sync.sh(console, logs, "find_dtbo_image", "patch_dtbo_image");
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");
break; break;
} }
Shell.Sync.su("rm -f " + patched);
} }
@Override @Override
protected Boolean doInBackground(Void... voids) { protected Boolean doInBackground(Void... voids) {
if (mode == FIX_ENV_MODE) { if (mode == FIX_ENV_MODE) {
installDir = new File("/data/adb/magisk"); installDir = new File("/data/adb/magisk");
Shell.Sync.sh("rm -rf " + installDir + "/*"); Shell.Sync.sh("rm -rf /data/adb/magisk/*");
} else { } else {
installDir = new File( installDir = new File(
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ?
@ -239,11 +236,11 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
return false; return false;
break; break;
case DIRECT_MODE: case DIRECT_MODE:
console.add("- Detecting ramdisk/boot image"); console.add("- Detecting target image");
mBoot = ShellUtils.fastCmd("find_boot_image", "echo \"$BOOTIMAGE\""); mBoot = ShellUtils.fastCmd("find_boot_image", "echo \"$BOOTIMAGE\"");
break; break;
case SECOND_SLOT_MODE: case SECOND_SLOT_MODE:
console.add("- Detecting ramdisk/boot image"); console.add("- Detecting target image");
char slot[] = ShellUtils.fastCmd("echo $SLOT").toCharArray(); char slot[] = ShellUtils.fastCmd("echo $SLOT").toCharArray();
if (slot[1] == 'a') slot[1] = 'b'; if (slot[1] == 'a') slot[1] = 'b';
else slot[1] = 'a'; else slot[1] = 'a';
@ -253,11 +250,11 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
break; break;
} }
if (mBoot == null) { if (mBoot == null) {
console.add("- Unable to detect ramdisk/boot image"); console.add("! Unable to detect target image");
return false; return false;
} }
console.add("- Use ramdisk/boot image: " + mBoot); console.add("- Target image: " + mBoot);
List<String> abis = Arrays.asList(Build.SUPPORTED_ABIS); List<String> abis = Arrays.asList(Build.SUPPORTED_ABIS);
String arch; String arch;
@ -278,14 +275,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
try { try {
extractFiles(arch); extractFiles(arch);
if (mode == FIX_ENV_MODE) { if (mode == FIX_ENV_MODE) {
Shell.Sync.sh( Shell.Sync.sh("fix_env");
"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"
);
} else { } else {
File patched = patchBoot(); File patched = patchBoot();
if (patched == null) if (patched == null)

View File

@ -44,6 +44,25 @@ env_check() {
return 0 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() { mm_patch_dtbo() {
if $KEEPVERITY; then if $KEEPVERITY; then
echo false echo false