|
@@ -17,7 +17,7 @@ import (
|
|
|
var (
|
|
var (
|
|
|
globalConfig structs.SysConfig
|
|
globalConfig structs.SysConfig
|
|
|
logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
|
logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
|
|
- basePath string
|
|
|
|
|
|
|
+ BasePath string
|
|
|
Version = "v2.0.0"
|
|
Version = "v2.0.0"
|
|
|
Ready = false
|
|
Ready = false
|
|
|
VersionServerReady = false
|
|
VersionServerReady = false
|
|
@@ -31,6 +31,7 @@ var (
|
|
|
WifiNetworks []string
|
|
WifiNetworks []string
|
|
|
HttpOpen = false
|
|
HttpOpen = false
|
|
|
UploadSecret string
|
|
UploadSecret string
|
|
|
|
|
+ checkInterval = 5 * time.Minute
|
|
|
confMutex sync.Mutex
|
|
confMutex sync.Mutex
|
|
|
versMutex sync.Mutex
|
|
versMutex sync.Mutex
|
|
|
)
|
|
)
|
|
@@ -38,12 +39,12 @@ var (
|
|
|
// try initializing from system.json on disk
|
|
// try initializing from system.json on disk
|
|
|
func init() {
|
|
func init() {
|
|
|
// try loading existing config
|
|
// try loading existing config
|
|
|
- basePath, err := os.Getwd()
|
|
|
|
|
|
|
+ BasePath, err := os.Getwd()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
errmsg := fmt.Sprintf("Couldn't get cwd: %v", err)
|
|
errmsg := fmt.Sprintf("Couldn't get cwd: %v", err)
|
|
|
logger.Error(errmsg)
|
|
logger.Error(errmsg)
|
|
|
}
|
|
}
|
|
|
- confPath := filepath.Join(basePath, "settings", "system.json")
|
|
|
|
|
|
|
+ confPath := filepath.Join(BasePath, "settings", "system.json")
|
|
|
file, err := os.Open(confPath)
|
|
file, err := os.Open(confPath)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
// create a default if it doesn't exist
|
|
// create a default if it doesn't exist
|
|
@@ -74,7 +75,7 @@ func UpdateConf(values map[string]interface{}) error {
|
|
|
// mutex lock to avoid race conditions
|
|
// mutex lock to avoid race conditions
|
|
|
confMutex.Lock()
|
|
confMutex.Lock()
|
|
|
defer confMutex.Unlock()
|
|
defer confMutex.Unlock()
|
|
|
- confPath := filepath.Join(basePath, "settings", "system.json")
|
|
|
|
|
|
|
+ confPath := filepath.Join(BasePath, "settings", "system.json")
|
|
|
file, err := ioutil.ReadFile(confPath)
|
|
file, err := ioutil.ReadFile(confPath)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
errmsg := fmt.Sprintf("Unable to load config: %v", err)
|
|
errmsg := fmt.Sprintf("Unable to load config: %v", err)
|
|
@@ -125,8 +126,8 @@ func createDefaultConf() error {
|
|
|
UpdateUrl: "https://version.groundseg.app",
|
|
UpdateUrl: "https://version.groundseg.app",
|
|
|
UpdateBranch: "latest",
|
|
UpdateBranch: "latest",
|
|
|
SwapVal: 16,
|
|
SwapVal: 16,
|
|
|
- SwapFile: filepath.Join(basePath, "settings", "swapfile"),
|
|
|
|
|
- KeyFile: filepath.Join(basePath, "settings", "session.key"),
|
|
|
|
|
|
|
+ SwapFile: filepath.Join(BasePath, "settings", "swapfile"),
|
|
|
|
|
+ KeyFile: filepath.Join(BasePath, "settings", "session.key"),
|
|
|
Sessions: struct {
|
|
Sessions: struct {
|
|
|
Authorized map[string]structs.SessionInfo `json:"authorized"`
|
|
Authorized map[string]structs.SessionInfo `json:"authorized"`
|
|
|
Unauthorized map[string]structs.SessionInfo `json:"unauthorized"`
|
|
Unauthorized map[string]structs.SessionInfo `json:"unauthorized"`
|
|
@@ -158,7 +159,7 @@ func createDefaultConf() error {
|
|
|
Privkey: "",
|
|
Privkey: "",
|
|
|
Salt: "",
|
|
Salt: "",
|
|
|
}
|
|
}
|
|
|
- path := filepath.Join(basePath, "settings", "system.json")
|
|
|
|
|
|
|
+ path := filepath.Join(BasePath, "settings", "system.json")
|
|
|
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
|
|
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
@@ -237,7 +238,7 @@ func CheckVersion() (structs.Version, bool) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// debug: re-marshal and write to disk
|
|
// debug: re-marshal and write to disk
|
|
|
- confPath := filepath.Join(basePath, "settings", "version_info.json")
|
|
|
|
|
|
|
+ confPath := filepath.Join(BasePath, "settings", "version_info.json")
|
|
|
file, err := os.Create(confPath)
|
|
file, err := os.Create(confPath)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
errmsg := fmt.Sprintf("Failed to create file: %v", err)
|
|
errmsg := fmt.Sprintf("Failed to create file: %v", err)
|
|
@@ -255,3 +256,18 @@ func CheckVersion() (structs.Version, bool) {
|
|
|
}
|
|
}
|
|
|
return VersionInfo, false
|
|
return VersionInfo, false
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func CheckVersionLoop() {
|
|
|
|
|
+ ticker := time.NewTicker(checkInterval)
|
|
|
|
|
+ for {
|
|
|
|
|
+ select {
|
|
|
|
|
+ case <-ticker.C:
|
|
|
|
|
+ latestVersion, _ := CheckVersion()
|
|
|
|
|
+ currentVersion := VersionInfo
|
|
|
|
|
+ if latestVersion != currentVersion {
|
|
|
|
|
+ fmt.Printf("New version available! Current: %s, Latest: %s\n", currentVersion, latestVersion)
|
|
|
|
|
+ // Handle the update logic here
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|