mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
fix: propagate host locale into LXC containers and write locale.conf
This commit is contained in:
@@ -17,3 +17,6 @@ lxc.net.0.link = lxcbr0
|
|||||||
lxc.net.0.flags = up
|
lxc.net.0.flags = up
|
||||||
|
|
||||||
lxc.rootfs.options = rshared
|
lxc.rootfs.options = rshared
|
||||||
|
|
||||||
|
# Environment
|
||||||
|
lxc.environment = LANG={lang}
|
||||||
|
|||||||
@@ -174,10 +174,15 @@ impl LxcContainer {
|
|||||||
config: LxcConfig,
|
config: LxcConfig,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let guid = new_guid();
|
let guid = new_guid();
|
||||||
|
let lang = std::env::var("LANG").unwrap_or_else(|_| "C.UTF-8".into());
|
||||||
let machine_id = hex::encode(rand::random::<[u8; 16]>());
|
let machine_id = hex::encode(rand::random::<[u8; 16]>());
|
||||||
let container_dir = Path::new(LXC_CONTAINER_DIR).join(&*guid);
|
let container_dir = Path::new(LXC_CONTAINER_DIR).join(&*guid);
|
||||||
tokio::fs::create_dir_all(&container_dir).await?;
|
tokio::fs::create_dir_all(&container_dir).await?;
|
||||||
let config_str = format!(include_str!("./config.template"), guid = &*guid);
|
let config_str = format!(
|
||||||
|
include_str!("./config.template"),
|
||||||
|
guid = &*guid,
|
||||||
|
lang = &lang,
|
||||||
|
);
|
||||||
tokio::fs::write(container_dir.join("config"), config_str).await?;
|
tokio::fs::write(container_dir.join("config"), config_str).await?;
|
||||||
let rootfs_dir = container_dir.join("rootfs");
|
let rootfs_dir = container_dir.join("rootfs");
|
||||||
let rootfs = OverlayGuard::mount(
|
let rootfs = OverlayGuard::mount(
|
||||||
@@ -215,6 +220,13 @@ impl LxcContainer {
|
|||||||
100000,
|
100000,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
write_file_owned_atomic(
|
||||||
|
rootfs_dir.join("etc/default/locale"),
|
||||||
|
format!("LANG={lang}\n"),
|
||||||
|
100000,
|
||||||
|
100000,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
Command::new("sed")
|
Command::new("sed")
|
||||||
.arg("-i")
|
.arg("-i")
|
||||||
.arg(format!("s/LXC_NAME/{guid}/g"))
|
.arg(format!("s/LXC_NAME/{guid}/g"))
|
||||||
|
|||||||
@@ -1261,9 +1261,15 @@ pub async fn save_language(language: &str) -> Result<(), Error> {
|
|||||||
"/media/startos/config/overlay/usr/lib/locale/locale-archive",
|
"/media/startos/config/overlay/usr/lib/locale/locale-archive",
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
let locale_content = format!("LANG={language}.UTF-8\n");
|
||||||
write_file_atomic(
|
write_file_atomic(
|
||||||
"/media/startos/config/overlay/etc/default/locale",
|
"/media/startos/config/overlay/etc/default/locale",
|
||||||
format!("LANG={language}.UTF-8\n").as_bytes(),
|
locale_content.as_bytes(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
write_file_atomic(
|
||||||
|
"/media/startos/config/overlay/etc/locale.conf",
|
||||||
|
locale_content.as_bytes(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user