locale configuration

axtloss/rework-partitioning
amy 3 years ago
parent a241d83130
commit b3d6ec3143

@ -0,0 +1,52 @@
use crate::internal::exec::*;
use crate::internal::*;
pub fn set_timezone(timezone: &str) {
exec_eval(exec(
"ln",
vec![
"-sf".to_string(),
format!("/usr/share/zoneinfo/{}", timezone),
"/etc/localtime".to_string(),
],
));
exec_eval(exec_chroot("hwclock", vec!["--systohc".to_string()]));
}
pub fn set_locale(locale: String) {
files_eval(files::append_file("/etc/locale.gen", "en_US.UTF-8 UTF-8"));
files_eval(files::append_file("/etc/locale.gen", locale.as_str()));
exec_eval(exec_chroot("locale-gen", vec!["".to_string()]));
files::create_file("/etc/locale.conf");
files_eval(files::append_file("/etc/locale.conf", "LANG=en_US.UTF-8"));
}
pub fn set_keyboard(keyboard: &str) {
files::create_file("/etc/vconsole.conf");
files_eval(files::append_file(
"/etc/vconsole.conf",
format!("KEYMAP={}", keyboard).as_str(),
));
}
fn files_eval(return_code: std::result::Result<(), std::io::Error>) {
match return_code {
Ok(_) => {
log("Success".to_string());
}
Err(e) => {
crash(format!("Failed to create file, Error: {}", e), 1);
}
}
}
fn exec_eval(return_code: std::result::Result<std::process::Output, std::io::Error>) {
match return_code {
Ok(_) => {
log("Success".to_string());
}
Err(e) => {
crash(format!("Failed with error: {}", e), 1);
}
}
}

@ -1,4 +1,5 @@
pub mod desktops;
pub mod locale;
pub mod network;
pub mod partition;
pub mod users;

