2016-02-15 07:09:34 -06:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2016-06-03 05:19:04 -05:00
|
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
|
2016-02-15 07:09:34 -06:00
|
|
|
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
|
2016-02-15 09:11:37 -06:00
|
|
|
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
2016-02-15 07:09:34 -06:00
|
|
|
"github.com/hashicorp/go-version"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ShouldUpgrade(installed string, remote m.Plugin) bool {
|
|
|
|
installedVersion, err1 := version.NewVersion(installed)
|
|
|
|
|
|
|
|
if err1 != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range remote.Versions {
|
|
|
|
remoteVersion, err2 := version.NewVersion(v.Version)
|
|
|
|
|
|
|
|
if err2 == nil {
|
|
|
|
if installedVersion.LessThan(remoteVersion) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func upgradeAllCommand(c CommandLine) error {
|
2016-03-28 14:42:26 -05:00
|
|
|
pluginsDir := c.GlobalString("pluginsDir")
|
2016-02-15 07:09:34 -06:00
|
|
|
|
2016-03-28 14:42:26 -05:00
|
|
|
localPlugins := s.GetLocalPlugins(pluginsDir)
|
2016-02-15 07:09:34 -06:00
|
|
|
|
2016-03-07 06:27:51 -06:00
|
|
|
remotePlugins, err := s.ListAllPlugins(c.GlobalString("repo"))
|
2016-02-15 07:09:34 -06:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
pluginsToUpgrade := make([]m.InstalledPlugin, 0)
|
|
|
|
|
|
|
|
for _, localPlugin := range localPlugins {
|
|
|
|
for _, remotePlugin := range remotePlugins.Plugins {
|
|
|
|
if localPlugin.Id == remotePlugin.Id {
|
|
|
|
if ShouldUpgrade(localPlugin.Info.Version, remotePlugin) {
|
|
|
|
pluginsToUpgrade = append(pluginsToUpgrade, localPlugin)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, p := range pluginsToUpgrade {
|
2016-06-03 05:19:04 -05:00
|
|
|
logger.Infof("Updating %v \n", p.Id)
|
2016-02-15 07:09:34 -06:00
|
|
|
|
2016-03-28 14:42:26 -05:00
|
|
|
s.RemoveInstalledPlugin(pluginsDir, p.Id)
|
2016-03-08 07:53:27 -06:00
|
|
|
InstallPlugin(p.Id, "", c)
|
2016-02-15 07:09:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|