Compare commits
No commits in common. "66d5c8588ac2e35681c8261d077a47818724ef22" and "bb39f3e3f24e08742fb4cd847791b49befb5f95d" have entirely different histories.
66d5c8588a
...
bb39f3e3f2
@ -20,14 +20,8 @@ fi
|
|||||||
# Echo a success message
|
# Echo a success message
|
||||||
echo "Build successful!"
|
echo "Build successful!"
|
||||||
|
|
||||||
if [ "$EUID" -eq 0 ]; then
|
mkdir -p ~/hero/bin/
|
||||||
echo "Running as root, copying to /usr/local/bin/"
|
cp target/debug/herodo ~/hero/bin/herodo
|
||||||
cp target/debug/herodo /usr/local/bin/herodo
|
|
||||||
else
|
|
||||||
echo "Running as non-root user, copying to ~/hero/bin/"
|
|
||||||
mkdir -p ~/hero/bin/
|
|
||||||
cp target/debug/herodo ~/hero/bin/herodo
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if a script name was provided
|
# Check if a script name was provided
|
||||||
if [ $# -eq 1 ]; then
|
if [ $# -eq 1 ]; then
|
||||||
|
@ -3,23 +3,23 @@
|
|||||||
|
|
||||||
fn nerdctl_download(){
|
fn nerdctl_download(){
|
||||||
let name="nerdctl";
|
let name="nerdctl";
|
||||||
let url="https://github.com/containerd/nerdctl/releases/download/v2.1.2/nerdctl-2.1.2-linux-amd64.tar.gz";
|
let url="https://github.com/containerd/nerdctl/releases/download/v2.0.4/nerdctl-2.0.4-linux-amd64.tar.gz";
|
||||||
download(url,`/tmp/${name}`,10000);
|
download(url,`/tmp/${name}`,20000);
|
||||||
copy_bin(`/tmp/${name}/*`);
|
copy(`/tmp/${name}/*`,"/root/hero/bin/");
|
||||||
delete(`/tmp/${name}`);
|
delete(`/tmp/${name}`);
|
||||||
|
|
||||||
let name="containerd";
|
let name="containerd";
|
||||||
let url="https://github.com/containerd/containerd/releases/download/v2.1.2/containerd-2.1.2-linux-amd64.tar.gz";
|
let url="https://github.com/containerd/containerd/releases/download/v2.0.4/containerd-2.0.4-linux-amd64.tar.gz";
|
||||||
download(url,`/tmp/${name}`,20000);
|
download(url,`/tmp/${name}`,20000);
|
||||||
copy_bin(`/tmp/${name}/bin/*`);
|
copy(`/tmp/${name}/bin/*`,"/root/hero/bin/");
|
||||||
delete(`/tmp/${name}`);
|
delete(`/tmp/${name}`);
|
||||||
|
|
||||||
run("apt-get -y install buildah runc");
|
run("apt-get -y install buildah 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);
|
||||||
// chmod_exec("/tmp/rfs");
|
chmod_exec("/tmp/rfs");
|
||||||
// mv(`/tmp/rfs`,"/root/hero/bin/");
|
mv(`/tmp/rfs`,"/root/hero/bin/");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,23 +3,32 @@
|
|||||||
//! This is the main entry point for the herodo binary.
|
//! This is the main entry point for the herodo binary.
|
||||||
//! It parses command line arguments and calls into the implementation in the cmd module.
|
//! It parses command line arguments and calls into the implementation in the cmd module.
|
||||||
|
|
||||||
|
use clap::{App, Arg};
|
||||||
use env_logger;
|
use env_logger;
|
||||||
use std::env;
|
|
||||||
use std::process;
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Initialize the logger
|
// Initialize the logger
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
|
// Parse command line arguments
|
||||||
|
let matches = App::new("herodo")
|
||||||
|
.version("0.1.0")
|
||||||
|
.author("SAL Team")
|
||||||
|
.about("Executes Rhai scripts for SAL")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("path")
|
||||||
|
.short("p")
|
||||||
|
.long("path")
|
||||||
|
.value_name("PATH")
|
||||||
|
.help("Path to a Rhai script file or directory containing Rhai scripts")
|
||||||
|
.required(true)
|
||||||
|
.takes_value(true),
|
||||||
|
)
|
||||||
|
.get_matches();
|
||||||
|
|
||||||
let args: Vec<String> = env::args().collect();
|
// Get the script path from arguments
|
||||||
|
let script_path = matches.value_of("path").unwrap();
|
||||||
if args.len() != 2 {
|
|
||||||
eprintln!("Usage: {} <script_path>", args[0]);
|
|
||||||
process::exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
let script_path = &args[1];
|
|
||||||
|
|
||||||
// Call the run function from the cmd module
|
// Call the run function from the cmd module
|
||||||
sal::cmd::herodo::run(script_path)
|
sal::cmd::herodo::run(script_path)
|
||||||
}
|
}
|
||||||
|
41
src/os/fs.rs
41
src/os/fs.rs
@ -4,8 +4,6 @@ use std::fs;
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use libc;
|
|
||||||
use dirs;
|
|
||||||
|
|
||||||
// Define a custom error type for file system operations
|
// Define a custom error type for file system operations
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -269,45 +267,6 @@ pub fn copy(src: &str, dest: &str) -> Result<String, FsError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Copy a binary to the correct location based on OS and user privileges.
|
|
||||||
*
|
|
||||||
* # Arguments
|
|
||||||
*
|
|
||||||
* * `src` - The source file path
|
|
||||||
*
|
|
||||||
* # Returns
|
|
||||||
*
|
|
||||||
* * `Ok(String)` - A success message indicating where the file was copied
|
|
||||||
* * `Err(FsError)` - An error if the copy operation failed
|
|
||||||
*
|
|
||||||
* # Examples
|
|
||||||
*
|
|
||||||
* ```no_run
|
|
||||||
* use sal::os::copy_bin;
|
|
||||||
*
|
|
||||||
* fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
* // Copy a binary
|
|
||||||
* let result = copy_bin("my_binary")?;
|
|
||||||
* Ok(())
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
pub fn copy_bin(src: &str) -> Result<String, FsError> {
|
|
||||||
let dest_path = if cfg!(target_os = "linux") && unsafe { libc::getuid() } == 0 {
|
|
||||||
Path::new("/usr/local/bin").to_path_buf()
|
|
||||||
} else {
|
|
||||||
dirs::home_dir()
|
|
||||||
.ok_or_else(|| FsError::DirectoryNotFound("Home directory not found".to_string()))?
|
|
||||||
.join("hero/bin")
|
|
||||||
};
|
|
||||||
|
|
||||||
let result = copy(src, dest_path.to_str().unwrap());
|
|
||||||
if let Ok(msg) = &result {
|
|
||||||
println!("{}", msg);
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a file or directory exists.
|
* Check if a file or directory exists.
|
||||||
|
@ -22,7 +22,6 @@ pub fn register_os_module(engine: &mut Engine) -> Result<(), Box<EvalAltResult>>
|
|||||||
|
|
||||||
// Register file system functions
|
// Register file system functions
|
||||||
engine.register_fn("copy", copy);
|
engine.register_fn("copy", copy);
|
||||||
engine.register_fn("copy_bin", copy_bin);
|
|
||||||
engine.register_fn("exist", exist);
|
engine.register_fn("exist", exist);
|
||||||
engine.register_fn("find_file", find_file);
|
engine.register_fn("find_file", find_file);
|
||||||
engine.register_fn("find_files", find_files);
|
engine.register_fn("find_files", find_files);
|
||||||
@ -75,13 +74,6 @@ pub fn copy(src: &str, dest: &str) -> Result<String, Box<EvalAltResult>> {
|
|||||||
os::copy(src, dest).to_rhai_error()
|
os::copy(src, dest).to_rhai_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wrapper for os::copy_bin
|
|
||||||
///
|
|
||||||
/// Copy a binary to the correct location based on OS and user privileges.
|
|
||||||
pub fn copy_bin(src: &str) -> Result<String, Box<EvalAltResult>> {
|
|
||||||
os::copy_bin(src).to_rhai_error()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Wrapper for os::exist
|
/// Wrapper for os::exist
|
||||||
///
|
///
|
||||||
/// Check if a file or directory exists.
|
/// Check if a file or directory exists.
|
||||||
|
Loading…
Reference in New Issue
Block a user