|
19 | 19 | package main |
20 | 20 |
|
21 | 21 | import ( |
22 | | - _ "embed" |
23 | 22 | "encoding/json" |
24 | 23 | "flag" |
25 | 24 | "io/ioutil" |
|
82 | 81 | crashreport = iniConf.Bool("crashreport", false, "enable crashreport logging") |
83 | 82 | ) |
84 | 83 |
|
85 | | -//go:embed config.ini |
86 | | -var configContent []byte |
87 | | - |
88 | 84 | // global clients |
89 | 85 | var ( |
90 | 86 | Tools tools.Tools |
@@ -209,26 +205,25 @@ func loop() { |
209 | 205 | var configPath *paths.Path |
210 | 206 |
|
211 | 207 | // see if the env var is defined, if it is take the config from there, this will override the default path |
212 | | - envConfig := os.Getenv("ARDUINO_CREATE_AGENT_CONFIG") |
213 | | - if envConfig != "" { |
| 208 | + if envConfig := os.Getenv("ARDUINO_CREATE_AGENT_CONFIG"); envConfig != "" { |
214 | 209 | configPath = paths.New(envConfig) |
215 | 210 | if configPath.NotExist() { |
216 | 211 | log.Panicf("config from env var %s does not exists", envConfig) |
217 | 212 | } |
218 | 213 | log.Infof("using config from env variable: %s", configPath) |
| 214 | + } else if defaultConfigPath := agentDir.Join("config.ini"); defaultConfigPath.Exist() { |
219 | 215 | // by default take the config from the ~/.arduino-create/config.ini file |
220 | | - } else if agentDir.Join("config.ini").Exist() { |
221 | | - configPath = agentDir.Join("config.ini") |
| 216 | + configPath = defaultConfigPath |
222 | 217 | log.Infof("using config from default: %s", configPath) |
223 | | - // take the config from the old folder where the agent's binary sits |
224 | 218 | } else { |
| 219 | + // take the config from the old folder where the agent's binary sits |
225 | 220 | oldConfigPath := srcDir.Join("config.ini") |
226 | 221 | if oldConfigPath.Exist() { |
227 | | - err := oldConfigPath.CopyTo(agentDir.Join("config.ini")) |
| 222 | + err := oldConfigPath.CopyTo(defaultConfigPath) |
228 | 223 | if err != nil { |
229 | 224 | log.Errorf("cannot copy old %s, to %s, generating new config", oldConfigPath, configPath) |
230 | 225 | } else { |
231 | | - configPath = agentDir.Join("config.ini") |
| 226 | + configPath = defaultConfigPath |
232 | 227 | log.Infof("copied old %s, to %s", oldConfigPath, configPath) |
233 | 228 | } |
234 | 229 | } |
@@ -710,18 +705,3 @@ func parseIni(filename string) (args []string, err error) { |
710 | 705 |
|
711 | 706 | return args, nil |
712 | 707 | } |
713 | | - |
714 | | -// generateConfig function will take a path as an input |
715 | | -// and will write the default config,ini file to that path, |
716 | | -// it will panic if something goes wrong |
717 | | -func generateConfig(destDir *paths.Path) *paths.Path { |
718 | | - // generate the config.ini file directly in destDir |
719 | | - configPath := destDir.Join("config.ini") |
720 | | - err := configPath.WriteFile(configContent) |
721 | | - if err != nil { |
722 | | - // if we do not have a config there's nothing else we can do |
723 | | - log.Panicf("cannot generate config: %s", err) |
724 | | - } |
725 | | - log.Infof("generated config in %s", configPath) |
726 | | - return configPath |
727 | | -} |
0 commit comments