diff --git a/home/control_update.go b/home/control_update.go index 566b8327..e711884d 100644 --- a/home/control_update.go +++ b/home/control_update.go @@ -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) diff --git a/update/check.go b/update/check.go new file mode 100644 index 00000000..56116459 --- /dev/null +++ b/update/check.go @@ -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 +} diff --git a/update/updater.go b/update/updater.go new file mode 100644 index 00000000..5e8cdbcf --- /dev/null +++ b/update/updater.go @@ -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 +}