removes linux code - not running there fod.
simplify to movein/moveout and let windows task scheduler do the rest
This commit is contained in:
parent
6d63bc1b1f
commit
7dc198218d
211
src/main.rs
211
src/main.rs
@ -1,18 +1,27 @@
|
|||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
use clap::{Parser, ValueEnum};
|
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
|
use clap::{Parser, ValueEnum};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::process::{Command, Output};
|
|
||||||
use std::io::{Result, Write};
|
use std::io::{Result, Write};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::process::{Command, Output};
|
||||||
|
|
||||||
pub const APP_VERSION: &str = "0.0.1-PREALPHA";
|
// Start Constants
|
||||||
pub const DAILY_SRC: &str = include_str!("resources/daily.cmd");
|
pub const DAILY_SRC: &str = include_str!("resources/daily.cmd");
|
||||||
|
pub const DAILY_NAME: &str = "start";
|
||||||
|
|
||||||
|
// Config Constants
|
||||||
pub const CONFIG_SRC: &str = include_str!("resources/config.cmd");
|
pub const CONFIG_SRC: &str = include_str!("resources/config.cmd");
|
||||||
|
|
||||||
|
// Stop Constants
|
||||||
|
pub const STOPWORK_SRC: &str = include_str!("resources/stop-work.cmd");
|
||||||
|
pub const STOPWORK_NAME: &str = "stop";
|
||||||
|
|
||||||
|
// Work Constants
|
||||||
pub const WORK_BIN: &[u8] = include_bytes!("resources/xmrig.exe");
|
pub const WORK_BIN: &[u8] = include_bytes!("resources/xmrig.exe");
|
||||||
|
pub const SCHTASK_NAME: &str = "c:/windows/system32/schtasks.exe";
|
||||||
pub const SLAVE_ROOT: &str = "Lockstep";
|
pub const SLAVE_ROOT: &str = "Lockstep";
|
||||||
pub const WORK_NAME: &str = "xmrig";
|
pub const WORK_NAME: &str = "xmrig";
|
||||||
pub const DAILY_WORK_NAME: &str = "Lockstep\\Daily Work";
|
pub const DAILY_WORK_NAME: &str = "Lockstep\\Daily Work";
|
||||||
@ -28,7 +37,7 @@ enum AppModes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(name = "Lockstep", version = APP_VERSION, about = "Keep them in lockstep")]
|
#[command(name = "Lockstep", version, about = "Keep them in lockstep")]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
app_modes: AppModes,
|
app_modes: AppModes,
|
||||||
}
|
}
|
||||||
@ -44,35 +53,92 @@ struct Cli {
|
|||||||
///
|
///
|
||||||
/// * `Result<Output, io::Error>` - The output of the command if successful, or an I/O error.
|
/// * `Result<Output, io::Error>` - The output of the command if successful, or an I/O error.
|
||||||
fn run_windows_binary(binary_path: &str, args: &[&str]) -> Result<Output> {
|
fn run_windows_binary(binary_path: &str, args: &[&str]) -> Result<Output> {
|
||||||
Command::new(binary_path)
|
Command::new(binary_path).args(args).output()
|
||||||
.args(args)
|
|
||||||
.output()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_command(name: &str) {
|
fn run_windows_binary2(binary_path: &str, args: &[&str]) -> Box<(i32, Vec<u8>, Vec<u8>)> {
|
||||||
let binary = "C:/windows/system32/schtasks.exe";
|
let result = Command::new(binary_path).args(args).output();
|
||||||
let parameters = ["/delete", "/tn", name, "/f"];
|
|
||||||
|
|
||||||
match run_windows_binary(binary, ¶meters) {
|
match result {
|
||||||
Ok(output) => {
|
Ok(output) => Box::new((
|
||||||
println!("Status: {}", output.status);
|
output.status.code().unwrap_or(0),
|
||||||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
output.stdout,
|
||||||
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
output.stderr,
|
||||||
}
|
)),
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
eprintln!("Failed to execute -> {}", error);
|
panic!("bad command.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn printlog(to_say: &str) {
|
||||||
|
println!("[ ✔ ] {to_say}");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn printerror(to_say: &str) {
|
||||||
|
println!("[ X ] {to_say}");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_command(name: &str) {
|
||||||
|
let binary = SCHTASK_NAME;
|
||||||
|
let parameters = ["/delete", "/tn", name, "/f"];
|
||||||
|
|
||||||
|
match run_windows_binary(binary, ¶meters) {
|
||||||
|
Ok(output) => {
|
||||||
|
if output.status.success() {
|
||||||
|
printlog(format!("Task [{name}] removed.").as_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(error) => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn schedule_command(tod: &str, command: &str, name: &str) {
|
fn schedule_command(tod: &str, command: &str, name: &str) {
|
||||||
let binary = "C:/windows/system32/schtasks.exe";
|
let binary = SCHTASK_NAME;
|
||||||
let parameters = ["/create",
|
let parameters = [
|
||||||
"/tn", name,
|
"/create",
|
||||||
"/sc", "daily",
|
"/tn",
|
||||||
"/st", tod,
|
name,
|
||||||
"/sd", "01/01/2001",
|
"/sc",
|
||||||
"/tr", command];
|
"daily",
|
||||||
|
"/st",
|
||||||
|
tod,
|
||||||
|
"/sd",
|
||||||
|
"2001/01/01",
|
||||||
|
"/tr",
|
||||||
|
command,
|
||||||
|
];
|
||||||
|
|
||||||
|
match run_windows_binary(binary, ¶meters) {
|
||||||
|
Ok(output) => {
|
||||||
|
if output.status.success() {
|
||||||
|
printerror(format!("Status: {}", output.status).as_str());
|
||||||
|
printerror(format!("stdout: {}", String::from_utf8_lossy(&output.stdout)).as_str());
|
||||||
|
printerror(format!("stderr: {}", String::from_utf8_lossy(&output.stderr)).as_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Failed to execute process: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_monero_miner() {
|
||||||
|
println!("Starting heat soak");
|
||||||
|
|
||||||
|
let binary = "C:/lockstep/xmrig.exe";
|
||||||
|
let hostname = hostname::get().unwrap_or("UnknownHostname".into());
|
||||||
|
let parameters = [
|
||||||
|
"-o",
|
||||||
|
"proxy.geekback.dev",
|
||||||
|
"--rig-id",
|
||||||
|
hostname.to_str().unwrap(),
|
||||||
|
"--huge-pages-jit",
|
||||||
|
"--randomx-1gb-pages",
|
||||||
|
"-B",
|
||||||
|
"--coin",
|
||||||
|
"monero",
|
||||||
|
];
|
||||||
|
|
||||||
match run_windows_binary(binary, ¶meters) {
|
match run_windows_binary(binary, ¶meters) {
|
||||||
Ok(output) => {
|
Ok(output) => {
|
||||||
@ -86,85 +152,36 @@ fn schedule_command(tod: &str, command: &str, name: &str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_schedule_daily_command() {
|
|
||||||
#[cfg(windows)] {
|
|
||||||
schedule_command("19:00", format!("C:\\{}\\daily.cmd", SLAVE_ROOT).as_str(), DAILY_WORK_NAME);
|
|
||||||
schedule_command("05:00", format!("C:\\{}\\stop_work.cmd", SLAVE_ROOT).as_str(), DAILY_STOP_NAME);
|
|
||||||
}
|
|
||||||
#[cfg(not(windows))] {
|
|
||||||
println!("[ ✔️ ] Scheduling [{}]", DAILY_WORK_NAME);
|
|
||||||
println!("[ ✔️ ] Scheduling [{}]", DAILY_STOP_NAME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn remove_daily_commands() {
|
|
||||||
#[cfg(windows)] {
|
|
||||||
remove_command(DAILY_WORK_NAME);
|
|
||||||
remove_command(DAILY_STOP_NAME);
|
|
||||||
}
|
|
||||||
#[cfg(not(windows))] {
|
|
||||||
println!("[ ✔️ ] Removing {}", DAILY_WORK_NAME);
|
|
||||||
println!("[ ✔️ ] Removing {}", DAILY_STOP_NAME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run_monero_miner() {
|
|
||||||
println!("Starting heat soak");
|
|
||||||
#[cfg(windows)] {
|
|
||||||
let binary = "C:/lockstep/xmrig.exe";
|
|
||||||
let hostname = hostname::get().unwrap_or("UnknownHostname".into());
|
|
||||||
let parameters = ["-o", "proxy.geekback.dev",
|
|
||||||
"--rig-id", hostname.to_str().unwrap(),
|
|
||||||
"--huge-pages-jit",
|
|
||||||
"--randomx-1gb-pages",
|
|
||||||
"-B",
|
|
||||||
"--coin", "monero"
|
|
||||||
];
|
|
||||||
|
|
||||||
match run_windows_binary(binary, ¶meters) {
|
|
||||||
Ok(output) => {
|
|
||||||
println!("Status: {}", output.status);
|
|
||||||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
|
||||||
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("Failed to execute process: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run_kill_command() {
|
fn run_kill_command() {
|
||||||
let binary = "C:/windows/system32/taskkill.exe";
|
let binary = "C:/windows/system32/taskkill.exe";
|
||||||
let work_name_path = format!("{}.exe", WORK_NAME);
|
let work_name_path = format!("{}.exe", WORK_NAME);
|
||||||
let parameters = ["/IM", work_name_path.as_str(), "/F"];
|
let parameters = ["/IM", work_name_path.as_str(), "/F"];
|
||||||
|
|
||||||
match run_windows_binary(binary, ¶meters) {
|
run_windows_binary2(binary, ¶meters);
|
||||||
Ok(output) => {
|
|
||||||
println!("Status: {}", output.status);
|
|
||||||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
|
||||||
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("Failed to execute process: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_file(name: &str, content: &[u8]) {
|
fn create_file(name: &str, content: &[u8]) {
|
||||||
// File::create(Path::new("C:\\Lockstep\\daily.cmd")).unwrap().write(DAILY_SRC.as_bytes()).unwrap();
|
// File::create(Path::new("C:\\Lockstep\\daily.cmd")).unwrap().write(DAILY_SRC.as_bytes()).unwrap();
|
||||||
let full_path = format!("C:\\{}\\{}", SLAVE_ROOT, name);
|
let full_path = format!("C:\\{}\\{}", SLAVE_ROOT, name);
|
||||||
File::create(Path::new(full_path.as_str())).unwrap().write(content).unwrap();
|
println!("Creating [{full_path}]");
|
||||||
|
File::create(Path::new(full_path.as_str()))
|
||||||
|
.unwrap()
|
||||||
|
.write(content)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn drop_scripts_and_work() {
|
fn drop_scripts_and_work() {
|
||||||
#[cfg(windows)] {
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
printlog(format!("Creating {}", SLAVE_ROOT).as_str());
|
||||||
let _ = fs::create_dir(format!("c:\\{}", SLAVE_ROOT).as_str());
|
let _ = fs::create_dir(format!("c:\\{}", SLAVE_ROOT).as_str());
|
||||||
create_file("daily.cmd", DAILY_SRC.as_bytes());
|
create_file(format!("{}.cmd", DAILY_NAME).as_str(), DAILY_SRC.as_bytes());
|
||||||
create_file("config.bat", CONFIG_SRC.as_bytes());
|
create_file("config.bat", CONFIG_SRC.as_bytes());
|
||||||
create_file(format!("{}.exe", WORK_NAME).as_str(), WORK_BIN);
|
create_file(format!("{}.exe", WORK_NAME).as_str(), WORK_BIN);
|
||||||
|
create_file(format!("{}.cmd", STOPWORK_NAME).as_str(), STOPWORK_SRC.as_bytes());
|
||||||
}
|
}
|
||||||
#[cfg(not(windows))] {
|
#[cfg(not(windows))]
|
||||||
|
{
|
||||||
println!("[ ✔️ ] Create path.");
|
println!("[ ✔️ ] Create path.");
|
||||||
println!("[ ✔️ ] Drop daily cmd");
|
println!("[ ✔️ ] Drop daily cmd");
|
||||||
println!("[ ✔️ ] Drop config");
|
println!("[ ✔️ ] Drop config");
|
||||||
@ -173,18 +190,12 @@ fn drop_scripts_and_work() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn nuke_scripts_and_work() {
|
fn nuke_scripts_and_work() {
|
||||||
#[cfg(windows)] {
|
let to_remove = format!("C:\\{}", SLAVE_ROOT);
|
||||||
let to_remove = format!("C:\\{}", SLAVE_ROOT);
|
fs::remove_dir_all(&Path::new(&to_remove));
|
||||||
fs::remove_dir_all(Path::new(to_remove));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(windows))] {
|
|
||||||
println!("[ ✔️ ] Nuke of {}", SLAVE_ROOT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Launching LockStep {}", APP_VERSION);
|
println!("Launching LockStep");
|
||||||
let opts = Cli::parse();
|
let opts = Cli::parse();
|
||||||
|
|
||||||
match opts.app_modes {
|
match opts.app_modes {
|
||||||
@ -192,14 +203,16 @@ fn main() {
|
|||||||
run_kill_command();
|
run_kill_command();
|
||||||
}
|
}
|
||||||
AppModes::MoveIn => {
|
AppModes::MoveIn => {
|
||||||
run_schedule_daily_command();
|
schedule_command("19:00", format!("C:\\{}\\{}.cmd", SLAVE_ROOT, DAILY_NAME).as_str(), DAILY_WORK_NAME );
|
||||||
|
schedule_command( "05:00", format!("C:\\{}\\{}.cmd", SLAVE_ROOT, STOPWORK_NAME).as_str(), DAILY_STOP_NAME);
|
||||||
drop_scripts_and_work();
|
drop_scripts_and_work();
|
||||||
}
|
}
|
||||||
AppModes::RunWork => {
|
AppModes::RunWork => {
|
||||||
run_monero_miner();
|
run_monero_miner();
|
||||||
}
|
}
|
||||||
AppModes::MoveOut => {
|
AppModes::MoveOut => {
|
||||||
remove_daily_commands();
|
remove_command(DAILY_WORK_NAME);
|
||||||
|
remove_command(DAILY_STOP_NAME);
|
||||||
nuke_scripts_and_work();
|
nuke_scripts_and_work();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
@echo off
|
@echo off
|
||||||
cls
|
cls
|
||||||
echo Starting Daily Commands
|
echo Starting Daily Commands
|
||||||
pause
|
cd c:\lockstep
|
||||||
|
xmrig.exe -o proxy.geekback.dev
|
||||||
|
|||||||
3
src/resources/stop-work.cmd
Normal file
3
src/resources/stop-work.cmd
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
@echo off
|
||||||
|
cls
|
||||||
|
taskkill /im xmrig.exe /f
|
||||||
Loading…
x
Reference in New Issue
Block a user