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
|
||||
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
|
||||
pub general: GeneralConfig,
|
||||
/// 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)]
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
// TODO : Setup users
|
||||
// TODO : Setup ssh (config + authorized_keys)
|
||||
// TODO : Setup virtualization
|
||||
// TODO : Setup docker
|
||||
|
@ -8,8 +7,9 @@
|
|||
// DRIVE SELECTION
|
||||
|
||||
use crate::{
|
||||
config::{DriveConfig, GeneralConfig, InstallConfig, PackageConfig},
|
||||
pkg, pkg::install_pkgs, run_command,
|
||||
config::{DriveConfig, GeneralConfig, InstallConfig, PackageConfig, UserConfig},
|
||||
pkg::{self, install_pkgs},
|
||||
run_command,
|
||||
};
|
||||
|
||||
pub fn str_vec(v: Vec<&str>) -> Vec<String> {
|
||||
|
@ -81,6 +81,7 @@ pub fn pacstrap(conf: &PackageConfig) {
|
|||
"git".into(),
|
||||
"networkmanager".into(),
|
||||
"nano".into(),
|
||||
"doas".into(),
|
||||
];
|
||||
|
||||
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) {
|
||||
// Drive Setup
|
||||
format_drives(&conf.drive, conf.general.encryption);
|
||||
|
@ -323,6 +348,8 @@ pub fn install(conf: InstallConfig) {
|
|||
|
||||
// System Setup
|
||||
first_boot_values(&conf.general);
|
||||
setup_users(&conf.user);
|
||||
|
||||
setup_bootloader();
|
||||
|
||||
match conf.general.mode {
|
||||
|
|
|
@ -11,4 +11,4 @@ pub fn install_pkgs(pkg: &[&str]) {
|
|||
cmd.extend_from_slice(pkg);
|
||||
|
||||
run_command(&str_vec(cmd), None, true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue