infrastructure/cmd/config-generator/zkgroups.go

37 lines
644 B
Go

package main
import (
"bytes"
"os"
"os/exec"
"strings"
)
func GenerateZKConfig() (z ZKConfig) {
z.Enabled = false
cmd := exec.Command("java", "-jar", "/usr/share/TextSecureServer.jar", "zkparams")
var out bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
panic(err)
}
for _, line := range strings.Split(out.String(), "\n") {
if len(line) == 0 {
continue
}
parts := strings.Split(line, ": ")
if len(parts) != 2 {
continue
} else {
}
if parts[0] == "Public" {
z.ServerPublic = parts[1]
} else if parts[0] == "Private" {
z.ServerSecret = parts[1]
}
}
return
}