only add numbers to jsonrpc2.yml config file; skip any other files

starting with a '+'
This commit is contained in:
Bernhard B
2021-10-10 17:54:08 +02:00
parent 0baa20f750
commit d7825a4da8

View File

@@ -43,34 +43,41 @@ func main() {
err := filepath.Walk(*signalCliConfigDir, func(path string, info os.FileInfo, err error) error { err := filepath.Walk(*signalCliConfigDir, func(path string, info os.FileInfo, err error) error {
filename := filepath.Base(path) filename := filepath.Base(path)
if strings.HasPrefix(filename, "+") && info.Mode().IsRegular() { if strings.HasPrefix(filename, "+") && info.Mode().IsRegular() {
fifoPathname := fifoBasePathName + strconv.FormatInt(ctr, 10) if utils.IsPhoneNumber(filename) {
tcpPort := tcpBasePort + ctr number := filename
jsonRpc2ClientConfig.AddEntry(filename, utils.ConfigEntry{TcpPort: tcpPort, FifoPathname: fifoPathname}) fifoPathname := fifoBasePathName + strconv.FormatInt(ctr, 10)
ctr += 1 tcpPort := tcpBasePort + ctr
_, err = exec.Command("mkfifo", fifoPathname).Output() jsonRpc2ClientConfig.AddEntry(number, utils.ConfigEntry{TcpPort: tcpPort, FifoPathname: fifoPathname})
if err != nil { ctr += 1
log.Fatal("Couldn't create fifo with name ", fifoPathname, ": ", err.Error()) _, err = exec.Command("mkfifo", fifoPathname).Output()
} if err != nil {
log.Fatal("Couldn't create fifo with name ", fifoPathname, ": ", err.Error())
}
_, err = exec.Command("chown", "1000:1000", fifoPathname).Output() _, err = exec.Command("chown", "1000:1000", fifoPathname).Output()
if err != nil { if err != nil {
log.Fatal("Couldn't change permissions of fifo with name ", fifoPathname, ": ", err.Error()) log.Fatal("Couldn't change permissions of fifo with name ", fifoPathname, ": ", err.Error())
} }
supervisorctlProgramName := "signal-cli-json-rpc-" + strconv.FormatInt(ctr, 10) supervisorctlProgramName := "signal-cli-json-rpc-" + strconv.FormatInt(ctr, 10)
supervisorctlLogFolder := "/var/log/" + supervisorctlProgramName supervisorctlLogFolder := "/var/log/" + supervisorctlProgramName
_, err = exec.Command("mkdir", "-p", supervisorctlLogFolder).Output() _, err = exec.Command("mkdir", "-p", supervisorctlLogFolder).Output()
if err != nil { if err != nil {
log.Fatal("Couldn't create log folder ", supervisorctlLogFolder, ": ", err.Error()) log.Fatal("Couldn't create log folder ", supervisorctlLogFolder, ": ", err.Error())
} }
//write supervisorctl config log.Info("Found number ", number, " and added it to jsonrpc2.yml")
supervisorctlConfigFilename := "/etc/supervisor/conf.d/" + "signal-cli-json-rpc-" + strconv.FormatInt(ctr, 10) + ".conf"
supervisorctlConfig := fmt.Sprintf(supervisorctlConfigTemplate, supervisorctlProgramName, supervisorctlProgramName, //write supervisorctl config
tcpPort, fifoPathname, filename, fifoPathname, supervisorctlProgramName, supervisorctlProgramName) supervisorctlConfigFilename := "/etc/supervisor/conf.d/" + "signal-cli-json-rpc-" + strconv.FormatInt(ctr, 10) + ".conf"
err = ioutil.WriteFile(supervisorctlConfigFilename, []byte(supervisorctlConfig), 0644) supervisorctlConfig := fmt.Sprintf(supervisorctlConfigTemplate, supervisorctlProgramName, supervisorctlProgramName,
if err != nil { tcpPort, fifoPathname, number, fifoPathname, supervisorctlProgramName, supervisorctlProgramName)
log.Fatal("Couldn't write ", supervisorctlConfigFilename, ": ", err.Error()) err = ioutil.WriteFile(supervisorctlConfigFilename, []byte(supervisorctlConfig), 0644)
if err != nil {
log.Fatal("Couldn't write ", supervisorctlConfigFilename, ": ", err.Error())
}
} else {
log.Error("Skipping ", filename, " as it is not a valid phone number!")
} }
} }
return nil return nil