mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 22:31:04 +00:00
Use runtime info to determine ARM version for upgrade (fixes #1051)
This commit is contained in:
parent
1219423091
commit
0fde4b3b2e
18
build.go
18
build.go
@ -72,17 +72,8 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
switch goarch {
|
switch goarch {
|
||||||
case "386", "amd64", "armv5", "armv6", "armv7":
|
case "386", "amd64", "arm", "armv5", "armv6", "armv7":
|
||||||
break
|
break
|
||||||
case "arm":
|
|
||||||
switch os.Getenv("GOARM") {
|
|
||||||
case "5", "6", "7":
|
|
||||||
goarch += "v" + os.Getenv("GOARM")
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
log.Println("Invalid goarch \"arm\". Use one of \"armv5\", \"armv6\", \"armv7\".")
|
|
||||||
log.Fatalln("Note that producing a correct \"armv5\" binary requires a rebuilt stdlib.")
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
log.Printf("Unknown goarch %q; proceed with caution!", goarch)
|
log.Printf("Unknown goarch %q; proceed with caution!", goarch)
|
||||||
}
|
}
|
||||||
@ -161,7 +152,7 @@ func checkRequiredGoVersion() {
|
|||||||
// This is a standard go build. Verify that it's new enough.
|
// This is a standard go build. Verify that it's new enough.
|
||||||
f, err := strconv.ParseFloat(vs, 64)
|
f, err := strconv.ParseFloat(vs, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("*** Could parse Go version out of %q.\n*** This isn't known to work, proceed on your own risk.", vs)
|
log.Printf("*** Couldn't parse Go version out of %q.\n*** This isn't known to work, proceed on your own risk.", vs)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if f < minGoVersion {
|
if f < minGoVersion {
|
||||||
@ -269,7 +260,7 @@ func listFiles(dir string) []string {
|
|||||||
|
|
||||||
func setBuildEnv() {
|
func setBuildEnv() {
|
||||||
os.Setenv("GOOS", goos)
|
os.Setenv("GOOS", goos)
|
||||||
if strings.HasPrefix(goarch, "arm") {
|
if strings.HasPrefix(goarch, "armv") {
|
||||||
os.Setenv("GOARCH", "arm")
|
os.Setenv("GOARCH", "arm")
|
||||||
os.Setenv("GOARM", goarch[4:])
|
os.Setenv("GOARM", goarch[4:])
|
||||||
} else {
|
} else {
|
||||||
@ -334,9 +325,6 @@ func ldflags() string {
|
|||||||
b.WriteString(fmt.Sprintf(" -X main.BuildUser %s", buildUser()))
|
b.WriteString(fmt.Sprintf(" -X main.BuildUser %s", buildUser()))
|
||||||
b.WriteString(fmt.Sprintf(" -X main.BuildHost %s", buildHost()))
|
b.WriteString(fmt.Sprintf(" -X main.BuildHost %s", buildHost()))
|
||||||
b.WriteString(fmt.Sprintf(" -X main.BuildEnv %s", buildEnvironment()))
|
b.WriteString(fmt.Sprintf(" -X main.BuildEnv %s", buildEnvironment()))
|
||||||
if strings.HasPrefix(goarch, "arm") {
|
|
||||||
b.WriteString(fmt.Sprintf(" -X main.GoArchExtra %s", goarch[3:]))
|
|
||||||
}
|
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,7 +598,7 @@ func restPostUpgrade(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if upgrade.CompareVersions(rel.Tag, Version) == 1 {
|
if upgrade.CompareVersions(rel.Tag, Version) == 1 {
|
||||||
err = upgrade.UpgradeTo(rel, GoArchExtra)
|
err = upgrade.UpgradeTo(rel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Warnln("upgrading:", err)
|
l.Warnln("upgrading:", err)
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
|
@ -62,7 +62,6 @@ var (
|
|||||||
IsRelease bool
|
IsRelease bool
|
||||||
IsBeta bool
|
IsBeta bool
|
||||||
LongVersion string
|
LongVersion string
|
||||||
GoArchExtra string // "", "v5", "v6", "v7"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -329,7 +328,7 @@ func main() {
|
|||||||
l.Fatalln("Cannot upgrade, database seems to be locked. Is another copy of Syncthing already running?")
|
l.Fatalln("Cannot upgrade, database seems to be locked. Is another copy of Syncthing already running?")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = upgrade.UpgradeTo(rel, GoArchExtra)
|
err = upgrade.UpgradeTo(rel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Fatalln("Upgrade:", err) // exits 1
|
l.Fatalln("Upgrade:", err) // exits 1
|
||||||
}
|
}
|
||||||
@ -1246,7 +1245,7 @@ func autoUpgrade() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
l.Infof("Automatic upgrade (current %q < latest %q)", Version, rel.Tag)
|
l.Infof("Automatic upgrade (current %q < latest %q)", Version, rel.Tag)
|
||||||
err = upgrade.UpgradeTo(rel, GoArchExtra)
|
err = upgrade.UpgradeTo(rel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Warnln("Automatic upgrade:", err)
|
l.Warnln("Automatic upgrade:", err)
|
||||||
continue
|
continue
|
||||||
|
25
internal/upgrade/releasename_darwin.go
Normal file
25
internal/upgrade/releasename_darwin.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2014 The Syncthing Authors.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU General Public License as published by the Free
|
||||||
|
// Software Foundation, either version 3 of the License, or (at your option)
|
||||||
|
// any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
// more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package upgrade
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func releaseName(tag string) string {
|
||||||
|
return fmt.Sprintf("syncthing-macosx-%s-%s.", runtime.GOARCH, tag)
|
||||||
|
}
|
38
internal/upgrade/releasename_linux_arm.go
Normal file
38
internal/upgrade/releasename_linux_arm.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// Copyright (C) 2014 The Syncthing Authors.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU General Public License as published by the Free
|
||||||
|
// Software Foundation, either version 3 of the License, or (at your option)
|
||||||
|
// any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
// more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package upgrade
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func releaseName(tag string) string {
|
||||||
|
return fmt.Sprintf("syncthing-linux-armv%s-%s.", goARM(), tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the current ARM architecture version for upgrade purposes. If we can't
|
||||||
|
// figure it out from the uname, default to ARMv6 (same as Go distribution).
|
||||||
|
func goARM() string {
|
||||||
|
var name syscall.Utsname
|
||||||
|
syscall.Uname(&name)
|
||||||
|
machine := string(name.Machine[:5])
|
||||||
|
if strings.HasPrefix(machine, "armv") {
|
||||||
|
return machine[4:]
|
||||||
|
}
|
||||||
|
return "6"
|
||||||
|
}
|
27
internal/upgrade/releasename_other.go
Normal file
27
internal/upgrade/releasename_other.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright (C) 2014 The Syncthing Authors.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU General Public License as published by the Free
|
||||||
|
// Software Foundation, either version 3 of the License, or (at your option)
|
||||||
|
// any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
// more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// +build !arm,!darwin
|
||||||
|
|
||||||
|
package upgrade
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func releaseName(tag string) string {
|
||||||
|
return fmt.Sprintf("syncthing-%s-%s-%s.", runtime.GOOS, runtime.GOARCH, tag)
|
||||||
|
}
|
@ -48,7 +48,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A wrapper around actual implementations
|
// A wrapper around actual implementations
|
||||||
func UpgradeTo(rel Release, archExtra string) error {
|
func UpgradeTo(rel Release) error {
|
||||||
select {
|
select {
|
||||||
case <-upgradeUnlocked:
|
case <-upgradeUnlocked:
|
||||||
path, err := osext.Executable()
|
path, err := osext.Executable()
|
||||||
@ -56,7 +56,7 @@ func UpgradeTo(rel Release, archExtra string) error {
|
|||||||
upgradeUnlocked <- true
|
upgradeUnlocked <- true
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = upgradeTo(path, rel, archExtra)
|
err = upgradeTo(path, rel)
|
||||||
// If we've failed to upgrade, unlock so that another attempt could be made
|
// If we've failed to upgrade, unlock so that another attempt could be made
|
||||||
if err != nil {
|
if err != nil {
|
||||||
upgradeUnlocked <- true
|
upgradeUnlocked <- true
|
||||||
|
@ -28,19 +28,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Upgrade to the given release, saving the previous binary with a ".old" extension.
|
// Upgrade to the given release, saving the previous binary with a ".old" extension.
|
||||||
func upgradeTo(path string, rel Release, archExtra string) error {
|
func upgradeTo(path string, rel Release) error {
|
||||||
osName := runtime.GOOS
|
expectedRelease := releaseName(rel.Tag)
|
||||||
if osName == "darwin" {
|
|
||||||
// We call the darwin release bundles macosx because that makes more
|
|
||||||
// sense for people downloading them
|
|
||||||
osName = "macosx"
|
|
||||||
}
|
|
||||||
expectedRelease := fmt.Sprintf("syncthing-%s-%s%s-%s.", osName, runtime.GOARCH, archExtra, rel.Tag)
|
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugf("expected release asset %q", expectedRelease)
|
l.Debugf("expected release asset %q", expectedRelease)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
package upgrade
|
package upgrade
|
||||||
|
|
||||||
func upgradeTo(path string, rel Release, extra string) error {
|
func upgradeTo(path string, rel Release) error {
|
||||||
return ErrUpgradeUnsupported
|
return ErrUpgradeUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,13 +28,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Upgrade to the given release, saving the previous binary with a ".old" extension.
|
// Upgrade to the given release, saving the previous binary with a ".old" extension.
|
||||||
func upgradeTo(path string, rel Release, archExtra string) error {
|
func upgradeTo(path string, rel Release) error {
|
||||||
expectedRelease := fmt.Sprintf("syncthing-%s-%s%s-%s.", runtime.GOOS, runtime.GOARCH, archExtra, rel.Tag)
|
expectedRelease := releaseName(rel.Tag)
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugf("expected release asset %q", expectedRelease)
|
l.Debugf("expected release asset %q", expectedRelease)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user