aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/commands
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2017-07-01 23:18:40 +0200
committerPacien TRAN-GIRARD2017-07-01 23:18:40 +0200
commitd221543bb9d6bc9b7344cc96f010a501ff35bb7f (patch)
treeb86dc361ac279615ded4cbf902743d90559a39db /app/src/main/java/org/pacien/tincapp/commands
parent3e3135b0c7fba811735a30e7fd155ca1e188c787 (diff)
downloadtincapp-d221543bb9d6bc9b7344cc96f010a501ff35bb7f.tar.gz
Support config located on external storage with the "external/" prefix
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/commands')
-rw-r--r--app/src/main/java/org/pacien/tincapp/commands/Tinc.kt30
-rw-r--r--app/src/main/java/org/pacien/tincapp/commands/Tincd.kt8
2 files changed, 16 insertions, 22 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt
index 91a2678..5116d63 100644
--- a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt
+++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt
@@ -8,22 +8,16 @@ import java.io.IOException
8 */ 8 */
9object Tinc { 9object Tinc {
10 10
11 private fun newCommand(netName: String): Command = 11 private fun newCommand(netConf: AppPaths.NetConf): Command =
12 Command(AppPaths.tinc().absolutePath) 12 Command(AppPaths.tinc().absolutePath)
13 .withOption("config", AppPaths.confDir(netName).absolutePath) 13 .withOption("config", AppPaths.confDir(netConf).absolutePath)
14 .withOption("pidfile", AppPaths.pidFile(netName).absolutePath) 14 .withOption("pidfile", AppPaths.pidFile(netConf).absolutePath)
15 15
16 // independently runnable commands 16 // independently runnable commands
17 17
18 @Throws(IOException::class) 18 @Throws(IOException::class)
19 fun network(): List<String> = 19 fun fsck(netConf: AppPaths.NetConf, fix: Boolean): List<String> {
20 Executor.call(Command(AppPaths.tinc().absolutePath) 20 var cmd = newCommand(netConf).withArguments("fsck")
21 .withOption("config", AppPaths.confDir().absolutePath)
22 .withArguments("network"))
23
24 @Throws(IOException::class)
25 fun fsck(netName: String, fix: Boolean): List<String> {
26 var cmd = newCommand(netName).withArguments("fsck")
27 if (fix) cmd = cmd.withOption("force") 21 if (fix) cmd = cmd.withOption("force")
28 return Executor.call(cmd) 22 return Executor.call(cmd)
29 } 23 }
@@ -31,18 +25,18 @@ object Tinc {
31 // commands requiring a running tinc daemon 25 // commands requiring a running tinc daemon
32 26
33 @Throws(IOException::class) 27 @Throws(IOException::class)
34 fun stop(netName: String) { 28 fun stop(netConf: AppPaths.NetConf) {
35 Executor.call(newCommand(netName).withArguments("stop")) 29 Executor.call(newCommand(netConf).withArguments("stop"))
36 } 30 }
37 31
38 @Throws(IOException::class) 32 @Throws(IOException::class)
39 fun dumpNodes(netName: String, reachable: Boolean): List<String> = 33 fun dumpNodes(netConf: AppPaths.NetConf, reachable: Boolean): List<String> =
40 Executor.call( 34 Executor.call(
41 if (reachable) newCommand(netName).withArguments("dump", "reachable", "nodes") 35 if (reachable) newCommand(netConf).withArguments("dump", "reachable", "nodes")
42 else newCommand(netName).withArguments("dump", "nodes")) 36 else newCommand(netConf).withArguments("dump", "nodes"))
43 37
44 @Throws(IOException::class) 38 @Throws(IOException::class)
45 fun info(netName: String, node: String): String = 39 fun info(netConf: AppPaths.NetConf, node: String): String =
46 Executor.call(newCommand(netName).withArguments("info", node)).joinToString("\n") 40 Executor.call(newCommand(netConf).withArguments("info", node)).joinToString("\n")
47 41
48} 42}
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt b/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt
index 19ebfbd..c54b328 100644
--- a/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt
+++ b/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt
@@ -9,12 +9,12 @@ import java.io.IOException
9object Tincd { 9object Tincd {
10 10
11 @Throws(IOException::class) 11 @Throws(IOException::class)
12 fun start(netName: String, fd: Int) { 12 fun start(netConf: AppPaths.NetConf, fd: Int) {
13 Executor.forkExec(Command(AppPaths.tincd().absolutePath) 13 Executor.forkExec(Command(AppPaths.tincd().absolutePath)
14 .withOption("no-detach") 14 .withOption("no-detach")
15 .withOption("config", AppPaths.confDir(netName).absolutePath) 15 .withOption("config", AppPaths.confDir(netConf).absolutePath)
16 .withOption("pidfile", AppPaths.pidFile(netName).absolutePath) 16 .withOption("pidfile", AppPaths.pidFile(netConf).absolutePath)
17 .withOption("logfile", AppPaths.logFile(netName).absolutePath) 17 .withOption("logfile", AppPaths.logFile(netConf).absolutePath)
18 .withOption("option", "DeviceType=fd") 18 .withOption("option", "DeviceType=fd")
19 .withOption("option", "Device=" + fd)) 19 .withOption("option", "Device=" + fd))
20 } 20 }