ksud: skip removing module if no modules exist, also add uninstall mangaer, reboot

This commit is contained in:
weishu
2024-04-23 15:32:15 +08:00
parent 0697db618e
commit 3aac979caa
3 changed files with 25 additions and 10 deletions

View File

@@ -189,10 +189,10 @@ pub fn restore(
new_boot = Some(PathBuf::from(backup_path));
from_backup = true;
} else {
println!("Warning: no backup {KSU_BACKUP_DIR}/{KSU_BACKUP_FILE_PREFIX}{sha} found!");
println!("- Warning: no backup {KSU_BACKUP_DIR}/{KSU_BACKUP_FILE_PREFIX}{sha} found!");
}
} else {
println!("Warning: no backup found!");
println!("- Cannot found backup image!");
}
if new_boot.is_none() {

View File

@@ -41,7 +41,7 @@ enum Commands {
Uninstall {
/// magiskboot path, if not specified, will search from $PATH
#[arg(long, default_value = None)]
magiskboot_path: Option<PathBuf>,
magiskboot: Option<PathBuf>,
},
/// SELinux policy Patch tool
@@ -308,7 +308,7 @@ pub fn run() -> Result<()> {
}
}
Commands::Install => utils::install(),
Commands::Uninstall { magiskboot_path } => utils::uninstall(magiskboot_path),
Commands::Uninstall { magiskboot } => utils::uninstall(magiskboot),
Commands::Sepolicy { command } => match command {
Sepolicy::Patch { sepolicy } => crate::sepolicy::live_patch(&sepolicy),
Sepolicy::Apply { file } => crate::sepolicy::apply_file(file),

View File

@@ -1,8 +1,12 @@
use anyhow::{bail, Context, Error, Ok, Result};
use std::{
fs::{create_dir_all, remove_file, write, File, OpenOptions},
io::{ErrorKind::AlreadyExists, ErrorKind::NotFound, Write},
io::{
ErrorKind::{AlreadyExists, NotFound},
Write,
},
path::Path,
process::Command,
};
use crate::{assets, boot_patch, defs, ksucalls, module, restorecon};
@@ -218,13 +222,24 @@ pub fn install() -> Result<()> {
}
pub fn uninstall(magiskboot_path: Option<PathBuf>) -> Result<()> {
if Path::new(defs::MODULE_DIR).exists() {
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)
std::fs::remove_file(defs::DAEMON_PATH)?;
println!("- Restore boot image..");
boot_patch::restore(None, magiskboot_path, true)?;
println!("- Uninstall KernelSU manager..");
Command::new("pm")
.args(["uninstall", "me.weishu.kernelsu"])
.spawn()?;
println!("- Rebooting in 5 seconds..");
std::thread::sleep(std::time::Duration::from_secs(5));
Command::new("reboot").spawn()?;
Ok(())
}
// TODO: use libxcp to improve the speed if cross's MSRV is 1.70