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 desktops;
pub mod locale;
pub mod network; pub mod network;
pub mod partition; pub mod partition;
pub mod users; pub mod users;

@ -81,23 +81,33 @@ pub fn partition(device: &str, mode: &str, efi: bool) {
fn part_nvme(device: &str, efi: bool) { fn part_nvme(device: &str, efi: bool) {
if efi { if efi {
returncode_eval(exec("mkfs.vfat", vec![ returncode_eval(exec(
String::from(format!("{}p1", device)), "mkfs.vfat",
])); vec![String::from(format!("{}p1", device))],
returncode_eval(exec("mkfs.btrfs", vec![ ));
String::from(format!("{}p2", device)), returncode_eval(exec(
])); "mkfs.btrfs",
vec![String::from(format!("{}p2", device))],
));
mount(format!("{}p2", device), "/mnt", ""); mount(format!("{}p2", device), "/mnt", "");
returncode_eval(exec_workdir("btrfs", "/mnt", vec![ returncode_eval(exec_workdir(
String::from("subvolume"), "btrfs",
String::from("create"), "/mnt",
String::from("@"), vec![
])); String::from("subvolume"),
returncode_eval(exec_workdir("btrfs", "/mnt", vec![ String::from("create"),
String::from("subvolume"), String::from("@"),
String::from("create"), ],
String::from("@home"), ));
])); returncode_eval(exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
],
));
umount("/mnt"); umount("/mnt");
mount(format!("{}p2", device), "/mnt/", "subvol=@"); mount(format!("{}p2", device), "/mnt/", "subvol=@");
files::create_directory("/mnt/boot"); 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!("{}p2", device), "/mnt/home", "subvol=@home");
mount(format!("{}p1", device), "/mnt/boot/efi", ""); mount(format!("{}p1", device), "/mnt/boot/efi", "");
} else { } else {
returncode_eval(exec("mkfs.ext4", vec![ returncode_eval(exec(
String::from(format!("{}p1", device)), "mkfs.ext4",
])); vec![String::from(format!("{}p1", device))],
returncode_eval(exec("mkfs.btrfs", vec![ ));
String::from(format!("{}p2", device)), returncode_eval(exec(
])); "mkfs.btrfs",
vec![String::from(format!("{}p2", device))],
));
mount(format!("{}p2", device), "/mnt/", ""); mount(format!("{}p2", device), "/mnt/", "");
returncode_eval(exec_workdir("btrfs", "/mnt", vec![ returncode_eval(exec_workdir(
String::from("subvolume"), "btrfs",
String::from("create"), "/mnt",
String::from("@"), vec![
])); String::from("subvolume"),
returncode_eval(exec_workdir("btrfs", "/mnt", vec![ String::from("create"),
String::from("subvolume"), String::from("@"),
String::from("create"), ],
String::from("@home"), ));
])); returncode_eval(exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
],
));
umount("/mnt"); umount("/mnt");
mount(format!("{}p2", device), "/mnt/", "subvol=@"); mount(format!("{}p2", device), "/mnt/", "subvol=@");
files::create_directory("/mnt/boot"); files::create_directory("/mnt/boot");
@ -134,23 +154,33 @@ fn part_nvme(device: &str, efi: bool) {
fn part_disk(device: &str, efi: bool) { fn part_disk(device: &str, efi: bool) {
if efi { if efi {
returncode_eval(exec("mkfs.vfat", vec![ returncode_eval(exec(
String::from(format!("{}1", device)), "mkfs.vfat",
])); vec![String::from(format!("{}1", device))],
returncode_eval(exec("mkfs.btrfs", vec![ ));
String::from(format!("{}2", device)), returncode_eval(exec(
])); "mkfs.btrfs",
vec![String::from(format!("{}2", device))],
));
mount(format!("{}2", device), "/mnt", ""); mount(format!("{}2", device), "/mnt", "");
returncode_eval(exec_workdir("btrfs", "/mnt", vec![ returncode_eval(exec_workdir(
String::from("subvolume"), "btrfs",
String::from("create"), "/mnt",
String::from("@"), vec![
])); String::from("subvolume"),
returncode_eval(exec_workdir("btrfs", "/mnt", vec![ String::from("create"),
String::from("subvolume"), String::from("@"),
String::from("create"), ],
String::from("@home"), ));
])); returncode_eval(exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
],
));
umount("/mnt"); umount("/mnt");
mount(format!("{}2", device), "/mnt/", "subvol=@"); mount(format!("{}2", device), "/mnt/", "subvol=@");
files::create_directory("/mnt/boot"); 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!("{}2", device), "/mnt/home", "subvol=@home");
mount(format!("{}1", device), "/mnt/boot/efi", ""); mount(format!("{}1", device), "/mnt/boot/efi", "");
} else { } else {
returncode_eval(exec("mkfs.ext4", vec![ returncode_eval(exec(
String::from(format!("{}1", device)), "mkfs.ext4",
])); vec![String::from(format!("{}1", device))],
returncode_eval(exec("mkfs.btrfs", vec![ ));
String::from(format!("{}2", device)), returncode_eval(exec(
])); "mkfs.btrfs",
vec![String::from(format!("{}2", device))],
));
mount(format!("{}2", device), "/mnt/", ""); mount(format!("{}2", device), "/mnt/", "");
returncode_eval(exec_workdir("btrfs", "/mnt", vec![ returncode_eval(exec_workdir(
String::from("subvolume"), "btrfs",
String::from("create"), "/mnt",
String::from("@"), vec![
])); String::from("subvolume"),
returncode_eval(exec_workdir("btrfs", "/mnt", vec![ String::from("create"),
String::from("subvolume"), String::from("@"),
String::from("create"), ],
String::from("@home"), ));
])); returncode_eval(exec_workdir(
"btrfs",
"/mnt",
vec![
String::from("subvolume"),
String::from("create"),
String::from("@home"),
],
));
umount("/mnt"); umount("/mnt");
mount(format!("{}2", device), "/mnt/", "subvol=@"); mount(format!("{}2", device), "/mnt/", "subvol=@");
files::create_directory("/mnt/boot"); files::create_directory("/mnt/boot");
@ -187,18 +227,19 @@ fn part_disk(device: &str, efi: bool) {
fn mount(partition: String, mountpoint: &str, options: &str) { fn mount(partition: String, mountpoint: &str, options: &str) {
let options = if options.is_empty() { "\"\"" } else { options }; let options = if options.is_empty() { "\"\"" } else { options };
returncode_eval(exec("mount", vec![ returncode_eval(exec(
String::from(partition), "mount",
String::from(mountpoint), vec![
String::from("-o"), String::from(partition),
String::from(options), String::from(mountpoint),
])); String::from("-o"),
String::from(options),
],
));
} }
fn umount(mountpoint: &str) { fn umount(mountpoint: &str) {
returncode_eval(exec("umount", vec![ returncode_eval(exec("umount", vec![String::from(mountpoint)]));
String::from(mountpoint),
]));
} }
fn returncode_eval(return_code: std::result::Result<std::process::Output, std::io::Error>) { 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 returncode
} }
pub fn exec_chroot(command: &str, args: Vec<String>) -> Result<std::process::Output, std::io::Error> { pub fn exec_chroot(
let returncode = Command::new("arch-chroot").args(&["/mnt", command]).args(args).output(); 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 returncode
} }
pub fn exec_workdir(command: &str, workdir: &str, args: Vec<String>,) -> Result<std::process::Output, std::io::Error> { pub fn exec_workdir(
let returncode = Command::new(command).args(args).current_dir(workdir).output(); 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 returncode
} }

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

Loading…
Cancel
Save