Add example user creation script and execution logic
parent
9db6b249c3
commit
a1b8750a8e
@ -0,0 +1,9 @@
|
||||
def main [cfg] {
|
||||
$cfg | get users | each {|$it| create_user $it } | ignore
|
||||
}
|
||||
|
||||
def create_user [user] {
|
||||
echo "This would create a user with:"
|
||||
echo $user
|
||||
echo
|
||||
}
|
@ -1,40 +1,29 @@
|
||||
use error::AppResult;
|
||||
use scripting::{
|
||||
loader::ScriptLoader,
|
||||
script::{Script, ScriptArgs},
|
||||
};
|
||||
use scripting::{loader::ScriptLoader, script::JSONArgs};
|
||||
use tasks::{SetupUsersScript, UsersConfig};
|
||||
|
||||
pub mod error;
|
||||
pub(crate) mod scripting;
|
||||
pub mod tasks;
|
||||
pub(crate) mod utils;
|
||||
|
||||
pub struct TestScript;
|
||||
|
||||
impl Script for TestScript {
|
||||
type Args = TestScriptArgs;
|
||||
|
||||
fn get_name() -> &'static str {
|
||||
"test.nu"
|
||||
}
|
||||
pub struct TaskExecutor {
|
||||
loader: ScriptLoader,
|
||||
}
|
||||
|
||||
pub struct TestScriptArgs {
|
||||
pub msg: String,
|
||||
impl TaskExecutor {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
loader: ScriptLoader::new(),
|
||||
}
|
||||
|
||||
impl ScriptArgs for TestScriptArgs {
|
||||
fn get_args(self) -> Vec<String> {
|
||||
vec![self.msg]
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn test_execute() -> AppResult<()> {
|
||||
let loader = ScriptLoader::new();
|
||||
let test_script = loader.load::<TestScript>()?;
|
||||
|
||||
test_script
|
||||
.execute(TestScriptArgs {
|
||||
msg: "'Hello World'".to_string(),
|
||||
})
|
||||
/// Sets up user accounts
|
||||
#[tracing::instrument(level = "debug", skip(self))]
|
||||
pub async fn setup_users(&self, users_cfg: UsersConfig) -> AppResult<()> {
|
||||
self.loader
|
||||
.load::<SetupUsersScript>()?
|
||||
.execute(JSONArgs(users_cfg))
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,28 @@
|
||||
use tourmaline::{
|
||||
tasks::{User, UsersConfig},
|
||||
TaskExecutor,
|
||||
};
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() {
|
||||
color_eyre::install().unwrap();
|
||||
tourmaline::test_execute().await.unwrap();
|
||||
dotenv::dotenv().unwrap();
|
||||
let executor = TaskExecutor::new();
|
||||
let user_cfg = UsersConfig {
|
||||
users: vec![
|
||||
User {
|
||||
name: String::from("test"),
|
||||
password: String::from("password"),
|
||||
sudoer: false,
|
||||
shell: String::from("/bin/zsh"),
|
||||
},
|
||||
User {
|
||||
name: String::from("test2"),
|
||||
password: String::from("superpassword"),
|
||||
sudoer: true,
|
||||
shell: String::from("/bin/nu"),
|
||||
},
|
||||
],
|
||||
};
|
||||
executor.setup_users(user_cfg).await.unwrap();
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
mod configure_locale;
|
||||
mod configure_network;
|
||||
mod create_partitions;
|
||||
mod install_base;
|
||||
mod install_bootloader;
|
||||
mod install_desktop;
|
||||
mod setup_users;
|
||||
|
||||
pub use configure_locale::*;
|
||||
pub use configure_network::*;
|
||||
pub use create_partitions::*;
|
||||
pub use install_base::*;
|
||||
pub use install_bootloader::*;
|
||||
pub use install_desktop::*;
|
||||
pub use setup_users::*;
|
@ -0,0 +1,26 @@
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::scripting::script::{JSONArgs, Script};
|
||||
|
||||
pub struct SetupUsersScript;
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
pub struct UsersConfig {
|
||||
pub users: Vec<User>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
pub struct User {
|
||||
pub name: String,
|
||||
pub password: String,
|
||||
pub sudoer: bool,
|
||||
pub shell: String,
|
||||
}
|
||||
|
||||
impl Script for SetupUsersScript {
|
||||
type Args = JSONArgs<UsersConfig>;
|
||||
|
||||
fn get_name() -> &'static str {
|
||||
"setup-users.nu"
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
use std::path::PathBuf;
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
const CONFIG_DIR: &str = "/etc";
|
||||
const DEFAULT_CONFIG_DIR: &str = "/etc";
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref CFG_PATH: PathBuf = PathBuf::from(CONFIG_DIR).join("tourmaline");
|
||||
pub static ref CFG_PATH: PathBuf = env::var("TRM_CFG_PATH").map(PathBuf::from).unwrap_or_else(|_| PathBuf::from(DEFAULT_CONFIG_DIR).join("tourmaline"));
|
||||
pub static ref SCRIPT_PATH: PathBuf = CFG_PATH.join("scripts");
|
||||
}
|
||||
|
Loading…
Reference in New Issue