diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 3b64df6f..ccece35a 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -620,6 +620,10 @@ nextFolder: go standbyMonitor() } + if cfg.Options.AutoUpgradeIntervalH > 0 { + go autoUpgrade() + } + events.Default.Log(events.StartupComplete, nil) go generateEvents() @@ -1172,3 +1176,36 @@ func standbyMonitor() { now = time.Now() } } + +func autoUpgrade() { + var skipped bool + interval := time.Duration(cfg.Options.AutoUpgradeIntervalH) * time.Hour + for { + if skipped { + time.Sleep(interval) + } else { + skipped = true + } + + rel, err := upgrade.LatestRelease(strings.Contains(Version, "-beta")) + if err != nil { + l.Warnln("Automatic upgrade:", err) + continue + } + + if upgrade.CompareVersions(rel.Tag, Version) <= 0 { + continue + } + + l.Infof("Automatic upgrade (current %q < latest %q)", Version, rel.Tag) + err = upgrade.UpgradeTo(rel, GoArchExtra) + if err != nil { + l.Warnln("Automatic upgrade:", err) + continue + } + l.Warnf("Automatically upgraded to version %q. Restarting in 1 minute.", rel.Tag) + time.Sleep(time.Minute) + stop <- exitUpgrading + return + } +} diff --git a/gui/app.js b/gui/app.js index 1325b009..48036e1f 100644 --- a/gui/app.js +++ b/gui/app.js @@ -533,6 +533,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca $scope.tmpOptions = angular.copy($scope.config.Options); $scope.tmpOptions.UREnabled = ($scope.tmpOptions.URAccepted > 0); $scope.tmpOptions.DeviceName = $scope.thisDevice().Name; + $scope.tmpOptions.AutoUpgradeEnabled = ($scope.tmpOptions.AutoUpgradeIntervalH > 0); $scope.tmpGUI = angular.copy($scope.config.GUI); $('#settings').modal(); }; @@ -563,6 +564,13 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca $scope.tmpOptions.URAccepted = -1; } + // Check if auto-upgrade has been enabled or disabled + if ($scope.tmpOptions.AutoUpgradeEnabled) { + $scope.tmpOptions.AutoUpgradeIntervalH = $scope.tmpOptions.AutoUpgradeIntervalH || 12; + } else { + $scope.tmpOptions.AutoUpgradeIntervalH = 0; + } + // Check if protocol will need to be changed on restart if ($scope.config.GUI.UseTLS !== $scope.tmpGUI.UseTLS) { $scope.protocolChanged = true; diff --git a/gui/index.html b/gui/index.html index e4584783..ec73376a 100644 --- a/gui/index.html +++ b/gui/index.html @@ -606,26 +606,36 @@ -