-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Linux: Use udev backend; add udev rules tool
- Loading branch information
Tyera Eulberg
committed
Feb 6, 2020
1 parent
5c2fc08
commit 3fad635
Showing
4 changed files
with
89 additions
and
90 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/// Implements udev rules on Linux for supported Ledger devices | ||
/// This script must be run with sudo privileges | ||
use std::{ | ||
error, | ||
fs::{File, OpenOptions}, | ||
io::{Read, Write}, | ||
path::Path, | ||
}; | ||
|
||
const LEDGER_UDEV_RULES: &'static str = r#" | ||
# Nano S | ||
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0001|1000|1001|1002|1003|1004|1005|1006|1007|1008|1009|100a|100b|100c|100d|100e|100f|1010|1011|1012|1013|1014|1015|1016|1017|1018|1019|101a|101b|101c|101d|101e|101f", TAG+="uaccess", TAG+="udev-acl", MODE="0666" | ||
# Nano X | ||
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0004|4000|4001|4002|4003|4004|4005|4006|4007|4008|4009|400a|400b|400c|400d|400e|400f|4010|4011|4012|4013|4014|4015|4016|4017|4018|4019|401a|401b|401c|401d|401e|401f", TAG+="uaccess", TAG+="udev-acl", MODE="0666" | ||
"#; | ||
|
||
fn main() -> Result<(), Box<dyn error::Error>> { | ||
if cfg!(target_os = "linux") { | ||
let mut contents = String::new(); | ||
if Path::new("/etc/udev/rules.d/20-hw1.rules").exists() { | ||
let mut file = File::open("/etc/udev/rules.d/20-hw1.rules")?; | ||
file.read_to_string(&mut contents)?; | ||
} | ||
if !contents.contains(LEDGER_UDEV_RULES) { | ||
let mut file = OpenOptions::new() | ||
.append(true) | ||
.create(true) | ||
.open("/etc/udev/rules.d/20-hw1.rules") | ||
.map_err(|e| { | ||
println!("Could not write to file; this script requires sudo privileges"); | ||
e | ||
})?; | ||
file.write(LEDGER_UDEV_RULES.as_bytes())?; | ||
println!("Ledger udev rules written"); | ||
} else { | ||
println!("Ledger udev rules already in place"); | ||
} | ||
} else { | ||
println!("Mismatched target_os; udev rules only required on linux os"); | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters