diff --git a/Makefile b/Makefile index cb4d0c1d9..574970109 100644 --- a/Makefile +++ b/Makefile @@ -47,13 +47,13 @@ test: build gomake-all: build @GO15VENDOREXPERIMENT=1 go install github.com/minio/minio -release: genversion - @echo "Installing minio for new version.go:" +release: version + @echo "Installing minio (new version):" @GO15VENDOREXPERIMENT=1 go install github.com/minio/minio -genversion: - @echo "Generating new minio version.go" - @cd ./pkg/version; go run genversion.go; cd - 1>/dev/null +version: + @echo "Generating new version.go" + @GO15VENDOREXPERIMENT=1 go run buildscripts/genversion.go pkg-remove: @GO15VENDOREXPERIMENT=1 govendor remove $(PKG) diff --git a/buildscripts/genversion.go b/buildscripts/genversion.go new file mode 100644 index 000000000..9392fa171 --- /dev/null +++ b/buildscripts/genversion.go @@ -0,0 +1,77 @@ +// +build ignore + +/* + * Minio Cloud Storage, (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 ( + "fmt" + "net/http" + "os" + "strings" + "text/template" + "time" +) + +var versionTemplate = `// -------- DO NOT EDIT -------- +// This file is autogenerated by genversion.go during the release process. + +package main + +const minioVersion = {{if .Version}}"{{.Version}}"{{else}}""{{end}} +const minioReleaseTag = {{if .ReleaseTag}}"{{.ReleaseTag}}"{{else}}""{{end}} +` + +// genVersion generates ‘version.go’. +func genVersion(version string) { + t := template.Must(template.New("version").Parse(versionTemplate)) + versionFile, err := os.OpenFile("version.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) + if err != nil { + fmt.Println("genversion: Unable to generate ‘version.go’. Error: %s.", err) + os.Exit(1) + } + defer versionFile.Close() + + err = t.Execute(versionFile, struct { + Version string + ReleaseTag string + }{version, genReleaseTag(version)}) + + if err != nil { + fmt.Println("genversion: Unable to generate ‘version.go’. Error: %s.", err) + os.Exit(1) + } +} + +// genReleaseTag prints release tag to the console for easy git tagging. +func genReleaseTag(version string) string { + relTag := strings.Replace(version, " ", "-", -1) + relTag = strings.Replace(relTag, ":", "-", -1) + relTag = strings.Replace(relTag, ",", "", -1) + return "RELEASE." + relTag +} + +func main() { + // Version is in HTTP TimeFormat. + version := time.Now().UTC().Format(http.TimeFormat) + + // generate ‘version.go’ file. + genVersion(version) + + fmt.Println("Version: \"" + version + "\"") + fmt.Println("Release-Tag: " + genReleaseTag(version)) +} diff --git a/main.go b/main.go index 3d1bab8cf..90e2f262d 100644 --- a/main.go +++ b/main.go @@ -18,33 +18,29 @@ package main import ( "fmt" - "net/http" "os" "os/user" "runtime" "strconv" - "time" "github.com/dustin/go-humanize" "github.com/minio/cli" - "github.com/minio/minio/pkg/version" ) func init() { // Check for the environment early on and gracefuly report. - u, err := user.Current() + + _, err := user.Current() if err != nil { Fatalf("Unable to obtain user's home directory. \nError: %s\n", err) } - var uid int - uid, err = strconv.Atoi(u.Uid) - if err != nil { - Fatalf("Unable to convert user id to an integer. \nError: %s\n", err) - } - if uid == 0 { - Fatalln("Please run as a normal user, running as root is disallowed") + + if os.Geteuid() == 0 { + Fatalln("Please run ‘minio’ as a non-root user.") } - verifyMinioRuntime() + + // Check if minio was compiled using a supported version of Golang. + checkGolangRuntimeVersion() } // Tries to get os/arch/platform specific information @@ -73,21 +69,6 @@ func getSystemData() map[string]string { } } -func init() { - if _, err := user.Current(); err != nil { - Fatalf("Unable to determine current user. Reason: %s\n", err) - } -} - -// getFormattedVersion - -func getFormattedVersion() string { - t, _ := time.Parse(time.RFC3339Nano, version.Version) - if t.IsZero() { - return "" - } - return t.Format(http.TimeFormat) -} - func findClosestCommands(command string) []string { var closestCommands []string for _, value := range commandsTree.PrefixMatch(command) { @@ -134,14 +115,14 @@ GLOBAL FLAGS: {{range .Flags}}{{.}} {{end}}{{end}} VERSION: - ` + getFormattedVersion() + + ` + minioVersion + `{{range $key, $value := ExtraInfo}} {{$key}}: {{$value}} {{end}} ` app.CommandNotFound = func(ctx *cli.Context, command string) { - msg := fmt.Sprintf("‘%s’ is not a mc command. See ‘minio help’.", command) + msg := fmt.Sprintf("‘%s’ is not a minio sub-command. See ‘minio help’.", command) closestCommands := findClosestCommands(command) if len(closestCommands) > 0 { msg += fmt.Sprintf("\n\nDid you mean one of these?\n") diff --git a/pkg/server/api/headers.go b/pkg/server/api/headers.go index 80626c2ce..f220cfd4b 100644 --- a/pkg/server/api/headers.go +++ b/pkg/server/api/headers.go @@ -22,11 +22,9 @@ import ( "encoding/json" "encoding/xml" "net/http" - "runtime" "strconv" "github.com/minio/minio/pkg/donut" - "github.com/minio/minio/pkg/version" ) // No encoder interface exists, so we create one. @@ -53,7 +51,10 @@ func generateRequestID() []byte { func setCommonHeaders(w http.ResponseWriter, acceptsType string, contentLength int) { // set unique request ID for each reply w.Header().Set("X-Amz-Request-Id", string(generateRequestID())) - w.Header().Set("Server", ("Minio/" + version.Version + " (" + runtime.GOOS + ";" + runtime.GOARCH + ")")) + + // TODO: Modularity comes in the way of passing global state like "version". A better approach needed here. -ab + // w.Header().Set("Server", ("Minio/" + version + " (" + runtime.GOOS + ";" + runtime.GOARCH + ")")) + w.Header().Set("Accept-Ranges", "bytes") w.Header().Set("Content-Type", acceptsType) w.Header().Set("Connection", "close") diff --git a/pkg/version/genversion.go b/pkg/version/genversion.go deleted file mode 100644 index dd2d12693..000000000 --- a/pkg/version/genversion.go +++ /dev/null @@ -1,85 +0,0 @@ -// +build ignore - -/* - * Minio Cloud Storage, (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 ( - "fmt" - "net/http" - "os" - "text/template" - "time" -) - -// Version version string -type Version struct { - Date string -} - -func writeVersion(version Version) error { - var versionTemplate = `// -------- DO NOT EDIT -------- -// This file is autogenerated by genversion.go during the release process. - -package version - -// Version autogenerated -const Version = {{if .Date}}"{{.Date}}"{{else}}""{{end}} -` - t := template.Must(template.New("version").Parse(versionTemplate)) - versionFile, err := os.OpenFile("version.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - if err != nil { - return err - } - defer versionFile.Close() - err = t.Execute(versionFile, version) - if err != nil { - return err - } - return nil -} - -func genVersion() { - t := time.Now().UTC() - date := t.Format(time.RFC3339Nano) - // Tag is of following format - // - // RELEASE.[WeekDay]-[Month]-[Day]-[Hour]-[Min]-[Sec]-GMT-[Year] - // - tag := fmt.Sprintf( - "RELEASE.%s-%s-%02d-%02d-%02d-%02d-GMT-%d", - t.Weekday().String()[0:3], - t.Month().String()[0:3], - t.Day(), - t.Hour(), - t.Minute(), - t.Second(), - t.Year()) - fmt.Println("Release-Tag: " + tag) - fmt.Println("Release-Version: " + t.Format(http.TimeFormat)) - version := Version{Date: date} - err := writeVersion(version) - if err != nil { - fmt.Print(err) - os.Exit(1) - } - fmt.Println("Successfully generated ‘version.go’") -} - -func main() { - genVersion() -} diff --git a/pkg/version/version.go b/pkg/version/version.go deleted file mode 100644 index 6424494e2..000000000 --- a/pkg/version/version.go +++ /dev/null @@ -1,7 +0,0 @@ -// -------- DO NOT EDIT -------- -// This file is autogenerated by genversion.go during the release process. - -package version - -// Version autogenerated -const Version = "2015-08-14T03:23:47.250240049Z" diff --git a/verify-runtime.go b/verify-runtime.go index da1836c51..661d1e18f 100644 --- a/verify-runtime.go +++ b/verify-runtime.go @@ -93,8 +93,3 @@ func checkGolangRuntimeVersion() { Errorln("Old Golang runtime version ‘" + v1.String() + "’ detected., ‘mc’ requires minimum go1.5.1 or later.") } } - -func verifyMinioRuntime() { - // add any other checks here. - checkGolangRuntimeVersion() -} diff --git a/version-main.go b/version-main.go index 09b62bfdb..d3866e9e2 100644 --- a/version-main.go +++ b/version-main.go @@ -16,13 +16,7 @@ package main -import ( - "net/http" - "time" - - "github.com/minio/cli" - "github.com/minio/minio/pkg/version" -) +import "github.com/minio/cli" var versionCmd = cli.Command{ Name: "version", @@ -40,10 +34,6 @@ EXAMPLES: } func mainVersion(ctxx *cli.Context) { - t, _ := time.Parse(time.RFC3339Nano, version.Version) - if t.IsZero() { - Println("") - return - } - Println(t.Format(http.TimeFormat)) + Println("Version: " + minioVersion) + Println("Release-Tag: " + minioReleaseTag) } diff --git a/version.go b/version.go new file mode 100644 index 000000000..ca3a65533 --- /dev/null +++ b/version.go @@ -0,0 +1,7 @@ +// -------- DO NOT EDIT -------- +// This file is autogenerated by genversion.go during the release process. + +package main + +const minioVersion = "Sat, 19 Sep 2015 06:15:16 GMT" +const minioReleaseTag = "RELEASE.Sat-19-Sep-2015-06-15-16-GMT" diff --git a/pkg/version/version_test.go b/version_test.go similarity index 87% rename from pkg/version/version_test.go rename to version_test.go index 0d92d7e67..86fc81b56 100644 --- a/pkg/version/version_test.go +++ b/version_test.go @@ -14,14 +14,13 @@ * limitations under the License. */ -package version_test +package main import ( + "net/http" "testing" "time" - "github.com/minio/minio/pkg/version" - . "gopkg.in/check.v1" ) @@ -32,6 +31,6 @@ type MySuite struct{} var _ = Suite(&MySuite{}) func (s *MySuite) TestVersion(c *C) { - _, err := time.Parse(version.Version, time.RFC3339Nano) + _, err := time.Parse(minioVersion, http.TimeFormat) c.Assert(err, NotNil) }