Added user configuration support to installer
This commit is contained in:
parent
73a30e4576
commit
eabd898ccf
4 changed files with 51 additions and 5 deletions
|
@ -34,3 +34,13 @@ 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
|
||||||
|
|
|
@ -8,7 +8,16 @@ pub struct InstallConfig {
|
||||||
/// General Configuration
|
/// General Configuration
|
||||||
pub general: GeneralConfig,
|
pub general: GeneralConfig,
|
||||||
/// Package Configuration
|
/// Package Configuration
|
||||||
pub pkg: PackageConfig
|
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)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
// 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
|
||||||
|
@ -8,8 +7,9 @@
|
||||||
// DRIVE SELECTION
|
// DRIVE SELECTION
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{DriveConfig, GeneralConfig, InstallConfig, PackageConfig},
|
config::{DriveConfig, GeneralConfig, InstallConfig, PackageConfig, UserConfig},
|
||||||
pkg, pkg::install_pkgs, 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> {
|
||||||
|
@ -81,6 +81,7 @@ pub fn pacstrap(conf: &PackageConfig) {
|
||||||
"git".into(),
|
"git".into(),
|
||||||
"networkmanager".into(),
|
"networkmanager".into(),
|
||||||
"nano".into(),
|
"nano".into(),
|
||||||
|
"doas".into(),
|
||||||
];
|
];
|
||||||
|
|
||||||
cmd.extend(conf.pkg.clone());
|
cmd.extend(conf.pkg.clone());
|
||||||
|
@ -312,6 +313,30 @@ 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);
|
||||||
|
@ -323,6 +348,8 @@ pub fn install(conf: InstallConfig) {
|
||||||
|
|
||||||
// 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 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue