mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-05-01 21:50:29 +03:00
Pull request: 2546 updater fix
Merge in DNS/adguard-home from 2546-updater-fix to master Closes #2546. Squashed commit of the following: commit af243c9fad710efe099506fda281e628c3e5ec30 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Jan 13 14:33:37 2021 +0300 updater: fix go 1.14 compat commit 742fba24b300ce51c04acb586996c3c75e56ea20 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Jan 13 13:58:27 2021 +0300 util: imp error check commit c2bdbce8af657a7f4b7e05c018cfacba86e06753 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Jan 11 18:51:26 2021 +0300 all: fix and refactor update checking
This commit is contained in:
parent
bba74859e2
commit
0d67aa251d
18 changed files with 669 additions and 465 deletions
internal/home
|
@ -27,8 +27,9 @@ import (
|
|||
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/sysutil"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/update"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/updater"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/util"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/version"
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
)
|
||||
|
@ -38,15 +39,6 @@ const (
|
|||
configSyslog = "syslog"
|
||||
)
|
||||
|
||||
// Update-related variables
|
||||
var (
|
||||
versionString = "dev"
|
||||
updateChannel = "none"
|
||||
versionCheckURL = ""
|
||||
ARMVersion = ""
|
||||
MIPSVersion = ""
|
||||
)
|
||||
|
||||
// Global context
|
||||
type homeContext struct {
|
||||
// Modules
|
||||
|
@ -65,7 +57,7 @@ type homeContext struct {
|
|||
web *Web // Web (HTTP, HTTPS) module
|
||||
tls *TLSMod // TLS module
|
||||
autoHosts util.AutoHosts // IP-hostname pairs taken from system configuration (e.g. /etc/hosts) files
|
||||
updater *update.Updater
|
||||
updater *updater.Updater
|
||||
|
||||
ipDetector *ipDetector
|
||||
|
||||
|
@ -99,14 +91,7 @@ func (c *homeContext) getDataDir() string {
|
|||
var Context homeContext
|
||||
|
||||
// Main is the entry point
|
||||
func Main(version, channel, armVer, mipsVer string) {
|
||||
// Init update-related global variables
|
||||
versionString = version
|
||||
updateChannel = channel
|
||||
ARMVersion = armVer
|
||||
MIPSVersion = mipsVer
|
||||
versionCheckURL = "https://static.adguard.com/adguardhome/" + updateChannel + "/version.json"
|
||||
|
||||
func Main() {
|
||||
// config can be specified, which reads options from there, but other command line flags have to override config values
|
||||
// therefore, we must do it manually instead of using a lib
|
||||
args := loadOptions()
|
||||
|
@ -139,20 +124,6 @@ func Main(version, channel, armVer, mipsVer string) {
|
|||
run(args)
|
||||
}
|
||||
|
||||
// version - returns the current version string
|
||||
func version() string {
|
||||
// TODO(a.garipov): I'm pretty sure we can extract some of this stuff
|
||||
// from the build info.
|
||||
msg := "AdGuard Home, version %s, channel %s, arch %s %s"
|
||||
if ARMVersion != "" {
|
||||
msg = msg + " v" + ARMVersion
|
||||
} else if MIPSVersion != "" {
|
||||
msg = msg + " " + MIPSVersion
|
||||
}
|
||||
|
||||
return fmt.Sprintf(msg, versionString, updateChannel, runtime.GOOS, runtime.GOARCH)
|
||||
}
|
||||
|
||||
func setupContext(args options) {
|
||||
Context.runningAsService = args.runningAsService
|
||||
Context.disableUpdate = args.disableUpdate
|
||||
|
@ -214,15 +185,16 @@ func setupConfig(args options) {
|
|||
|
||||
Context.autoHosts.Init("")
|
||||
|
||||
Context.updater = update.NewUpdater(update.Config{
|
||||
Client: Context.client,
|
||||
WorkDir: Context.workDir,
|
||||
VersionURL: versionCheckURL,
|
||||
VersionString: versionString,
|
||||
OS: runtime.GOOS,
|
||||
Arch: runtime.GOARCH,
|
||||
ARMVersion: ARMVersion,
|
||||
ConfigName: config.getConfigFilename(),
|
||||
Context.updater = updater.NewUpdater(&updater.Config{
|
||||
Client: Context.client,
|
||||
Version: version.Version(),
|
||||
Channel: version.Channel(),
|
||||
GOARCH: runtime.GOARCH,
|
||||
GOOS: runtime.GOOS,
|
||||
GOARM: version.GOARM(),
|
||||
GOMIPS: version.GOMIPS(),
|
||||
WorkDir: Context.workDir,
|
||||
ConfName: config.getConfigFilename(),
|
||||
})
|
||||
|
||||
Context.clients.Init(config.Clients, Context.dhcpServer, &Context.autoHosts)
|
||||
|
@ -260,7 +232,7 @@ func run(args options) {
|
|||
memoryUsage(args)
|
||||
|
||||
// print the first message after logger is configured
|
||||
log.Println(version())
|
||||
log.Println(version.Full())
|
||||
log.Debug("Current working directory is %s", Context.workDir)
|
||||
if args.runningAsService {
|
||||
log.Info("AdGuard Home is running as a service")
|
||||
|
@ -690,10 +662,11 @@ func customDialContext(ctx context.Context, network, addr string) (net.Conn, err
|
|||
return nil, agherr.Many(fmt.Sprintf("couldn't dial to %s", addr), dialErrs...)
|
||||
}
|
||||
|
||||
func getHTTPProxy(req *http.Request) (*url.URL, error) {
|
||||
if len(config.ProxyURL) == 0 {
|
||||
func getHTTPProxy(_ *http.Request) (*url.URL, error) {
|
||||
if config.ProxyURL == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return url.Parse(config.ProxyURL)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue