Pull request: 4223 home: cmd update

Merge in DNS/adguard-home from 4223-cmd-update to master

Squashed commit of the following:

commit ffda71246f37eaba0cb190840f1370ba65099d7c
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Tue Nov 15 16:32:10 2022 +0200

    home: cmd update

commit 9c4e1c33da78952a2b1477ac380a0cf042a8990f
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Tue Nov 15 13:51:33 2022 +0200

    home: cmd update

commit 6a564dc30771b3675e8861ca3befaaee15d83026
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Mon Nov 14 11:05:06 2022 +0200

    all: docs

commit a546bdbdb6f3f78c40908bc1864f2a1ae1c9071f
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Mon Nov 14 10:55:16 2022 +0200

    home: cmd update

commit cbbb594980d3d163fe0489494b0ddca5f679d6e6
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Mon Nov 14 10:16:09 2022 +0200

    home: imp code

commit 677f8a7ca0f47da0ac636e5bab9db24506cf5041
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Sun Nov 13 14:12:48 2022 +0200

    home: cmd update
This commit is contained in:
Dimitry Kolyshev 2022-11-15 17:44:50 +03:00
parent 167b112511
commit 93882d6860
4 changed files with 66 additions and 0 deletions
internal/home

View file

@ -542,6 +542,11 @@ func run(opts options, clientBuildFS fs.FS) {
}
}
// TODO(a.garipov): This could be made much earlier and could be done on
// the first run as well, but to achieve this we need to bypass requests
// over dnsforward resolver.
cmdlineUpdate(opts)
Context.web.Start()
// wait indefinitely for other go-routines to complete their job
@ -927,3 +932,37 @@ type jsonError struct {
// Message is the error message, an opaque string.
Message string `json:"message"`
}
// cmdlineUpdate updates current application and exits.
func cmdlineUpdate(opts options) {
if !opts.performUpdate {
return
}
log.Info("starting update")
if Context.firstRun {
log.Info("update not allowed on first run")
os.Exit(0)
}
_, err := Context.updater.VersionInfo(true)
if err != nil {
vcu := Context.updater.VersionCheckURL()
log.Error("getting version info from %s: %s", vcu, err)
os.Exit(0)
}
if Context.updater.NewVersion() == "" {
log.Info("no updates available")
os.Exit(0)
}
err = Context.updater.Update()
fatalOnError(err)
os.Exit(0)
}