-
Notifications
You must be signed in to change notification settings - Fork 31
/
build.rs
56 lines (45 loc) · 1.7 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
47
48
49
50
51
52
53
54
55
56
#![allow(dead_code)]
use std::fs::File;
use std::io::{self, Write};
use std::path::Path;
fn download<P: AsRef<Path> + Copy>(url: &str, file_path: P) -> bool {
use reqwest::blocking as http;
if Path::exists(file_path.as_ref()) {
return false;
}
let rest = http::get(url).unwrap_or_else(|_| panic!("URL: {} download failed!!!", url));
let bytes = rest.bytes().expect("read bytes from server failed!!!");
write_all_to_file(file_path, bytes);
true
}
fn write_all_to_file<P: AsRef<Path> + Copy, T: AsRef<[u8]>>(file_path: P, text: T) {
let mut file = File::create(file_path)
.unwrap_or_else(|_| panic!("Create file {:?} failed", file_path.as_ref()));
file.write_all(text.as_ref()).unwrap();
}
fn append_text_to_file<P: AsRef<Path> + Copy, T: AsRef<[u8]>>(file_path: P, text: T) {
let mut file = File::options()
.append(true)
.create(true)
.open(file_path)
.unwrap_or_else(|_| panic!("Create file {:?} failed", file_path.as_ref()));
file.write_all(text.as_ref()).unwrap();
}
fn main() -> io::Result<()> {
std::fs::create_dir_all("./logs")?;
if download(
"https://cdn.jsdelivr.net/gh/pymumu/smartdns/etc/smartdns/smartdns.conf",
"etc/smartdns/smartdns.conf",
) {
// append_text_to_file("./etc/smartdns/smartdns.conf", "\nconf-file custom.conf\n");
}
download(
"https://cdn.jsdelivr.net/gh/pymumu/smartdns/package/openwrt/files/etc/init.d/smartdns",
"src/service/linux/initd/openwrt/files/etc/init.d/smartdns-rs",
);
download(
"https://cdn.jsdelivr.net/gh/mullvad/windows-service-rs/src/shell_escape.rs",
"src/service/windows/shell_escape.rs",
);
Ok(())
}