7 Commits
1.0.3 ... 1.0.5

Author SHA1 Message Date
f67342de1a Bump version 2023-08-23 21:33:56 +03:00
98c48af331 Fixed brace expansion 2023-08-23 21:33:14 +03:00
3cf1e79883 Added pkgbuild 2023-08-14 19:19:00 +03:00
0d95364e50 Added pkgbuild 2023-08-14 19:10:34 +03:00
48635fc091 Added PKGBUILD 2023-08-14 18:23:12 +03:00
5ed62d9323 Fix some error handling 2023-08-02 16:29:37 +03:00
c635ed0dd0 Fix some error handling 2023-07-31 12:10:36 +03:00
6 changed files with 78 additions and 13 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
target target
pkg
*zst

View File

@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.4] - 2023-08-14
### Changed
- Expansion host strings.
## [1.0.1] - 2023-06-20 ## [1.0.1] - 2023-06-20
### Changed ### Changed

2
Cargo.lock generated
View File

@ -1043,7 +1043,7 @@ checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]] [[package]]
name = "rexec" name = "rexec"
version = "1.0.2" version = "1.0.4"
dependencies = [ dependencies = [
"brace-expand", "brace-expand",
"clap 4.3.4", "clap 4.3.4",

View File

@ -1,6 +1,7 @@
[package] [package]
name = "rexec" name = "rexec"
version = "1.0.3" version = "1.0.5"
readme = "https://github.com/house-of-vanity/rexec#readme"
edition = "2021" edition = "2021"
description = "Parallel SSH executor" description = "Parallel SSH executor"
repository = "https://github.com/house-of-vanity/rexec" repository = "https://github.com/house-of-vanity/rexec"

25
PKGBUILD Normal file
View File

@ -0,0 +1,25 @@
# Maintainer: AB <gh@hexor.ru>
pkgname=rexec
pkgver=1.0.4.r0.g3cf1e79
pkgrel=1
pkgdesc="Parallel SSH executor"
url="https://github.com/house-of-vanity/rexec"
license=("WTFPL")
arch=("x86_64")
makedepends=("cargo")
pkgver() {
(git describe --long --tags || echo "$pkgver") | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}
build() {
return 0
}
package() {
cd ..
usrdir="$pkgdir/usr"
mkdir -p $usrdir
cargo install --no-track --path . --root "$usrdir"
}

View File

@ -24,13 +24,17 @@ struct Args {
#[arg(short, long, default_value_t = whoami::username())] #[arg(short, long, default_value_t = whoami::username())]
username: String, username: String,
#[arg(short, long, help = "Use known_hosts to build servers list")] #[arg(
short,
long,
help = "Use known_hosts to build servers list instead of string expansion."
)]
known_hosts: bool, known_hosts: bool,
#[arg( #[arg(
short, short,
long, long,
help = "Expression to build server list. List and range expansion available. Example: 'web-[1:12]-io-{prod,dev}'" help = "Expression to build server list. List and range expansion are supported. Example: 'web-[1:12]-io-{prod,dev}'"
)] )]
expression: String, expression: String,
@ -92,13 +96,25 @@ fn expand_string(s: &str) -> Vec<Host> {
while let Some(r) = result.iter().find(|s| s.contains('[')) { while let Some(r) = result.iter().find(|s| s.contains('[')) {
let r = r.clone(); let r = r.clone();
let start = r.find('[').unwrap(); let start = r.find('[').unwrap();
let end = r.find(']').unwrap(); let end = match r[start..].find(']') {
let colon = r.find(':').unwrap(); None => {
let low = r[start+1..colon].parse::<i32>().unwrap(); error!("Error parsing host expression. Wrong range expansion '[a:b]'");
let high = r[colon+1..end].parse::<i32>().unwrap(); process::exit(1);
}
Some(s) => s + start,
};
let colon = match r[start..end].find(':') {
None => {
error!("Error parsing host expression. Missing colon in range expansion '[a:b]'");
process::exit(1);
}
Some(c) => c + start,
};
let low = r[start + 1..colon].parse::<i32>().unwrap();
let high = r[colon + 1..end].parse::<i32>().unwrap();
result.retain(|s| s != &r); result.retain(|s| s != &r);
for val in expand_range(low, high) { for val in expand_range(low, high) {
let new_str = format!("{}{}{}", &r[..start], val, &r[end+1..]); let new_str = format!("{}{}{}", &r[..start], val, &r[end + 1..]);
result.push(new_str); result.push(new_str);
} }
} }
@ -106,11 +122,17 @@ fn expand_string(s: &str) -> Vec<Host> {
while let Some(r) = result.iter().find(|s| s.contains('{')) { while let Some(r) = result.iter().find(|s| s.contains('{')) {
let r = r.clone(); let r = r.clone();
let start = r.find('{').unwrap(); let start = r.find('{').unwrap();
let end = r.find('}').unwrap(); let end = match r.find('}') {
let list = &r[start+1..end]; None => {
error!("Error parsing host expression. Wrong range expansion '{{one,two}}'");
process::exit(1);
}
Some(s) => s,
};
let list = &r[start + 1..end];
result.retain(|s| s != &r); result.retain(|s| s != &r);
for val in expand_list(list) { for val in expand_list(list) {
let new_str = format!("{}{}{}", &r[..start], val, &r[end+1..]); let new_str = format!("{}{}{}", &r[..start], val, &r[end + 1..]);
result.push(new_str); result.push(new_str);
} }
} }
@ -124,7 +146,6 @@ fn expand_string(s: &str) -> Vec<Host> {
hosts hosts
} }
fn main() { fn main() {
env_logger::Builder::from_env(Env::default().default_filter_or("info")) env_logger::Builder::from_env(Env::default().default_filter_or("info"))
.format_timestamp(None) .format_timestamp(None)
@ -159,6 +180,16 @@ fn main() {
// Build MasshHostConfig hostnames list // Build MasshHostConfig hostnames list
let mut massh_hosts: Vec<MasshHostConfig> = vec![]; let mut massh_hosts: Vec<MasshHostConfig> = vec![];
let mut hosts_and_ips: HashMap<IpAddr, String> = HashMap::new(); let mut hosts_and_ips: HashMap<IpAddr, String> = HashMap::new();
if args.parallel != 100 {
warn!("Parallelism: {} thread{}", &args.parallel, {
if args.parallel != 1 {
"s."
} else {
"."
}
});
}
info!("Matched hosts:"); info!("Matched hosts:");
for host in matched_hosts.iter() { for host in matched_hosts.iter() {
let ip = match lookup_host(&host.name) { let ip = match lookup_host(&host.name) {