mirror of
https://github.com/tiann/KernelSU.git
synced 2025-02-20 11:43:32 +08:00
ksud: Add uninstall
This commit is contained in:
parent
4922d89823
commit
0697db618e
@ -37,6 +37,13 @@ enum Commands {
|
||||
/// Install KernelSU userspace component to system
|
||||
Install,
|
||||
|
||||
/// Uninstall KernelSU modules and itself(LKM Only)
|
||||
Uninstall {
|
||||
/// magiskboot path, if not specified, will search from $PATH
|
||||
#[arg(long, default_value = None)]
|
||||
magiskboot_path: Option<PathBuf>,
|
||||
},
|
||||
|
||||
/// SELinux policy Patch tool
|
||||
Sepolicy {
|
||||
#[command(subcommand)]
|
||||
@ -301,6 +308,7 @@ pub fn run() -> Result<()> {
|
||||
}
|
||||
}
|
||||
Commands::Install => utils::install(),
|
||||
Commands::Uninstall { magiskboot_path } => utils::uninstall(magiskboot_path),
|
||||
Commands::Sepolicy { command } => match command {
|
||||
Sepolicy::Patch { sepolicy } => crate::sepolicy::live_patch(&sepolicy),
|
||||
Sepolicy::Apply { file } => crate::sepolicy::apply_file(file),
|
||||
|
@ -604,13 +604,21 @@ pub fn disable_module(id: &str) -> Result<()> {
|
||||
}
|
||||
|
||||
pub fn disable_all_modules() -> Result<()> {
|
||||
mark_all_modules(defs::DISABLE_FILE_NAME)
|
||||
}
|
||||
|
||||
pub fn uninstall_all_modules() -> Result<()> {
|
||||
mark_all_modules(defs::REMOVE_FILE_NAME)
|
||||
}
|
||||
|
||||
fn mark_all_modules(flag_file: &str) -> Result<()> {
|
||||
// we assume the module dir is already mounted
|
||||
let dir = std::fs::read_dir(defs::MODULE_DIR)?;
|
||||
for entry in dir.flatten() {
|
||||
let path = entry.path();
|
||||
let disable_flag = path.join(defs::DISABLE_FILE_NAME);
|
||||
if let Err(e) = ensure_file_exists(disable_flag) {
|
||||
warn!("Failed to disable module: {}: {}", path.display(), e);
|
||||
let flag = path.join(flag_file);
|
||||
if let Err(e) = ensure_file_exists(flag) {
|
||||
warn!("Failed to mark module: {}: {}", path.display(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ use std::{
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use crate::{assets, defs, ksucalls, restorecon};
|
||||
use crate::{assets, boot_patch, defs, ksucalls, module, restorecon};
|
||||
use std::fs::metadata;
|
||||
#[allow(unused_imports)]
|
||||
use std::fs::{set_permissions, Permissions};
|
||||
@ -217,6 +217,16 @@ pub fn install() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn uninstall(magiskboot_path: Option<PathBuf>) -> Result<()> {
|
||||
println!("- Uninstall modules..");
|
||||
module::uninstall_all_modules()?;
|
||||
module::prune_modules()?;
|
||||
println!("- Removing directories..");
|
||||
std::fs::remove_dir_all(defs::WORKING_DIR)?;
|
||||
println!("- Uninstall KernelSU itself..");
|
||||
boot_patch::restore(None, magiskboot_path, true)
|
||||
}
|
||||
|
||||
// TODO: use libxcp to improve the speed if cross's MSRV is 1.70
|
||||
pub fn copy_sparse_file<P: AsRef<Path>, Q: AsRef<Path>>(
|
||||
src: P,
|
||||
|
Loading…
x
Reference in New Issue
Block a user