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));
|
new_boot = Some(PathBuf::from(backup_path));
|
||||||
from_backup = true;
|
from_backup = true;
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
println!("Warning: no backup found!");
|
println!("- Cannot found backup image!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if new_boot.is_none() {
|
if new_boot.is_none() {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ enum Commands {
|
|||||||
Uninstall {
|
Uninstall {
|
||||||
/// magiskboot path, if not specified, will search from $PATH
|
/// magiskboot path, if not specified, will search from $PATH
|
||||||
#[arg(long, default_value = None)]
|
#[arg(long, default_value = None)]
|
||||||
magiskboot_path: Option<PathBuf>,
|
magiskboot: Option<PathBuf>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// SELinux policy Patch tool
|
/// SELinux policy Patch tool
|
||||||
@@ -308,7 +308,7 @@ pub fn run() -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Commands::Install => utils::install(),
|
Commands::Install => utils::install(),
|
||||||
Commands::Uninstall { magiskboot_path } => utils::uninstall(magiskboot_path),
|
Commands::Uninstall { magiskboot } => utils::uninstall(magiskboot),
|
||||||
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),
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
use anyhow::{bail, Context, Error, Ok, Result};
|
use anyhow::{bail, Context, Error, Ok, Result};
|
||||||
use std::{
|
use std::{
|
||||||
fs::{create_dir_all, remove_file, write, File, OpenOptions},
|
fs::{create_dir_all, remove_file, write, File, OpenOptions},
|
||||||
io::{ErrorKind::AlreadyExists, ErrorKind::NotFound, Write},
|
io::{
|
||||||
|
ErrorKind::{AlreadyExists, NotFound},
|
||||||
|
Write,
|
||||||
|
},
|
||||||
path::Path,
|
path::Path,
|
||||||
|
process::Command,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{assets, boot_patch, defs, ksucalls, module, restorecon};
|
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<()> {
|
pub fn uninstall(magiskboot_path: Option<PathBuf>) -> Result<()> {
|
||||||
println!("- Uninstall modules..");
|
if Path::new(defs::MODULE_DIR).exists() {
|
||||||
module::uninstall_all_modules()?;
|
println!("- Uninstall modules..");
|
||||||
module::prune_modules()?;
|
module::uninstall_all_modules()?;
|
||||||
|
module::prune_modules()?;
|
||||||
|
}
|
||||||
println!("- Removing directories..");
|
println!("- Removing directories..");
|
||||||
std::fs::remove_dir_all(defs::WORKING_DIR)?;
|
std::fs::remove_dir_all(defs::WORKING_DIR)?;
|
||||||
println!("- Uninstall KernelSU itself..");
|
std::fs::remove_file(defs::DAEMON_PATH)?;
|
||||||
boot_patch::restore(None, magiskboot_path, true)
|
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
|
// TODO: use libxcp to improve the speed if cross's MSRV is 1.70
|
||||||
|
|||||||
Reference in New Issue
Block a user