From bb80a7c2159c25189ec9940f20c4436a86e81968 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Mon, 27 Feb 2023 17:07:31 +0300 Subject: [PATCH] Pull request 1752: 5373-mips-autoupdate Updates #5270. Updates #5373. Squashed commit of the following: commit ad4654fa63beac13c4fbb38aa8fd06eaec25cb5e Author: Ainar Garipov Date: Mon Feb 27 17:00:28 2023 +0300 updater: imp docs commit c3482766df6b831eae529e209ea7fa0a87f1b417 Merge: 1cbee78b 386add03 Author: Ainar Garipov Date: Mon Feb 27 16:59:13 2023 +0300 Merge branch 'master' into 5373-mips-autoupdate commit 1cbee78b94914c7d72c837cd2fad96a50ac2c30a Author: Ainar Garipov Date: Mon Feb 27 11:57:28 2023 +0300 all: fix autoupdate on mips* --- CHANGELOG.md | 4 +++ internal/home/controlupdate.go | 2 +- internal/updater/check.go | 54 ++++++++++++++++++++++------------ internal/updater/updater.go | 6 ++-- scripts/make/build-release.sh | 10 +++++++ 5 files changed, 54 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66f798e8..f9851241 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,11 +30,15 @@ NOTE: Add new changes BELOW THIS COMMENT. ### Fixed +- Automatic update on MIPS64 and little-endian 32-bit MIPS architectures + ([#5270], [#5373]). - Requirements to domain names in domain-specific upstream configurations have been relaxed to meet those from [RFC 3696][rfc3696] ([#4884]). - Failing service installation via script on FreeBSD ([#5431]). [#4884]: https://github.com/AdguardTeam/AdGuardHome/issues/4884 +[#5270]: https://github.com/AdguardTeam/AdGuardHome/issues/5270 +[#5373]: https://github.com/AdguardTeam/AdGuardHome/issues/5373 [#5431]: https://github.com/AdguardTeam/AdGuardHome/issues/5431 [#5468]: https://github.com/AdguardTeam/AdGuardHome/issues/5468 diff --git a/internal/home/controlupdate.go b/internal/home/controlupdate.go index 5718bfaa..1cea1d14 100644 --- a/internal/home/controlupdate.go +++ b/internal/home/controlupdate.go @@ -98,7 +98,7 @@ func requestVersionInfo(resp *versionResponse, recheck bool) (err error) { if err != nil { vcu := Context.updater.VersionCheckURL() - return fmt.Errorf("getting version info from %s: %s", vcu, err) + return fmt.Errorf("getting version info from %s: %w", vcu, err) } return nil diff --git a/internal/updater/check.go b/internal/updater/check.go index 5de7ecfc..a72e58ee 100644 --- a/internal/updater/check.go +++ b/internal/updater/check.go @@ -10,6 +10,9 @@ import ( "github.com/AdguardTeam/AdGuardHome/internal/aghalg" "github.com/AdguardTeam/AdGuardHome/internal/aghio" "github.com/AdguardTeam/golibs/errors" + "github.com/AdguardTeam/golibs/log" + "golang.org/x/exp/maps" + "golang.org/x/exp/slices" ) // TODO(a.garipov): Make configurable. @@ -81,9 +84,9 @@ func (u *Updater) parseVersionResponse(data []byte) (VersionInfo, error) { return info, fmt.Errorf("version.json: %w", err) } - for _, v := range versionJSON { + for k, v := range versionJSON { if v == "" { - return info, fmt.Errorf("version.json: invalid data") + return info, fmt.Errorf("version.json: bad data: value for key %q is empty", k) } } @@ -91,9 +94,9 @@ func (u *Updater) parseVersionResponse(data []byte) (VersionInfo, error) { info.Announcement = versionJSON["announcement"] info.AnnouncementURL = versionJSON["announcement_url"] - packageURL, ok := u.downloadURL(versionJSON) - if !ok { - return info, fmt.Errorf("version.json: packageURL not found") + packageURL, key, found := u.downloadURL(versionJSON) + if !found { + return info, fmt.Errorf("version.json: no package URL: key %q not found in object", key) } info.CanAutoUpdate = aghalg.BoolToNullBool(info.NewVersion != u.version) @@ -104,25 +107,40 @@ func (u *Updater) parseVersionResponse(data []byte) (VersionInfo, error) { return info, nil } -// downloadURL returns the download URL for current build. -func (u *Updater) downloadURL(json map[string]string) (string, bool) { - var key string - +// downloadURL returns the download URL for current build as well as its key in +// versionObj. If the key is not found, it additionally prints an informative +// log message. +func (u *Updater) downloadURL(versionObj map[string]string) (dlURL, key string, ok bool) { if u.goarch == "arm" && u.goarm != "" { key = fmt.Sprintf("download_%s_%sv%s", u.goos, u.goarch, u.goarm) - } else if u.goarch == "mips" && u.gomips != "" { + } else if isMIPS(u.goarch) && u.gomips != "" { key = fmt.Sprintf("download_%s_%s_%s", u.goos, u.goarch, u.gomips) - } - - val, ok := json[key] - if !ok { + } else { key = fmt.Sprintf("download_%s_%s", u.goos, u.goarch) - val, ok = json[key] } - if !ok { - return "", false + dlURL, ok = versionObj[key] + if ok { + return dlURL, key, true } - return val, true + keys := maps.Keys(versionObj) + slices.Sort(keys) + log.Error("updater: key %q not found; got keys %q", key, keys) + + return "", key, false +} + +// isMIPS returns true if arch is any MIPS architecture. +func isMIPS(arch string) (ok bool) { + switch arch { + case + "mips", + "mips64", + "mips64le", + "mipsle": + return true + default: + return false + } } diff --git a/internal/updater/updater.go b/internal/updater/updater.go index f042ab3c..1fdd858e 100644 --- a/internal/updater/updater.go +++ b/internal/updater/updater.go @@ -272,7 +272,7 @@ func (u *Updater) backup(firstRun bool) (err error) { wd := u.workDir err = copySupportingFiles(u.unpackedFiles, wd, u.backupDir) if err != nil { - return fmt.Errorf("copySupportingFiles(%s, %s) failed: %s", wd, u.backupDir, err) + return fmt.Errorf("copySupportingFiles(%s, %s) failed: %w", wd, u.backupDir, err) } return nil @@ -283,7 +283,7 @@ func (u *Updater) backup(firstRun bool) (err error) { func (u *Updater) replace() error { err := copySupportingFiles(u.unpackedFiles, u.updateDir, u.workDir) if err != nil { - return fmt.Errorf("copySupportingFiles(%s, %s) failed: %s", u.updateDir, u.workDir, err) + return fmt.Errorf("copySupportingFiles(%s, %s) failed: %w", u.updateDir, u.workDir, err) } log.Debug("updater: renaming: %s to %s", u.currentExeName, u.backupExeName) @@ -315,7 +315,7 @@ func (u *Updater) clean() { // MaxPackageFileSize is a maximum package file length in bytes. The largest // package whose size is limited by this constant currently has the size of // approximately 9 MiB. -const MaxPackageFileSize = 32 * 1024 * 1024 +const MaxPackageFileSize = 32 * 10 * 1024 // Download package file and save it to disk func (u *Updater) downloadPackageFile() (err error) { diff --git a/scripts/make/build-release.sh b/scripts/make/build-release.sh index 6194d87b..2884f568 100644 --- a/scripts/make/build-release.sh +++ b/scripts/make/build-release.sh @@ -390,6 +390,16 @@ echo "{ \"selfupdate_min_version\": \"0.0\", " >> "$version_json" +# Add the MIPS* object keys without the "softfloat" part to mitigate the +# consequences of #5373. +# +# TODO(a.garipov): Remove this around fall 2023. +echo " + \"download_linux_mips64\": \"${version_download_url}/AdGuardHome_linux_mips64_softfloat.tar.gz\", + \"download_linux_mips64le\": \"${version_download_url}/AdGuardHome_linux_mips64le_softfloat.tar.gz\", + \"download_linux_mipsle\": \"${version_download_url}/AdGuardHome_linux_mipsle_softfloat.tar.gz\", +" >> "$version_json" + # Same as with checksums above, don't use ls, because files matching one of the # patterns may be absent. ar_files="$( find "./${dist}/" ! -name "${dist}" -prune \( -name '*.tar.gz' -o -name '*.zip' \) )"