Add function to generate script files (and generate them)

integration-not-installation
trivernis 2 years ago
parent e27e798a38
commit fae57a7e3f
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing after Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing before Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing after Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing before Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing after Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing before Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing after Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing before Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing after Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing before Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing after Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing before Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing after Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing before Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing after Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing before Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing after Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing before Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing after Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing before Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing after Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing before Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing after Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing before Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing after Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,6 @@
def main [cfg] {
echo "Executing before Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -1,5 +1,6 @@
def main [cfg] {
echo "Running after creating users"
$TRM_CONFIG | describe
$TRM_CONFIG
}
echo "Executing after Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -1,4 +1,6 @@
def main [cfg] {
echo "Running before creating users"
echo $TRM_VERSION
}
echo "Executing before Task with task config: " $cfg
echo "The global config is: " $TRM_CONFIG
}

@ -0,0 +1,5 @@
def main [cfg] {
echo "Executing Task with config" $cfg
}

@ -0,0 +1,5 @@
def main [cfg] {
echo "Executing Task with config" $cfg
}

@ -0,0 +1,5 @@
def main [cfg] {
echo "Executing Task with config" $cfg
}

@ -0,0 +1,5 @@
def main [cfg] {
echo "Executing Task with config" $cfg
}

@ -0,0 +1,5 @@
def main [cfg] {
echo "Executing Task with config" $cfg
}

@ -0,0 +1,5 @@
def main [cfg] {
echo "Executing Task with config" $cfg
}

@ -0,0 +1,5 @@
def main [cfg] {
echo "Executing Task with config" $cfg
}

@ -0,0 +1,5 @@
def main [cfg] {
echo "Executing Task with config" $cfg
}

@ -0,0 +1,5 @@
def main [cfg] {
echo "Executing Task with config" $cfg
}

@ -0,0 +1,5 @@
def main [cfg] {
echo "Executing Task with config" $cfg
}

@ -0,0 +1,5 @@
def main [cfg] {
echo "Executing Task with config" $cfg
}

@ -0,0 +1,5 @@
def main [cfg] {
echo "Executing Task with config" $cfg
}

@ -0,0 +1,5 @@
def main [cfg] {
echo "Executing Task with config" $cfg
}

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

@ -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<miette::Error> for AppError {

@ -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),+) => {

@ -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<TaskFiles> {
__all_tasks!(
ConfigureLocaleScript,
ConfigureNetworkScript,
ConfigureUnakiteScript,
CreatePartitionsScript,
InstallBaseScript,
InstallBootloaderScript,
InstallDesktopScript,
InstallExtraPackagesScript,
InstallFlatpakScript,
InstallKernelsScript,
InstallTimeshiftScript,
InstallZRamDScript,
SetupRootUserScript,
SetupUsersScript
)
}

@ -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<P: AsRef<Path>>(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(())
}

Loading…
Cancel
Save