This commit is contained in:
parent
c689ee87d4
commit
633a0ef410
6 changed files with 65 additions and 15 deletions
|
@ -58,6 +58,9 @@ password = "testpass"
|
|||
# Allow user to use `doas` as root
|
||||
doas_root= true
|
||||
|
||||
# Add user to Docker group
|
||||
docker = true
|
||||
|
||||
# SSH Configuration
|
||||
# If `[ssh]` is set, openssh will be installed and enabled.
|
||||
[ssh]
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::fmt::Display;
|
|||
use serde::Deserialize;
|
||||
|
||||
/// Declarative install configuration
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct InstallConfig {
|
||||
/// Drive Configuration
|
||||
pub drive: DriveConfig,
|
||||
|
@ -19,32 +19,33 @@ pub struct InstallConfig {
|
|||
pub ai: Option<OllamaConfig>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct OllamaConfig {
|
||||
pub models: Option<Vec<String>>,
|
||||
pub gpu: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct SSHConfig {
|
||||
pub sshd_config: Option<String>,
|
||||
pub key: Option<Vec<SSHKey>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct SSHKey {
|
||||
pub key: String,
|
||||
pub users: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct UserConfig {
|
||||
pub name: String,
|
||||
pub password: String,
|
||||
pub doas_root: bool,
|
||||
pub doas_root: Option<bool>,
|
||||
pub docker: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct PackageConfig {
|
||||
/// Packages to install
|
||||
pub pkg: Vec<String>,
|
||||
|
@ -54,7 +55,7 @@ pub struct PackageConfig {
|
|||
pub docker: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct DriveConfig {
|
||||
/// Boot Drive Path
|
||||
pub boot: String,
|
||||
|
@ -64,7 +65,7 @@ pub struct DriveConfig {
|
|||
pub encryption: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct GeneralConfig {
|
||||
/// Presets
|
||||
pub mode: InstallMode,
|
||||
|
@ -82,7 +83,7 @@ pub struct GeneralConfig {
|
|||
pub root_password: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub enum InstallMode {
|
||||
/// Basic Arch Linux Installation
|
||||
Base,
|
||||
|
|
24
src/install/docker.rs
Normal file
24
src/install/docker.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use crate::{
|
||||
config::UserConfig,
|
||||
linux::{arch_chroot, systemd_service_enable},
|
||||
pkg::install_pkgs,
|
||||
print_status,
|
||||
};
|
||||
|
||||
/// Setup docker on the system
|
||||
pub fn setup_docker(conf: &[UserConfig]) {
|
||||
print_status("Setting up Docker");
|
||||
install_pkgs(&["docker", "docker-compose"]);
|
||||
|
||||
systemd_service_enable("docker.service");
|
||||
|
||||
for user in conf {
|
||||
if user.docker.unwrap_or_default() {
|
||||
arch_chroot(
|
||||
&vec!["usermod", "-a", "-G", "docker", user.name.as_str()],
|
||||
None,
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
// DRIVE SELECTION
|
||||
|
||||
use boot::setup_bootloader;
|
||||
use docker::setup_docker;
|
||||
use drives::{format_drives, mount_drives};
|
||||
use first_boot::{first_boot_values, genfstab};
|
||||
use kernel::setup_mkinitcpio;
|
||||
|
@ -17,6 +18,7 @@ use yansi::{Color, Paint};
|
|||
use zram::setup_zram;
|
||||
|
||||
pub mod boot;
|
||||
pub mod docker;
|
||||
pub mod drives;
|
||||
pub mod first_boot;
|
||||
pub mod kernel;
|
||||
|
@ -85,7 +87,7 @@ pub fn install(conf: InstallConfig) {
|
|||
// System Setup
|
||||
first_boot_values(&conf.general);
|
||||
setup_skel(&conf.general);
|
||||
setup_users(&conf.user.unwrap_or_default());
|
||||
setup_users(&conf.user.as_ref().unwrap_or(&Vec::new()));
|
||||
|
||||
setup_ssh(conf.ssh);
|
||||
|
||||
|
@ -118,7 +120,13 @@ pub fn install(conf: InstallConfig) {
|
|||
}
|
||||
|
||||
if conf.pkg.docker.unwrap_or_default() {
|
||||
// TODO : Enable docker
|
||||
let user_conf = if let Some(user_conf) = &conf.user {
|
||||
user_conf.clone()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
setup_docker(&user_conf);
|
||||
}
|
||||
|
||||
if let Some(ai) = conf.ai {
|
||||
|
|
|
@ -17,7 +17,7 @@ pub fn setup_users(conf: &[UserConfig]) {
|
|||
|
||||
change_passwd(&user.name, &user.password);
|
||||
|
||||
if user.doas_root {
|
||||
if user.doas_root.unwrap_or_default() {
|
||||
print_status(&format!("Allowing root doas for {}", user.name));
|
||||
doas_conf.push_str(&format!("permit {} as root\n", user.name));
|
||||
}
|
||||
|
|
16
src/print.rs
16
src/print.rs
|
@ -92,10 +92,24 @@ pub fn print_config(conf: &InstallConfig) {
|
|||
let user_conf = conf.user.as_ref().unwrap_or(&empty);
|
||||
|
||||
for user in user_conf {
|
||||
let mut groups = Vec::new();
|
||||
|
||||
if user.doas_root.unwrap_or_default() {
|
||||
groups.push("🔑");
|
||||
}
|
||||
|
||||
if user.docker.unwrap_or_default() {
|
||||
groups.push("🐋");
|
||||
}
|
||||
|
||||
users_info.add_str(format!(
|
||||
"👤 {}{}",
|
||||
user.name,
|
||||
if user.doas_root { "🔑" } else { "" }
|
||||
if !groups.is_empty() {
|
||||
format!(" [ {} ]", groups.join(" "))
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue