ksud: uninstall module at next boot. close #740
This commit is contained in:
@@ -3,6 +3,7 @@ use log::{info, warn};
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::{collections::HashMap, path::Path};
|
use std::{collections::HashMap, path::Path};
|
||||||
|
|
||||||
|
use crate::module::prune_modules;
|
||||||
use crate::{
|
use crate::{
|
||||||
assets, defs, mount, restorecon,
|
assets, defs, mount, restorecon,
|
||||||
utils::{self, ensure_clean_dir, ensure_dir_exists},
|
utils::{self, ensure_clean_dir, ensure_dir_exists},
|
||||||
@@ -148,6 +149,10 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Err(e) = prune_modules() {
|
||||||
|
warn!("prune modules failed: {}", e);
|
||||||
|
}
|
||||||
|
|
||||||
// Then exec common post-fs-data scripts
|
// Then exec common post-fs-data scripts
|
||||||
if let Err(e) = crate::module::exec_common_scripts("post-fs-data.d", true) {
|
if let Err(e) = crate::module::exec_common_scripts("post-fs-data.d", true) {
|
||||||
warn!("exec common post-fs-data scripts failed: {}", e);
|
warn!("exec common post-fs-data scripts failed: {}", e);
|
||||||
|
|||||||
@@ -158,11 +158,14 @@ pub fn load_sepolicy_rule() -> Result<()> {
|
|||||||
let dir = std::fs::read_dir(modules_dir)?;
|
let dir = std::fs::read_dir(modules_dir)?;
|
||||||
for entry in dir.flatten() {
|
for entry in dir.flatten() {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
let disabled = path.join(defs::DISABLE_FILE_NAME);
|
if path.join(defs::DISABLE_FILE_NAME).exists() {
|
||||||
if disabled.exists() {
|
|
||||||
info!("{} is disabled, skip", path.display());
|
info!("{} is disabled, skip", path.display());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if path.join(defs::REMOVE_FILE_NAME).exists() {
|
||||||
|
warn!("{} is removed, skip", path.display());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let rule_file = path.join("sepolicy.rule");
|
let rule_file = path.join("sepolicy.rule");
|
||||||
if !rule_file.exists() {
|
if !rule_file.exists() {
|
||||||
@@ -225,9 +228,12 @@ pub fn exec_post_fs_data() -> Result<()> {
|
|||||||
let dir = std::fs::read_dir(modules_dir)?;
|
let dir = std::fs::read_dir(modules_dir)?;
|
||||||
for entry in dir.flatten() {
|
for entry in dir.flatten() {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
let disabled = path.join(defs::DISABLE_FILE_NAME);
|
if path.join(defs::DISABLE_FILE_NAME).exists() {
|
||||||
if disabled.exists() {
|
info!("{} is disabled, skip", path.display());
|
||||||
warn!("{} is disabled, skip", path.display());
|
continue;
|
||||||
|
}
|
||||||
|
if path.join(defs::REMOVE_FILE_NAME).exists() {
|
||||||
|
warn!("{} is removed, skip", path.display());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,9 +276,12 @@ pub fn exec_services() -> Result<()> {
|
|||||||
let dir = std::fs::read_dir(modules_dir)?;
|
let dir = std::fs::read_dir(modules_dir)?;
|
||||||
for entry in dir.flatten() {
|
for entry in dir.flatten() {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
let disabled = path.join(defs::DISABLE_FILE_NAME);
|
if path.join(defs::DISABLE_FILE_NAME).exists() {
|
||||||
if disabled.exists() {
|
info!("{} is disabled, skip", path.display());
|
||||||
warn!("{} is disabled, skip", path.display());
|
continue;
|
||||||
|
}
|
||||||
|
if path.join(defs::REMOVE_FILE_NAME).exists() {
|
||||||
|
warn!("{} is removed, skip", path.display());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,11 +301,14 @@ pub fn load_system_prop() -> Result<()> {
|
|||||||
let dir = std::fs::read_dir(modules_dir)?;
|
let dir = std::fs::read_dir(modules_dir)?;
|
||||||
for entry in dir.flatten() {
|
for entry in dir.flatten() {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
let disabled = path.join(defs::DISABLE_FILE_NAME);
|
if path.join(defs::DISABLE_FILE_NAME).exists() {
|
||||||
if disabled.exists() {
|
|
||||||
info!("{} is disabled, skip", path.display());
|
info!("{} is disabled, skip", path.display());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if path.join(defs::REMOVE_FILE_NAME).exists() {
|
||||||
|
warn!("{} is removed, skip", path.display());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let system_prop = path.join("system.prop");
|
let system_prop = path.join("system.prop");
|
||||||
if !system_prop.exists() {
|
if !system_prop.exists() {
|
||||||
@@ -316,6 +328,33 @@ pub fn load_system_prop() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn prune_modules() -> Result<()> {
|
||||||
|
let modules_dir = Path::new(defs::MODULE_DIR);
|
||||||
|
let dir = std::fs::read_dir(modules_dir)?;
|
||||||
|
for entry in dir.flatten() {
|
||||||
|
let path = entry.path();
|
||||||
|
let remove = path.join(defs::REMOVE_FILE_NAME);
|
||||||
|
if !remove.exists() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
info!("remove module: {}", path.display());
|
||||||
|
|
||||||
|
let uninstaller = path.join("uninstall.sh");
|
||||||
|
if uninstaller.exists() {
|
||||||
|
if let Err(e) = exec_script(uninstaller, true) {
|
||||||
|
warn!("Failed to exec uninstaller: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(e) = remove_dir_all(&path) {
|
||||||
|
warn!("Failed to remove {}: {}", path.display(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn _install_module(zip: &str) -> Result<()> {
|
fn _install_module(zip: &str) -> Result<()> {
|
||||||
ensure_boot_completed()?;
|
ensure_boot_completed()?;
|
||||||
|
|
||||||
@@ -557,11 +596,8 @@ pub fn uninstall_module(id: &str) -> Result<()> {
|
|||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
if module_id.eq(mid) {
|
if module_id.eq(mid) {
|
||||||
let uninstall_script = path.join("uninstall.sh");
|
let remove_file = path.join(defs::REMOVE_FILE_NAME);
|
||||||
if uninstall_script.exists() {
|
File::create(remove_file).with_context(|| "Failed to create remove file.")?;
|
||||||
exec_script(uninstall_script, true)?;
|
|
||||||
}
|
|
||||||
remove_dir_all(path)?;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -570,7 +606,10 @@ pub fn uninstall_module(id: &str) -> Result<()> {
|
|||||||
let target_module_path = format!("{update_dir}/{mid}");
|
let target_module_path = format!("{update_dir}/{mid}");
|
||||||
let target_module = Path::new(&target_module_path);
|
let target_module = Path::new(&target_module_path);
|
||||||
if target_module.exists() {
|
if target_module.exists() {
|
||||||
remove_dir_all(target_module)?;
|
let remove_file = target_module.join(defs::REMOVE_FILE_NAME);
|
||||||
|
if !remove_file.exists() {
|
||||||
|
File::create(remove_file).with_context(|| "Failed to create remove file.")?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = mark_module_state(id, defs::REMOVE_FILE_NAME, true);
|
let _ = mark_module_state(id, defs::REMOVE_FILE_NAME, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user