From 4e2b88b3d09249e68b94e486f50cf6b17faedd8f Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 16 Mar 2023 04:07:00 -0700 Subject: [PATCH] Rename rules to preinit It is possible that we will allow more preinit files for modules. Rename the partition and folders from rules to preinit. --- .../magisk/core/model/module/LocalModule.kt | 8 ++-- .../topjohnwu/magisk/core/utils/ShellInit.kt | 8 ++-- app/src/main/res/raw/manager.sh | 4 +- docs/details.md | 23 +++------- native/src/base/files.cpp | 16 +++---- native/src/base/files.hpp | 2 +- native/src/core/bootstages.cpp | 34 +++++++-------- native/src/core/core.hpp | 2 +- native/src/core/magisk.cpp | 5 +-- native/src/core/module.cpp | 2 +- native/src/include/magisk.hpp | 27 ++++++------ native/src/init/init.hpp | 2 +- native/src/init/mount.cpp | 42 ++++++++++--------- native/src/init/rootdir.cpp | 4 +- native/src/init/selinux.cpp | 16 +++---- scripts/avd_patch.sh | 4 +- scripts/boot_patch.sh | 21 +++++----- scripts/util_functions.sh | 8 ++-- 18 files changed, 110 insertions(+), 118 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt b/app/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt index 1e27048fb..3d966d380 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt @@ -43,10 +43,10 @@ data class LocalModule( set(enable) { if (enable) { disableFile.delete() - Shell.cmd("copy_rules").submit() + Shell.cmd("copy_preinit_files").submit() } else { !disableFile.createNewFile() - Shell.cmd("copy_rules").submit() + Shell.cmd("copy_preinit_files").submit() } } @@ -56,10 +56,10 @@ data class LocalModule( if (remove) { if (updateFile.exists()) return removeFile.createNewFile() - Shell.cmd("copy_rules").submit() + Shell.cmd("copy_preinit_files").submit() } else { removeFile.delete() - Shell.cmd("copy_rules").submit() + Shell.cmd("copy_preinit_files").submit() } } diff --git a/app/src/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt b/app/src/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt index c18a3dbff..25d12fb93 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt @@ -41,7 +41,7 @@ class ShellInit : Shell.Initializer() { } if (shell.isRoot) { - add("export MAGISKTMP=\$(magisk --path)/.magisk") + add("export MAGISKTMP=\$(magisk --path)") // Test if we can properly execute stuff in /data Info.noDataExec = !shell.newJob().add("$localBB sh -c \"$localBB true\"").exec().isSuccess } @@ -49,9 +49,9 @@ class ShellInit : Shell.Initializer() { if (Info.noDataExec) { // Copy it out of /data to workaround Samsung bullshit add( - "if [ -x \$MAGISKTMP/busybox/busybox ]; then", - " cp -af $localBB \$MAGISKTMP/busybox/busybox", - " exec \$MAGISKTMP/busybox/busybox sh", + "if [ -x \$MAGISKTMP/.magisk/busybox/busybox ]; then", + " cp -af $localBB \$MAGISKTMP/.magisk/busybox/busybox", + " exec \$MAGISKTMP/.magisk/busybox/busybox sh", "else", " cp -af $localBB /dev/busybox", " exec /dev/busybox sh", diff --git a/app/src/main/res/raw/manager.sh b/app/src/main/res/raw/manager.sh index e8e6ae3b2..a412694a7 100644 --- a/app/src/main/res/raw/manager.sh +++ b/app/src/main/res/raw/manager.sh @@ -14,7 +14,7 @@ env_check() { [ -f "$MAGISKBIN/magiskpolicy" ] || return 1 fi if [ "$2" -ge 25210 ]; then - [ -b "$MAGISKTMP/block/rules" ] || return 2 + [ -b "$MAGISKTMP/.magisk/block/preinit" ] || return 2 fi grep -xqF "MAGISK_VER='$1'" "$MAGISKBIN/util_functions.sh" || return 3 grep -xqF "MAGISK_VER_CODE=$2" "$MAGISKBIN/util_functions.sh" || return 3 @@ -67,7 +67,7 @@ direct_install() { rm -f $1/new-boot.img fix_env $1 run_migrations - copy_rules + copy_preinit_files return 0 } diff --git a/docs/details.md b/docs/details.md index 72a9c1dd4..02046def7 100644 --- a/docs/details.md +++ b/docs/details.md @@ -12,39 +12,28 @@ Magisk will mount a `tmpfs` directory to store some temporary data. For devices # Binaries like magisk, magiskinit, and all symlinks to # applets are directly stored in this path. This means when # this is /sbin, these binaries will be directly in PATH. -MAGISKBASE=$(magisk --path) +MAGISKTMP=$(magisk --path) # Magisk internal stuffs -MAGISKTMP=$MAGISKBASE/.magisk - -# Magisk's BusyBox directory. Within this folder stores -# the busybox binary and symlinks to all of its applets. -# Any usage of this directory is deprecated, please -# directly call /data/adb/magisk/busybox and use -# BusyBox's ASH Standalone mode. -# The creation of this path will be removed in the future. -$MAGISKTMP/busybox +INTERNALDIR=$MAGISKTMP/.magisk # /data/adb/modules will be bind mounted here. # The original folder is not used due to nosuid mount flag. -$MAGISKTMP/modules +$INTERNALDIR/modules # The current Magisk installation config -$MAGISKTMP/config +$INTERNALDIR/config # Partition mirrors # Each directory in this path will be mounted with the # partition of its directory name. # e.g. system, system_ext, vendor, data ... -$MAGISKTMP/mirror - -# Block devices Magisk creates internally to mount mirrors. -$MAGISKTMP/block +$INTERNALDIR/mirror # Root directory patch files # On system-as-root devices, / is not writable. # All pre-init patched files are stored here and bind mounted. -$MAGISKTMP/rootdir +$INTERNALDIR/rootdir ``` ### Paths in `/data` diff --git a/native/src/base/files.cpp b/native/src/base/files.cpp index d0942a586..f790573a1 100644 --- a/native/src/base/files.cpp +++ b/native/src/base/files.cpp @@ -506,14 +506,14 @@ string find_apk_path(const char *pkg) { return path.append("/base.apk"); } -string find_rules_dir(const char *base_dir) { - string rules_dir = base_dir; - if (access((rules_dir + "/unencrypted").data(), F_OK) == 0) { - rules_dir += "/unencrypted/magisk"; - } else if (access((rules_dir + "/adb").data(), F_OK) == 0) { - rules_dir += "/adb/modules"; +string resolve_preinit_dir(const char *base_dir) { + string dir = base_dir; + if (access((dir + "/unencrypted").data(), F_OK) == 0) { + dir += "/unencrypted/magisk"; + } else if (access((dir + "/adb").data(), F_OK) == 0) { + dir += "/adb/modules"; } else { - rules_dir += "/magisk"; + dir += "/magisk"; } - return rules_dir; + return dir; } diff --git a/native/src/base/files.hpp b/native/src/base/files.hpp index d7d259457..97dd12328 100644 --- a/native/src/base/files.hpp +++ b/native/src/base/files.hpp @@ -107,7 +107,7 @@ void frm_rf(int dirfd); void clone_dir(int src, int dest); std::vector parse_mount_info(const char *pid); std::string find_apk_path(const char *pkg); -std::string find_rules_dir(const char *base_dir); +std::string resolve_preinit_dir(const char *base_dir); using sFILE = std::unique_ptr; using sDIR = std::unique_ptr; diff --git a/native/src/core/bootstages.cpp b/native/src/core/bootstages.cpp index 12b8d59d3..365d4209d 100644 --- a/native/src/core/bootstages.cpp +++ b/native/src/core/bootstages.cpp @@ -60,20 +60,20 @@ static void mount_mirrors() { restorecon(); } - // check and mount rules - if (struct stat st{}; stat((MAGISKTMP + "/" BLOCKDIR "/rules").data(), &st) == 0 && (st.st_mode & S_IFBLK)) { - dev_t rules_dev = st.st_rdev; + // Check and mount preinit mirror + if (struct stat st{}; stat((MAGISKTMP + "/" PREINITDEV).data(), &st) == 0 && (st.st_mode & S_IFBLK)) { + dev_t preinit_dev = st.st_rdev; for (const auto &info: self_mount_info) { - if (info.root == "/" && info.device == rules_dev) { + if (info.root == "/" && info.device == preinit_dev) { auto flags = split_ro(info.fs_option, ","); auto rw = std::any_of(flags.begin(), flags.end(), [](const auto &flag) { return flag == "rw"sv; }); if (!rw) continue; - string custom_rules_dir = find_rules_dir(info.target.data()); - xmkdir(custom_rules_dir.data(), 0700); - auto rules_dir = MAGISKTMP + "/" RULESDIR; - mount_mirror(custom_rules_dir, rules_dir); + string preinit_dir = resolve_preinit_dir(info.target.data()); + xmkdir(preinit_dir.data(), 0700); + auto mirror_dir = MAGISKTMP + "/" PREINITMIRR; + mount_mirror(preinit_dir, mirror_dir); break; } } @@ -104,7 +104,7 @@ static void mount_mirrors() { } } -dev_t find_rules_device() { +dev_t find_preinit_device() { const int UNKNOWN = 0; const int PERSIST = 1; const int METADATA = 2; @@ -113,12 +113,12 @@ dev_t find_rules_device() { int matched = UNKNOWN; dev_t rules_dev = 0; bool encrypted = getprop("ro.crypto.state") == "encrypted"; - string custom_rules_dir; + string preinit_dir; bool mount = getuid() == 0 && getenv("MAGISKTMP"); for (const auto &info: parse_mount_info("self")) { - if (info.target.ends_with(RULESDIR)) + if (info.target.ends_with(PREINITMIRR)) return info.device; if (info.root != "/" || info.source.find("/dm-") != string::npos) continue; @@ -146,17 +146,17 @@ dev_t find_rules_device() { } else continue; if (mount) { - custom_rules_dir = find_rules_dir(info.target.data()); + preinit_dir = resolve_preinit_dir(info.target.data()); } rules_dev = info.device; matched = new_matched; } - if (!custom_rules_dir.empty()) { - auto rules_dir = getenv("MAGISKTMP") + "/rules"s; - mkdirs(custom_rules_dir.data(), 0700); - mkdirs(rules_dir.data(), 0700); - xmount(custom_rules_dir.data(), rules_dir.data(), nullptr, MS_BIND, nullptr); + if (!preinit_dir.empty()) { + auto mirror_dir = string(getenv("MAGISKTMP")) + "/" PREINITMIRR; + mkdirs(preinit_dir.data(), 0700); + mkdirs(mirror_dir.data(), 0700); + xmount(preinit_dir.data(), mirror_dir.data(), nullptr, MS_BIND, nullptr); } return rules_dev; diff --git a/native/src/core/core.hpp b/native/src/core/core.hpp index cd3e74f75..a21fcc738 100644 --- a/native/src/core/core.hpp +++ b/native/src/core/core.hpp @@ -6,7 +6,7 @@ extern bool RECOVERY_MODE; extern std::atomic pkg_xml_ino; -dev_t find_rules_device(); +dev_t find_preinit_device(); void unlock_blocks(); void reboot(); void start_log_daemon(); diff --git a/native/src/core/magisk.cpp b/native/src/core/magisk.cpp index 005fefabd..425679d94 100644 --- a/native/src/core/magisk.cpp +++ b/native/src/core/magisk.cpp @@ -122,7 +122,6 @@ int magisk_main(int argc, char *argv[]) { do_reboot = 1; } else { usage(); - exit(1); } int fd = connect_daemon(MainRequest::REMOVE_MODULES); write_int(fd, do_reboot); @@ -134,8 +133,8 @@ int magisk_main(int argc, char *argv[]) { return 0; } else if (argc >= 3 && argv[1] == "--install-module"sv) { install_module(argv[2]); - } else if (argv[1] == "--rules-device"sv) { - auto dev = find_rules_device(); + } else if (argv[1] == "--preinit-device"sv) { + auto dev = find_preinit_device(); if (dev) printf("%u:%u\n", major(dev), minor(dev)); return dev ? 0 : 1; } diff --git a/native/src/core/module.cpp b/native/src/core/module.cpp index 94dea6c8d..71df53fe1 100644 --- a/native/src/core/module.cpp +++ b/native/src/core/module.cpp @@ -437,7 +437,7 @@ void handle_modules() { } static int check_rules_dir(char *buf, size_t sz) { - int off = ssprintf(buf, sz, "%s/%s", MAGISKTMP.data(), RULESDIR); + int off = ssprintf(buf, sz, "%s/%s", MAGISKTMP.data(), PREINITMIRR); struct stat st1{}; struct stat st2{}; if (xstat(buf, &st1) < 0 || xstat(MODULEROOT, &st2) < 0) diff --git a/native/src/include/magisk.hpp b/native/src/include/magisk.hpp index 16a091e4a..aa1aa9f3e 100644 --- a/native/src/include/magisk.hpp +++ b/native/src/include/magisk.hpp @@ -15,19 +15,20 @@ #define MAGISKDB SECURE_DIR "/magisk.db" // tmpfs paths -extern std::string MAGISKTMP; -#define INTLROOT ".magisk" -#define MIRRDIR INTLROOT "/mirror" -#define RULESDIR INTLROOT "/rules" -#define BLOCKDIR INTLROOT "/block" -#define WORKERDIR INTLROOT "/worker" -#define MODULEMNT INTLROOT "/modules" -#define BBPATH INTLROOT "/busybox" -#define ROOTOVL INTLROOT "/rootdir" -#define SHELLPTS INTLROOT "/pts" -#define ROOTMNT ROOTOVL "/.mount_list" -#define ZYGISKBIN INTLROOT "/zygisk" -#define SELINUXMOCK INTLROOT "/selinux" +extern std::string MAGISKTMP; +#define INTLROOT ".magisk" +#define MIRRDIR INTLROOT "/mirror" +#define PREINITMIRR INTLROOT "/preinit" +#define BLOCKDIR INTLROOT "/block" +#define PREINITDEV BLOCKDIR "/preinit" +#define WORKERDIR INTLROOT "/worker" +#define MODULEMNT INTLROOT "/modules" +#define BBPATH INTLROOT "/busybox" +#define ROOTOVL INTLROOT "/rootdir" +#define SHELLPTS INTLROOT "/pts" +#define ROOTMNT ROOTOVL "/.mount_list" +#define ZYGISKBIN INTLROOT "/zygisk" +#define SELINUXMOCK INTLROOT "/selinux" constexpr const char *applet_names[] = { "su", "resetprop", nullptr }; diff --git a/native/src/init/init.hpp b/native/src/init/init.hpp index aaa92a3be..9688bded8 100644 --- a/native/src/init/init.hpp +++ b/native/src/init/init.hpp @@ -57,7 +57,7 @@ public: class MagiskInit : public BaseInit { private: - dev_t rules_dev = 0; + dev_t preinit_dev = 0; void parse_config_file(); void patch_sepolicy(const char *in, const char *out); diff --git a/native/src/init/mount.cpp b/native/src/init/mount.cpp index a1427370b..a401d8337 100644 --- a/native/src/init/mount.cpp +++ b/native/src/init/mount.cpp @@ -111,38 +111,40 @@ static void switch_root(const string &path) { frm_rf(root); } -static void mount_rules_dir(string path, dev_t rules_dev) { - if (!rules_dev) return; - xmknod(BLOCKDIR "/rules", S_IFBLK | 0600, rules_dev); - xmkdir(MIRRDIR "/rules", 0); +#define PREINITMNT MIRRDIR "/preinit" + +static void mount_preinit_dir(string path, dev_t preinit_dev) { + if (!preinit_dev) return; + xmknod(PREINITDEV, S_IFBLK | 0600, preinit_dev); + xmkdir(PREINITMNT, 0); bool mounted = false; - // first of all, find if rules dev is already mounted + // First, find if it is already mounted for (auto &info : parse_mount_info("self")) { - if (info.root == "/" && info.device == rules_dev) { + if (info.root == "/" && info.device == preinit_dev) { // Already mounted, just bind mount - xmount(info.target.data(), MIRRDIR "/rules", nullptr, MS_BIND, nullptr); + xmount(info.target.data(), PREINITMNT, nullptr, MS_BIND, nullptr); mounted = true; break; } } - if (mounted || mount(BLOCKDIR "/rules", MIRRDIR "/rules", "ext4", MS_RDONLY, nullptr) == 0 || - mount(BLOCKDIR "/rules", MIRRDIR "/rules", "f2fs", MS_RDONLY, nullptr) == 0) { - string custom_rules_dir = find_rules_dir(MIRRDIR "/rules"); + if (mounted || mount(PREINITDEV, PREINITMNT, "ext4", MS_RDONLY, nullptr) == 0 || + mount(PREINITDEV, PREINITMNT, "f2fs", MS_RDONLY, nullptr) == 0) { + string preinit_dir = resolve_preinit_dir(PREINITMNT); // Create bind mount - xmkdirs(RULESDIR, 0); - if (access(custom_rules_dir.data(), F_OK)) { - LOGW("empty rules: %s\n", custom_rules_dir.data()); + xmkdirs(PREINITMIRR, 0); + if (access(preinit_dir.data(), F_OK)) { + LOGW("empty preinit: %s\n", preinit_dir.data()); } else { - LOGD("rules: %s\n", custom_rules_dir.data()); - xmount(custom_rules_dir.data(), RULESDIR, nullptr, MS_BIND, nullptr); - mount_list.emplace_back(path += "/" RULESDIR); + LOGD("preinit: %s\n", preinit_dir.data()); + xmount(preinit_dir.data(), PREINITMIRR, nullptr, MS_BIND, nullptr); + mount_list.emplace_back(path += "/" PREINITMIRR); } - xumount2(MIRRDIR "/rules", MNT_DETACH); + xumount2(PREINITMNT, MNT_DETACH); } else { - PLOGE("Failed to mount rules %u:%u", major(rules_dev), minor(rules_dev)); - unlink(BLOCKDIR "/rules"); + PLOGE("Failed to mount rules %u:%u", major(preinit_dev), minor(preinit_dev)); + unlink(PREINITDEV); } } @@ -246,7 +248,7 @@ void MagiskInit::setup_tmp(const char *path) { xmkdir(BLOCKDIR, 0); xmkdir(WORKERDIR, 0); - mount_rules_dir(path, rules_dev); + mount_preinit_dir(path, preinit_dev); cp_afc(".backup/.magisk", INTLROOT "/config"); rm_rf(".backup"); diff --git a/native/src/init/rootdir.cpp b/native/src/init/rootdir.cpp index 4bb0c36e5..3d322b803 100644 --- a/native/src/init/rootdir.cpp +++ b/native/src/init/rootdir.cpp @@ -185,7 +185,7 @@ static void extract_files(bool sbin) { void MagiskInit::parse_config_file() { dev_t dev = 0; parse_prop_file("/data/.backup/.magisk", [&dev](auto key, auto value) -> bool { - if (key == "RULESDEVICE") { + if (key == "PREINITDEVICE") { unsigned int dev_major = 0; unsigned int dev_minor = 0; sscanf(value.data(), "%u:%u", &dev_major, &dev_minor); @@ -194,7 +194,7 @@ void MagiskInit::parse_config_file() { } return true; }); - rules_dev = dev; + preinit_dev = dev; } #define ROOTMIR MIRRDIR "/system_root" diff --git a/native/src/init/selinux.cpp b/native/src/init/selinux.cpp index eceab94ba..4eb68a09b 100644 --- a/native/src/init/selinux.cpp +++ b/native/src/init/selinux.cpp @@ -15,12 +15,12 @@ void MagiskInit::patch_sepolicy(const char *in, const char *out) { sepol->magisk_rules(); // Custom rules - if (auto dir = xopen_dir(RULESDIR)) { + if (auto dir = xopen_dir(PREINITMIRR)) { for (dirent *entry; (entry = xreaddir(dir.get()));) { - auto rule = RULESDIR "/"s + entry->d_name + "/sepolicy.rule"; + auto rule = PREINITMIRR "/"s + entry->d_name + "/sepolicy.rule"; if (xaccess(rule.data(), R_OK) == 0 && - access((RULESDIR "/"s + entry->d_name + "/disable").data(), F_OK) != 0 && - access((RULESDIR "/"s + entry->d_name + "/remove").data(), F_OK) != 0) { + access((PREINITMIRR "/"s + entry->d_name + "/disable").data(), F_OK) != 0 && + access((PREINITMIRR "/"s + entry->d_name + "/remove").data(), F_OK) != 0) { LOGD("Loading custom sepolicy patch: [%s]\n", rule.data()); sepol->load_rule_file(rule.data()); } @@ -96,12 +96,12 @@ bool MagiskInit::hijack_sepolicy() { // Read all custom rules into memory string rules; - if (auto dir = xopen_dir(RULESDIR)) { + if (auto dir = xopen_dir(PREINITMIRR)) { for (dirent *entry; (entry = xreaddir(dir.get()));) { - auto rule_file = RULESDIR "/"s + entry->d_name + "/sepolicy.rule"; + auto rule_file = PREINITMIRR "/"s + entry->d_name + "/sepolicy.rule"; if (xaccess(rule_file.data(), R_OK) == 0 && - access((RULESDIR "/"s + entry->d_name + "/disable").data(), F_OK) != 0 && - access((RULESDIR "/"s + entry->d_name + "/remove").data(), F_OK) != 0) { + access((PREINITMIRR "/"s + entry->d_name + "/disable").data(), F_OK) != 0 && + access((PREINITMIRR "/"s + entry->d_name + "/remove").data(), F_OK) != 0) { LOGD("Load custom sepolicy patch: [%s]\n", rule_file.data()); full_read(rule_file.data(), rules); rules += '\n'; diff --git a/scripts/avd_patch.sh b/scripts/avd_patch.sh index 4b1215260..1508cab1e 100644 --- a/scripts/avd_patch.sh +++ b/scripts/avd_patch.sh @@ -63,9 +63,9 @@ export KEEPFORCEENCRYPT=true echo "KEEPVERITY=$KEEPVERITY" > config echo "KEEPFORCEENCRYPT=$KEEPFORCEENCRYPT" >> config if [ -e "/system/bin/linker64" ]; then - echo "RULESDEVICE=$(./magisk64 --rules-device)" >> config + echo "PREINITDEVICE=$(./magisk64 --preinit-device)" >> config else - echo "RULESDEVICE=$(./magisk32 --rules-device)" >> config + echo "PREINITDEVICE=$(./magisk32 --preinit-device)" >> config fi # For API 28, we also patch advancedFeatures.ini to disable SAR # Manually override skip_initramfs by setting RECOVERYMODE=true diff --git a/scripts/boot_patch.sh b/scripts/boot_patch.sh index 52fd4051e..1a42f7d77 100644 --- a/scripts/boot_patch.sh +++ b/scripts/boot_patch.sh @@ -77,7 +77,6 @@ fi export KEEPVERITY export KEEPFORCEENCRYPT export PATCHVBMETAFLAG -export MAGISKTMP chmod -R 755 . @@ -138,7 +137,7 @@ case $((STATUS & 3)) in ;; esac -# Work around custom legacy Sony /init -> /(s)bin/init_sony : /init.real setup +# Workaround custom legacy Sony /init -> /(s)bin/init_sony : /init.real setup INIT=init if [ $((STATUS & 4)) -ne 0 ]; then INIT=init.real @@ -153,24 +152,26 @@ ui_print "- Patching ramdisk" # Compress to save precious ramdisk space SKIP32="#" SKIP64="#" -if [ -f magisk32 ]; then - $BOOTMODE && [ -z "$RULESDEVICE" ] && RULESDEVICE=$(./magisk32 --rules-device) - ./magiskboot compress=xz magisk32 magisk32.xz - unset SKIP32 -fi if [ -f magisk64 ]; then - $BOOTMODE && [ -z "$RULESDEVICE" ] && RULESDEVICE=$(./magisk64 --rules-device) + $BOOTMODE && [ -z "$PREINITDEVICE" ] && PREINITDEVICE=$(./magisk64 --preinit-device) ./magiskboot compress=xz magisk64 magisk64.xz unset SKIP64 fi +if [ -f magisk32 ]; then + $BOOTMODE && [ -z "$PREINITDEVICE" ] && PREINITDEVICE=$(./magisk32 --preinit-device) + ./magiskboot compress=xz magisk32 magisk32.xz + unset SKIP32 +fi ./magiskboot compress=xz stub.apk stub.xz echo "KEEPVERITY=$KEEPVERITY" > config echo "KEEPFORCEENCRYPT=$KEEPFORCEENCRYPT" >> config echo "PATCHVBMETAFLAG=$PATCHVBMETAFLAG" >> config echo "RECOVERYMODE=$RECOVERYMODE" >> config -[ -n "$RULESDEVICE" ] && ui_print "- Rules partition device ID: $RULESDEVICE" -[ -n "$RULESDEVICE" ] && echo "RULESDEVICE=$RULESDEVICE" >> config +if [ -n "$PREINITDEVICE" ]; then + ui_print "- Pre-init storage partition device ID: $PREINITDEVICE" + echo "PREINITDEVICE=$PREINITDEVICE" >> config +fi [ -n "$SHA1" ] && echo "SHA1=$SHA1" >> config ./magiskboot cpio ramdisk.cpio \ diff --git a/scripts/util_functions.sh b/scripts/util_functions.sh index fe104cee6..a46033efa 100644 --- a/scripts/util_functions.sh +++ b/scripts/util_functions.sh @@ -49,7 +49,7 @@ getvar() { local VARNAME=$1 local VALUE local PROPPATH='/data/.magisk /cache/.magisk' - [ ! -z $MAGISKTMP ] && PROPPATH="$MAGISKTMP/config $PROPPATH" + [ ! -z $MAGISKTMP ] && PROPPATH="$MAGISKTMP/.magisk/config $PROPPATH" VALUE=$(grep_prop $VARNAME $PROPPATH) [ ! -z $VALUE ] && eval $VARNAME=\$VALUE } @@ -629,7 +629,7 @@ run_migrations() { done } -copy_rules() { +copy_preinit_files() { local RULESDIR=$(magisk --path)/.magisk/rules if ! grep -q " $RULESDIR " /proc/mounts; then ui_print "- Unable to find rules dir" @@ -785,10 +785,10 @@ install_module() { cp -af $MODPATH/module.prop $NVBASE/modules/$MODID/module.prop fi - # Copy over custom rules + # Copy over custom sepolicy rules if [ -f $MODPATH/sepolicy.rule ]; then ui_print "- Installing custom sepolicy rules" - copy_rules + copy_preinit_files fi # Remove stuff that doesn't belong to modules and clean up any empty directories