mirror of
https://github.com/minio/mc.git
synced 2025-11-12 01:02:26 +03:00
82 lines
2.2 KiB
Go
82 lines
2.2 KiB
Go
/*
|
||
* Minio Client (C) 2015 Minio, Inc.
|
||
*
|
||
* 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.
|
||
*/
|
||
|
||
package main
|
||
|
||
import (
|
||
"errors"
|
||
"fmt"
|
||
"runtime"
|
||
"time"
|
||
|
||
"github.com/minio/cli"
|
||
"github.com/minio/mc/pkg/console"
|
||
"github.com/minio/minio/pkg/iodine"
|
||
)
|
||
|
||
const (
|
||
mcUpdateURL = "http://dl.minio.io:9000/updates/2015/Apr" + "/mc" + "." + runtime.GOOS + "." + runtime.GOARCH
|
||
)
|
||
|
||
func doUpdateCheck(config *hostConfig) (string, error) {
|
||
clnt, err := getNewClient(mcUpdateURL, config)
|
||
if err != nil {
|
||
return "Unable to create client: " + mcUpdateURL, iodine.New(err, map[string]string{"failedURL": mcUpdateURL})
|
||
}
|
||
latest, err := clnt.Stat()
|
||
if err != nil {
|
||
return "No update available at this time", nil
|
||
}
|
||
current, _ := time.Parse(time.RFC3339Nano, BuildDate)
|
||
if current.IsZero() {
|
||
return "BuildDate is empty, must be a custom build cannot update", nil
|
||
}
|
||
if latest.Time.After(current) {
|
||
printUpdateNotify("new", "old")
|
||
return "", nil
|
||
}
|
||
return "You have latest build", nil
|
||
|
||
}
|
||
|
||
// runUpdateCmd -
|
||
func runUpdateCmd(ctx *cli.Context) {
|
||
if ctx.Args().First() == "help" {
|
||
cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code
|
||
}
|
||
if !isMcConfigExist() {
|
||
console.Fatalln(console.ErrorMessage{
|
||
Message: "Please run \"mc config generate\"",
|
||
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
||
})
|
||
}
|
||
hostConfig, err := getHostConfig(mcUpdateURL)
|
||
if err != nil {
|
||
console.Fatalln(console.ErrorMessage{
|
||
Message: fmt.Sprintf("Unable to read configuration for host ‘%s’", mcUpdateURL),
|
||
Error: iodine.New(err, nil),
|
||
})
|
||
}
|
||
msg, err := doUpdateCheck(hostConfig)
|
||
if err != nil {
|
||
console.Fatalln(console.ErrorMessage{
|
||
Message: msg,
|
||
Error: iodine.New(err, nil),
|
||
})
|
||
}
|
||
console.Infoln(console.Message(msg))
|
||
}
|