about summary refs log tree commit diff
path: root/pkgs/by-name/un/uni-sync/config_path.patch
blob: c59bf80125ae06d8030a0b08abc2ccd930fb7e4d (plain) (blame)
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
diff --git a/src/main.rs b/src/main.rs
index 357a33b..7073497 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,4 @@
-use std::env;
+use std::path::PathBuf;
 
 mod devices;
 
@@ -8,12 +8,23 @@ fn main() -> Result<(), std::io::Error> {
         configs: vec![]
     };
 
-    let mut config_path = env::current_exe()?;
-    config_path.pop();
-    config_path.push("uni-sync.json");
+    let mut config_path = PathBuf::from("/etc/uni-sync/uni-sync.json");
 
     if !config_path.exists() {
-        std::fs::write(&config_path, serde_json::to_string_pretty(&configs).unwrap())?;
+        match std::fs::create_dir_all(config_path.parent().unwrap()) {
+            Ok(result) => result,
+            Err(_) => {
+                println!("Please run uni-sync with elevated permissions.");
+                std::process::exit(0);
+            }
+        };
+        match std::fs::write(&config_path, serde_json::to_string_pretty(&configs).unwrap()) {
+            Ok(result) => result,
+            Err(_) => {
+                println!("Please run uni-sync with elevated permissions.");
+                std::process::exit(0);
+            }
+        };
     }
 
     let config_content = std::fs::read_to_string(&config_path).unwrap();