feat: add dev-packages
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
dee3421313
commit
22a0d5a22b
@ -1,4 +1,8 @@
|
|||||||
use bindings::exports::component::churn_tasks::task::Guest;
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
|
use bindings::{
|
||||||
|
component::churn_tasks::process::Process, exports::component::churn_tasks::task::Guest,
|
||||||
|
};
|
||||||
|
|
||||||
#[allow(warnings)]
|
#[allow(warnings)]
|
||||||
mod bindings;
|
mod bindings;
|
||||||
@ -11,10 +15,61 @@ impl Guest for Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn should_run() -> bool {
|
fn should_run() -> bool {
|
||||||
true
|
if !std::path::PathBuf::from("/usr/local/bin/starship").exists() {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
if !std::path::PathBuf::from("/root/.bashrc").exists() {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Ok(content) = std::fs::read_to_string("/root/.bashrc") {
|
||||||
|
if !content.contains("starship") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
}
|
}
|
||||||
fn execute() {
|
fn execute() {
|
||||||
println!("running dev-packages installation");
|
println!("running dev-packages installation");
|
||||||
|
|
||||||
|
Process::new().run_process(
|
||||||
|
&[
|
||||||
|
"bash",
|
||||||
|
"-c",
|
||||||
|
"curl -sS https://starship.rs/install.sh | sh -s -- --force",
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.map(|i| i.to_string())
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if !std::path::PathBuf::from("/root/.bashrc").exists() {
|
||||||
|
if let Ok(content) = std::fs::read_to_string("/root/.bashrc") {
|
||||||
|
if !content.contains("starship") {
|
||||||
|
let mut bashrc = std::fs::File::options()
|
||||||
|
.append(true)
|
||||||
|
.open("/root/.bashrc")
|
||||||
|
.expect("failed to open bash");
|
||||||
|
|
||||||
|
bashrc
|
||||||
|
.write_all(r#"eval "$(starship init bash)"#.as_bytes())
|
||||||
|
.expect("failed to write to bashrc file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let mut bashrc = std::fs::File::options()
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open("/root/.bashrc")
|
||||||
|
.expect("failed to open bash");
|
||||||
|
|
||||||
|
bashrc
|
||||||
|
.write_all(r#"eval "$(starship init bash)""#.as_bytes())
|
||||||
|
.expect("failed to write to bashrc file");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user