Compare commits

..

2 commits

Author SHA1 Message Date
eabd898ccf
Added user configuration support to installer 2024-12-28 00:41:57 +01:00
73a30e4576
update 2024-12-28 00:33:50 +01:00
4 changed files with 95 additions and 46 deletions

View file

@ -6,16 +6,41 @@ root = "/dev/null"
[general] [general]
# Use LUKS encryption on root drive # Use LUKS encryption on root drive
encryption = true encryption = true
# Preset # Preset
mode = "Desktop" mode = "Desktop"
# System Locale # System Locale
locale = "de_DE.UTF-8" locale = "de_DE.UTF-8"
# Keymap
keymap = "de-latin1"
# Timezone
timezone = "Europe/Berlin"
# Hostname
hostname = "navos"
[pkg]
# Additional packages # Additional packages
pkg = [ pkg = [
"nano", "nano",
"micro" "micro"
] ]
# Enable virtualization # Enable virtualization
virtualization = true virtualization = true
# Enable docker # Enable docker
docker = true docker = true
[[user]]
# Username
name = "testuser"
# User password
password = "testpass"
# Allow user to use doas as root
doas_root= true

View file

@ -7,6 +7,27 @@ pub struct InstallConfig {
pub drive: DriveConfig, pub drive: DriveConfig,
/// General Configuration /// General Configuration
pub general: GeneralConfig, pub general: GeneralConfig,
/// Package Configuration
pub pkg: PackageConfig,
/// User Configuration
pub user: Vec<UserConfig>,
}
#[derive(Debug, Deserialize)]
pub struct UserConfig {
pub name: String,
pub password: String,
pub doas_root: bool,
}
#[derive(Debug, Deserialize)]
pub struct PackageConfig {
/// Packages to install
pub pkg: Vec<String>,
/// Enable libvirt
pub virtualization: bool,
/// Enable docker
pub docker: bool,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
@ -31,12 +52,6 @@ pub struct GeneralConfig {
pub timezone: String, pub timezone: String,
/// Hostname /// Hostname
pub hostname: String, pub hostname: String,
/// Packages to install
pub pkg: Vec<String>,
/// Enable libvirt
pub virtualization: bool,
/// Enable docker
pub docker: bool,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]

View file

@ -1,13 +1,15 @@
// TODO : Setup users
// TODO : Setup ssh (config + authorized_keys) // TODO : Setup ssh (config + authorized_keys)
// TODO : Setup virtualization // TODO : Setup virtualization
// TODO : Setup docker // TODO : Setup docker
// TODO : Autojoin docker swarm
// TODO : Autojoin teleport
// DRIVE SELECTION // DRIVE SELECTION
use crate::{ use crate::{
config::{DriveConfig, GeneralConfig, InstallConfig}, config::{DriveConfig, GeneralConfig, InstallConfig, PackageConfig, UserConfig},
pkg, run_command, pkg::{self, install_pkgs},
run_command,
}; };
pub fn str_vec(v: Vec<&str>) -> Vec<String> { pub fn str_vec(v: Vec<&str>) -> Vec<String> {
@ -67,7 +69,7 @@ pub fn mount_drives(conf: &DriveConfig, encrypted: bool) {
// PACSTRAP // PACSTRAP
pub fn pacstrap(conf: &GeneralConfig) { pub fn pacstrap(conf: &PackageConfig) {
let mut cmd: Vec<String> = vec![ let mut cmd: Vec<String> = vec![
"pacstrap".into(), "pacstrap".into(),
"-K".into(), "-K".into(),
@ -79,6 +81,7 @@ pub fn pacstrap(conf: &GeneralConfig) {
"git".into(), "git".into(),
"networkmanager".into(), "networkmanager".into(),
"nano".into(), "nano".into(),
"doas".into(),
]; ];
cmd.extend(conf.pkg.clone()); cmd.extend(conf.pkg.clone());
@ -157,18 +160,7 @@ pub fn uncomment_first_value_of(value: &str, file: &str) {
} }
pub fn setup_zram() { pub fn setup_zram() {
run_command( install_pkgs(&["zram-generator"]);
&str_vec(vec![
"arch-chroot",
"/mnt",
"pacman",
"-Syu",
"--noconfirm",
"zram-generator",
]),
None,
false,
);
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"),
@ -282,18 +274,7 @@ pub fn setup_secure_boot() {
// TPM Unlock // TPM Unlock
pub fn setup_tpm_unlock(conf: &DriveConfig) { pub fn setup_tpm_unlock(conf: &DriveConfig) {
run_command( install_pkgs(&["tpm2-tools"]);
&str_vec(vec![
"arch-chroot",
"/mnt",
"pacman",
"-Syu",
"--noconfirm",
"tpm2-tools",
]),
None,
false,
);
// systemd-cryptenroll --tpm2-device=list // systemd-cryptenroll --tpm2-device=list
@ -324,15 +305,6 @@ pub fn setup_tpm_unlock(conf: &DriveConfig) {
); );
} }
pub fn install_pkgs(pkg: &[&str]) {
let mut cmd = vec!["arch-chroot", "/mnt", "pacman", "-Syu"];
cmd.extend_from_slice(pkg);
cmd.push("--noconfirm");
run_command(&str_vec(cmd), None, true);
}
pub fn setup_bootloader() { pub fn setup_bootloader() {
run_command( run_command(
&str_vec(vec!["arch-chroot", "/mnt", "bootctl", "install"]), &str_vec(vec!["arch-chroot", "/mnt", "bootctl", "install"]),
@ -341,17 +313,43 @@ pub fn setup_bootloader() {
); );
} }
pub fn setup_users(conf: &[UserConfig]) {
let mut doas_conf = String::new();
for user in conf {
run_command(
&str_vec(vec!["arch-chroot", "/mnt", "useradd", "-m", &user.name]),
None,
false,
);
run_command(
&str_vec(vec!["arch-chroot", "/mnt", "passwd", &user.name]),
Some(&format!("{}\n{}\n", user.password, user.password)),
false,
);
if user.doas_root {
doas_conf.push_str(&format!("permit {} as root\n", user.name));
}
}
std::fs::write("/mnt/etc/doas.conf", doas_conf).unwrap();
}
pub fn install(conf: InstallConfig) { pub fn install(conf: InstallConfig) {
// Drive Setup // Drive Setup
format_drives(&conf.drive, conf.general.encryption); format_drives(&conf.drive, conf.general.encryption);
mount_drives(&conf.drive, conf.general.encryption); mount_drives(&conf.drive, conf.general.encryption);
// Base Install // Base Install
pacstrap(&conf.general); pacstrap(&conf.pkg);
genfstab(); genfstab();
// System Setup // System Setup
first_boot_values(&conf.general); first_boot_values(&conf.general);
setup_users(&conf.user);
setup_bootloader(); setup_bootloader();
match conf.general.mode { match conf.general.mode {
@ -367,11 +365,11 @@ pub fn install(conf: InstallConfig) {
} }
} }
if conf.general.virtualization { if conf.pkg.virtualization {
// TODO : Enable virtualization // TODO : Enable virtualization
} }
if conf.general.docker { if conf.pkg.docker {
// TODO : Enable docker // TODO : Enable docker
} }

View file

@ -1,3 +1,14 @@
use crate::{install::str_vec, run_command};
pub const DESKTOP_PKG: [&str; 2] = ["plasma", "sddm"]; pub const DESKTOP_PKG: [&str; 2] = ["plasma", "sddm"];
pub const SERVER_PKG: [&str; 1] = ["tmux"]; pub const SERVER_PKG: [&str; 1] = ["tmux"];
pub fn install_pkgs(pkg: &[&str]) {
let mut cmd = vec!["arch-chroot", "/mnt", "pacman", "-Syu"];
cmd.push("--noconfirm");
cmd.extend_from_slice(pkg);
run_command(&str_vec(cmd), None, true);
}