ksud: some refactor
This commit is contained in:
22
userspace/ksud/src/assets.rs
Normal file
22
userspace/ksud/src/assets.rs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
use anyhow::Result;
|
||||||
|
use const_format::concatcp;
|
||||||
|
use crate::{utils, defs};
|
||||||
|
|
||||||
|
pub const RESETPROP_PATH: &str = concatcp!(defs::BINARY_DIR, "resetprop");
|
||||||
|
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
const RESETPROP: &[u8] = include_bytes!("../bin/aarch64/resetprop");
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
const RESETPROP: &[u8] = include_bytes!("../bin/x86_64/resetprop");
|
||||||
|
|
||||||
|
pub const BUSYBOX_PATH: &str = concatcp!(defs::BINARY_DIR, "busybox");
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
const BUSYBOX: &[u8] = include_bytes!("../bin/aarch64/busybox");
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
const BUSYBOX: &[u8] = include_bytes!("../bin/x86_64/busybox");
|
||||||
|
|
||||||
|
pub fn ensure_bin_assets() -> Result<()> {
|
||||||
|
utils::ensure_binary(RESETPROP_PATH, RESETPROP)?;
|
||||||
|
utils::ensure_binary(BUSYBOX_PATH, BUSYBOX)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::{collections::HashMap, path::Path};
|
use std::{collections::HashMap, path::Path};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
defs,
|
assets, defs,
|
||||||
utils::{ensure_clean_dir, ensure_dir_exists, mount_image},
|
utils::{ensure_clean_dir, ensure_dir_exists, mount_image},
|
||||||
};
|
};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use sys_mount::{FilesystemType, Mount, MountFlags};
|
use sys_mount::{FilesystemType, Mount, MountFlags};
|
||||||
|
|
||||||
fn mount_partition(partition: &str, lowerdir: &mut Vec<String>) {
|
fn mount_partition(partition: &str, lowerdir: &mut Vec<String>) {
|
||||||
@@ -105,6 +105,8 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
// we should clean the module mount point if it exists
|
// we should clean the module mount point if it exists
|
||||||
ensure_clean_dir(module_dir)?;
|
ensure_clean_dir(module_dir)?;
|
||||||
|
|
||||||
|
assets::ensure_bin_assets().with_context(|| "Failed to extract bin assets")?;
|
||||||
|
|
||||||
if Path::new(module_update_img).exists() {
|
if Path::new(module_update_img).exists() {
|
||||||
if module_update_flag.exists() {
|
if module_update_flag.exists() {
|
||||||
// if modules_update.img exists, and the the flag indicate this is an update
|
// if modules_update.img exists, and the the flag indicate this is an update
|
||||||
@@ -177,7 +179,8 @@ pub fn daemon() -> Result<()> {
|
|||||||
|
|
||||||
pub fn install() -> Result<()> {
|
pub fn install() -> Result<()> {
|
||||||
ensure_dir_exists(defs::ADB_DIR)?;
|
ensure_dir_exists(defs::ADB_DIR)?;
|
||||||
std::fs::copy("/proc/self/exe", defs::DAEMON_PATH)
|
std::fs::copy("/proc/self/exe", defs::DAEMON_PATH)?;
|
||||||
.map(|_| ())
|
|
||||||
.map_err(anyhow::Error::from)
|
// install binary assets also!
|
||||||
|
assets::ensure_bin_assets().with_context(|| "Failed to extract assets")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ mod module;
|
|||||||
mod restorecon;
|
mod restorecon;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod sepolicy;
|
mod sepolicy;
|
||||||
|
mod assets;
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
cli::run()
|
cli::run()
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use crate::{
|
|||||||
restorecon::{restore_syscon, setsyscon},
|
restorecon::{restore_syscon, setsyscon},
|
||||||
sepolicy,
|
sepolicy,
|
||||||
utils::*,
|
utils::*,
|
||||||
|
assets,
|
||||||
};
|
};
|
||||||
|
|
||||||
use const_format::concatcp;
|
use const_format::concatcp;
|
||||||
@@ -295,21 +296,7 @@ pub fn exec_services() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
const RESETPROP_PATH: &str = concatcp!(defs::BINARY_DIR, "resetprop");
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
const RESETPROP: &[u8] = include_bytes!("../bin/aarch64/resetprop");
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
const RESETPROP: &[u8] = include_bytes!("../bin/x86_64/resetprop");
|
|
||||||
|
|
||||||
const BUSYBOX_PATH: &str = concatcp!(defs::BINARY_DIR, "busybox");
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
const BUSYBOX: &[u8] = include_bytes!("../bin/aarch64/busybox");
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
const BUSYBOX: &[u8] = include_bytes!("../bin/x86_64/busybox");
|
|
||||||
|
|
||||||
pub fn load_system_prop() -> Result<()> {
|
pub fn load_system_prop() -> Result<()> {
|
||||||
ensure_binary(RESETPROP_PATH, RESETPROP)?;
|
|
||||||
ensure_binary(BUSYBOX_PATH, BUSYBOX)?;
|
|
||||||
|
|
||||||
let modules_dir = Path::new(defs::MODULE_DIR);
|
let modules_dir = Path::new(defs::MODULE_DIR);
|
||||||
let dir = std::fs::read_dir(modules_dir)?;
|
let dir = std::fs::read_dir(modules_dir)?;
|
||||||
@@ -328,7 +315,7 @@ pub fn load_system_prop() -> Result<()> {
|
|||||||
println!("load {} system.prop", path.display());
|
println!("load {} system.prop", path.display());
|
||||||
|
|
||||||
// resetprop -n --file system.prop
|
// resetprop -n --file system.prop
|
||||||
Command::new(RESETPROP_PATH)
|
Command::new(assets::RESETPROP_PATH)
|
||||||
.arg("-n")
|
.arg("-n")
|
||||||
.arg("--file")
|
.arg("--file")
|
||||||
.arg(&system_prop)
|
.arg(&system_prop)
|
||||||
@@ -345,9 +332,11 @@ pub fn install_module(zip: String) -> Result<()> {
|
|||||||
// print banner
|
// print banner
|
||||||
println!(include_str!("banner"));
|
println!(include_str!("banner"));
|
||||||
|
|
||||||
|
assets::ensure_bin_assets().with_context(|| "Failed to extract assets")?;
|
||||||
|
|
||||||
// first check if workding dir is usable
|
// first check if workding dir is usable
|
||||||
ensure_dir_exists(defs::WORKING_DIR)?;
|
ensure_dir_exists(defs::WORKING_DIR).with_context(|| "Failed to create working dir")?;
|
||||||
ensure_dir_exists(defs::BINARY_DIR)?;
|
ensure_dir_exists(defs::BINARY_DIR).with_context(|| "Failed to create bin dir")?;
|
||||||
|
|
||||||
// read the module_id from zip, if faild if will return early.
|
// read the module_id from zip, if faild if will return early.
|
||||||
let mut buffer: Vec<u8> = Vec::new();
|
let mut buffer: Vec<u8> = Vec::new();
|
||||||
|
|||||||
Reference in New Issue
Block a user