Skip to content

Commit

Permalink
installer: Write locale.conf now if locale is selected
Browse files Browse the repository at this point in the history
Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
ikeycode committed Jul 9, 2024
1 parent 6834c4a commit 942c453
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
9 changes: 7 additions & 2 deletions crates/installer/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use topology::disk::Builder;

use crate::{
steps::{
AddRepo, BindMount, Cleanup, Context, FormatPartition, InstallPackages, MountPartition, SetPassword, Step,
Unmount,
AddRepo, BindMount, Cleanup, Context, FormatPartition, InstallPackages, MountPartition, SetLocale, SetPassword,
Step, Unmount,
},
BootPartition, Model, SystemPartition,
};
Expand Down Expand Up @@ -225,6 +225,11 @@ impl Installer {
}
}

// System locale
if let Some(locale) = model.locale {
s.push(Step::set_locale(SetLocale { locale }));
}

// Get the sync call in for unmounts
c.push(Cleanup::sync_fs());
// Lastly, flip cleanups to front in reverse (due to mounts)
Expand Down
12 changes: 11 additions & 1 deletion crates/installer/src/steps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub enum Step<'a> {
Install(Box<packaging::InstallPackages>),
Mount(Box<partitions::MountPartition<'a>>),
SetPassword(Box<postinstall::SetPassword<'a>>),
SetLocale(Box<postinstall::SetLocale<'a>>),
}

impl<'a> Step<'a> {
Expand Down Expand Up @@ -49,6 +50,11 @@ impl<'a> Step<'a> {
Self::Bind(Box::new(b))
}

/// Set system locale
pub fn set_locale(l: postinstall::SetLocale<'a>) -> Self {
Self::SetLocale(Box::new(l))
}

pub fn set_password(a: postinstall::SetPassword<'a>) -> Self {
Self::SetPassword(Box::new(a))
}
Expand All @@ -62,6 +68,7 @@ impl<'a> Step<'a> {
Step::Install(_) => "install-packages",
Step::Mount(_) => "mount-partition",
Step::SetPassword(_) => "set-password",
Step::SetLocale(_) => "set-locale",
}
}

Expand All @@ -74,6 +81,7 @@ impl<'a> Step<'a> {
Step::Install(s) => s.title(),
Step::Mount(s) => s.title(),
Step::SetPassword(s) => s.title(),
Step::SetLocale(s) => s.title(),
}
}

Expand All @@ -86,6 +94,7 @@ impl<'a> Step<'a> {
Step::Install(s) => s.describe(),
Step::Mount(s) => s.describe(),
Step::SetPassword(s) => s.describe(),
Step::SetLocale(s) => s.describe(),
}
}

Expand All @@ -98,6 +107,7 @@ impl<'a> Step<'a> {
Step::Install(s) => Ok(s.execute(context).await?),
Step::Mount(s) => Ok(s.execute(context).await?),
Step::SetPassword(s) => Ok(s.execute(context).await?),
Step::SetLocale(s) => Ok(s.execute(context).await?),
}
}

Expand All @@ -120,4 +130,4 @@ mod cleanup;
pub use cleanup::Cleanup;

mod postinstall;
pub use postinstall::SetPassword;
pub use postinstall::{SetLocale, SetPassword};
25 changes: 25 additions & 0 deletions crates/installer/src/steps/postinstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

//! Post-installation tasks
use system::locale::Locale;
use tokio::process::Command;

use crate::Account;
Expand Down Expand Up @@ -38,3 +39,27 @@ impl<'a> SetPassword<'a> {
Ok(())
}
}

/// Update locale in `locale.conf`
#[derive(Debug)]
pub struct SetLocale<'a> {
pub(crate) locale: &'a Locale<'a>,
}

impl<'a> SetLocale<'a> {
pub(super) fn title(&self) -> String {
"Set system locale".to_string()
}

pub(super) fn describe(&self) -> String {
self.locale.display_name.clone()
}

pub(super) async fn execute(&self, context: &'a impl Context<'a>) -> Result<(), Error> {
let contents = format!("LANG={}\n", self.locale.name);
let path = context.root().join("etc").join("locale.conf");
tokio::fs::write(path, &contents).await?;

Ok(())
}
}

0 comments on commit 942c453

Please sign in to comment.