mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
refactor: change kiosk parameter from Option<bool> to bool
Simplifies the setup API by making kiosk mandatory at the protocol level, with platform-specific filtering applied at the database layer.
This commit is contained in:
@@ -10,6 +10,7 @@ use tracing::instrument;
|
|||||||
use ts_rs::TS;
|
use ts_rs::TS;
|
||||||
|
|
||||||
use super::target::BackupTargetId;
|
use super::target::BackupTargetId;
|
||||||
|
use crate::PackageId;
|
||||||
use crate::backup::os::OsBackup;
|
use crate::backup::os::OsBackup;
|
||||||
use crate::context::setup::SetupResult;
|
use crate::context::setup::SetupResult;
|
||||||
use crate::context::{RpcContext, SetupContext};
|
use crate::context::{RpcContext, SetupContext};
|
||||||
@@ -26,7 +27,6 @@ use crate::service::service_map::DownloadInstallFuture;
|
|||||||
use crate::setup::SetupExecuteProgress;
|
use crate::setup::SetupExecuteProgress;
|
||||||
use crate::system::{save_language, sync_kiosk};
|
use crate::system::{save_language, sync_kiosk};
|
||||||
use crate::util::serde::{IoFormat, Pem};
|
use crate::util::serde::{IoFormat, Pem};
|
||||||
use crate::{PLATFORM, PackageId};
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Parser, TS)]
|
#[derive(Deserialize, Serialize, Parser, TS)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
@@ -90,7 +90,7 @@ pub async fn recover_full_server(
|
|||||||
recovery_source: TmpMountGuard,
|
recovery_source: TmpMountGuard,
|
||||||
server_id: &str,
|
server_id: &str,
|
||||||
recovery_password: &str,
|
recovery_password: &str,
|
||||||
kiosk: Option<bool>,
|
kiosk: bool,
|
||||||
hostname: Option<ServerHostnameInfo>,
|
hostname: Option<ServerHostnameInfo>,
|
||||||
SetupExecuteProgress {
|
SetupExecuteProgress {
|
||||||
init_phases,
|
init_phases,
|
||||||
@@ -123,7 +123,6 @@ pub async fn recover_full_server(
|
|||||||
os_backup.account.hostname = h;
|
os_backup.account.hostname = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
let kiosk = Some(kiosk.unwrap_or(true)).filter(|_| &*PLATFORM != "raspberrypi");
|
|
||||||
sync_kiosk(kiosk).await?;
|
sync_kiosk(kiosk).await?;
|
||||||
|
|
||||||
let language = ctx.language.peek(|a| a.clone());
|
let language = ctx.language.peek(|a| a.clone());
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ pub struct Database {
|
|||||||
impl Database {
|
impl Database {
|
||||||
pub fn init(
|
pub fn init(
|
||||||
account: &AccountInfo,
|
account: &AccountInfo,
|
||||||
kiosk: Option<bool>,
|
kiosk: bool,
|
||||||
language: Option<InternedString>,
|
language: Option<InternedString>,
|
||||||
keyboard: Option<KeyboardOptions>,
|
keyboard: Option<KeyboardOptions>,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ pub struct Public {
|
|||||||
impl Public {
|
impl Public {
|
||||||
pub fn init(
|
pub fn init(
|
||||||
account: &AccountInfo,
|
account: &AccountInfo,
|
||||||
kiosk: Option<bool>,
|
kiosk: bool,
|
||||||
language: Option<InternedString>,
|
language: Option<InternedString>,
|
||||||
keyboard: Option<KeyboardOptions>,
|
keyboard: Option<KeyboardOptions>,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
@@ -149,7 +149,7 @@ impl Public {
|
|||||||
echoip_urls: default_echoip_urls(),
|
echoip_urls: default_echoip_urls(),
|
||||||
ram: 0,
|
ram: 0,
|
||||||
devices: Vec::new(),
|
devices: Vec::new(),
|
||||||
kiosk,
|
kiosk: Some(kiosk).filter(|_| &*PLATFORM != "raspberrypi"),
|
||||||
language,
|
language,
|
||||||
keyboard,
|
keyboard,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -174,7 +174,9 @@ pub async fn init(
|
|||||||
local_auth.complete();
|
local_auth.complete();
|
||||||
|
|
||||||
// Re-enroll MOK on every boot if Secure Boot key exists but isn't enrolled yet
|
// Re-enroll MOK on every boot if Secure Boot key exists but isn't enrolled yet
|
||||||
if let Err(e) = crate::util::mok::enroll_mok(std::path::Path::new(crate::util::mok::DKMS_MOK_PUB)).await {
|
if let Err(e) =
|
||||||
|
crate::util::mok::enroll_mok(std::path::Path::new(crate::util::mok::DKMS_MOK_PUB)).await
|
||||||
|
{
|
||||||
tracing::warn!("MOK enrollment failed: {e}");
|
tracing::warn!("MOK enrollment failed: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,7 +371,7 @@ pub async fn init(
|
|||||||
enable_zram.complete();
|
enable_zram.complete();
|
||||||
|
|
||||||
update_server_info.start();
|
update_server_info.start();
|
||||||
sync_kiosk(server_info.as_kiosk().de()?).await?;
|
sync_kiosk(server_info.as_kiosk().de()?.unwrap_or(false)).await?;
|
||||||
let ram = get_mem_info().await?.total.0 as u64 * 1024 * 1024;
|
let ram = get_mem_info().await?.total.0 as u64 * 1024 * 1024;
|
||||||
let devices = lshw().await?;
|
let devices = lshw().await?;
|
||||||
let status_info = ServerStatus {
|
let status_info = ServerStatus {
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ pub async fn list_disks(ctx: SetupContext) -> Result<Vec<DiskInfo>, Error> {
|
|||||||
async fn setup_init(
|
async fn setup_init(
|
||||||
ctx: &SetupContext,
|
ctx: &SetupContext,
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
kiosk: Option<bool>,
|
kiosk: bool,
|
||||||
hostname: Option<ServerHostnameInfo>,
|
hostname: Option<ServerHostnameInfo>,
|
||||||
init_phases: InitPhases,
|
init_phases: InitPhases,
|
||||||
) -> Result<(AccountInfo, InitResult), Error> {
|
) -> Result<(AccountInfo, InitResult), Error> {
|
||||||
@@ -137,9 +137,8 @@ async fn setup_init(
|
|||||||
account.save(m)?;
|
account.save(m)?;
|
||||||
let info = m.as_public_mut().as_server_info_mut();
|
let info = m.as_public_mut().as_server_info_mut();
|
||||||
info.as_password_hash_mut().ser(&account.password)?;
|
info.as_password_hash_mut().ser(&account.password)?;
|
||||||
if let Some(kiosk) = kiosk {
|
info.as_kiosk_mut()
|
||||||
info.as_kiosk_mut().ser(&Some(kiosk))?;
|
.ser(&Some(kiosk).filter(|_| &*PLATFORM != "raspberrypi"))?;
|
||||||
}
|
|
||||||
if let Some(language) = language.clone() {
|
if let Some(language) = language.clone() {
|
||||||
info.as_language_mut().ser(&Some(language))?;
|
info.as_language_mut().ser(&Some(language))?;
|
||||||
}
|
}
|
||||||
@@ -174,8 +173,7 @@ async fn setup_init(
|
|||||||
pub struct AttachParams {
|
pub struct AttachParams {
|
||||||
pub password: Option<EncryptedWire>,
|
pub password: Option<EncryptedWire>,
|
||||||
pub guid: InternedString,
|
pub guid: InternedString,
|
||||||
#[ts(optional)]
|
pub kiosk: bool,
|
||||||
pub kiosk: Option<bool>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip_all)]
|
#[instrument(skip_all)]
|
||||||
@@ -411,8 +409,7 @@ pub struct SetupExecuteParams {
|
|||||||
guid: InternedString,
|
guid: InternedString,
|
||||||
password: Option<EncryptedWire>,
|
password: Option<EncryptedWire>,
|
||||||
recovery_source: Option<RecoverySource<EncryptedWire>>,
|
recovery_source: Option<RecoverySource<EncryptedWire>>,
|
||||||
#[ts(optional)]
|
kiosk: bool,
|
||||||
kiosk: Option<bool>,
|
|
||||||
name: Option<InternedString>,
|
name: Option<InternedString>,
|
||||||
hostname: Option<InternedString>,
|
hostname: Option<InternedString>,
|
||||||
}
|
}
|
||||||
@@ -549,7 +546,7 @@ pub async fn execute_inner(
|
|||||||
guid: InternedString,
|
guid: InternedString,
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
recovery_source: Option<RecoverySource<String>>,
|
recovery_source: Option<RecoverySource<String>>,
|
||||||
kiosk: Option<bool>,
|
kiosk: bool,
|
||||||
hostname: Option<ServerHostnameInfo>,
|
hostname: Option<ServerHostnameInfo>,
|
||||||
) -> Result<(SetupResult, RpcContext), Error> {
|
) -> Result<(SetupResult, RpcContext), Error> {
|
||||||
let progress = &ctx.progress;
|
let progress = &ctx.progress;
|
||||||
@@ -622,7 +619,7 @@ async fn fresh_setup(
|
|||||||
ctx: &SetupContext,
|
ctx: &SetupContext,
|
||||||
guid: InternedString,
|
guid: InternedString,
|
||||||
password: &str,
|
password: &str,
|
||||||
kiosk: Option<bool>,
|
kiosk: bool,
|
||||||
hostname: Option<ServerHostnameInfo>,
|
hostname: Option<ServerHostnameInfo>,
|
||||||
SetupExecuteProgress {
|
SetupExecuteProgress {
|
||||||
init_phases,
|
init_phases,
|
||||||
@@ -633,7 +630,6 @@ async fn fresh_setup(
|
|||||||
let account = AccountInfo::new(password, root_ca_start_time().await, hostname)?;
|
let account = AccountInfo::new(password, root_ca_start_time().await, hostname)?;
|
||||||
|
|
||||||
let db = ctx.db().await?;
|
let db = ctx.db().await?;
|
||||||
let kiosk = Some(kiosk.unwrap_or(true)).filter(|_| &*PLATFORM != "raspberrypi");
|
|
||||||
sync_kiosk(kiosk).await?;
|
sync_kiosk(kiosk).await?;
|
||||||
|
|
||||||
let language = ctx.language.peek(|a| a.clone());
|
let language = ctx.language.peek(|a| a.clone());
|
||||||
@@ -684,7 +680,7 @@ async fn recover(
|
|||||||
recovery_source: BackupTargetFS,
|
recovery_source: BackupTargetFS,
|
||||||
server_id: String,
|
server_id: String,
|
||||||
recovery_password: String,
|
recovery_password: String,
|
||||||
kiosk: Option<bool>,
|
kiosk: bool,
|
||||||
hostname: Option<ServerHostnameInfo>,
|
hostname: Option<ServerHostnameInfo>,
|
||||||
progress: SetupExecuteProgress,
|
progress: SetupExecuteProgress,
|
||||||
) -> Result<(SetupResult, RpcContext), Error> {
|
) -> Result<(SetupResult, RpcContext), Error> {
|
||||||
@@ -709,7 +705,7 @@ async fn migrate(
|
|||||||
guid: InternedString,
|
guid: InternedString,
|
||||||
old_guid: &str,
|
old_guid: &str,
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
kiosk: Option<bool>,
|
kiosk: bool,
|
||||||
hostname: Option<ServerHostnameInfo>,
|
hostname: Option<ServerHostnameInfo>,
|
||||||
SetupExecuteProgress {
|
SetupExecuteProgress {
|
||||||
init_phases,
|
init_phases,
|
||||||
|
|||||||
@@ -319,13 +319,11 @@ pub fn kernel_logs<C: Context + AsRef<RpcContinuations>>() -> ParentHandler<C, L
|
|||||||
const DISABLE_KIOSK_PATH: &str =
|
const DISABLE_KIOSK_PATH: &str =
|
||||||
"/media/startos/config/overlay/etc/systemd/system/getty@tty1.service.d/autologin.conf";
|
"/media/startos/config/overlay/etc/systemd/system/getty@tty1.service.d/autologin.conf";
|
||||||
|
|
||||||
pub async fn sync_kiosk(kiosk: Option<bool>) -> Result<(), Error> {
|
pub async fn sync_kiosk(kiosk: bool) -> Result<(), Error> {
|
||||||
if let Some(kiosk) = kiosk {
|
if kiosk {
|
||||||
if kiosk {
|
enable_kiosk().await?;
|
||||||
enable_kiosk().await?;
|
} else {
|
||||||
} else {
|
disable_kiosk().await?;
|
||||||
disable_kiosk().await?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ import type { EncryptedWire } from './EncryptedWire'
|
|||||||
export type AttachParams = {
|
export type AttachParams = {
|
||||||
password: EncryptedWire | null
|
password: EncryptedWire | null
|
||||||
guid: string
|
guid: string
|
||||||
kiosk?: boolean
|
kiosk: boolean
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export type SetupExecuteParams = {
|
|||||||
guid: string
|
guid: string
|
||||||
password: EncryptedWire | null
|
password: EncryptedWire | null
|
||||||
recoverySource: RecoverySource<EncryptedWire> | null
|
recoverySource: RecoverySource<EncryptedWire> | null
|
||||||
kiosk?: boolean
|
kiosk: boolean
|
||||||
name: string | null
|
name: string | null
|
||||||
hostname: string | null
|
hostname: string | null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ export class StateService {
|
|||||||
await this.api.attach({
|
await this.api.attach({
|
||||||
guid: this.dataDriveGuid,
|
guid: this.dataDriveGuid,
|
||||||
password: password ? await this.api.encrypt(password) : null,
|
password: password ? await this.api.encrypt(password) : null,
|
||||||
|
kiosk: this.kiosk,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,6 +107,7 @@ export class StateService {
|
|||||||
name,
|
name,
|
||||||
hostname,
|
hostname,
|
||||||
recoverySource,
|
recoverySource,
|
||||||
|
kiosk: this.kiosk,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user