diff --git a/src/lib.rs b/src/lib.rs index 9f96576..8f46a85 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ use error::AppResult; -use scripting::loader::ScriptLoader; -use tasks::{SetupUsersScript, UsersConfig}; +use scripting::{loader::ScriptLoader, script::Script}; +use tasks::*; pub mod error; pub(crate) mod scripting; @@ -11,14 +11,31 @@ pub struct TaskExecutor { loader: ScriptLoader, } +macro_rules! tasks { + ($($function:ident => $script:ident),+) => { + $( + #[tracing::instrument(level = "trace", skip(self))] + pub async fn $function(&self, cfg: <$script as crate::scripting::script::Script>::Args) -> AppResult<()> { + self.execute::<$script>(cfg).await + } + )+ + } +} + impl TaskExecutor { - /// Sets up user accounts - #[tracing::instrument(level = "trace", skip(self))] - pub async fn setup_users(&self, users_cfg: UsersConfig) -> AppResult<()> { - self.loader - .load::()? - .execute(users_cfg) - .await + tasks!( + setup_users => SetupUsersScript, + configure_network => ConfigureNetworkScript, + create_partitions => CreatePartitionsScript, + install_base => InstallBaseScript, + install_bootloader => InstallBootloaderScript, + install_desktop => InstallDesktopScript, + configure_local => ConfigureLocaleScript + ); + + #[inline] + async fn execute(&self, args: S::Args) -> AppResult<()> { + self.loader.load::()?.execute(args).await } } diff --git a/src/tasks/configure_locale.rs b/src/tasks/configure_locale.rs index e69de29..bad5362 100644 --- a/src/tasks/configure_locale.rs +++ b/src/tasks/configure_locale.rs @@ -0,0 +1,15 @@ +use serde::Serialize; + +use crate::script; + +script!(ConfigureLocaleScript { + file = "configure-locale.nu" + args = LocaleConfig +}); + +#[derive(Clone, Serialize, Debug)] +pub struct LocaleConfig { + pub locale: Vec, + pub keymap: String, + pub timezone: String, +} diff --git a/src/tasks/configure_network.rs b/src/tasks/configure_network.rs index e69de29..773d398 100644 --- a/src/tasks/configure_network.rs +++ b/src/tasks/configure_network.rs @@ -0,0 +1,14 @@ +use serde::Serialize; + +use crate::script; + +script!(ConfigureNetworkScript { + file = "configure-network.nu" + args = NetworkConfig +}); + +#[derive(Clone, Debug, Serialize)] +pub struct NetworkConfig { + pub hostname: String, + pub ipv6_loopback: bool, +} diff --git a/src/tasks/create_partitions.rs b/src/tasks/create_partitions.rs index e69de29..dfc5bb3 100644 --- a/src/tasks/create_partitions.rs +++ b/src/tasks/create_partitions.rs @@ -0,0 +1,46 @@ +use std::path::PathBuf; + +use serde::Serialize; + +use crate::script; + +script!(CreatePartitionsScript { + file = "create-partitions.nu" + args = PartitionsConfig +}); + +#[derive(Clone, Debug, Serialize)] +pub struct PartitionsConfig { + pub device: PathBuf, + pub efi_partition: bool, + pub partitions: Partitions, +} + +#[derive(Clone, Debug, Serialize)] +pub enum Partitions { + Auto, + Manual(Vec), +} + +#[derive(Clone, Debug, Serialize)] +pub struct Partition { + pub mountpoint: PathBuf, + pub blockdevice: PathBuf, + pub filesystem: Option, +} + +#[derive(Clone, Debug, Serialize)] +pub enum FileSystem { + VFAT, + BFS, + CramFS, + Ext2, + Ext3, + Ext4, + FAT, + MSDOS, + XFS, + BTRFS, + Minix, + F2FS, +} diff --git a/src/tasks/install_base.rs b/src/tasks/install_base.rs index e69de29..7552edc 100644 --- a/src/tasks/install_base.rs +++ b/src/tasks/install_base.rs @@ -0,0 +1,8 @@ +use crate::script; + +script!(InstallBaseScript { + file = "install-base.nu" + args = InstallBaseArgs +}); + +type InstallBaseArgs = (); diff --git a/src/tasks/install_bootloader.rs b/src/tasks/install_bootloader.rs index e69de29..d9ef33f 100644 --- a/src/tasks/install_bootloader.rs +++ b/src/tasks/install_bootloader.rs @@ -0,0 +1,22 @@ +use std::path::PathBuf; + +use serde::Serialize; + +use crate::script; + +script!(InstallBootloaderScript { + file = "install-bootloader.nu" + args = BooloaderConfig +}); + +#[derive(Clone, Debug, Serialize)] +pub struct BooloaderConfig { + preset: BootloaderPreset, + location: PathBuf, +} + +#[derive(Clone, Debug, Serialize)] +pub enum BootloaderPreset { + GrubEfi, + Legacy, +} diff --git a/src/tasks/install_desktop.rs b/src/tasks/install_desktop.rs index e69de29..9c6f07a 100644 --- a/src/tasks/install_desktop.rs +++ b/src/tasks/install_desktop.rs @@ -0,0 +1,26 @@ +use serde::Serialize; + +use crate::script; + +script!(InstallDesktopScript { + file = "install-desktop.nu" + args = DesktopConfig +}); + +#[derive(Clone, Debug, Serialize)] +pub enum DesktopConfig { + Onyx, + KdePlasma, + Mate, + Gnome, + Cinnamon, + Xfce, + Budgie, + Enlightenment, + Lxqt, + Sway, + I3Gaps, + HerbstluftWM, + AwesomeWM, + BSPWM, +}