1
0
mirror of https://github.com/minio/mc.git synced 2026-01-04 02:44:40 +03:00

Version is now based on MD5SUM of its binary

This commit is contained in:
Anand Babu (AB) Periasamy
2015-04-24 20:46:42 -07:00
parent 155239996f
commit e359d125a5
3 changed files with 30 additions and 37 deletions

View File

@@ -1,34 +0,0 @@
#!/usr/bin/env bash
#
# Mini Copy (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.
#
CONST_FILE=build-constants.go
cat > $CONST_FILE <<EOF
/*
* ** DO NOT EDIT THIS FILE. THIS FILE IS AUTO GENERATED BY RUNNING MAKE **
*/
package main
const (
mcGitCommitHash = "__GIT_COMMIT_HASH__"
)
EOF
commit_id=$(git log --format="%H" -n 1)
sed -i "s/__GIT_COMMIT_HASH__/$commit_id/" $CONST_FILE

28
hash-binary.go Normal file
View File

@@ -0,0 +1,28 @@
package main
import (
"fmt"
"io"
"os"
"crypto/md5"
)
// mustHashBinarySelf computes MD5SUM of a binary file on disk
func hashBinary(progName string) (string, error) {
h := md5.New()
file, err := os.Open(progName) // For read access.
if err != nil {
return "", err
}
io.Copy(h, file)
return fmt.Sprintf("%x", h.Sum(nil)), nil
}
// mustHashBinarySelf computes MD5SUM of its binary file on disk
func mustHashBinarySelf() string {
hash, _ := hashBinary(os.Args[0])
return hash
}

View File

@@ -78,13 +78,12 @@ func getSystemData() map[string]string {
}
}
// Version number
var Version = "Development"
// Version is based on MD5SUM of its binary
var Version = mustHashBinarySelf()
func main() {
app := cli.NewApp()
app.Usage = "Mini Copy for object storage and filesystems"
log.Println(Version)
app.Version = Version
app.Commands = options
app.Flags = flags