diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | config/default.json (renamed from config/config.json) | 0 | ||||
-rw-r--r-- | utils/config.go | 17 |
4 files changed, 24 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index e3646b174..30737cf6d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ npm-debug.log webapp/yarn-error.log mattermost.mattermost-license config/mattermost.mattermost-license +config/config.json web/static/js/bundle*.js web/static/js/bundle*.js.map @@ -279,6 +279,10 @@ test-te: start-docker prepare-enterprise do-cover-file test-postgres: start-docker prepare-enterprise @echo Testing Postgres + if [ ! -f config/config.json ]; then \ + cp config/default.json config/config.json; \ + fi; \ + @sed -i'' -e 's|"DriverName": "mysql"|"DriverName": "postgres"|g' config/config.json @sed -i'' -e 's|"DataSource": "mmuser:mostest@tcp(dockerhost:3306)/mattermost_test?charset=utf8mb4,utf8"|"DataSource": "postgres://mmuser:mostest@dockerhost:5432?sslmode=disable"|g' config/config.json @@ -387,6 +391,8 @@ package: build build-client cp -RL templates $(DIST_PATH) cp -RL i18n $(DIST_PATH) + mv $(DIST_PATH)/config/default.json $(DIST_PATH)/config/config.json + @# Disable developer settings sed -i'' -e 's|"ConsoleLevel": "DEBUG"|"ConsoleLevel": "INFO"|g' $(DIST_PATH)/config/config.json sed -i'' -e 's|"SiteURL": "http://localhost:8065"|"SiteURL": ""|g' $(DIST_PATH)/config/config.json diff --git a/config/config.json b/config/default.json index e7e67855a..e7e67855a 100644 --- a/config/config.json +++ b/config/default.json diff --git a/utils/config.go b/utils/config.go index 36474c921..aa5b50146 100644 --- a/utils/config.go +++ b/utils/config.go @@ -7,6 +7,7 @@ import ( "crypto/md5" "encoding/json" "fmt" + "io" "io/ioutil" "os" "path/filepath" @@ -309,6 +310,22 @@ func LoadConfig(fileName string) { configReadErr := viper.ReadInConfig() if configReadErr != nil { + if _, ok := configReadErr.(viper.ConfigFileNotFoundError); ok { + // In case of a file-not-found error, try to copy default.json if it's present. + defaultPath := FindConfigFile("default.json") + if src, err := os.Open(defaultPath); err == nil { + if dest, err := os.OpenFile(filepath.Join(filepath.Dir(defaultPath), "config.json"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600); err == nil { + if _, err := io.Copy(dest, src); err == nil { + configReadErr = viper.ReadInConfig() + } + dest.Close() + } + src.Close() + } + } + } + + if configReadErr != nil { errMsg := T("utils.config.load_config.opening.panic", map[string]interface{}{"Filename": fileName, "Error": configReadErr.Error()}) fmt.Fprintln(os.Stderr, errMsg) os.Exit(1) |