-
Notifications
You must be signed in to change notification settings - Fork 46
/
build.rs
56 lines (48 loc) · 1.6 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
use fomat_macros::fomat;
use std::{env, fs::File, io::Write};
fn service(description: &str, appid: &str, exec: &str) -> String {
fomat!(
"[Unit]\n"
"Description=" (description) "\n"
"Wants=" (appid) ".timer\n"
"\n"
"[Service]\n"
"ExecStart=" (exec) "\n"
"\n"
"[Install]\n"
"WantedBy=default.target\n"
)
}
fn timer(description: &str, appid: &str, minutes: u16) -> String {
fomat!(
"[Unit]\n"
"Description=" (description) "\n"
"Requires=" (appid) ".service\n"
"\n"
"[Timer]\n"
"Unit=" (appid) ".service\n"
"OnUnitInactiveSec=" (minutes) "m\n"
"AccuracySec=1s\n"
"\n"
"[Install]\n"
"WantedBy=timers.target\n"
)
}
fn main() {
let appid = env::var("APPID").unwrap();
let prefix = env::var("prefix").unwrap();
let timer_path = ["../target/", &appid, ".timer"].concat();
let service_path = ["../target/", &appid, ".service"].concat();
let exec = [&prefix, "/bin/", &appid].concat();
let timer = timer("Checks for new firmware every day", &appid, 1440);
let service =
service("Check for firmware updates, and display a notification if found", &appid, &exec);
File::create(timer_path)
.expect("failed to create timer service")
.write_all(timer.to_string().as_bytes())
.expect("failed to write timer service");
File::create(service_path)
.expect("failed to create service service")
.write_all(service.to_string().as_bytes())
.expect("failed to write service service");
}