diff --git a/CHANGELOG.md b/CHANGELOG.md index 9886db3a..34349225 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [4.5.0] 6/1/2024 + +**Spire Auto Updates** Add ability to disable auto updates on bootup via **eqemu_config.json** option **spire.disable_auto_updates** if set. + ## [4.4.0] 6/1/2024 **Zone Log Streaming** Fix minor issue where unauthenticated users could not stream zone logs. diff --git a/internal/eqemuserverconfig/config.go b/internal/eqemuserverconfig/config.go index 2c4514ff..3d15e928 100644 --- a/internal/eqemuserverconfig/config.go +++ b/internal/eqemuserverconfig/config.go @@ -150,9 +150,10 @@ type EQEmuConfigJson struct { ServerCodePath string `json:"serverCodePath,omitempty"` } `json:"web-admin,omitempty"` Spire struct { - EncryptionKey string `json:"encryption_key,omitempty"` - HttpPort int `json:"http_port,omitempty"` - LauncherStart bool `json:"launcher_start"` // starts server launcher + EncryptionKey string `json:"encryption_key,omitempty"` + HttpPort int `json:"http_port,omitempty"` + LauncherStart bool `json:"launcher_start"` // starts server launcher + DisableAutoUpdates bool `json:"disable_auto_updates,omitempty"` // disable auto updates } `json:"spire,omitempty"` } @@ -165,8 +166,12 @@ var lock = &sync.Mutex{} // We utilize a cache to prevent reading the file on every call func (e *Config) Get() EQEmuConfigJson { configFile := e.pathmgmt.GetEQEmuServerConfigFilePath() + stat, err := os.Stat(configFile) + if err != nil { + return EQEmuConfigJson{} + } + if len(configFile) > 0 { - stat, _ := os.Stat(configFile) if stat.ModTime().After(lastModifiedTime) || lastModifiedTime.IsZero() { e.logger.Debug().Any("path", configFile).Msg("Reading eqemu config file") body, err := os.ReadFile(e.pathmgmt.GetEQEmuServerConfigFilePath()) @@ -194,6 +199,38 @@ func (e *Config) Get() EQEmuConfigJson { return EQEmuConfigJson{} } +// GetIfExists returns the eqemu config json if the file exists +// This function shouldn't really exist and the original getter should have bubbled errors up +// Clean all of this up another time +func (e *Config) GetIfExists() (EQEmuConfigJson, bool) { + configFile := e.pathmgmt.GetEQEmuServerConfigFilePath() + stat, err := os.Stat(configFile) + if err != nil { + return EQEmuConfigJson{}, false + } + + if len(configFile) > 0 { + if err == nil && stat.ModTime().After(lastModifiedTime) || lastModifiedTime.IsZero() { + e.logger.Debug().Any("path", configFile).Msg("Reading eqemu config file") + body, _ := os.ReadFile(e.pathmgmt.GetEQEmuServerConfigFilePath()) + + config := EQEmuConfigJson{} + _ = json.Unmarshal(body, &config) + + lastModifiedTime = stat.ModTime() + lock.Lock() + cachedConfig = &config + lock.Unlock() + + return config, true + } else if cachedConfig != nil { + return *cachedConfig, true + } + } + + return EQEmuConfigJson{}, false +} + // Exists will return true if the eqemu_config.json file exists func (e *Config) Exists() bool { return len(e.pathmgmt.GetEQEmuServerConfigFilePath()) > 0 diff --git a/internal/updater/updater.go b/internal/updater/updater.go index ff47278b..bc60a678 100644 --- a/internal/updater/updater.go +++ b/internal/updater/updater.go @@ -7,7 +7,9 @@ import ( "fmt" "github.com/Akkadius/spire/internal/download" "github.com/Akkadius/spire/internal/env" + "github.com/Akkadius/spire/internal/eqemuserverconfig" "github.com/Akkadius/spire/internal/logger" + "github.com/Akkadius/spire/internal/pathmgmt" "github.com/Akkadius/spire/internal/unzip" "github.com/google/go-github/v41/github" "github.com/mattn/go-isatty" @@ -23,15 +25,22 @@ import ( // Updater is a service that checks for updates to the app type Updater struct { // this is the package.json embedded in the binary which contains the app version - packageJson []byte - logger *logger.AppLogger + packageJson []byte + logger *logger.AppLogger + serverconfig *eqemuserverconfig.Config } // NewUpdater creates a new updater service func NewUpdater(packageJson []byte) *Updater { + appLogger := logger.ProvideAppLogger() + pathmgr := pathmgmt.NewPathManagement(appLogger) return &Updater{ packageJson: packageJson, - logger: logger.ProvideAppLogger(), + logger: appLogger, + serverconfig: eqemuserverconfig.NewConfig( + appLogger, + pathmgr, + ), } } @@ -67,6 +76,11 @@ func (s *Updater) getAppVersion() (error, EnvResponse) { // CheckForUpdates checks for updates to the app func (s *Updater) CheckForUpdates(interactive bool) bool { + config, exists := s.serverconfig.GetIfExists() + if exists && config.Spire.DisableAutoUpdates { + s.logger.Info().Any("spire.disable_auto_updates", config.Spire.DisableAutoUpdates).Msg("Auto updates are disabled via config") + return false + } // get executable name and path executableName := filepath.Base(os.Args[0]) diff --git a/package.json b/package.json index fb6ca007..27d062f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "spire", - "version": "4.4.0", + "version": "4.5.0", "repository": { "type": "git", "url": "https://github.com/Akkadius/spire.git"