-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
46 lines (46 loc) · 1.4 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::fs;
use std::path::PathBuf;
#[cfg(unix)]
use std::process::Command;
#[cfg(windows)]
fn main() {
let program_data = PathBuf::from("C:\\ProgramData\\klone");
if program_data.is_dir() {
return;
}
let _ = fs::create_dir_all(&program_data);
let _ = fs::write(
program_data.join("exclusions.json"),
format!("[{:?},{:?},{:?},{:?}]", "*/.git", "*.o", "*.bin", "*.lock"),
);
let _ = fs::write(
program_data.join("defaults.json"),
format!(
"{} {:?}:{:?}, {:?}:{:?} {}\n",
"{", "origin", "None", "target", "None", "}"
),
);
}
#[cfg(unix)]
fn main() {
// Not the best for security but, only way I can think of doing this
// TODO Checks if the files exist
if PathBuf::from("/etc/klone/").is_dir() {
return;
}
let mut input = String::new();
println!("Enter sudo password to create the neccesary files for the app to ");
std::io::stdin().read_line(&mut input).unwrap();
let _ = Command::new("sudo").args(["mkdir", "/etc/klone"]).output();
let _ = Command::new("sudo")
.args(["chmod", "-R", "777", "/etc/klone/"])
.output();
let _ = fs::write("/etc/klone/exclusions.json", "[]");
let _ = fs::write(
"/etc/klone/defaults.json",
format!(
"{} {:?}:{:?}, {:?}:{:?} {}\n",
"{", "origin", "None", "target", "None", "}"
),
);
}