2015-10-18 00:03:46 +02:00
|
|
|
|
/*
|
2017-02-15 09:31:00 +01:00
|
|
|
|
* Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc.
|
2015-10-18 00:03:46 +02:00
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-08-19 01:23:42 +02:00
|
|
|
|
package cmd
|
2015-10-18 00:03:46 +02:00
|
|
|
|
|
|
|
|
|
import (
|
2017-06-24 22:17:28 +02:00
|
|
|
|
"bufio"
|
2017-12-15 21:33:42 +01:00
|
|
|
|
"crypto"
|
|
|
|
|
"encoding/hex"
|
2017-02-15 09:31:00 +01:00
|
|
|
|
"fmt"
|
2015-12-23 02:11:11 +01:00
|
|
|
|
"io/ioutil"
|
2015-10-18 00:03:46 +02:00
|
|
|
|
"net/http"
|
2016-10-13 03:09:08 +02:00
|
|
|
|
"os"
|
2017-02-21 10:32:05 +01:00
|
|
|
|
"path/filepath"
|
2015-10-18 00:03:46 +02:00
|
|
|
|
"runtime"
|
2015-12-23 02:11:11 +01:00
|
|
|
|
"strings"
|
2015-10-18 00:03:46 +02:00
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/fatih/color"
|
2017-12-15 21:33:42 +01:00
|
|
|
|
"github.com/inconshreveable/go-update"
|
2015-10-18 00:03:46 +02:00
|
|
|
|
"github.com/minio/cli"
|
2018-01-17 19:54:31 +01:00
|
|
|
|
_ "github.com/minio/sha256-simd" // Needed for sha256 hash verifier.
|
2017-12-15 21:33:42 +01:00
|
|
|
|
"github.com/segmentio/go-prompt"
|
2015-10-18 00:03:46 +02:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Check for new software updates.
|
|
|
|
|
var updateCmd = cli.Command{
|
|
|
|
|
Name: "update",
|
2015-11-26 06:06:29 +01:00
|
|
|
|
Usage: "Check for a new software update.",
|
2015-10-18 00:03:46 +02:00
|
|
|
|
Action: mainUpdate,
|
2017-02-15 09:31:00 +01:00
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
|
cli.BoolFlag{
|
|
|
|
|
Name: "quiet",
|
2018-01-04 16:56:43 +01:00
|
|
|
|
Usage: "Disable any update prompt message.",
|
2017-02-15 09:31:00 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
2015-10-18 00:03:46 +02:00
|
|
|
|
CustomHelpTemplate: `Name:
|
2017-02-16 02:45:08 +01:00
|
|
|
|
{{.HelpName}} - {{.Usage}}
|
2015-10-18 00:03:46 +02:00
|
|
|
|
|
|
|
|
|
USAGE:
|
2017-02-20 05:46:06 +01:00
|
|
|
|
{{.HelpName}}{{if .VisibleFlags}} [FLAGS]{{end}}
|
2017-02-16 02:45:08 +01:00
|
|
|
|
{{if .VisibleFlags}}
|
2015-11-26 06:06:29 +01:00
|
|
|
|
FLAGS:
|
2017-02-15 11:25:38 +01:00
|
|
|
|
{{range .VisibleFlags}}{{.}}
|
2017-02-16 02:45:08 +01:00
|
|
|
|
{{end}}{{end}}
|
2017-02-15 09:31:00 +01:00
|
|
|
|
EXIT STATUS:
|
|
|
|
|
0 - You are already running the most recent version.
|
2017-12-15 21:33:42 +01:00
|
|
|
|
1 - New update was applied successfully.
|
2017-02-15 09:31:00 +01:00
|
|
|
|
-1 - Error in getting update information.
|
2015-11-26 06:06:29 +01:00
|
|
|
|
|
2017-02-20 05:46:06 +01:00
|
|
|
|
EXAMPLES:
|
2017-12-15 21:33:42 +01:00
|
|
|
|
1. Check and update minio:
|
2018-01-04 16:56:43 +01:00
|
|
|
|
$ {{.HelpName}}
|
2017-02-20 05:46:06 +01:00
|
|
|
|
`,
|
2015-10-18 00:03:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-21 10:32:05 +01:00
|
|
|
|
const (
|
|
|
|
|
minioReleaseTagTimeLayout = "2006-01-02T15-04-05Z"
|
2017-12-15 21:33:42 +01:00
|
|
|
|
minioOSARCH = runtime.GOOS + "-" + runtime.GOARCH
|
|
|
|
|
minioReleaseURL = "https://dl.minio.io/server/minio/release/" + minioOSARCH + "/"
|
2017-02-21 10:32:05 +01:00
|
|
|
|
)
|
2017-02-15 09:31:00 +01:00
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
var (
|
|
|
|
|
// Newer official download info URLs appear earlier below.
|
|
|
|
|
minioReleaseInfoURLs = []string{
|
|
|
|
|
minioReleaseURL + "minio.sha256sum",
|
|
|
|
|
minioReleaseURL + "minio.shasum",
|
2015-12-23 02:11:11 +01:00
|
|
|
|
}
|
2017-10-10 01:12:13 +02:00
|
|
|
|
)
|
2015-12-23 02:11:11 +01:00
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
// minioVersionToReleaseTime - parses a standard official release
|
|
|
|
|
// Minio version string.
|
|
|
|
|
//
|
|
|
|
|
// An official binary's version string is the release time formatted
|
|
|
|
|
// with RFC3339 (in UTC) - e.g. `2017-09-29T19:16:56Z`
|
|
|
|
|
func minioVersionToReleaseTime(version string) (releaseTime time.Time, err error) {
|
|
|
|
|
return time.Parse(time.RFC3339, version)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// releaseTimeToReleaseTag - converts a time to a string formatted as
|
|
|
|
|
// an official Minio release tag.
|
|
|
|
|
//
|
|
|
|
|
// An official minio release tag looks like:
|
|
|
|
|
// `RELEASE.2017-09-29T19-16-56Z`
|
|
|
|
|
func releaseTimeToReleaseTag(releaseTime time.Time) string {
|
|
|
|
|
return "RELEASE." + releaseTime.Format(minioReleaseTagTimeLayout)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// releaseTagToReleaseTime - reverse of `releaseTimeToReleaseTag()`
|
|
|
|
|
func releaseTagToReleaseTime(releaseTag string) (releaseTime time.Time, err error) {
|
|
|
|
|
tagTimePart := strings.TrimPrefix(releaseTag, "RELEASE.")
|
|
|
|
|
if tagTimePart == releaseTag {
|
|
|
|
|
return releaseTime, fmt.Errorf("%s is not a valid release tag", releaseTag)
|
|
|
|
|
}
|
|
|
|
|
return time.Parse(minioReleaseTagTimeLayout, tagTimePart)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// getModTime - get the file modification time of `path`
|
|
|
|
|
func getModTime(path string) (t time.Time, err error) {
|
|
|
|
|
// Convert to absolute path
|
|
|
|
|
absPath, err := filepath.Abs(path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return t, fmt.Errorf("Unable to get absolute path of %s. %s", path, err)
|
2017-02-21 10:32:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-13 12:01:15 +02:00
|
|
|
|
// Version is minio non-standard, we will use minio binary's
|
|
|
|
|
// ModTime as release time.
|
|
|
|
|
fi, err := os.Stat(absPath)
|
2016-04-29 23:24:10 +02:00
|
|
|
|
if err != nil {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
return t, fmt.Errorf("Unable to get ModTime of %s. %s", absPath, err)
|
2015-12-23 02:11:11 +01:00
|
|
|
|
}
|
2017-02-15 09:31:00 +01:00
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
// Return the ModTime
|
|
|
|
|
return fi.ModTime().UTC(), nil
|
2015-12-23 02:11:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
// GetCurrentReleaseTime - returns this process's release time. If it
|
|
|
|
|
// is official minio version, parsed version is returned else minio
|
|
|
|
|
// binary's mod time is returned.
|
2017-02-15 09:31:00 +01:00
|
|
|
|
func GetCurrentReleaseTime() (releaseTime time.Time, err error) {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
if releaseTime, err = minioVersionToReleaseTime(Version); err == nil {
|
|
|
|
|
return releaseTime, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Looks like version is minio non-standard, we use minio
|
|
|
|
|
// binary's ModTime as release time:
|
|
|
|
|
return getModTime(os.Args[0])
|
2017-02-15 09:31:00 +01:00
|
|
|
|
}
|
2016-10-13 03:09:08 +02:00
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
// IsDocker - returns if the environment minio is running in docker or
|
|
|
|
|
// not. The check is a simple file existence check.
|
|
|
|
|
//
|
2017-06-13 02:33:21 +02:00
|
|
|
|
// https://github.com/moby/moby/blob/master/daemon/initlayer/setup_unix.go#L25
|
|
|
|
|
//
|
|
|
|
|
// "/.dockerenv": "file",
|
|
|
|
|
//
|
2017-10-10 01:12:13 +02:00
|
|
|
|
func IsDocker() bool {
|
2017-10-13 12:01:15 +02:00
|
|
|
|
_, err := os.Stat("/.dockerenv")
|
2017-10-10 01:12:13 +02:00
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
|
return false
|
2016-10-13 03:09:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
// Log error, as we will not propagate it to caller
|
2017-06-13 02:33:21 +02:00
|
|
|
|
errorIf(err, "Error in docker check.")
|
2017-02-15 09:31:00 +01:00
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
return err == nil
|
2017-02-15 09:31:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-13 02:33:21 +02:00
|
|
|
|
// IsDCOS returns true if minio is running in DCOS.
|
|
|
|
|
func IsDCOS() bool {
|
|
|
|
|
// http://mesos.apache.org/documentation/latest/docker-containerizer/
|
|
|
|
|
// Mesos docker containerizer sets this value
|
|
|
|
|
return os.Getenv("MESOS_CONTAINER_NAME") != ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IsKubernetes returns true if minio is running in kubernetes.
|
2017-06-09 11:42:12 +02:00
|
|
|
|
func IsKubernetes() bool {
|
|
|
|
|
// Kubernetes env used to validate if we are
|
|
|
|
|
// indeed running inside a kubernetes pod
|
|
|
|
|
// is KUBERNETES_SERVICE_HOST but in future
|
|
|
|
|
// we might need to enhance this.
|
|
|
|
|
return os.Getenv("KUBERNETES_SERVICE_HOST") != ""
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 03:53:45 +02:00
|
|
|
|
// IsBOSH returns true if minio is deployed from a bosh package
|
|
|
|
|
func IsBOSH() bool {
|
|
|
|
|
// "/var/vcap/bosh" exists in BOSH deployed instance.
|
|
|
|
|
_, err := os.Stat("/var/vcap/bosh")
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Log error, as we will not propagate it to caller
|
|
|
|
|
errorIf(err, "Error in BOSH check.")
|
|
|
|
|
|
|
|
|
|
return err == nil
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-24 22:17:28 +02:00
|
|
|
|
// Minio Helm chart uses DownwardAPIFile to write pod label info to /podinfo/labels
|
|
|
|
|
// More info: https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/#store-pod-fields
|
|
|
|
|
// Check if this is Helm package installation and report helm chart version
|
|
|
|
|
func getHelmVersion(helmInfoFilePath string) string {
|
|
|
|
|
// Read the file exists.
|
|
|
|
|
helmInfoFile, err := os.Open(helmInfoFilePath)
|
2017-10-10 01:12:13 +02:00
|
|
|
|
if err != nil {
|
|
|
|
|
// Log errors and return "" as Minio can be deployed
|
|
|
|
|
// without Helm charts as well.
|
|
|
|
|
if !os.IsNotExist(err) {
|
|
|
|
|
errorIf(err, "Unable to read %s", helmInfoFilePath)
|
|
|
|
|
}
|
2017-06-24 22:17:28 +02:00
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(helmInfoFile)
|
|
|
|
|
for scanner.Scan() {
|
|
|
|
|
if strings.Contains(scanner.Text(), "chart=") {
|
|
|
|
|
helmChartVersion := strings.TrimPrefix(scanner.Text(), "chart=")
|
|
|
|
|
// remove quotes from the chart version
|
|
|
|
|
return strings.Trim(helmChartVersion, `"`)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
// IsSourceBuild - returns if this binary is a non-official build from
|
|
|
|
|
// source code.
|
2017-02-15 09:31:00 +01:00
|
|
|
|
func IsSourceBuild() bool {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
_, err := minioVersionToReleaseTime(Version)
|
|
|
|
|
return err != nil
|
2017-02-15 09:31:00 +01:00
|
|
|
|
}
|
2016-03-25 01:20:49 +01:00
|
|
|
|
|
2017-02-15 09:31:00 +01:00
|
|
|
|
// DO NOT CHANGE USER AGENT STYLE.
|
|
|
|
|
// The style should be
|
2017-06-09 11:42:12 +02:00
|
|
|
|
//
|
2017-10-10 01:12:13 +02:00
|
|
|
|
// Minio (<OS>; <ARCH>[; <MODE>][; dcos][; kubernetes][; docker][; source]) Minio/<VERSION> Minio/<RELEASE-TAG> Minio/<COMMIT-ID> [Minio/universe-<PACKAGE-NAME>] [Minio/helm-<HELM-VERSION>]
|
2017-02-15 09:31:00 +01:00
|
|
|
|
//
|
2017-10-10 01:12:13 +02:00
|
|
|
|
// Any change here should be discussed by opening an issue at
|
|
|
|
|
// https://github.com/minio/minio/issues.
|
2017-03-16 20:21:58 +01:00
|
|
|
|
func getUserAgent(mode string) string {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
|
|
|
|
|
userAgentParts := []string{}
|
|
|
|
|
// Helper function to concisely append a pair of strings to a
|
|
|
|
|
// the user-agent slice.
|
|
|
|
|
uaAppend := func(p, q string) {
|
|
|
|
|
userAgentParts = append(userAgentParts, p, q)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uaAppend("Minio (", runtime.GOOS)
|
|
|
|
|
uaAppend("; ", runtime.GOARCH)
|
2017-03-16 20:21:58 +01:00
|
|
|
|
if mode != "" {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
uaAppend("; ", mode)
|
2017-03-16 20:21:58 +01:00
|
|
|
|
}
|
2017-06-13 02:33:21 +02:00
|
|
|
|
if IsDCOS() {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
uaAppend("; ", "dcos")
|
2017-06-13 02:33:21 +02:00
|
|
|
|
}
|
2017-06-09 11:42:12 +02:00
|
|
|
|
if IsKubernetes() {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
uaAppend("; ", "kubernetes")
|
2017-06-09 11:42:12 +02:00
|
|
|
|
}
|
2017-02-15 09:31:00 +01:00
|
|
|
|
if IsDocker() {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
uaAppend("; ", "docker")
|
2017-02-15 09:31:00 +01:00
|
|
|
|
}
|
2017-10-27 03:53:45 +02:00
|
|
|
|
if IsBOSH() {
|
|
|
|
|
uaAppend("; ", "bosh")
|
|
|
|
|
}
|
2017-02-15 09:31:00 +01:00
|
|
|
|
if IsSourceBuild() {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
uaAppend("; ", "source")
|
2016-03-25 01:20:49 +01:00
|
|
|
|
}
|
2017-02-15 09:31:00 +01:00
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
uaAppend(") Minio/", Version)
|
|
|
|
|
uaAppend(" Minio/", ReleaseTag)
|
|
|
|
|
uaAppend(" Minio/", CommitID)
|
2017-06-13 02:33:21 +02:00
|
|
|
|
if IsDCOS() {
|
|
|
|
|
universePkgVersion := os.Getenv("MARATHON_APP_LABEL_DCOS_PACKAGE_VERSION")
|
|
|
|
|
// On DC/OS environment try to the get universe package version.
|
|
|
|
|
if universePkgVersion != "" {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
uaAppend(" Minio/universe-", universePkgVersion)
|
2017-06-13 02:33:21 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-24 22:17:28 +02:00
|
|
|
|
|
|
|
|
|
if IsKubernetes() {
|
|
|
|
|
// In Kubernetes environment, try to fetch the helm package version
|
|
|
|
|
helmChartVersion := getHelmVersion("/podinfo/labels")
|
|
|
|
|
if helmChartVersion != "" {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
uaAppend(" Minio/helm-", helmChartVersion)
|
2017-06-24 22:17:28 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 03:53:45 +02:00
|
|
|
|
pcfTileVersion := os.Getenv("MINIO_PCF_TILE_VERSION")
|
|
|
|
|
if pcfTileVersion != "" {
|
|
|
|
|
uaAppend(" Minio/pcf-tile-", pcfTileVersion)
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
return strings.Join(userAgentParts, "")
|
2017-02-15 09:31:00 +01:00
|
|
|
|
}
|
2016-03-25 01:20:49 +01:00
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
func downloadReleaseURL(releaseChecksumURL string, timeout time.Duration, mode string) (content string, err error) {
|
2017-02-15 09:31:00 +01:00
|
|
|
|
req, err := http.NewRequest("GET", releaseChecksumURL, nil)
|
|
|
|
|
if err != nil {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
return content, err
|
2016-03-25 01:20:49 +01:00
|
|
|
|
}
|
2017-03-16 20:21:58 +01:00
|
|
|
|
req.Header.Set("User-Agent", getUserAgent(mode))
|
2016-03-25 01:20:49 +01:00
|
|
|
|
|
|
|
|
|
client := &http.Client{
|
2017-02-15 09:31:00 +01:00
|
|
|
|
Timeout: timeout,
|
2017-03-01 18:18:55 +01:00
|
|
|
|
Transport: &http.Transport{
|
|
|
|
|
// need to close connection after usage.
|
|
|
|
|
DisableKeepAlives: true,
|
|
|
|
|
},
|
2016-03-25 01:20:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-15 09:31:00 +01:00
|
|
|
|
resp, err := client.Do(req)
|
2016-08-19 17:09:05 +02:00
|
|
|
|
if err != nil {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
return content, err
|
2017-02-15 09:31:00 +01:00
|
|
|
|
}
|
|
|
|
|
if resp == nil {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
return content, fmt.Errorf("No response from server to download URL %s", releaseChecksumURL)
|
2016-08-19 17:09:05 +02:00
|
|
|
|
}
|
2017-03-01 18:18:55 +01:00
|
|
|
|
defer resp.Body.Close()
|
2016-08-19 17:09:05 +02:00
|
|
|
|
|
2017-02-15 09:31:00 +01:00
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
return content, fmt.Errorf("Error downloading URL %s. Response: %v", releaseChecksumURL, resp.Status)
|
2017-02-15 09:31:00 +01:00
|
|
|
|
}
|
2017-10-10 01:12:13 +02:00
|
|
|
|
contentBytes, err := ioutil.ReadAll(resp.Body)
|
2016-10-13 03:09:08 +02:00
|
|
|
|
if err != nil {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
return content, fmt.Errorf("Error reading response. %s", err)
|
2016-10-13 03:09:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
return string(contentBytes), err
|
2017-02-15 09:31:00 +01:00
|
|
|
|
}
|
2016-10-24 22:44:15 +02:00
|
|
|
|
|
2017-02-15 09:31:00 +01:00
|
|
|
|
// DownloadReleaseData - downloads release data from minio official server.
|
2017-03-16 20:21:58 +01:00
|
|
|
|
func DownloadReleaseData(timeout time.Duration, mode string) (data string, err error) {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
for _, url := range minioReleaseInfoURLs {
|
|
|
|
|
data, err = downloadReleaseURL(url, timeout, mode)
|
|
|
|
|
if err == nil {
|
|
|
|
|
return data, err
|
|
|
|
|
}
|
2017-05-13 06:40:22 +02:00
|
|
|
|
}
|
2017-10-10 01:12:13 +02:00
|
|
|
|
return data, fmt.Errorf("Failed to fetch release URL - last error: %s", err)
|
2017-02-15 09:31:00 +01:00
|
|
|
|
}
|
2016-10-13 03:09:08 +02:00
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
// parseReleaseData - parses release info file content fetched from
|
|
|
|
|
// official minio download server.
|
|
|
|
|
//
|
|
|
|
|
// The expected format is a single line with two words like:
|
|
|
|
|
//
|
|
|
|
|
// fbe246edbd382902db9a4035df7dce8cb441357d minio.RELEASE.2016-10-07T01-16-39Z
|
|
|
|
|
//
|
|
|
|
|
// The second word must be `minio.` appended to a standard release tag.
|
2017-12-15 21:33:42 +01:00
|
|
|
|
func parseReleaseData(data string) (sha256Hex string, releaseTime time.Time, err error) {
|
2017-02-15 09:31:00 +01:00
|
|
|
|
fields := strings.Fields(data)
|
|
|
|
|
if len(fields) != 2 {
|
|
|
|
|
err = fmt.Errorf("Unknown release data `%s`", data)
|
2017-12-15 21:33:42 +01:00
|
|
|
|
return sha256Hex, releaseTime, err
|
2015-10-18 00:03:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-15 21:33:42 +01:00
|
|
|
|
sha256Hex = fields[0]
|
2017-02-15 09:31:00 +01:00
|
|
|
|
releaseInfo := fields[1]
|
2017-10-10 01:12:13 +02:00
|
|
|
|
|
|
|
|
|
fields = strings.SplitN(releaseInfo, ".", 2)
|
|
|
|
|
if len(fields) != 2 {
|
2017-02-15 09:31:00 +01:00
|
|
|
|
err = fmt.Errorf("Unknown release information `%s`", releaseInfo)
|
2017-12-15 21:33:42 +01:00
|
|
|
|
return sha256Hex, releaseTime, err
|
2016-03-25 01:20:49 +01:00
|
|
|
|
}
|
2017-10-10 01:12:13 +02:00
|
|
|
|
if fields[0] != "minio" {
|
|
|
|
|
err = fmt.Errorf("Unknown release `%s`", releaseInfo)
|
2017-12-15 21:33:42 +01:00
|
|
|
|
return sha256Hex, releaseTime, err
|
2017-02-15 09:31:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
releaseTime, err = releaseTagToReleaseTime(fields[1])
|
2017-02-15 09:31:00 +01:00
|
|
|
|
if err != nil {
|
2017-10-10 01:12:13 +02:00
|
|
|
|
err = fmt.Errorf("Unknown release tag format. %s", err)
|
2017-02-15 09:31:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-15 21:33:42 +01:00
|
|
|
|
return sha256Hex, releaseTime, err
|
2017-02-15 09:31:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-15 21:33:42 +01:00
|
|
|
|
func getLatestReleaseTime(timeout time.Duration, mode string) (sha256Hex string, releaseTime time.Time, err error) {
|
2017-03-16 20:21:58 +01:00
|
|
|
|
data, err := DownloadReleaseData(timeout, mode)
|
2016-08-19 17:09:05 +02:00
|
|
|
|
if err != nil {
|
2017-12-15 21:33:42 +01:00
|
|
|
|
return sha256Hex, releaseTime, err
|
2016-03-25 01:20:49 +01:00
|
|
|
|
}
|
2016-08-19 17:09:05 +02:00
|
|
|
|
|
2017-02-15 09:31:00 +01:00
|
|
|
|
return parseReleaseData(data)
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-13 02:33:21 +02:00
|
|
|
|
const (
|
|
|
|
|
// Kubernetes deployment doc link.
|
|
|
|
|
kubernetesDeploymentDoc = "https://docs.minio.io/docs/deploy-minio-on-kubernetes"
|
|
|
|
|
|
|
|
|
|
// Mesos deployment doc link.
|
|
|
|
|
mesosDeploymentDoc = "https://docs.minio.io/docs/deploy-minio-on-dc-os"
|
|
|
|
|
)
|
2017-06-09 11:42:12 +02:00
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
func getDownloadURL(releaseTag string) (downloadURL string) {
|
2017-06-13 02:33:21 +02:00
|
|
|
|
// Check if we are in DCOS environment, return
|
|
|
|
|
// deployment guide for update procedures.
|
|
|
|
|
if IsDCOS() {
|
|
|
|
|
return mesosDeploymentDoc
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 11:42:12 +02:00
|
|
|
|
// Check if we are in kubernetes environment, return
|
|
|
|
|
// deployment guide for update procedures.
|
|
|
|
|
if IsKubernetes() {
|
|
|
|
|
return kubernetesDeploymentDoc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if we are docker environment, return docker update command
|
2017-02-15 09:31:00 +01:00
|
|
|
|
if IsDocker() {
|
2017-06-09 11:42:12 +02:00
|
|
|
|
// Construct release tag name.
|
2017-10-10 01:12:13 +02:00
|
|
|
|
return fmt.Sprintf("docker pull minio/minio:%s", releaseTag)
|
2017-02-15 09:31:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 01:12:13 +02:00
|
|
|
|
// For binary only installations, we return link to the latest binary.
|
2017-02-15 09:31:00 +01:00
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
|
return minioReleaseURL + "minio.exe"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return minioReleaseURL + "minio"
|
|
|
|
|
}
|
2015-10-18 00:03:46 +02:00
|
|
|
|
|
2017-12-15 21:33:42 +01:00
|
|
|
|
func getUpdateInfo(timeout time.Duration, mode string) (updateMsg string, sha256Hex string, currentReleaseTime, latestReleaseTime time.Time, err error) {
|
2017-05-31 18:22:00 +02:00
|
|
|
|
currentReleaseTime, err = GetCurrentReleaseTime()
|
2016-08-19 17:09:05 +02:00
|
|
|
|
if err != nil {
|
2017-12-15 21:33:42 +01:00
|
|
|
|
return updateMsg, sha256Hex, currentReleaseTime, latestReleaseTime, err
|
2016-03-25 01:20:49 +01:00
|
|
|
|
}
|
2015-10-18 00:03:46 +02:00
|
|
|
|
|
2017-12-15 21:33:42 +01:00
|
|
|
|
sha256Hex, latestReleaseTime, err = getLatestReleaseTime(timeout, mode)
|
2017-02-15 09:31:00 +01:00
|
|
|
|
if err != nil {
|
2017-12-15 21:33:42 +01:00
|
|
|
|
return updateMsg, sha256Hex, currentReleaseTime, latestReleaseTime, err
|
2015-10-18 00:03:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-15 21:33:42 +01:00
|
|
|
|
var older time.Duration
|
|
|
|
|
var downloadURL string
|
2017-02-15 09:31:00 +01:00
|
|
|
|
if latestReleaseTime.After(currentReleaseTime) {
|
|
|
|
|
older = latestReleaseTime.Sub(currentReleaseTime)
|
2017-10-10 01:12:13 +02:00
|
|
|
|
downloadURL = getDownloadURL(releaseTimeToReleaseTag(latestReleaseTime))
|
2015-10-18 00:03:46 +02:00
|
|
|
|
}
|
2016-03-25 01:20:49 +01:00
|
|
|
|
|
2017-12-15 21:33:42 +01:00
|
|
|
|
return prepareUpdateMessage(downloadURL, older), sha256Hex, currentReleaseTime, latestReleaseTime, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func doUpdate(sha256Hex string, latestReleaseTime time.Time, ok bool) (successMsg string, err error) {
|
|
|
|
|
if !ok {
|
|
|
|
|
successMsg = greenColorSprintf("Minio update to version RELEASE.%s cancelled.",
|
|
|
|
|
latestReleaseTime.Format(minioReleaseTagTimeLayout))
|
|
|
|
|
return successMsg, nil
|
|
|
|
|
}
|
|
|
|
|
var sha256Sum []byte
|
|
|
|
|
sha256Sum, err = hex.DecodeString(sha256Hex)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return successMsg, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp, err := http.Get(getDownloadURL(releaseTimeToReleaseTag(latestReleaseTime)))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return successMsg, err
|
|
|
|
|
}
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
|
|
// FIXME: add support for gpg verification as well.
|
|
|
|
|
if err = update.RollbackError(update.Apply(resp.Body,
|
|
|
|
|
update.Options{
|
|
|
|
|
Hash: crypto.SHA256,
|
|
|
|
|
Checksum: sha256Sum,
|
|
|
|
|
},
|
|
|
|
|
)); err != nil {
|
|
|
|
|
return successMsg, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return greenColorSprintf("Minio updated to version RELEASE.%s successfully.",
|
|
|
|
|
latestReleaseTime.Format(minioReleaseTagTimeLayout)), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func shouldUpdate(quiet bool, sha256Hex string, latestReleaseTime time.Time) (ok bool) {
|
|
|
|
|
ok = true
|
|
|
|
|
if !quiet {
|
|
|
|
|
ok = prompt.Confirm(greenColorSprintf("Update to RELEASE.%s [%s]", latestReleaseTime.Format(minioReleaseTagTimeLayout), "yes"))
|
|
|
|
|
}
|
|
|
|
|
return ok
|
2015-10-18 00:03:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-15 21:33:42 +01:00
|
|
|
|
var greenColorSprintf = color.New(color.FgGreen, color.Bold).SprintfFunc()
|
|
|
|
|
|
2018-01-04 16:56:43 +01:00
|
|
|
|
func mainUpdate(ctx *cli.Context) {
|
2017-02-15 09:31:00 +01:00
|
|
|
|
if len(ctx.Args()) != 0 {
|
|
|
|
|
cli.ShowCommandHelpAndExit(ctx, "update", -1)
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-15 21:33:42 +01:00
|
|
|
|
handleCommonEnvVars()
|
|
|
|
|
|
2017-02-15 09:31:00 +01:00
|
|
|
|
quiet := ctx.Bool("quiet") || ctx.GlobalBool("quiet")
|
2017-03-24 00:36:00 +01:00
|
|
|
|
if quiet {
|
|
|
|
|
log.EnableQuiet()
|
2017-02-15 09:31:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-16 20:21:58 +01:00
|
|
|
|
minioMode := ""
|
2017-12-15 21:33:42 +01:00
|
|
|
|
updateMsg, sha256Hex, _, latestReleaseTime, err := getUpdateInfo(10*time.Second, minioMode)
|
2017-02-15 09:31:00 +01:00
|
|
|
|
if err != nil {
|
2017-03-24 00:36:00 +01:00
|
|
|
|
log.Println(err)
|
2017-02-15 09:31:00 +01:00
|
|
|
|
os.Exit(-1)
|
|
|
|
|
}
|
2016-11-28 21:15:36 +01:00
|
|
|
|
|
2017-12-15 21:33:42 +01:00
|
|
|
|
// Nothing to update running the latest release.
|
|
|
|
|
if updateMsg == "" {
|
|
|
|
|
log.Println(greenColorSprintf("You are already running the most recent version of ‘minio’."))
|
2018-01-04 16:56:43 +01:00
|
|
|
|
os.Exit(0)
|
2016-11-24 00:48:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-15 21:33:42 +01:00
|
|
|
|
log.Println(updateMsg)
|
|
|
|
|
// if the in-place update is disabled then we shouldn't ask the
|
|
|
|
|
// user to update the binaries.
|
|
|
|
|
if strings.Contains(updateMsg, minioReleaseURL) && !globalInplaceUpdateDisabled {
|
|
|
|
|
var successMsg string
|
|
|
|
|
successMsg, err = doUpdate(sha256Hex, latestReleaseTime, shouldUpdate(quiet, sha256Hex, latestReleaseTime))
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
os.Exit(-1)
|
|
|
|
|
}
|
|
|
|
|
log.Println(successMsg)
|
2018-01-04 16:56:43 +01:00
|
|
|
|
os.Exit(1)
|
2017-12-15 21:33:42 +01:00
|
|
|
|
}
|
2015-10-18 00:03:46 +02:00
|
|
|
|
}
|