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