CFG_VER/APP_VER in the env file: invalid configs replaced, updates follow APP_VER (dev/stable/pin)

This commit is contained in:
mram
2026-09-21 09:28:29 +02:00
parent 272a3a467d
commit 44a8e9fbdc
12 changed files with 322 additions and 142 deletions
+10 -22
View File
@@ -15,8 +15,6 @@ import (
"os/signal"
"path/filepath"
"syscall"
"gpu-turnstile/internal/config"
)
// Name matches the Windows service name; the systemd unit is Name + ".service".
@@ -172,26 +170,16 @@ func Install(configPath string, copyBin bool, version string) error {
}
}
exe = installedExe
data, readErr := os.ReadFile(etcConfig)
switch {
case os.IsNotExist(readErr):
if configPath != "" {
copyFile(configPath, etcConfig, 0o644) //nolint:errcheck // best effort
} else if err := os.WriteFile(etcConfig, []byte(config.SampleEnv(version, "")), 0o644); err != nil {
// Fully commented sample covering every setting; LOG_FILE
// stays commented — stderr goes to the journal on Linux.
return fmt.Errorf("write %s: %w", etcConfig, err)
}
case readErr != nil:
return fmt.Errorf("read %s: %w", etcConfig, readErr)
default:
// An installer-written config from an older version gets any
// new settings appended; hand-written files stay untouched.
if synced, changed := config.SyncSample(string(data), version, ""); changed {
if err := os.WriteFile(etcConfig, []byte(synced), 0o644); err != nil {
return fmt.Errorf("write %s: %w", etcConfig, err)
}
}
if _, err := os.Stat(etcConfig); os.IsNotExist(err) && configPath != "" {
copyFile(configPath, etcConfig, 0o644) //nolint:errcheck // best effort
}
// Missing configs get a fully commented sample (LOG_FILE stays
// commented — stderr goes to the journal on Linux);
// installer-written ones from older versions get new settings
// appended; anything without CFG_VER is invalid and gets replaced
// (backup kept as .bak).
if err := syncEnvFile(etcConfig, version, ""); err != nil {
return err
}
} else if configPath != "" {
if abs, absErr := filepath.Abs(configPath); absErr == nil {