ksud: Add uninstall
This commit is contained in:
@@ -37,6 +37,13 @@ enum Commands {
|
|||||||
/// Install KernelSU userspace component to system
|
/// Install KernelSU userspace component to system
|
||||||
Install,
|
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
|
/// SELinux policy Patch tool
|
||||||
Sepolicy {
|
Sepolicy {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
@@ -301,6 +308,7 @@ pub fn run() -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Commands::Install => utils::install(),
|
Commands::Install => utils::install(),
|
||||||
|
Commands::Uninstall { magiskboot_path } => utils::uninstall(magiskboot_path),
|
||||||
Commands::Sepolicy { command } => match command {
|
Commands::Sepolicy { command } => match command {
|
||||||
Sepolicy::Patch { sepolicy } => crate::sepolicy::live_patch(&sepolicy),
|
Sepolicy::Patch { sepolicy } => crate::sepolicy::live_patch(&sepolicy),
|
||||||
Sepolicy::Apply { file } => crate::sepolicy::apply_file(file),
|
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<()> {
|
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
|
// we assume the module dir is already mounted
|
||||||
let dir = std::fs::read_dir(defs::MODULE_DIR)?;
|
let dir = std::fs::read_dir(defs::MODULE_DIR)?;
|
||||||
for entry in dir.flatten() {
|
for entry in dir.flatten() {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
let disable_flag = path.join(defs::DISABLE_FILE_NAME);
|
let flag = path.join(flag_file);
|
||||||
if let Err(e) = ensure_file_exists(disable_flag) {
|
if let Err(e) = ensure_file_exists(flag) {
|
||||||
warn!("Failed to disable module: {}: {}", path.display(), e);
|
warn!("Failed to mark module: {}: {}", path.display(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use std::{
|
|||||||
path::Path,
|
path::Path,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{assets, defs, ksucalls, restorecon};
|
use crate::{assets, boot_patch, defs, ksucalls, module, restorecon};
|
||||||
use std::fs::metadata;
|
use std::fs::metadata;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use std::fs::{set_permissions, Permissions};
|
use std::fs::{set_permissions, Permissions};
|
||||||
@@ -217,6 +217,16 @@ pub fn install() -> Result<()> {
|
|||||||
Ok(())
|
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
|
// 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>>(
|
pub fn copy_sparse_file<P: AsRef<Path>, Q: AsRef<Path>>(
|
||||||
src: P,
|
src: P,
|
||||||
|
|||||||
Reference in New Issue
Block a user