Auto-update interface

This commit is contained in:
Andrey Meshkov 2020-07-20 21:14:07 +03:00
parent 62ccd3fb41
commit 1bb183c2aa
3 changed files with 46 additions and 0 deletions

View file

@ -244,6 +244,8 @@ func getUpdateInfo(jsonData []byte) (*updateInfo, error) {
if runtime.GOOS == "windows" {
binName = "AdGuardHome.exe"
}
// TODO: This is a mistake, work dir can be different
u.curBinName = filepath.Join(workDir, binName)
if !util.FileExists(u.curBinName) {
return nil, fmt.Errorf("executable file %s doesn't exist", u.curBinName)

13
update/check.go Normal file
View file

@ -0,0 +1,13 @@
package update
type VersionInfo struct {
NewVersion string
Announcement string
AnnouncementURL string
SelfUpdateMinVersion string
CanAutoUpdate bool
}
func (u *Updater) GetVersionResponse() (VersionInfo, error) {
return VersionInfo{}, nil
}

31
update/updater.go Normal file
View file

@ -0,0 +1,31 @@
package update
import (
"os"
"path/filepath"
)
type Updater struct {
DisableUpdate bool
currentBinary string // current binary executable
workDir string // updater work dir (where backup/upd dirs will be created)
}
// NewUpdater - creates a new instance of the Updater
func NewUpdater(workDir string) *Updater {
return &Updater{
currentBinary: filepath.Base(os.Args[0]),
workDir: workDir,
}
}
// 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
}