mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-05 22:20:33 -04:00
Add steamos-reset-tool usage.
Instead of using steamos-factory-reset-config which resets both the OS and the user home partitions use steamos-reset-tool which has arguments for each or resetting both.
This commit is contained in:
parent
c62b244d24
commit
f7bfdd7d7a
8 changed files with 140 additions and 31 deletions
|
@ -65,11 +65,13 @@
|
|||
Perform factory reset of device. Runs steamos-factory-reset script for
|
||||
now.
|
||||
|
||||
@kind: 1 = Clear just user settings, 2 = Clear just OS, 3 = clear both user settings and OS
|
||||
@returns: Status of reset operation.
|
||||
|
||||
Valid statuses: 0 = Unknown, 1 = RebootRequired
|
||||
-->
|
||||
<method name="PrepareFactoryReset">
|
||||
<arg type="u" name="kind" direction="in"/>
|
||||
<arg type="u" name="status" direction="out"/>
|
||||
</method>
|
||||
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
[factory_reset]
|
||||
script = "/usr/bin/steamos-factory-reset-config"
|
||||
[factory_reset.all]
|
||||
script = "/usr/bin/steamos-reset-tool"
|
||||
script_args = ["factory-reset", "--reset-all"]
|
||||
|
||||
[factory_reset.os]
|
||||
script = "/usr/bin/steamos-reset-tool"
|
||||
script_args = ["factory-reset", "--reset-os"]
|
||||
|
||||
[factory_reset.user]
|
||||
script = "/usr/bin/steamos-reset-tool"
|
||||
script_args = ["factory-reset", "--reset-user-data"]
|
||||
|
||||
[update_bios]
|
||||
script = "/usr/bin/jupiter-biosupdate"
|
||||
|
|
|
@ -11,7 +11,7 @@ use itertools::Itertools;
|
|||
use std::collections::HashMap;
|
||||
use std::io::Cursor;
|
||||
use steamos_manager::cec::HdmiCecState;
|
||||
use steamos_manager::hardware::FanControlState;
|
||||
use steamos_manager::hardware::{FactoryResetKind, FanControlState};
|
||||
use steamos_manager::power::{CPUScalingGovernor, GPUPerformanceLevel, GPUPowerProfile};
|
||||
use steamos_manager::proxy::{
|
||||
AmbientLightSensor1Proxy, CpuScaling1Proxy, FactoryReset1Proxy, FanControl1Proxy,
|
||||
|
@ -160,8 +160,11 @@ enum Commands {
|
|||
/// Trim applicable drives
|
||||
TrimDevices,
|
||||
|
||||
/// Factory reset the device
|
||||
FactoryReset,
|
||||
/// Factory reset the os/user partitions
|
||||
PrepareFactoryReset {
|
||||
/// Valid kind(s) are `user`, `os`, `all`
|
||||
kind: FactoryResetKind,
|
||||
},
|
||||
}
|
||||
|
||||
async fn get_all_properties(conn: &Connection) -> Result<()> {
|
||||
|
@ -413,9 +416,9 @@ async fn main() -> Result<()> {
|
|||
let proxy = UpdateDock1Proxy::new(&conn).await?;
|
||||
let _ = proxy.update_dock().await?;
|
||||
}
|
||||
Commands::FactoryReset => {
|
||||
Commands::PrepareFactoryReset { kind } => {
|
||||
let proxy = FactoryReset1Proxy::new(&conn).await?;
|
||||
let _ = proxy.prepare_factory_reset().await?;
|
||||
let _ = proxy.prepare_factory_reset(*kind as u32).await?;
|
||||
}
|
||||
Commands::TrimDevices => {
|
||||
let proxy = Storage1Proxy::new(&conn).await?;
|
||||
|
|
|
@ -68,6 +68,15 @@ impl fmt::Display for HardwareCurrentlySupported {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Display, EnumString, PartialEq, Debug, Copy, Clone, TryFromPrimitive)]
|
||||
#[strum(ascii_case_insensitive)]
|
||||
#[repr(u32)]
|
||||
pub enum FactoryResetKind {
|
||||
User = 1,
|
||||
OS = 2,
|
||||
All = 3,
|
||||
}
|
||||
|
||||
pub(crate) async fn variant() -> Result<HardwareVariant> {
|
||||
let board_vendor = fs::read_to_string(path(BOARD_VENDOR_PATH)).await?;
|
||||
if board_vendor.trim_end() != "Valve" {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
use anyhow::Result;
|
||||
use anyhow::{anyhow, Result};
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::OsStr;
|
||||
use tokio::fs::File;
|
||||
|
@ -19,7 +19,7 @@ use zbus::{fdo, interface, Connection, SignalContext};
|
|||
use crate::daemon::root::{Command, RootCommand};
|
||||
use crate::daemon::DaemonCommand;
|
||||
use crate::error::{to_zbus_error, to_zbus_fdo_error};
|
||||
use crate::hardware::{variant, FanControl, FanControlState, HardwareVariant};
|
||||
use crate::hardware::{variant, FactoryResetKind, FanControl, FanControlState, HardwareVariant};
|
||||
use crate::job::JobManager;
|
||||
use crate::platform::platform_config;
|
||||
use crate::power::{
|
||||
|
@ -54,7 +54,9 @@ macro_rules! with_platform_config {
|
|||
|
||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||
#[repr(u32)]
|
||||
enum PrepareFactoryReset {
|
||||
enum PrepareFactoryResetResult {
|
||||
// NOTE: both old PrepareFactoryReset and new PrepareFactoryResetExt use these
|
||||
// result values.
|
||||
Unknown = 0,
|
||||
RebootRequired = 1,
|
||||
}
|
||||
|
@ -85,14 +87,28 @@ impl SteamOSManager {
|
|||
|
||||
#[interface(name = "com.steampowered.SteamOSManager1.RootManager")]
|
||||
impl SteamOSManager {
|
||||
async fn prepare_factory_reset(&self) -> fdo::Result<u32> {
|
||||
// Run steamos factory reset script and return true on success
|
||||
async fn prepare_factory_reset(&self, kind: u32) -> fdo::Result<u32> {
|
||||
// Run steamos-reset with arguments based on flags passed and return 1 on success
|
||||
with_platform_config! {
|
||||
config = factory_reset ("PrepareFactoryReset") => {
|
||||
let res = run_script(&config.script, &config.script_args).await;
|
||||
config = factory_reset("PrepareFactoryReset") => {
|
||||
let res =
|
||||
match FactoryResetKind::try_from(kind) {
|
||||
Ok(FactoryResetKind::User) => {
|
||||
run_script(&config.user.script, &config.user.script_args).await
|
||||
},
|
||||
Ok(FactoryResetKind::OS) => {
|
||||
run_script(&config.os.script, &config.os.script_args).await
|
||||
},
|
||||
Ok(FactoryResetKind::All) => {
|
||||
run_script(&config.all.script, &config.all.script_args).await
|
||||
},
|
||||
Err(_) => {
|
||||
Err(anyhow!("Unable to generate command arguments for steamos-reset-tool script"))
|
||||
}
|
||||
};
|
||||
Ok(match res {
|
||||
Ok(()) => PrepareFactoryReset::RebootRequired as u32,
|
||||
Err(_) => PrepareFactoryReset::Unknown as u32,
|
||||
Ok(()) => PrepareFactoryResetResult::RebootRequired as u32,
|
||||
Err(_) => PrepareFactoryResetResult::Unknown as u32,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -391,7 +407,7 @@ mod test {
|
|||
use crate::daemon::channel;
|
||||
use crate::daemon::root::RootContext;
|
||||
use crate::hardware::test::fake_model;
|
||||
use crate::platform::{PlatformConfig, ScriptConfig};
|
||||
use crate::platform::{PlatformConfig, ResetConfig};
|
||||
use crate::power::test::{format_clocks, read_clocks};
|
||||
use crate::power::{self, get_gpu_performance_level};
|
||||
use crate::process::test::{code, exit, ok};
|
||||
|
@ -439,7 +455,7 @@ mod test {
|
|||
default_path = "/com/steampowered/SteamOSManager1"
|
||||
)]
|
||||
trait PrepareFactoryReset {
|
||||
fn prepare_factory_reset(&self) -> zbus::Result<u32>;
|
||||
fn prepare_factory_reset(&self, kind: u32) -> zbus::Result<u32>;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -447,7 +463,7 @@ mod test {
|
|||
let test = start().await.expect("start");
|
||||
|
||||
let mut config = PlatformConfig::default();
|
||||
config.factory_reset = Some(ScriptConfig::default());
|
||||
config.factory_reset = Some(ResetConfig::default());
|
||||
test.h.test.platform_config.replace(Some(config));
|
||||
|
||||
let name = test.connection.unique_name().unwrap();
|
||||
|
@ -457,20 +473,83 @@ mod test {
|
|||
|
||||
test.h.test.process_cb.set(ok);
|
||||
assert_eq!(
|
||||
proxy.prepare_factory_reset().await.unwrap(),
|
||||
PrepareFactoryReset::RebootRequired as u32
|
||||
proxy
|
||||
.prepare_factory_reset(FactoryResetKind::All as u32)
|
||||
.await
|
||||
.unwrap(),
|
||||
PrepareFactoryResetResult::RebootRequired as u32
|
||||
);
|
||||
|
||||
test.h.test.process_cb.set(code);
|
||||
assert_eq!(
|
||||
proxy.prepare_factory_reset().await.unwrap(),
|
||||
PrepareFactoryReset::Unknown as u32
|
||||
proxy
|
||||
.prepare_factory_reset(FactoryResetKind::All as u32)
|
||||
.await
|
||||
.unwrap(),
|
||||
PrepareFactoryResetResult::Unknown as u32
|
||||
);
|
||||
|
||||
test.h.test.process_cb.set(exit);
|
||||
assert_eq!(
|
||||
proxy.prepare_factory_reset().await.unwrap(),
|
||||
PrepareFactoryReset::Unknown as u32
|
||||
proxy
|
||||
.prepare_factory_reset(FactoryResetKind::All as u32)
|
||||
.await
|
||||
.unwrap(),
|
||||
PrepareFactoryResetResult::Unknown as u32
|
||||
);
|
||||
|
||||
test.h.test.process_cb.set(ok);
|
||||
assert_eq!(
|
||||
proxy
|
||||
.prepare_factory_reset(FactoryResetKind::OS as u32)
|
||||
.await
|
||||
.unwrap(),
|
||||
PrepareFactoryResetResult::RebootRequired as u32
|
||||
);
|
||||
|
||||
test.h.test.process_cb.set(code);
|
||||
assert_eq!(
|
||||
proxy
|
||||
.prepare_factory_reset(FactoryResetKind::OS as u32)
|
||||
.await
|
||||
.unwrap(),
|
||||
PrepareFactoryResetResult::Unknown as u32
|
||||
);
|
||||
|
||||
test.h.test.process_cb.set(exit);
|
||||
assert_eq!(
|
||||
proxy
|
||||
.prepare_factory_reset(FactoryResetKind::OS as u32)
|
||||
.await
|
||||
.unwrap(),
|
||||
PrepareFactoryResetResult::Unknown as u32
|
||||
);
|
||||
|
||||
test.h.test.process_cb.set(ok);
|
||||
assert_eq!(
|
||||
proxy
|
||||
.prepare_factory_reset(FactoryResetKind::User as u32)
|
||||
.await
|
||||
.unwrap(),
|
||||
PrepareFactoryResetResult::RebootRequired as u32
|
||||
);
|
||||
|
||||
test.h.test.process_cb.set(code);
|
||||
assert_eq!(
|
||||
proxy
|
||||
.prepare_factory_reset(FactoryResetKind::User as u32)
|
||||
.await
|
||||
.unwrap(),
|
||||
PrepareFactoryResetResult::Unknown as u32
|
||||
);
|
||||
|
||||
test.h.test.process_cb.set(exit);
|
||||
assert_eq!(
|
||||
proxy
|
||||
.prepare_factory_reset(FactoryResetKind::User as u32)
|
||||
.await
|
||||
.unwrap(),
|
||||
PrepareFactoryResetResult::Unknown as u32
|
||||
);
|
||||
|
||||
test.connection.close().await.unwrap();
|
||||
|
|
|
@ -251,8 +251,8 @@ impl CpuScaling1 {
|
|||
|
||||
#[interface(name = "com.steampowered.SteamOSManager1.FactoryReset1")]
|
||||
impl FactoryReset1 {
|
||||
async fn prepare_factory_reset(&self) -> fdo::Result<u32> {
|
||||
method!(self, "PrepareFactoryReset")
|
||||
async fn prepare_factory_reset(&self, flags: u32) -> fdo::Result<u32> {
|
||||
method!(self, "PrepareFactoryReset", flags)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -661,7 +661,7 @@ mod test {
|
|||
use crate::hardware::test::fake_model;
|
||||
use crate::hardware::HardwareVariant;
|
||||
use crate::platform::{
|
||||
PlatformConfig, RangeConfig, ScriptConfig, ServiceConfig, StorageConfig,
|
||||
PlatformConfig, RangeConfig, ResetConfig, ScriptConfig, ServiceConfig, StorageConfig,
|
||||
};
|
||||
use crate::systemd::test::{MockManager, MockUnit};
|
||||
use crate::{power, testing};
|
||||
|
@ -678,7 +678,7 @@ mod test {
|
|||
|
||||
fn all_config() -> Option<PlatformConfig> {
|
||||
Some(PlatformConfig {
|
||||
factory_reset: Some(ScriptConfig::default()),
|
||||
factory_reset: Some(ResetConfig::default()),
|
||||
update_bios: Some(ScriptConfig::default()),
|
||||
update_dock: Some(ScriptConfig::default()),
|
||||
storage: Some(StorageConfig::default()),
|
||||
|
|
|
@ -21,7 +21,7 @@ static CONFIG: OnceCell<Option<PlatformConfig>> = OnceCell::const_new();
|
|||
#[derive(Clone, Default, Deserialize, Debug)]
|
||||
#[serde(default)]
|
||||
pub(crate) struct PlatformConfig {
|
||||
pub factory_reset: Option<ScriptConfig>,
|
||||
pub factory_reset: Option<ResetConfig>,
|
||||
pub update_bios: Option<ScriptConfig>,
|
||||
pub update_dock: Option<ScriptConfig>,
|
||||
pub storage: Option<StorageConfig>,
|
||||
|
@ -45,6 +45,13 @@ pub(crate) struct ScriptConfig {
|
|||
pub script_args: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Deserialize, Debug)]
|
||||
pub(crate) struct ResetConfig {
|
||||
pub all: ScriptConfig,
|
||||
pub os: ScriptConfig,
|
||||
pub user: ScriptConfig,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Debug)]
|
||||
pub(crate) enum ServiceConfig {
|
||||
#[serde(rename = "systemd")]
|
||||
|
|
|
@ -20,5 +20,5 @@ use zbus::proxy;
|
|||
)]
|
||||
trait FactoryReset1 {
|
||||
/// PrepareFactoryReset method
|
||||
fn prepare_factory_reset(&self) -> zbus::Result<u32>;
|
||||
fn prepare_factory_reset(&self, kind: u32) -> zbus::Result<u32>;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue