...
This commit is contained in:
parent
8a8ead17cb
commit
e7e8e7daf8
@ -1,45 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn nerdctl_download(){
|
|
||||||
let name="nerdctl";
|
|
||||||
let url="https://github.com/containerd/nerdctl/releases/download/v2.1.2/nerdctl-2.1.2-linux-amd64.tar.gz";
|
|
||||||
download(url,`/tmp/${name}`,10000);
|
|
||||||
copy_bin(`/tmp/${name}/*`);
|
|
||||||
delete(`/tmp/${name}`);
|
|
||||||
|
|
||||||
let name="containerd";
|
|
||||||
let url="https://github.com/containerd/containerd/releases/download/v2.1.2/containerd-2.1.2-linux-amd64.tar.gz";
|
|
||||||
download(url,`/tmp/${name}`,20000);
|
|
||||||
copy_bin(`/tmp/${name}/bin/*`);
|
|
||||||
delete(`/tmp/${name}`);
|
|
||||||
|
|
||||||
run("apt-get -y install buildah runc");
|
|
||||||
|
|
||||||
// let url="https://github.com/threefoldtech/rfs/releases/download/v2.0.6/rfs";
|
|
||||||
// download_file(url,`/tmp/rfs`,10000);
|
|
||||||
// chmod_exec("/tmp/rfs");
|
|
||||||
// mv(`/tmp/rfs`,"/root/hero/bin/");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ipfs_download(){
|
|
||||||
let name="ipfs";
|
|
||||||
let url="https://github.com/ipfs/kubo/releases/download/v0.34.1/kubo_v0.34.1_linux-amd64.tar.gz";
|
|
||||||
download(url,`/tmp/${name}`,20);
|
|
||||||
copy(`/tmp/${name}/kubo/ipfs`,"/root/hero/bin/ipfs");
|
|
||||||
// delete(`/tmp/${name}`);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
let d=download(`https://git.threefold.info/herocode/sal/raw/branch/main/examples/containers/nerdctl_install.rhai`,`/tmp/nerdctl_install.rhai`,0);
|
|
||||||
|
|
||||||
print(`Repo path: ${d}`);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// nerdctl_download();
|
|
||||||
// ipfs_download();
|
|
||||||
|
|
||||||
"done"
|
|
@ -19,9 +19,7 @@ fn zinit(){
|
|||||||
download_file(url,`/tmp/${name}`,5000);
|
download_file(url,`/tmp/${name}`,5000);
|
||||||
copy_bin(`/tmp/${name}`);
|
copy_bin(`/tmp/${name}`);
|
||||||
delete(`/tmp/${name}`);
|
delete(`/tmp/${name}`);
|
||||||
|
screen_new("zinit", "zinit init");
|
||||||
let name="containerd";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
platform_check_linux_x86();
|
platform_check_linux_x86();
|
||||||
|
@ -14,7 +14,9 @@ fn nerdctl_download(){
|
|||||||
copy_bin(`/tmp/${name}/bin/*`);
|
copy_bin(`/tmp/${name}/bin/*`);
|
||||||
delete(`/tmp/${name}`);
|
delete(`/tmp/${name}`);
|
||||||
|
|
||||||
run("apt-get -y install buildah runc");
|
package_install("buildah");
|
||||||
|
package_install("runc");
|
||||||
|
|
||||||
|
|
||||||
// let url="https://github.com/threefoldtech/rfs/releases/download/v2.0.6/rfs";
|
// let url="https://github.com/threefoldtech/rfs/releases/download/v2.0.6/rfs";
|
||||||
// download_file(url,`/tmp/rfs`,10000);
|
// download_file(url,`/tmp/rfs`,10000);
|
||||||
|
@ -12,8 +12,10 @@
|
|||||||
|
|
||||||
mod run;
|
mod run;
|
||||||
mod mgmt;
|
mod mgmt;
|
||||||
|
mod screen;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
pub use run::*;
|
pub use run::*;
|
||||||
pub use mgmt::*;
|
pub use mgmt::*;
|
||||||
|
pub use screen::{new as new_screen, kill as kill_screen};
|
48
src/process/screen.rs
Normal file
48
src/process/screen.rs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
use crate::process::run_command;
|
||||||
|
use anyhow::Result;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
/// Executes a command in a new screen session.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `name` - The name of the screen session.
|
||||||
|
/// * `cmd` - The command to execute.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// * `Result<()>` - Ok if the command was executed successfully, otherwise an error.
|
||||||
|
pub fn new(name: &str, cmd: &str) -> Result<()> {
|
||||||
|
let script_path = format!("/tmp/cmd_{}.sh", name);
|
||||||
|
let mut script_content = String::new();
|
||||||
|
|
||||||
|
if !cmd.starts_with("#!") {
|
||||||
|
script_content.push_str("#!/bin/bash\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
script_content.push_str("set -e\n");
|
||||||
|
script_content.push_str(cmd);
|
||||||
|
|
||||||
|
fs::write(&script_path, script_content)?;
|
||||||
|
fs::set_permissions(&script_path, std::os::unix::fs::PermissionsExt::from_mode(0o755))?;
|
||||||
|
|
||||||
|
let screen_cmd = format!("screen -d -m -S {} {}", name, script_path);
|
||||||
|
run_command(&screen_cmd)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Kills a screen session.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `name` - The name of the screen session to kill.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// * `Result<()>` - Ok if the session was killed successfully, otherwise an error.
|
||||||
|
pub fn kill(name: &str) -> Result<()> {
|
||||||
|
let cmd = format!("screen -S {} -X quit", name);
|
||||||
|
run_command(&cmd)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
@ -14,6 +14,7 @@ mod postgresclient;
|
|||||||
mod process;
|
mod process;
|
||||||
mod redisclient;
|
mod redisclient;
|
||||||
mod rfs;
|
mod rfs;
|
||||||
|
mod screen;
|
||||||
mod vault;
|
mod vault;
|
||||||
mod text;
|
mod text;
|
||||||
mod zinit;
|
mod zinit;
|
||||||
@ -186,6 +187,9 @@ pub fn register(engine: &mut Engine) -> Result<(), Box<rhai::EvalAltResult>> {
|
|||||||
// Register Platform module functions
|
// Register Platform module functions
|
||||||
platform::register(engine);
|
platform::register(engine);
|
||||||
|
|
||||||
|
// Register Screen module functions
|
||||||
|
screen::register(engine);
|
||||||
|
|
||||||
// Register utility functions
|
// Register utility functions
|
||||||
engine.register_fn("is_def_fn", |_name: &str| -> bool {
|
engine.register_fn("is_def_fn", |_name: &str| -> bool {
|
||||||
// This is a utility function to check if a function is defined in the engine
|
// This is a utility function to check if a function is defined in the engine
|
||||||
|
26
src/rhai/screen.rs
Normal file
26
src/rhai/screen.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
use crate::process::{new_screen, kill_screen};
|
||||||
|
use rhai::{Engine, Module, EvalAltResult};
|
||||||
|
|
||||||
|
fn screen_error_to_rhai_error<T>(result: anyhow::Result<T>) -> Result<T, Box<EvalAltResult>> {
|
||||||
|
result.map_err(|e| {
|
||||||
|
Box::new(EvalAltResult::ErrorRuntime(
|
||||||
|
format!("Screen error: {}", e).into(),
|
||||||
|
rhai::Position::NONE,
|
||||||
|
))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn register(engine: &mut Engine) {
|
||||||
|
let mut module = Module::new();
|
||||||
|
|
||||||
|
module.set_native_fn("screen_new", |name: &str, cmd: &str| {
|
||||||
|
screen_error_to_rhai_error(new_screen(name, cmd))
|
||||||
|
});
|
||||||
|
|
||||||
|
module.set_native_fn("screen_kill", |name: &str| {
|
||||||
|
screen_error_to_rhai_error(kill_screen(name))
|
||||||
|
});
|
||||||
|
|
||||||
|
engine.register_static_module("screen", module.into());
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user