@ -81,23 +81,33 @@ pub fn partition(device: &str, mode: &str, efi: bool) {
fn part_nvme(device: &str, efi: bool) {
if efi {
returncode_eval(exec("mkfs.vfat", vec![
String::from(format!("{}p1", device)),
]));
returncode_eval(exec("mkfs.btrfs", vec![
String::from(format!("{}p2", device)),
]));
returncode_eval(exec(
"mkfs.vfat",
vec![String::from(format!("{}p1", device))],
));
returncode_eval(exec(
"mkfs.btrfs",
vec![String::from(format!("{}p2", device))],
));
mount(format!("{}p2", device), "/mnt", "");
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
returncode_eval(exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@"),
]));
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
],
));
returncode_eval(exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
]));
],
));
umount("/mnt");
mount(format!("{}p2", device), "/mnt/", "subvol=@");
files::create_directory("/mnt/boot");
@ -106,23 +116,33 @@ fn part_nvme(device: &str, efi: bool) {
mount(format!("{}p2", device), "/mnt/home", "subvol=@home");
mount(format!("{}p1", device), "/mnt/boot/efi", "");
} else {
returncode_eval(exec("mkfs.ext4", vec![
String::from(format!("{}p1", device)),
]));
returncode_eval(exec("mkfs.btrfs", vec![
String::from(format!("{}p2", device)),
]));
returncode_eval(exec(
"mkfs.ext4",
vec![String::from(format!("{}p1", device))],
));
returncode_eval(exec(
"mkfs.btrfs",
vec![String::from(format!("{}p2", device))],
));
mount(format!("{}p2", device), "/mnt/", "");
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
returncode_eval(exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@"),
]));
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
],
));
returncode_eval(exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
]));
],
));
umount("/mnt");
mount(format!("{}p2", device), "/mnt/", "subvol=@");
files::create_directory("/mnt/boot");
@ -134,23 +154,33 @@ fn part_nvme(device: &str, efi: bool) {
fn part_disk(device: &str, efi: bool) {
if efi {
returncode_eval(exec("mkfs.vfat", vec![
String::from(format!("{}1", device)),
]));
returncode_eval(exec("mkfs.btrfs", vec![
String::from(format!("{}2", device)),
]));
returncode_eval(exec(
"mkfs.vfat",
vec![String::from(format!("{}1", device))],
));
returncode_eval(exec(
"mkfs.btrfs",
vec![String::from(format!("{}2", device))],
));
mount(format!("{}2", device), "/mnt", "");
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
returncode_eval(exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@"),
]));
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
],
));
returncode_eval(exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
]));
],
));
umount("/mnt");
mount(format!("{}2", device), "/mnt/", "subvol=@");
files::create_directory("/mnt/boot");
@ -159,23 +189,33 @@ fn part_disk(device: &str, efi: bool) {
mount(format!("{}2", device), "/mnt/home", "subvol=@home");
mount(format!("{}1", device), "/mnt/boot/efi", "");
} else {
returncode_eval(exec("mkfs.ext4", vec![
String::from(format!("{}1", device)),
]));
returncode_eval(exec("mkfs.btrfs", vec![
String::from(format!("{}2", device)),
]));
returncode_eval(exec(
"mkfs.ext4",
vec![String::from(format!("{}1", device))],
));
returncode_eval(exec(
"mkfs.btrfs",
vec![String::from(format!("{}2", device))],
));
mount(format!("{}2", device), "/mnt/", "");
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
returncode_eval(exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@"),
]));
returncode_eval(exec_workdir("btrfs", "/mnt", vec![
],
));
returncode_eval(exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
]));
],
));
umount("/mnt");
mount(format!("{}2", device), "/mnt/", "subvol=@");
files::create_directory("/mnt/boot");
@ -187,18 +227,19 @@ fn part_disk(device: &str, efi: bool) {
fn mount(partition: String, mountpoint: &str, options: &str) {
let options = if options.is_empty() { "\"\"" } else { options };
returncode_eval(exec("mount", vec![
returncode_eval(exec(
"mount",
vec![
String::from(partition),
String::from(mountpoint),
String::from("-o"),
String::from(options),
]));
],
));
}
fn umount(mountpoint: &str) {
returncode_eval(exec("umount", vec![
String::from(mountpoint),
]));
returncode_eval(exec("umount", vec![String::from(mountpoint)]));
}
fn returncode_eval(return_code: std::result::Result<std::process::Output, std::io::Error>) {

@ -5,12 +5,25 @@ pub fn exec(command: &str, args: Vec<String>) -> Result<std::process::Output, st
returncode
}
pub fn exec_chroot(command: &str, args: Vec<String>) -> Result<std::process::Output, std::io::Error> {
let returncode = Command::new("arch-chroot").args(&["/mnt", command]).args(args).output();
pub fn exec_chroot(
command: &str,
args: Vec<String>,
) -> Result<std::process::Output, std::io::Error> {
let returncode = Command::new("arch-chroot")
.args(&["/mnt", command])
.args(args)
.output();
returncode
}
pub fn exec_workdir(command: &str, workdir: &str, args: Vec<String>,) -> Result<std::process::Output, std::io::Error> {
let returncode = Command::new(command).args(args).current_dir(workdir).output();
pub fn exec_workdir(
command: &str,
workdir: &str,
args: Vec<String>,
) -> Result<std::process::Output, std::io::Error> {
let returncode = Command::new(command)
.args(args)
.current_dir(workdir)
.output();
returncode
}

@ -115,10 +115,15 @@ fn main() {
} else if let Some(app) = app.subcommand_matches("locale") {
let kbrlayout = app.value_of("keyboard").unwrap();
let timezn = app.value_of("timezone").unwrap();
let locale = app.values_of("locales").unwrap();
println!("keyboard layout: {}", kbrlayout);
println!("timezone: {}", timezn);
println!("locales: {:?}", locale);
let locale: String = app
.values_of("locales")
.unwrap()
.into_iter()
.map(|s| s.to_string())
.collect();
locale::set_locale(locale);
locale::set_keyboard(kbrlayout);
locale::set_timezone(timezn);
} else if let Some(app) = app.subcommand_matches("networking") {
network::enable_ipv6(app.value_of("ipv6").unwrap().parse::<bool>().unwrap());
network::set_hostname(app.value_of("hostname").unwrap())

Loading…
Cancel
Save