Add script definitions for all base tasks

Signed-off-by: trivernis <trivernis@protonmail.com>
integration-not-installation
trivernis 2 years ago
parent 2b6e663f54
commit 662d3f749c
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,6 +1,6 @@
use error::AppResult; use error::AppResult;
use scripting::loader::ScriptLoader; use scripting::{loader::ScriptLoader, script::Script};
use tasks::{SetupUsersScript, UsersConfig}; use tasks::*;
pub mod error; pub mod error;
pub(crate) mod scripting; pub(crate) mod scripting;
@ -11,14 +11,31 @@ pub struct TaskExecutor {
loader: ScriptLoader, loader: ScriptLoader,
} }
impl TaskExecutor { macro_rules! tasks {
/// Sets up user accounts ($($function:ident => $script:ident),+) => {
$(
#[tracing::instrument(level = "trace", skip(self))] #[tracing::instrument(level = "trace", skip(self))]
pub async fn setup_users(&self, users_cfg: UsersConfig) -> AppResult<()> { pub async fn $function(&self, cfg: <$script as crate::scripting::script::Script>::Args) -> AppResult<()> {
self.loader self.execute::<$script>(cfg).await
.load::<SetupUsersScript>()? }
.execute(users_cfg) )+
.await }
}
impl TaskExecutor {
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<S: Script>(&self, args: S::Args) -> AppResult<()> {
self.loader.load::<S>()?.execute(args).await
} }
} }

@ -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<String>,
pub keymap: String,
pub timezone: String,
}

@ -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,
}

@ -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<Partition>),
}
#[derive(Clone, Debug, Serialize)]
pub struct Partition {
pub mountpoint: PathBuf,
pub blockdevice: PathBuf,
pub filesystem: Option<FileSystem>,
}
#[derive(Clone, Debug, Serialize)]
pub enum FileSystem {
VFAT,
BFS,
CramFS,
Ext2,
Ext3,
Ext4,
FAT,
MSDOS,
XFS,
BTRFS,
Minix,
F2FS,
}

@ -0,0 +1,8 @@
use crate::script;
script!(InstallBaseScript {
file = "install-base.nu"
args = InstallBaseArgs
});
type InstallBaseArgs = ();

@ -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,
}

@ -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,
}
Loading…
Cancel
Save