From fae57a7e3f24e0bebcdc824ff1427643d538117c Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 1 Oct 2022 11:56:49 +0200 Subject: [PATCH] Add function to generate script files (and generate them) --- .../crystal/hooks/configure-locale.post.nu | 6 ++ configs/crystal/hooks/configure-locale.pre.nu | 6 ++ .../crystal/hooks/configure-network.post.nu | 6 ++ .../crystal/hooks/configure-network.pre.nu | 6 ++ .../crystal/hooks/configure-unakite.post.nu | 6 ++ .../crystal/hooks/configure-unakite.pre.nu | 6 ++ .../crystal/hooks/create-partitions.post.nu | 6 ++ .../crystal/hooks/create-partitions.pre.nu | 6 ++ configs/crystal/hooks/install-base.post.nu | 6 ++ configs/crystal/hooks/install-base.pre.nu | 6 ++ .../crystal/hooks/install-bootloader.post.nu | 6 ++ .../crystal/hooks/install-bootloader.pre.nu | 6 ++ configs/crystal/hooks/install-desktop.post.nu | 6 ++ configs/crystal/hooks/install-desktop.pre.nu | 6 ++ .../hooks/install-extra-packages.post.nu | 6 ++ .../hooks/install-extra-packages.pre.nu | 6 ++ configs/crystal/hooks/install-flatpak.post.nu | 6 ++ configs/crystal/hooks/install-flatpak.pre.nu | 6 ++ configs/crystal/hooks/install-kernels.post.nu | 6 ++ configs/crystal/hooks/install-kernels.pre.nu | 6 ++ .../crystal/hooks/install-timeshift.post.nu | 6 ++ .../crystal/hooks/install-timeshift.pre.nu | 6 ++ configs/crystal/hooks/install-zramd.post.nu | 6 ++ configs/crystal/hooks/install-zramd.pre.nu | 6 ++ configs/crystal/hooks/setup-root-user.post.nu | 6 ++ configs/crystal/hooks/setup-root-user.pre.nu | 6 ++ configs/crystal/hooks/setup-users.post.nu | 9 +-- configs/crystal/hooks/setup-users.pre.nu | 8 ++- configs/crystal/scripts/configure-locale.nu | 5 ++ configs/crystal/scripts/configure-network.nu | 5 ++ configs/crystal/scripts/configure-unakite.nu | 5 ++ configs/crystal/scripts/create-partitions.nu | 5 ++ configs/crystal/scripts/install-base.nu | 5 ++ configs/crystal/scripts/install-bootloader.nu | 5 ++ configs/crystal/scripts/install-desktop.nu | 5 ++ .../crystal/scripts/install-extra-packages.nu | 5 ++ configs/crystal/scripts/install-flatpak.nu | 5 ++ configs/crystal/scripts/install-kernels.nu | 5 ++ configs/crystal/scripts/install-timeshift.nu | 5 ++ configs/crystal/scripts/install-zramd.nu | 5 ++ configs/crystal/scripts/setup-root-user.nu | 5 ++ configs/crystal/scripts/setup-users.nu | 10 +--- src/error.rs | 5 +- src/lib.rs | 1 + src/tasks/mod.rs | 60 +++++++++++++++++++ src/utils.rs | 48 +++++++++++++++ 46 files changed, 347 insertions(+), 15 deletions(-) create mode 100644 configs/crystal/hooks/configure-locale.post.nu create mode 100644 configs/crystal/hooks/configure-locale.pre.nu create mode 100644 configs/crystal/hooks/configure-network.post.nu create mode 100644 configs/crystal/hooks/configure-network.pre.nu create mode 100644 configs/crystal/hooks/configure-unakite.post.nu create mode 100644 configs/crystal/hooks/configure-unakite.pre.nu create mode 100644 configs/crystal/hooks/create-partitions.post.nu create mode 100644 configs/crystal/hooks/create-partitions.pre.nu create mode 100644 configs/crystal/hooks/install-base.post.nu create mode 100644 configs/crystal/hooks/install-base.pre.nu create mode 100644 configs/crystal/hooks/install-bootloader.post.nu create mode 100644 configs/crystal/hooks/install-bootloader.pre.nu create mode 100644 configs/crystal/hooks/install-desktop.post.nu create mode 100644 configs/crystal/hooks/install-desktop.pre.nu create mode 100644 configs/crystal/hooks/install-extra-packages.post.nu create mode 100644 configs/crystal/hooks/install-extra-packages.pre.nu create mode 100644 configs/crystal/hooks/install-flatpak.post.nu create mode 100644 configs/crystal/hooks/install-flatpak.pre.nu create mode 100644 configs/crystal/hooks/install-kernels.post.nu create mode 100644 configs/crystal/hooks/install-kernels.pre.nu create mode 100644 configs/crystal/hooks/install-timeshift.post.nu create mode 100644 configs/crystal/hooks/install-timeshift.pre.nu create mode 100644 configs/crystal/hooks/install-zramd.post.nu create mode 100644 configs/crystal/hooks/install-zramd.pre.nu create mode 100644 configs/crystal/hooks/setup-root-user.post.nu create mode 100644 configs/crystal/hooks/setup-root-user.pre.nu create mode 100644 configs/crystal/scripts/configure-locale.nu create mode 100644 configs/crystal/scripts/configure-network.nu create mode 100644 configs/crystal/scripts/configure-unakite.nu create mode 100644 configs/crystal/scripts/create-partitions.nu create mode 100644 configs/crystal/scripts/install-base.nu create mode 100644 configs/crystal/scripts/install-bootloader.nu create mode 100644 configs/crystal/scripts/install-desktop.nu create mode 100644 configs/crystal/scripts/install-extra-packages.nu create mode 100644 configs/crystal/scripts/install-flatpak.nu create mode 100644 configs/crystal/scripts/install-kernels.nu create mode 100644 configs/crystal/scripts/install-timeshift.nu create mode 100644 configs/crystal/scripts/install-zramd.nu create mode 100644 configs/crystal/scripts/setup-root-user.nu diff --git a/configs/crystal/hooks/configure-locale.post.nu b/configs/crystal/hooks/configure-locale.post.nu new file mode 100644 index 0000000..998c816 --- /dev/null +++ b/configs/crystal/hooks/configure-locale.post.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing after Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/configure-locale.pre.nu b/configs/crystal/hooks/configure-locale.pre.nu new file mode 100644 index 0000000..ed28ebe --- /dev/null +++ b/configs/crystal/hooks/configure-locale.pre.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing before Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/configure-network.post.nu b/configs/crystal/hooks/configure-network.post.nu new file mode 100644 index 0000000..998c816 --- /dev/null +++ b/configs/crystal/hooks/configure-network.post.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing after Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/configure-network.pre.nu b/configs/crystal/hooks/configure-network.pre.nu new file mode 100644 index 0000000..ed28ebe --- /dev/null +++ b/configs/crystal/hooks/configure-network.pre.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing before Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/configure-unakite.post.nu b/configs/crystal/hooks/configure-unakite.post.nu new file mode 100644 index 0000000..998c816 --- /dev/null +++ b/configs/crystal/hooks/configure-unakite.post.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing after Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/configure-unakite.pre.nu b/configs/crystal/hooks/configure-unakite.pre.nu new file mode 100644 index 0000000..ed28ebe --- /dev/null +++ b/configs/crystal/hooks/configure-unakite.pre.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing before Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/create-partitions.post.nu b/configs/crystal/hooks/create-partitions.post.nu new file mode 100644 index 0000000..998c816 --- /dev/null +++ b/configs/crystal/hooks/create-partitions.post.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing after Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/create-partitions.pre.nu b/configs/crystal/hooks/create-partitions.pre.nu new file mode 100644 index 0000000..ed28ebe --- /dev/null +++ b/configs/crystal/hooks/create-partitions.pre.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing before Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-base.post.nu b/configs/crystal/hooks/install-base.post.nu new file mode 100644 index 0000000..998c816 --- /dev/null +++ b/configs/crystal/hooks/install-base.post.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing after Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-base.pre.nu b/configs/crystal/hooks/install-base.pre.nu new file mode 100644 index 0000000..ed28ebe --- /dev/null +++ b/configs/crystal/hooks/install-base.pre.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing before Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-bootloader.post.nu b/configs/crystal/hooks/install-bootloader.post.nu new file mode 100644 index 0000000..998c816 --- /dev/null +++ b/configs/crystal/hooks/install-bootloader.post.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing after Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-bootloader.pre.nu b/configs/crystal/hooks/install-bootloader.pre.nu new file mode 100644 index 0000000..ed28ebe --- /dev/null +++ b/configs/crystal/hooks/install-bootloader.pre.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing before Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-desktop.post.nu b/configs/crystal/hooks/install-desktop.post.nu new file mode 100644 index 0000000..998c816 --- /dev/null +++ b/configs/crystal/hooks/install-desktop.post.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing after Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-desktop.pre.nu b/configs/crystal/hooks/install-desktop.pre.nu new file mode 100644 index 0000000..ed28ebe --- /dev/null +++ b/configs/crystal/hooks/install-desktop.pre.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing before Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-extra-packages.post.nu b/configs/crystal/hooks/install-extra-packages.post.nu new file mode 100644 index 0000000..998c816 --- /dev/null +++ b/configs/crystal/hooks/install-extra-packages.post.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing after Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-extra-packages.pre.nu b/configs/crystal/hooks/install-extra-packages.pre.nu new file mode 100644 index 0000000..ed28ebe --- /dev/null +++ b/configs/crystal/hooks/install-extra-packages.pre.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing before Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-flatpak.post.nu b/configs/crystal/hooks/install-flatpak.post.nu new file mode 100644 index 0000000..998c816 --- /dev/null +++ b/configs/crystal/hooks/install-flatpak.post.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing after Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-flatpak.pre.nu b/configs/crystal/hooks/install-flatpak.pre.nu new file mode 100644 index 0000000..ed28ebe --- /dev/null +++ b/configs/crystal/hooks/install-flatpak.pre.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing before Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-kernels.post.nu b/configs/crystal/hooks/install-kernels.post.nu new file mode 100644 index 0000000..998c816 --- /dev/null +++ b/configs/crystal/hooks/install-kernels.post.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing after Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-kernels.pre.nu b/configs/crystal/hooks/install-kernels.pre.nu new file mode 100644 index 0000000..ed28ebe --- /dev/null +++ b/configs/crystal/hooks/install-kernels.pre.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing before Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-timeshift.post.nu b/configs/crystal/hooks/install-timeshift.post.nu new file mode 100644 index 0000000..998c816 --- /dev/null +++ b/configs/crystal/hooks/install-timeshift.post.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing after Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-timeshift.pre.nu b/configs/crystal/hooks/install-timeshift.pre.nu new file mode 100644 index 0000000..ed28ebe --- /dev/null +++ b/configs/crystal/hooks/install-timeshift.pre.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing before Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-zramd.post.nu b/configs/crystal/hooks/install-zramd.post.nu new file mode 100644 index 0000000..998c816 --- /dev/null +++ b/configs/crystal/hooks/install-zramd.post.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing after Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/install-zramd.pre.nu b/configs/crystal/hooks/install-zramd.pre.nu new file mode 100644 index 0000000..ed28ebe --- /dev/null +++ b/configs/crystal/hooks/install-zramd.pre.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing before Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/setup-root-user.post.nu b/configs/crystal/hooks/setup-root-user.post.nu new file mode 100644 index 0000000..998c816 --- /dev/null +++ b/configs/crystal/hooks/setup-root-user.post.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing after Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/setup-root-user.pre.nu b/configs/crystal/hooks/setup-root-user.pre.nu new file mode 100644 index 0000000..ed28ebe --- /dev/null +++ b/configs/crystal/hooks/setup-root-user.pre.nu @@ -0,0 +1,6 @@ + +def main [cfg] { + echo "Executing before Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/setup-users.post.nu b/configs/crystal/hooks/setup-users.post.nu index 960f294..998c816 100644 --- a/configs/crystal/hooks/setup-users.post.nu +++ b/configs/crystal/hooks/setup-users.post.nu @@ -1,5 +1,6 @@ + def main [cfg] { - echo "Running after creating users" - $TRM_CONFIG | describe - $TRM_CONFIG -} \ No newline at end of file + echo "Executing after Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/hooks/setup-users.pre.nu b/configs/crystal/hooks/setup-users.pre.nu index 4b5e949..ed28ebe 100644 --- a/configs/crystal/hooks/setup-users.pre.nu +++ b/configs/crystal/hooks/setup-users.pre.nu @@ -1,4 +1,6 @@ + def main [cfg] { - echo "Running before creating users" - echo $TRM_VERSION -} \ No newline at end of file + echo "Executing before Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + \ No newline at end of file diff --git a/configs/crystal/scripts/configure-locale.nu b/configs/crystal/scripts/configure-locale.nu new file mode 100644 index 0000000..5514d55 --- /dev/null +++ b/configs/crystal/scripts/configure-locale.nu @@ -0,0 +1,5 @@ + +def main [cfg] { + echo "Executing Task with config" $cfg +} + \ No newline at end of file diff --git a/configs/crystal/scripts/configure-network.nu b/configs/crystal/scripts/configure-network.nu new file mode 100644 index 0000000..5514d55 --- /dev/null +++ b/configs/crystal/scripts/configure-network.nu @@ -0,0 +1,5 @@ + +def main [cfg] { + echo "Executing Task with config" $cfg +} + \ No newline at end of file diff --git a/configs/crystal/scripts/configure-unakite.nu b/configs/crystal/scripts/configure-unakite.nu new file mode 100644 index 0000000..5514d55 --- /dev/null +++ b/configs/crystal/scripts/configure-unakite.nu @@ -0,0 +1,5 @@ + +def main [cfg] { + echo "Executing Task with config" $cfg +} + \ No newline at end of file diff --git a/configs/crystal/scripts/create-partitions.nu b/configs/crystal/scripts/create-partitions.nu new file mode 100644 index 0000000..5514d55 --- /dev/null +++ b/configs/crystal/scripts/create-partitions.nu @@ -0,0 +1,5 @@ + +def main [cfg] { + echo "Executing Task with config" $cfg +} + \ No newline at end of file diff --git a/configs/crystal/scripts/install-base.nu b/configs/crystal/scripts/install-base.nu new file mode 100644 index 0000000..5514d55 --- /dev/null +++ b/configs/crystal/scripts/install-base.nu @@ -0,0 +1,5 @@ + +def main [cfg] { + echo "Executing Task with config" $cfg +} + \ No newline at end of file diff --git a/configs/crystal/scripts/install-bootloader.nu b/configs/crystal/scripts/install-bootloader.nu new file mode 100644 index 0000000..5514d55 --- /dev/null +++ b/configs/crystal/scripts/install-bootloader.nu @@ -0,0 +1,5 @@ + +def main [cfg] { + echo "Executing Task with config" $cfg +} + \ No newline at end of file diff --git a/configs/crystal/scripts/install-desktop.nu b/configs/crystal/scripts/install-desktop.nu new file mode 100644 index 0000000..5514d55 --- /dev/null +++ b/configs/crystal/scripts/install-desktop.nu @@ -0,0 +1,5 @@ + +def main [cfg] { + echo "Executing Task with config" $cfg +} + \ No newline at end of file diff --git a/configs/crystal/scripts/install-extra-packages.nu b/configs/crystal/scripts/install-extra-packages.nu new file mode 100644 index 0000000..5514d55 --- /dev/null +++ b/configs/crystal/scripts/install-extra-packages.nu @@ -0,0 +1,5 @@ + +def main [cfg] { + echo "Executing Task with config" $cfg +} + \ No newline at end of file diff --git a/configs/crystal/scripts/install-flatpak.nu b/configs/crystal/scripts/install-flatpak.nu new file mode 100644 index 0000000..5514d55 --- /dev/null +++ b/configs/crystal/scripts/install-flatpak.nu @@ -0,0 +1,5 @@ + +def main [cfg] { + echo "Executing Task with config" $cfg +} + \ No newline at end of file diff --git a/configs/crystal/scripts/install-kernels.nu b/configs/crystal/scripts/install-kernels.nu new file mode 100644 index 0000000..5514d55 --- /dev/null +++ b/configs/crystal/scripts/install-kernels.nu @@ -0,0 +1,5 @@ + +def main [cfg] { + echo "Executing Task with config" $cfg +} + \ No newline at end of file diff --git a/configs/crystal/scripts/install-timeshift.nu b/configs/crystal/scripts/install-timeshift.nu new file mode 100644 index 0000000..5514d55 --- /dev/null +++ b/configs/crystal/scripts/install-timeshift.nu @@ -0,0 +1,5 @@ + +def main [cfg] { + echo "Executing Task with config" $cfg +} + \ No newline at end of file diff --git a/configs/crystal/scripts/install-zramd.nu b/configs/crystal/scripts/install-zramd.nu new file mode 100644 index 0000000..5514d55 --- /dev/null +++ b/configs/crystal/scripts/install-zramd.nu @@ -0,0 +1,5 @@ + +def main [cfg] { + echo "Executing Task with config" $cfg +} + \ No newline at end of file diff --git a/configs/crystal/scripts/setup-root-user.nu b/configs/crystal/scripts/setup-root-user.nu new file mode 100644 index 0000000..5514d55 --- /dev/null +++ b/configs/crystal/scripts/setup-root-user.nu @@ -0,0 +1,5 @@ + +def main [cfg] { + echo "Executing Task with config" $cfg +} + \ No newline at end of file diff --git a/configs/crystal/scripts/setup-users.nu b/configs/crystal/scripts/setup-users.nu index 1a89a1a..5514d55 100644 --- a/configs/crystal/scripts/setup-users.nu +++ b/configs/crystal/scripts/setup-users.nu @@ -1,9 +1,5 @@ + def main [cfg] { - $cfg | get users | each {|$it| create_user $it } | ignore + echo "Executing Task with config" $cfg } - -def create_user [user] { - echo "This would create a user with:" - echo $user - echo -} \ No newline at end of file + \ No newline at end of file diff --git a/src/error.rs b/src/error.rs index d2564a4..b70572e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::{io, path::PathBuf}; use miette::Diagnostic; use nu_protocol::ShellError; @@ -32,6 +32,9 @@ pub enum AppError { #[error("Missing config")] MissingConfig, + + #[error("IO Error: {0}")] + Io(#[from] io::Error), } impl From for AppError { diff --git a/src/lib.rs b/src/lib.rs index a76454d..ebf61f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,7 @@ pub mod error; pub(crate) mod scripting; pub mod tasks; pub(crate) mod utils; +pub use utils::generate_script_files; macro_rules! tasks { ($($function:ident => $script:ident),+) => { diff --git a/src/tasks/mod.rs b/src/tasks/mod.rs index b624bce..4751943 100644 --- a/src/tasks/mod.rs +++ b/src/tasks/mod.rs @@ -13,6 +13,8 @@ mod install_zramd; mod setup_root_user; mod setup_users; +use std::path::{Path, PathBuf}; + pub use configure_locale::*; pub use configure_network::*; pub use configure_unakite::*; @@ -27,3 +29,61 @@ pub use install_timeshift::*; pub use install_zramd::*; pub use setup_root_user::*; pub use setup_users::*; + +use crate::scripting::script::Script; + +pub struct TaskFiles { + script: String, + pre_hook: String, + post_hook: String, +} + +impl TaskFiles { + pub fn script_path(&self, base: &Path) -> PathBuf { + base.join("scripts").join(&self.script) + } + + pub fn pre_hook_path(&self, base: &Path) -> PathBuf { + base.join("hooks").join(&self.pre_hook) + } + + pub fn post_hook_path(&self, base: &Path) -> PathBuf { + base.join("hooks").join(&self.post_hook) + } +} + +macro_rules! __all_tasks { + ($($task:ident),+) => { + { + let mut list = Vec::new(); + $( + list.push(TaskFiles { + script: $task::get_name().into(), + pre_hook: $task::get_pre_hook().into(), + post_hook: $task::get_post_hook().into(), + }); + )+ + + list + } + }; +} + +pub fn all_tasks() -> Vec { + __all_tasks!( + ConfigureLocaleScript, + ConfigureNetworkScript, + ConfigureUnakiteScript, + CreatePartitionsScript, + InstallBaseScript, + InstallBootloaderScript, + InstallDesktopScript, + InstallExtraPackagesScript, + InstallFlatpakScript, + InstallKernelsScript, + InstallTimeshiftScript, + InstallZRamDScript, + SetupRootUserScript, + SetupUsersScript + ) +} diff --git a/src/utils.rs b/src/utils.rs index 3469a0d..4cd7a9a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,12 @@ +use std::path::Path; use std::{env, path::PathBuf}; +use tokio::fs; + +use crate::error::AppResult; + +use crate::tasks::all_tasks; + const DEFAULT_CONFIG_DIR: &str = "/etc"; lazy_static::lazy_static! { @@ -7,3 +14,44 @@ lazy_static::lazy_static! { pub static ref SCRIPT_PATH: PathBuf = CFG_PATH.join("scripts"); pub static ref HOOK_PATH: PathBuf = CFG_PATH.join("hooks"); } + +pub async fn generate_script_files>(output: P) -> AppResult<()> { + let tasks = all_tasks(); + + for task in tasks { + fs::write( + task.script_path(output.as_ref()), + r#" +def main [cfg] { + echo "Executing Task with config" $cfg +} + "# + .to_string(), + ) + .await?; + fs::write( + task.pre_hook_path(output.as_ref()), + r#" +def main [cfg] { + echo "Executing before Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + "# + .to_string(), + ) + .await?; + fs::write( + task.post_hook_path(output.as_ref()), + r#" +def main [cfg] { + echo "Executing after Task with task config: " $cfg + echo "The global config is: " $TRM_CONFIG +} + "# + .to_string(), + ) + .await?; + } + + Ok(()) +}