ksud: skip removing module if no modules exist, also add uninstall mangaer, reboot
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user