Add layout part of create_partitiosn and custom commands
parent
4ad2700f06
commit
eecaa70b59
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,49 @@
|
|||||||
|
module auto_partition {
|
||||||
|
|
||||||
|
export def efi [device: string] {
|
||||||
|
info "Creating efi partitions"
|
||||||
|
efi_layout $device
|
||||||
|
}
|
||||||
|
|
||||||
|
def efi_layout [device: string] {
|
||||||
|
run parted -s $device mklabel gpt
|
||||||
|
debug "Partition table created"
|
||||||
|
|
||||||
|
run parted -s $device mkpart fat32 0 300
|
||||||
|
debug "EFI partition created"
|
||||||
|
|
||||||
|
run parted -s $device mkpart primary btrfs 512MIB 100%
|
||||||
|
debug "Root partition created"
|
||||||
|
}
|
||||||
|
|
||||||
|
export def bios [device: string] {
|
||||||
|
debug "Creating bios partitions"
|
||||||
|
bios_layout $device
|
||||||
|
}
|
||||||
|
|
||||||
|
def bios_layout [device: string] {
|
||||||
|
parted -s $device mklabel msdos
|
||||||
|
parted -s $device mkpart primary ext4 1MIB 512MIB
|
||||||
|
parted -s $device mkpart primary btrfs 512MIB 100%
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Applies all system changes of `create-partitions`
|
# Applies all system changes of `create-partitions`
|
||||||
def main [cfg] {
|
def main [cfg] {
|
||||||
echo "Executing up task `create-partitions` with config" $cfg
|
debug $"Creating partitions with config ($cfg)"
|
||||||
|
|
||||||
|
if $cfg.partitions == "Auto" {
|
||||||
|
info "Creating partitions automatically..."
|
||||||
|
use auto_partition
|
||||||
|
|
||||||
|
if $cfg.efi_partition {
|
||||||
|
auto_partition efi $cfg.device
|
||||||
|
} else {
|
||||||
|
auto_partition bios $cfg.device
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
info "Creating partitions manually"
|
||||||
|
}
|
||||||
|
|
||||||
|
info "Partitions created"
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
use embed_nu::{
|
||||||
|
nu_protocol::{engine::Command, Signature, SyntaxShape},
|
||||||
|
CallExt, PipelineData,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct DebugCommand;
|
||||||
|
|
||||||
|
impl Command for DebugCommand {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"debug"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> embed_nu::nu_protocol::Signature {
|
||||||
|
Signature::new("debug")
|
||||||
|
.rest("rest", SyntaxShape::Any, "the message to print")
|
||||||
|
.category(embed_nu::nu_protocol::Category::Custom("Tourmaline".into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn usage(&self) -> &str {
|
||||||
|
"Prints the given message and values with debug severity (only when --verbose is passed to tourmaline)"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(
|
||||||
|
&self,
|
||||||
|
engine_state: &embed_nu::nu_protocol::engine::EngineState,
|
||||||
|
stack: &mut embed_nu::nu_protocol::engine::Stack,
|
||||||
|
call: &embed_nu::nu_protocol::ast::Call,
|
||||||
|
_input: embed_nu::PipelineData,
|
||||||
|
) -> Result<embed_nu::PipelineData, embed_nu::nu_protocol::ShellError> {
|
||||||
|
let args: Vec<String> = call.rest(engine_state, stack, 0)?;
|
||||||
|
tracing::debug!("{}", args.join(" "));
|
||||||
|
|
||||||
|
Ok(PipelineData::empty())
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
use embed_nu::{
|
||||||
|
nu_protocol::{engine::Command, Signature, SyntaxShape},
|
||||||
|
CallExt, PipelineData,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct InfoCommand;
|
||||||
|
|
||||||
|
impl Command for InfoCommand {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"info"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> embed_nu::nu_protocol::Signature {
|
||||||
|
Signature::new("info")
|
||||||
|
.rest("rest", SyntaxShape::Any, "the message to print")
|
||||||
|
.category(embed_nu::nu_protocol::Category::Custom("Tourmaline".into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn usage(&self) -> &str {
|
||||||
|
"Prints the given message and values with info severity"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(
|
||||||
|
&self,
|
||||||
|
engine_state: &embed_nu::nu_protocol::engine::EngineState,
|
||||||
|
stack: &mut embed_nu::nu_protocol::engine::Stack,
|
||||||
|
call: &embed_nu::nu_protocol::ast::Call,
|
||||||
|
_input: embed_nu::PipelineData,
|
||||||
|
) -> Result<embed_nu::PipelineData, embed_nu::nu_protocol::ShellError> {
|
||||||
|
let args: Vec<String> = call.rest(engine_state, stack, 0)?;
|
||||||
|
tracing::info!("{}", args.join(" "));
|
||||||
|
|
||||||
|
Ok(PipelineData::empty())
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
mod debug;
|
||||||
|
mod info;
|
||||||
|
mod run;
|
||||||
|
pub use debug::*;
|
||||||
|
pub use info::*;
|
||||||
|
pub use run::*;
|
@ -0,0 +1,66 @@
|
|||||||
|
use std::{
|
||||||
|
io::Write,
|
||||||
|
process::{Command, Stdio},
|
||||||
|
};
|
||||||
|
|
||||||
|
use embed_nu::{
|
||||||
|
nu_protocol::{ShellError, Signature, SyntaxShape},
|
||||||
|
CallExt, PipelineData,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct RunCommand;
|
||||||
|
|
||||||
|
impl embed_nu::nu_protocol::engine::Command for RunCommand {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"run"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> embed_nu::nu_protocol::Signature {
|
||||||
|
Signature::new("run")
|
||||||
|
.required("executable", SyntaxShape::String, "The executable to run")
|
||||||
|
.rest(
|
||||||
|
"rest",
|
||||||
|
SyntaxShape::String,
|
||||||
|
"the args for the given command",
|
||||||
|
)
|
||||||
|
.allows_unknown_args()
|
||||||
|
.category(embed_nu::nu_protocol::Category::Custom("Tourmalin".into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn usage(&self) -> &str {
|
||||||
|
"run <executable> [...<args>]"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(
|
||||||
|
&self,
|
||||||
|
engine_state: &embed_nu::nu_protocol::engine::EngineState,
|
||||||
|
stack: &mut embed_nu::nu_protocol::engine::Stack,
|
||||||
|
call: &embed_nu::nu_protocol::ast::Call,
|
||||||
|
input: embed_nu::PipelineData,
|
||||||
|
) -> Result<embed_nu::PipelineData, embed_nu::nu_protocol::ShellError> {
|
||||||
|
let executable: String = call.req(engine_state, stack, 0)?;
|
||||||
|
let args: Vec<String> = call.rest(engine_state, stack, 1)?;
|
||||||
|
tracing::debug!("Running {executable} {}", args.join(" "));
|
||||||
|
|
||||||
|
let mut cmd = Command::new(&executable)
|
||||||
|
.args(args)
|
||||||
|
.stdout(Stdio::inherit())
|
||||||
|
.stderr(Stdio::inherit())
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.spawn()?;
|
||||||
|
|
||||||
|
let mut stdin = cmd.stdin.take().unwrap();
|
||||||
|
stdin.write_all(input.collect_string_strict(call.span())?.0.as_bytes())?;
|
||||||
|
|
||||||
|
if cmd.wait().is_err() {
|
||||||
|
Err(ShellError::ExternalCommand(
|
||||||
|
executable,
|
||||||
|
String::from("Is it written correctly?"),
|
||||||
|
call.span(),
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
Ok(PipelineData::empty())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue