This commit is contained in:
JMARyA 2024-12-28 05:14:29 +01:00
parent 17a137e47c
commit 4a70ffa906
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
6 changed files with 49 additions and 21 deletions

View file

@ -1,31 +1,49 @@
// GENFSTAB // GENFSTAB
use crate::{config::GeneralConfig, run_command}; use crate::{config::GeneralConfig, print_status, run_command};
use super::{str_vec, uncomment_first_value_of}; use super::{str_vec, uncomment_first_value_of};
pub fn genfstab() { pub fn genfstab() {
print_status("Generating fstab");
let (stdout, _) = run_command(&str_vec(vec!["genfstab", "-U", "/mnt"]), None, false); let (stdout, _) = run_command(&str_vec(vec!["genfstab", "-U", "/mnt"]), None, false);
std::fs::write("/mnt/etc/fstab", stdout).unwrap(); std::fs::write("/mnt/etc/fstab", stdout).unwrap();
} }
pub fn first_boot_values(conf: &GeneralConfig) { pub fn first_boot_values(conf: &GeneralConfig) {
// CHROOT // Locale
run_command( print_status(&format!("Setting locale {}", conf.locale));
&vec![ std::fs::write(
"arch-chroot".into(), "/mnt/etc/locale.conf",
"/mnt".into(), format!("LANG=\"{}\"\n", conf.locale),
"systemd-firstboot".into(), )
format!("--locale={}", conf.locale), .unwrap();
format!("--keymap={}", conf.keymap),
format!("--timezone={}", conf.timezone), // Timezone
format!("--hostname={}", conf.hostname), print_status(&format!("Setting timezone {}", conf.timezone));
], let tz_paths = conf.timezone.split('/').collect::<Vec<&str>>();
None, let mut tz_link = std::path::PathBuf::from("/usr/share/zoneinfo/");
false,
); for path in tz_paths {
tz_link.push(path);
}
std::os::unix::fs::symlink(tz_link, "/mnt/etc/localtime").unwrap();
// Keymap
print_status("Writing /etc/vconsole.conf");
std::fs::write(
"/mnt/etc/vconsole.conf",
format!("KEYMAP=\"{}\"", conf.keymap),
)
.unwrap();
// Hostname
print_status("Writing /etc/hostname");
std::fs::write("/mnt/etc/hostname", format!("{}\n", conf.hostname)).unwrap();
// LOCALE // LOCALE
print_status("Setting locale");
uncomment_first_value_of(&conf.locale, "/mnt/etc/locale.gen"); uncomment_first_value_of(&conf.locale, "/mnt/etc/locale.gen");
run_command( run_command(
&str_vec(vec!["arch-chroot", "/mnt", "locale-gen"]), &str_vec(vec!["arch-chroot", "/mnt", "locale-gen"]),

View file

@ -1,16 +1,18 @@
// MKINITCPIO + UKI // MKINITCPIO + UKI
use crate::run_command; use crate::{print_status, run_command};
use super::str_vec; use super::str_vec;
pub fn setup_mkinitcpio() { pub fn setup_mkinitcpio() {
print_status("Writing /etc/mkinitcpio.d/linux.preset");
std::fs::write( std::fs::write(
"/mnt/etc/mkinitcpio.d/linux.preset", "/mnt/etc/mkinitcpio.d/linux.preset",
include_str!("../root/mkinitcpio/linux.preset"), include_str!("../root/mkinitcpio/linux.preset"),
) )
.unwrap(); .unwrap();
// TODO : more configs // TODO : more configs
print_status("Writing /etc/mkinitcpio.conf");
std::fs::write( std::fs::write(
"/mnt/etc/mkinitcpio.conf", "/mnt/etc/mkinitcpio.conf",
include_str!("../root/mkinitcpio.conf"), include_str!("../root/mkinitcpio.conf"),

View file

@ -1,4 +1,4 @@
use crate::{config::SSHConfig, pkg::install_pkgs}; use crate::{config::SSHConfig, pkg::install_pkgs, print_status};
use std::io::Write; use std::io::Write;
pub fn setup_ssh(conf: &Option<SSHConfig>) { pub fn setup_ssh(conf: &Option<SSHConfig>) {
@ -6,6 +6,7 @@ pub fn setup_ssh(conf: &Option<SSHConfig>) {
install_pkgs(&["openssh"]); install_pkgs(&["openssh"]);
if let Some(sshd_config) = &conf.sshd_config { if let Some(sshd_config) = &conf.sshd_config {
print_status("Writing /etc/ssh/sshd_config");
let content = std::fs::read_to_string(sshd_config).unwrap(); let content = std::fs::read_to_string(sshd_config).unwrap();
std::fs::write("/mnt/etc/ssh/sshd_config", content).unwrap(); std::fs::write("/mnt/etc/ssh/sshd_config", content).unwrap();
} }
@ -26,6 +27,7 @@ pub fn setup_ssh(conf: &Option<SSHConfig>) {
.open(path) .open(path)
.unwrap(); .unwrap();
print_status(&format!("Adding key to authorized_keys for {}", user));
writeln!(authorized_keys, "{}", format!("{}\n", key.key)).unwrap(); writeln!(authorized_keys, "{}", format!("{}\n", key.key)).unwrap();
} }
} }

View file

@ -1,4 +1,4 @@
use crate::{config::UserConfig, run_command}; use crate::{config::UserConfig, print_status, run_command};
use super::str_vec; use super::str_vec;
@ -19,6 +19,7 @@ pub fn setup_users(conf: &[UserConfig]) {
); );
if user.doas_root { if user.doas_root {
print_status(&format!("Allowing root doas for {}", user.name));
doas_conf.push_str(&format!("permit {} as root\n", user.name)); doas_conf.push_str(&format!("permit {} as root\n", user.name));
} }
} }

View file

@ -1,9 +1,10 @@
use crate::{pkg::install_pkgs, run_command}; use crate::{pkg::install_pkgs, print_status, run_command};
use super::str_vec; use super::str_vec;
pub fn setup_zram() { pub fn setup_zram() {
install_pkgs(&["zram-generator"]); install_pkgs(&["zram-generator"]);
print_status("Writing /etc/systemd/zram-generator.conf");
std::fs::write( std::fs::write(
"/mnt/etc/systemd/zram-generator.conf", "/mnt/etc/systemd/zram-generator.conf",
include_str!("../root/zram-generator.conf"), include_str!("../root/zram-generator.conf"),

View file

@ -16,12 +16,16 @@ fn is_root() -> bool {
getuid() == Uid::from_raw(0) getuid() == Uid::from_raw(0)
} }
fn run_command(cmd: &[String], input: Option<&str>, inherit: bool) -> (String, String) { fn print_status(msg: &str) {
println!( println!(
"{} {}", "{} {}",
"-->".paint(Color::Red), "-->".paint(Color::Red),
cmd.join(" ").paint(Color::Blue.bold()) msg.paint(Color::Blue.bold())
); );
}
fn run_command(cmd: &[String], input: Option<&str>, inherit: bool) -> (String, String) {
print_status(&cmd.join(" "));
let mut cmd_setup = std::process::Command::new(cmd[0].clone()); let mut cmd_setup = std::process::Command::new(cmd[0].clone());
let mut cmd_setup = cmd_setup.args(cmd.into_iter().skip(1).collect::<Vec<_>>()); let mut cmd_setup = cmd_setup.args(cmd.into_iter().skip(1).collect::<Vec<_>>());