Add magiskboot to kernelsu working directory (#1684)

Add the magiskboot binary to the /data/adb/ksu/bin directory so that
scripts/programs can call magiskboot to patch the boot/init_boot image.

---------

Co-authored-by: weishu <twsxtd@gmail.com>
This commit is contained in:
fsxitutu
2024-05-01 09:48:59 +08:00
committed by GitHub
parent e9b6fcfa22
commit 839fc0534e
4 changed files with 14 additions and 4 deletions

View File

@@ -35,7 +35,10 @@ enum Commands {
BootCompleted,
/// Install KernelSU userspace component to system
Install,
Install {
#[arg(long, default_value = None)]
magiskboot: Option<PathBuf>,
},
/// Uninstall KernelSU modules and itself(LKM Only)
Uninstall {
@@ -307,7 +310,7 @@ pub fn run() -> Result<()> {
Module::Shrink => module::shrink_ksu_images(),
}
}
Commands::Install => utils::install(),
Commands::Install { magiskboot } => utils::install(magiskboot),
Commands::Uninstall { magiskboot } => utils::uninstall(magiskboot),
Commands::Sepolicy { command } => match command {
Sepolicy::Patch { sepolicy } => crate::sepolicy::live_patch(&sepolicy),

View File

@@ -12,6 +12,7 @@ pub const PROFILE_TEMPLATE_DIR: &str = concatcp!(PROFILE_DIR, "templates/");
pub const KSURC_PATH: &str = concatcp!(WORKING_DIR, ".ksurc");
pub const KSU_OVERLAY_SOURCE: &str = "KSU";
pub const DAEMON_PATH: &str = concatcp!(ADB_DIR, "ksud");
pub const MAGISKBOOT_PATH: &str = concatcp!(BINARY_DIR, "magiskboot");
#[cfg(target_os = "android")]
pub const DAEMON_LINK_PATH: &str = concatcp!(BINARY_DIR, "ksud");

View File

@@ -208,7 +208,7 @@ fn link_ksud_to_bin() -> Result<()> {
Ok(())
}
pub fn install() -> Result<()> {
pub fn install(magiskboot: Option<PathBuf>) -> Result<()> {
ensure_dir_exists(defs::ADB_DIR)?;
std::fs::copy("/proc/self/exe", defs::DAEMON_PATH)?;
restorecon::lsetfilecon(defs::DAEMON_PATH, restorecon::ADB_CON)?;
@@ -218,6 +218,11 @@ pub fn install() -> Result<()> {
#[cfg(target_os = "android")]
link_ksud_to_bin()?;
if let Some(magiskboot) = magiskboot {
ensure_dir_exists(defs::BINARY_DIR)?;
let _ = std::fs::copy(magiskboot, defs::MAGISKBOOT_PATH);
}
Ok(())
}