Fix version/channel linking

This commit is contained in:
Andrey Meshkov 2019-06-20 14:36:26 +03:00
parent 4ddae72faf
commit f1e6a30931
5 changed files with 29 additions and 18 deletions

View File

@ -23,7 +23,7 @@ $(STATIC): $(JSFILES) client/node_modules
$(TARGET): $(STATIC) *.go home/*.go dhcpd/*.go dnsfilter/*.go dnsforward/*.go
GOOS=$(NATIVE_GOOS) GOARCH=$(NATIVE_GOARCH) GO111MODULE=off go get -v github.com/gobuffalo/packr/...
PATH=$(GOPATH)/bin:$(PATH) packr -z
CGO_ENABLED=0 go build -ldflags="-s -w -X home.VersionString=$(GIT_VERSION) -X home.updateChannel=$(CHANNEL)" -asmflags="-trimpath=$(PWD)" -gcflags="-trimpath=$(PWD)"
CGO_ENABLED=0 go build -ldflags="-s -w -X main.version=$(GIT_VERSION) -X main.channel=$(CHANNEL)" -asmflags="-trimpath=$(PWD)" -gcflags="-trimpath=$(PWD)"
PATH=$(GOPATH)/bin:$(PATH) packr clean
clean:

View File

@ -109,7 +109,7 @@ func handleStatus(w http.ResponseWriter, r *http.Request) {
"bootstrap_dns": config.DNS.BootstrapDNS,
"upstream_dns": config.DNS.UpstreamDNS,
"all_servers": config.DNS.AllServers,
"version": VersionString,
"version": versionString,
"language": config.Language,
}

View File

@ -43,7 +43,7 @@ func getVersionResp(data []byte) []byte {
}
_, ok := versionJSON[fmt.Sprintf("download_%s_%s", runtime.GOOS, runtime.GOARCH)]
if ok && ret["new_version"] != VersionString && VersionString >= selfUpdateMinVersion {
if ok && ret["new_version"] != versionString && versionString >= selfUpdateMinVersion {
ret["can_autoupdate"] = true
}
@ -145,12 +145,12 @@ func getUpdateInfo(jsonData []byte) (*updateInfo, error) {
return nil, fmt.Errorf("Invalid JSON")
}
if u.newVer == VersionString {
if u.newVer == versionString {
return nil, fmt.Errorf("No need to update")
}
u.updateDir = filepath.Join(workDir, fmt.Sprintf("agh-update-%s", u.newVer))
u.backupDir = filepath.Join(workDir, fmt.Sprintf("agh-backup-%s", VersionString))
u.backupDir = filepath.Join(workDir, fmt.Sprintf("agh-backup-%s", versionString))
_, pkgFileName := filepath.Split(u.pkgURL)
if len(pkgFileName) == 0 {
@ -360,7 +360,7 @@ func getPackageFile(u *updateInfo) error {
// Perform an update procedure
func doUpdate(u *updateInfo) error {
log.Info("Updating from %s to %s. URL:%s Package:%s",
VersionString, u.newVer, u.pkgURL, u.pkgName)
versionString, u.newVer, u.pkgURL, u.pkgName)
_ = os.Mkdir(u.updateDir, 0755)

View File

@ -25,15 +25,6 @@ import (
"github.com/gobuffalo/packr"
)
// VersionString will be set through ldflags, contains current version
var VersionString = "undefined"
// updateChannel can be set via ldflags
var updateChannel = "release"
var versionCheckURL = "https://static.adguard.com/adguardhome/" + updateChannel + "/version.json"
const versionCheckPeriod = time.Hour * 8
var httpServer *http.Server
var httpsServer struct {
server *http.Server
@ -48,8 +39,22 @@ const (
configSyslog = "syslog"
)
// Update-related variables
var (
versionString string
updateChannel string
versionCheckURL string
)
const versionCheckPeriod = time.Hour * 8
// main is the entry point
func Main() {
func Main(version string, channel string) {
// Init update-related global variables
versionString = version
updateChannel = channel
versionCheckURL = "https://static.adguard.com/adguardhome/" + updateChannel + "/version.json"
// 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()
@ -81,7 +86,7 @@ func run(args options) {
enableTLS13()
// print the first message after logger is configured
log.Printf("AdGuard Home, version %s, channel %s\n", VersionString, updateChannel)
log.Printf("AdGuard Home, version %s, channel %s\n", versionString, updateChannel)
log.Debug("Current working directory is %s", config.ourWorkingDir)
if args.runningAsService {
log.Info("AdGuard Home is running as a service")

View File

@ -4,6 +4,12 @@ import (
"github.com/AdguardTeam/AdGuardHome/home"
)
// version will be set through ldflags, contains current version
var version = "undefined"
// channel can be set via ldflags
var channel = "release"
func main() {
home.Main()
home.Main(version, channel)
}