added more sanity checks + restructured code a bit

This commit is contained in:
Bernhard B
2021-09-11 23:03:01 +02:00
parent 79fa00fdf1
commit 2a0347eea2
5 changed files with 67 additions and 30 deletions

View File

@@ -73,8 +73,45 @@ func main() {
log.Fatal("Couldn't set env variable: ", err.Error())
}
useNative := utils.GetEnv("USE_NATIVE", "")
if useNative != "" {
log.Warning("The env variable USE_NATIVE is deprecated. Please use the env variable MODE instead")
}
signalCliMode := client.Normal
mode := utils.GetEnv("MODE", "normal")
if mode == "normal" {
signalCliMode = client.Normal
} else if mode == "json-rpc" {
signalCliMode = client.JsonRpc
} else if mode == "native" {
signalCliMode = client.Native
}
if useNative != "" {
_, modeEnvVariableSet := os.LookupEnv("MODE")
if modeEnvVariableSet {
log.Fatal("You have both the USE_NATIVE and the MODE env variable set. Please remove the deprecated env variable USE_NATIVE!")
}
}
if useNative == "1" || signalCliMode == client.Native {
if supportsSignalCliNative == "0" {
log.Error("signal-cli-native is not support on this system...falling back to signal-cli")
signalCliMode = client.Normal
}
}
if signalCliMode == client.JsonRpc {
_, autoReceiveScheduleEnvVariableSet := os.LookupEnv("AUTO_RECEIVE_SCHEDULE")
if autoReceiveScheduleEnvVariableSet {
log.Fatal("Env variable AUTO_RECEIVE_SCHEDULE can't be used with mode json-rpc")
}
}
jsonRpc2ClientConfigPathPath := *signalCliConfig + "/jsonrpc2.yml"
signalClient := client.NewSignalClient(*signalCliConfig, *attachmentTmpDir, *avatarTmpDir, client.JsonRpc, jsonRpc2ClientConfigPathPath)
signalClient := client.NewSignalClient(*signalCliConfig, *attachmentTmpDir, *avatarTmpDir, signalCliMode, jsonRpc2ClientConfigPathPath)
err = signalClient.Init()
if err != nil {
log.Fatal("Couldn't init Signal Client: ", err.Error())