Add setup wizard binary - #92
Conversation
|
|
||
| println!(); | ||
| println!("{YELLOW}Run:{RESET}"); | ||
| println!(" {GREEN}cargo {}{RESET}", args.join(" ")); |
There was a problem hiding this comment.
A datadir with spaces silently runs against a truncated path. Perhaps quote each arg with a single-quote?
There was a problem hiding this comment.
Passing with ~/My Node is creating the 'My Node' folder in my home directory. Maybe this is a Linux/MacOS discrepancy in the PathBuf type?
There was a problem hiding this comment.
Apologies, cold card related stuff ate my day yesterday so I didn't get to suggesting fixes. Also my comment wasn't clear on this, I meant the printed string, not the args passed to Command. Typed bare, ~/My Node works when the wizard launches the node itself, since Command::args passes it as one argv entry, it's only the printed line that splits when pasted. It's also worth noting that path expansion can also introduce spaces the user never typed.
Here's a suggestion...
| println!(" {GREEN}cargo {}{RESET}", args.join(" ")); | |
| let printable: Vec<Cow<'_, str>> = args.iter().map(|a| shell_quote(a)).collect(); | |
| println!(" {GREEN}cargo {}{RESET}", printable.join(" ")); |
use std::borrow::Cow;
fn shell_quote(arg: &str) -> Cow<'_, str> {
let safe = |c: char| c.is_ascii_alphanumeric() || "-_./=:,@+~".contains(c);
if !arg.is_empty() && arg.chars().all(safe) {
Cow::Borrowed(arg)
} else {
Cow::Owned(format!("'{}'", arg.replace('\'', r"'\''")))
}
}
Each arg is printed bare if it's made only of characters a shell already treats literally, otherwise I am wrapping them in single quotes:
signet -> signet
--daemon=true -> --daemon=true
~/.kernel-node -> ~/.kernel-node
/tmp/kn demo -> '/tmp/kn demo'
/tmp/$HOME/keys.bin -> '/tmp/$HOME/keys.bin'
/home/me/o'brien/keys.bin -> '/home/me/o'\''brien/keys.bin'
I put single quotes on something like $HOME so it stays literal instead of expanding. I put ~ in the bare set because quoting it would suppress expansion and make the default datadir look broken, but that's a judgement call on my part, I think it's correct either way. The last one is an awkward case. You can't nest a single quote, so it closes, emits an escaped one, and reopens.
There was a problem hiding this comment.
Nice, applied that suggestion in the latest push. Sorry about the coldcard debacle. In fact, I was gonna open and issue to potentially bump our rand and make explicit we are using the SysRng, which internally uses the getrandom syscall on the Linux kernel. This syscall uses entropy generated from different sources like CPU temperature, mouse clicks, etc and is believed to be CSRNG
There was a problem hiding this comment.
In fact, I was gonna open and issue to potentially bump our
randand make explicit we are using theSysRng, which internally uses thegetrandomsyscall on the Linux kernel. This syscall uses entropy generated from different sources like CPU temperature, mouse clicks, etc and is believed to be CSRNG
Agreed, was thinking about that & related matters as well.
There was a problem hiding this comment.
I was gonna open and issue to potentially bump our rand and make explicit we are using the SysRng
which crate are you referring to? I noticed the wallet uses rand via secp:
let mut rng = bitcoin::secp256k1::rand::thread_rng();
I don't see rand in the node crate though..
There was a problem hiding this comment.
Yeah, rand is the correct crate, just an older version. thread_rng is considered secure. The propose of the refactor would be to make it abundantly clear to ourselves and others that the source is CSRNG. The current state of the rand book recommends:
let rng = StdRng::try_from_rng(&mut SysRng).unwrap();There was a problem hiding this comment.
Hmm I created this PR last year (in october) to bump rand from 0.8 to 0.9 p2pderivatives/rust-bitcoin-coin-selection#234 for the coin-selection crate. Cant remember why, but the PR switches from thread_rng to rng it looks like.
There was a problem hiding this comment.
Anyway, I think you would want to open an issue on the secp256k1 crate to bump the rand dep there? Although it looks like master is on 0.9.x for rand.
4ebde34 to
58f25b5
Compare
|
ACK 76a809d |
Closes #91
Common configuration options can be set via this setup program that prompts the user. This uses the existing
libcdependency for raw mode in the terminal.