refactor
This commit is contained in:
parent
753f53d4da
commit
227b97b27f
6 changed files with 87 additions and 63 deletions
29
src/install/desktop.rs
Normal file
29
src/install/desktop.rs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
use crate::{
|
||||||
|
config::InstallConfig,
|
||||||
|
linux::install_file,
|
||||||
|
pkg::{self, install_pkgs},
|
||||||
|
print_status,
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::navos::setup_navos;
|
||||||
|
|
||||||
|
pub fn setup_desktop(conf: &InstallConfig) {
|
||||||
|
setup_navos();
|
||||||
|
install_pkgs(&pkg::DESKTOP_PKG);
|
||||||
|
print_status("Enable SDDM");
|
||||||
|
print_status("Set keyboard layout for SDDM");
|
||||||
|
install_file(
|
||||||
|
"/mnt/usr/share/sddm/scripts/Xsetup",
|
||||||
|
&format!(
|
||||||
|
"#!/bin/sh\n# Xsetup\nsetxkbmap {},us\n",
|
||||||
|
conf.general.keyboard_layout
|
||||||
|
),
|
||||||
|
0o644,
|
||||||
|
);
|
||||||
|
|
||||||
|
std::os::unix::fs::symlink(
|
||||||
|
"/usr/lib/systemd/system/sddm.service",
|
||||||
|
"/mnt/etc/systemd/system/display-manager.service",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
|
@ -4,6 +4,7 @@
|
||||||
// DRIVE SELECTION
|
// DRIVE SELECTION
|
||||||
|
|
||||||
use boot::setup_bootloader;
|
use boot::setup_bootloader;
|
||||||
|
use desktop::setup_desktop;
|
||||||
use docker::setup_docker;
|
use docker::setup_docker;
|
||||||
use drives::{format_drives, mount_drives};
|
use drives::{format_drives, mount_drives};
|
||||||
use first_boot::{first_boot_values, genfstab};
|
use first_boot::{first_boot_values, genfstab};
|
||||||
|
@ -14,10 +15,12 @@ use security::{setup_secure_boot, setup_tpm_unlock};
|
||||||
use skel::setup_skel;
|
use skel::setup_skel;
|
||||||
use ssh::setup_ssh;
|
use ssh::setup_ssh;
|
||||||
use user::setup_users;
|
use user::setup_users;
|
||||||
|
use virt::setup_virtualization;
|
||||||
use yansi::{Color, Paint};
|
use yansi::{Color, Paint};
|
||||||
use zram::setup_zram;
|
use zram::setup_zram;
|
||||||
|
|
||||||
pub mod boot;
|
pub mod boot;
|
||||||
|
pub mod desktop;
|
||||||
pub mod docker;
|
pub mod docker;
|
||||||
pub mod drives;
|
pub mod drives;
|
||||||
pub mod first_boot;
|
pub mod first_boot;
|
||||||
|
@ -28,13 +31,12 @@ pub mod security;
|
||||||
pub mod skel;
|
pub mod skel;
|
||||||
pub mod ssh;
|
pub mod ssh;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
pub mod virt;
|
||||||
pub mod zram;
|
pub mod zram;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{InstallConfig, InstallMode},
|
config::InstallConfig,
|
||||||
linux::{arch_chroot, install_file, systemd_service_enable},
|
|
||||||
pkg::{self, install_pkgs, pacstrap},
|
pkg::{self, install_pkgs, pacstrap},
|
||||||
print_status,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn uncomment_first_value_of(value: &str, file: &str) {
|
pub fn uncomment_first_value_of(value: &str, file: &str) {
|
||||||
|
@ -91,31 +93,14 @@ pub fn install(conf: InstallConfig) {
|
||||||
setup_skel(&conf.general);
|
setup_skel(&conf.general);
|
||||||
setup_users(&conf.user.as_ref().unwrap_or(&Vec::new()));
|
setup_users(&conf.user.as_ref().unwrap_or(&Vec::new()));
|
||||||
|
|
||||||
setup_ssh(conf.ssh);
|
setup_ssh(&conf.ssh);
|
||||||
|
|
||||||
setup_bootloader();
|
setup_bootloader();
|
||||||
|
|
||||||
match conf.general.mode {
|
match conf.general.mode {
|
||||||
crate::config::InstallMode::Base => {}
|
crate::config::InstallMode::Base => {}
|
||||||
crate::config::InstallMode::Desktop => {
|
crate::config::InstallMode::Desktop => {
|
||||||
setup_navos();
|
setup_desktop(&conf);
|
||||||
install_pkgs(&pkg::DESKTOP_PKG);
|
|
||||||
print_status("Enable SDDM");
|
|
||||||
print_status("Set keyboard layout for SDDM");
|
|
||||||
install_file(
|
|
||||||
"/mnt/usr/share/sddm/scripts/Xsetup",
|
|
||||||
&format!(
|
|
||||||
"#!/bin/sh\n# Xsetup\nsetxkbmap {},us\n",
|
|
||||||
conf.general.keyboard_layout
|
|
||||||
),
|
|
||||||
0o644,
|
|
||||||
);
|
|
||||||
|
|
||||||
std::os::unix::fs::symlink(
|
|
||||||
"/usr/lib/systemd/system/sddm.service",
|
|
||||||
"/mnt/etc/systemd/system/display-manager.service",
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
crate::config::InstallMode::Server => {
|
crate::config::InstallMode::Server => {
|
||||||
setup_navos();
|
setup_navos();
|
||||||
|
@ -127,29 +112,7 @@ pub fn install(conf: InstallConfig) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.pkg.virtualization.unwrap_or_default() {
|
if conf.pkg.virtualization.unwrap_or_default() {
|
||||||
let user_conf = if let Some(user_conf) = &conf.user {
|
setup_virtualization(&conf);
|
||||||
user_conf.clone()
|
|
||||||
} else {
|
|
||||||
Vec::new()
|
|
||||||
};
|
|
||||||
|
|
||||||
install_pkgs(&["libvirt"]);
|
|
||||||
|
|
||||||
if matches!(conf.general.mode, InstallMode::Desktop) {
|
|
||||||
install_pkgs(&["virt-manager"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
systemd_service_enable("libvirtd.service");
|
|
||||||
|
|
||||||
for user in user_conf {
|
|
||||||
if user.virtualization.unwrap_or_default() {
|
|
||||||
arch_chroot(
|
|
||||||
&vec!["usermod", "-a", "-G", "libvirt", user.name.as_str()],
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.pkg.docker.unwrap_or_default() {
|
if conf.pkg.docker.unwrap_or_default() {
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::io::Write;
|
||||||
/// Setup SSH on the system
|
/// Setup SSH on the system
|
||||||
///
|
///
|
||||||
/// This should be done after `setup_users()` to ensure that the users directories exist.
|
/// This should be done after `setup_users()` to ensure that the users directories exist.
|
||||||
pub fn setup_ssh(conf: Option<SSHConfig>) {
|
pub fn setup_ssh(conf: &Option<SSHConfig>) {
|
||||||
if let Some(conf) = conf {
|
if let Some(conf) = conf {
|
||||||
install_pkgs(&["openssh"]);
|
install_pkgs(&["openssh"]);
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ pub fn setup_ssh(conf: Option<SSHConfig>) {
|
||||||
install_file("/mnt/etc/ssh/sshd_config", &content, 0o644);
|
install_file("/mnt/etc/ssh/sshd_config", &content, 0o644);
|
||||||
}
|
}
|
||||||
|
|
||||||
for key in &conf.key.unwrap_or_default() {
|
for key in conf.key.as_ref().unwrap_or(&Vec::new()) {
|
||||||
for user in &key.users {
|
for user in &key.users {
|
||||||
let path = if user == "root" {
|
let path = if user == "root" {
|
||||||
std::fs::create_dir_all("/root/.ssh").unwrap();
|
std::fs::create_dir_all("/root/.ssh").unwrap();
|
||||||
|
|
31
src/install/virt.rs
Normal file
31
src/install/virt.rs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
use crate::{
|
||||||
|
config::{InstallConfig, InstallMode},
|
||||||
|
linux::{arch_chroot, systemd_service_enable},
|
||||||
|
pkg::install_pkgs,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn setup_virtualization(conf: &InstallConfig) {
|
||||||
|
let user_conf = if let Some(user_conf) = &conf.user {
|
||||||
|
user_conf.clone()
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
};
|
||||||
|
|
||||||
|
install_pkgs(&["libvirt"]);
|
||||||
|
|
||||||
|
if matches!(conf.general.mode, InstallMode::Desktop) {
|
||||||
|
install_pkgs(&["virt-manager"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
systemd_service_enable("libvirtd.service");
|
||||||
|
|
||||||
|
for user in user_conf {
|
||||||
|
if user.virtualization.unwrap_or_default() {
|
||||||
|
arch_chroot(
|
||||||
|
&vec!["usermod", "-a", "-G", "libvirt", user.name.as_str()],
|
||||||
|
None,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -75,6 +75,7 @@ pub fn install_file(path: &str, content: &str, permissions: u32) {
|
||||||
file.write_all(content.as_bytes()).unwrap();
|
file.write_all(content.as_bytes()).unwrap();
|
||||||
|
|
||||||
let permissions = std::fs::Permissions::from_mode(permissions);
|
let permissions = std::fs::Permissions::from_mode(permissions);
|
||||||
|
// TODO : Fix permission format
|
||||||
print_status(&format!("Wrote file {path} [{permissions:#?}]"));
|
print_status(&format!("Wrote file {path} [{permissions:#?}]"));
|
||||||
std::fs::set_permissions(path, permissions).unwrap();
|
std::fs::set_permissions(path, permissions).unwrap();
|
||||||
}
|
}
|
||||||
|
|
32
src/main.rs
32
src/main.rs
|
@ -97,20 +97,20 @@ pub fn read_conf(config_file: &str) -> InstallConfig {
|
||||||
let config_content = std::fs::read_to_string(config_file);
|
let config_content = std::fs::read_to_string(config_file);
|
||||||
|
|
||||||
match config_content {
|
match config_content {
|
||||||
Ok(content) => match toml::from_str(&content) {
|
Ok(content) => match toml::from_str(&content) {
|
||||||
Ok(config) => config,
|
Ok(config) => config,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
"Error: Could not deserialize TOML file.".paint(Color::Red),
|
"Error: Could not deserialize TOML file.".paint(Color::Red),
|
||||||
e.paint(Color::Red)
|
e.paint(Color::Red)
|
||||||
);
|
);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(_) => {
|
|
||||||
eprintln!("{}", "Error: Could not read config file.".paint(Color::Red));
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
Err(_) => {
|
||||||
|
eprintln!("{}", "Error: Could not read config file.".paint(Color::Red));
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue