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

@@ -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<()> {
println!("- Uninstall modules..");
module::uninstall_all_modules()?;
module::prune_modules()?;
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