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
|
||||
|
||||
use boot::setup_bootloader;
|
||||
use desktop::setup_desktop;
|
||||
use docker::setup_docker;
|
||||
use drives::{format_drives, mount_drives};
|
||||
use first_boot::{first_boot_values, genfstab};
|
||||
|
@ -14,10 +15,12 @@ use security::{setup_secure_boot, setup_tpm_unlock};
|
|||
use skel::setup_skel;
|
||||
use ssh::setup_ssh;
|
||||
use user::setup_users;
|
||||
use virt::setup_virtualization;
|
||||
use yansi::{Color, Paint};
|
||||
use zram::setup_zram;
|
||||
|
||||
pub mod boot;
|
||||
pub mod desktop;
|
||||
pub mod docker;
|
||||
pub mod drives;
|
||||
pub mod first_boot;
|
||||
|
@ -28,13 +31,12 @@ pub mod security;
|
|||
pub mod skel;
|
||||
pub mod ssh;
|
||||
pub mod user;
|
||||
pub mod virt;
|
||||
pub mod zram;
|
||||
|
||||
use crate::{
|
||||
config::{InstallConfig, InstallMode},
|
||||
linux::{arch_chroot, install_file, systemd_service_enable},
|
||||
config::InstallConfig,
|
||||
pkg::{self, install_pkgs, pacstrap},
|
||||
print_status,
|
||||
};
|
||||
|
||||
pub fn uncomment_first_value_of(value: &str, file: &str) {
|
||||
|
@ -91,31 +93,14 @@ pub fn install(conf: InstallConfig) {
|
|||
setup_skel(&conf.general);
|
||||
setup_users(&conf.user.as_ref().unwrap_or(&Vec::new()));
|
||||
|
||||
setup_ssh(conf.ssh);
|
||||
setup_ssh(&conf.ssh);
|
||||
|
||||
setup_bootloader();
|
||||
|
||||
match conf.general.mode {
|
||||
crate::config::InstallMode::Base => {}
|
||||
crate::config::InstallMode::Desktop => {
|
||||
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();
|
||||
setup_desktop(&conf);
|
||||
}
|
||||
crate::config::InstallMode::Server => {
|
||||
setup_navos();
|
||||
|
@ -127,29 +112,7 @@ pub fn install(conf: InstallConfig) {
|
|||
}
|
||||
|
||||
if conf.pkg.virtualization.unwrap_or_default() {
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
setup_virtualization(&conf);
|
||||
}
|
||||
|
||||
if conf.pkg.docker.unwrap_or_default() {
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::io::Write;
|
|||
/// Setup SSH on the system
|
||||
///
|
||||
/// 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 {
|
||||
install_pkgs(&["openssh"]);
|
||||
|
||||
|
@ -14,7 +14,7 @@ pub fn setup_ssh(conf: Option<SSHConfig>) {
|
|||
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 {
|
||||
let path = if user == "root" {
|
||||
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();
|
||||
|
||||
let permissions = std::fs::Permissions::from_mode(permissions);
|
||||
// TODO : Fix permission format
|
||||
print_status(&format!("Wrote file {path} [{permissions:#?}]"));
|
||||
std::fs::set_permissions(path, permissions).unwrap();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue