Skip to content

Commit

Permalink
Pull request: all: updater exe name
Browse files Browse the repository at this point in the history
Merge in DNS/adguard-home from 4219-updater to master

Squashed commit of the following:

commit f569a5f
Merge: a90b4fa 3505ce8
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Thu Jul 7 22:14:50 2022 +0530

    Merge remote-tracking branch 'origin/master' into 4219-updater

    # Conflicts:
    #	CHANGELOG.md

commit a90b4fa
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Thu Jul 7 21:56:17 2022 +0530

    home: imp code

commit da0f96b
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Thu Jul 7 21:48:40 2022 +0530

    updater: exe name

commit 246dc9c
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Thu Jul 7 19:18:02 2022 +0530

    all: imp docs

commit 042382d
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Thu Jul 7 18:02:25 2022 +0530

    all: updater exe name

commit a180c46
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Thu Jul 7 17:47:46 2022 +0530

    docs: updater exe name

commit 1a98a6e
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Thu Jul 7 17:40:44 2022 +0530

    all: updater exe name

commit 1b13f5d
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Thu Jul 7 17:14:57 2022 +0530

    all: updater exe name
  • Loading branch information
Mizzick committed Jul 7, 2022
1 parent 3505ce8 commit 77e5e27
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ and this project adheres to

### Fixed

- Updater no longer expects a hardcoded name for `AdGuardHome` executable
([#4219]).
- Inconsistent names of runtime clients from hosts files ([#4683]).
- PTR requests for addresses leased by DHCP will now be resolved into hostnames
under `dhcp.local_domain_name` ([#4699]).
- Broken service installation on OpenWrt ([#4677]).

[#2993]: https://github.com/AdguardTeam/AdGuardHome/issues/2993
[#3057]: https://github.com/AdguardTeam/AdGuardHome/issues/3057
[#4219]: https://github.com/AdguardTeam/AdGuardHome/issues/4219
[#4677]: https://github.com/AdguardTeam/AdGuardHome/issues/4677
[#4683]: https://github.com/AdguardTeam/AdGuardHome/issues/4683
[#4699]: https://github.com/AdguardTeam/AdGuardHome/issues/4699
Expand Down
14 changes: 6 additions & 8 deletions internal/home/controlupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"syscall"
"time"
Expand Down Expand Up @@ -180,19 +179,18 @@ func finishUpdate(ctx context.Context) {
cleanup(ctx)
cleanupAlways()

exeName := "AdGuardHome"
if runtime.GOOS == "windows" {
exeName = "AdGuardHome.exe"
curBinName, err := os.Executable()
if err != nil {
log.Fatalf("executable path request failed: %s", err)
}
curBinName := filepath.Join(Context.workDir, exeName)

if runtime.GOOS == "windows" {
if Context.runningAsService {
// Note:
// we can't restart the service via "kardianos/service" package - it kills the process first
// we can't start a new instance - Windows doesn't allow it
cmd := exec.Command("cmd", "/c", "net stop AdGuardHome & net start AdGuardHome")
err := cmd.Start()
err = cmd.Start()
if err != nil {
log.Fatalf("exec.Command() failed: %s", err)
}
Expand All @@ -204,14 +202,14 @@ func finishUpdate(ctx context.Context) {
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Start()
err = cmd.Start()
if err != nil {
log.Fatalf("exec.Command() failed: %s", err)
}
os.Exit(0)
} else {
log.Info("Restarting: %v", os.Args)
err := syscall.Exec(curBinName, os.Args, os.Environ())
err = syscall.Exec(curBinName, os.Args, os.Environ())
if err != nil {
log.Fatalf("syscall.Exec() failed: %s", err)
}
Expand Down
17 changes: 11 additions & 6 deletions internal/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ func (u *Updater) Update() (err error) {
log.Info("updater: updating")
defer func() { log.Info("updater: finished; errors: %v", err) }()

err = u.prepare()
execPath, err := os.Executable()
if err != nil {
return err
}

err = u.prepare(filepath.Base(execPath))
if err != nil {
return err
}
Expand Down Expand Up @@ -162,7 +167,8 @@ func (u *Updater) VersionCheckURL() (vcu string) {
return u.versionCheckURL
}

func (u *Updater) prepare() (err error) {
// prepare fills all necessary fields in Updater object.
func (u *Updater) prepare(exeName string) (err error) {
u.updateDir = filepath.Join(u.workDir, fmt.Sprintf("agh-update-%s", u.newVersion))

_, pkgNameOnly := filepath.Split(u.packageURL)
Expand All @@ -173,13 +179,13 @@ func (u *Updater) prepare() (err error) {
u.packageName = filepath.Join(u.updateDir, pkgNameOnly)
u.backupDir = filepath.Join(u.workDir, "agh-backup")

exeName := "AdGuardHome"
updateExeName := "AdGuardHome"
if u.goos == "windows" {
exeName = "AdGuardHome.exe"
updateExeName = "AdGuardHome.exe"
}

u.backupExeName = filepath.Join(u.backupDir, exeName)
u.updateExeName = filepath.Join(u.updateDir, exeName)
u.updateExeName = filepath.Join(u.updateDir, updateExeName)

log.Debug(
"updater: updating from %s to %s using url: %s",
Expand All @@ -188,7 +194,6 @@ func (u *Updater) prepare() (err error) {
u.packageURL,
)

// TODO(a.garipov): Use os.Args[0] instead?
u.currentExeName = filepath.Join(u.workDir, exeName)
_, err = os.Stat(u.currentExeName)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/updater/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestUpdate(t *testing.T) {
u.newVersion = "v0.103.1"
u.packageURL = fakeURL.String()

require.NoError(t, u.prepare())
require.NoError(t, u.prepare("AdGuardHome"))

u.currentExeName = filepath.Join(wd, "AdGuardHome")

Expand Down Expand Up @@ -209,7 +209,7 @@ func TestUpdateWindows(t *testing.T) {
u.newVersion = "v0.103.1"
u.packageURL = fakeURL.String()

require.NoError(t, u.prepare())
require.NoError(t, u.prepare("AdGuardHome.exe"))

u.currentExeName = filepath.Join(wd, "AdGuardHome.exe")

Expand Down

0 comments on commit 77e5e27

Please sign in to comment.