badguardhome/update/updater.go

39 lines
916 B
Go
Raw Normal View History

2020-07-20 18:14:07 +00:00
package update
import (
"os"
"path/filepath"
2020-07-21 09:17:23 +00:00
"time"
2020-07-20 18:14:07 +00:00
)
type Updater struct {
DisableUpdate bool
currentBinary string // current binary executable
workDir string // updater work dir (where backup/upd dirs will be created)
2020-07-21 09:17:23 +00:00
// cached version.json to avoid hammering github.io for each page reload
versionCheckJSON []byte
versionCheckLastTime time.Time
2020-07-20 18:14:07 +00:00
}
// NewUpdater - creates a new instance of the Updater
func NewUpdater(workDir string) *Updater {
return &Updater{
2020-07-21 09:17:23 +00:00
currentBinary: filepath.Base(os.Args[0]),
workDir: workDir,
versionCheckJSON: nil,
versionCheckLastTime: time.Time{},
2020-07-20 18:14:07 +00:00
}
}
// DoUpdate - conducts the auto-update
// 1. Downloads the update file
// 2. Unpacks it and checks the contents
// 3. Backups the current version and configuration
// 4. Replaces the old files
// 5. Restarts the service
func (u *Updater) DoUpdate() error {
return nil
}