Bake version string into binary, add "--version" switch

Example:

	./gocryptfs -version
	gocryptfs v0.2-20-gabcef9e-dirty; on-disk format 1

Note that you MUST compile using "./build.bash" for this to work.
This commit is contained in:
Jakob Unterwurzacher 2015-11-01 13:55:35 +01:00
parent af923d2d16
commit 3f490d4d86
2 changed files with 12 additions and 2 deletions

View File

@ -2,4 +2,6 @@
set -eu set -eu
go build GITVERSION=$(git describe --tags --dirty)
go build -ldflags="-X main.GitVersion=$GITVERSION" && ./gocryptfs -version

10
main.go
View File

@ -33,6 +33,8 @@ const (
ERREXIT_MOUNTPOINT = 10 ERREXIT_MOUNTPOINT = 10
) )
var GitVersion = "[version not set - please compile using ./build.bash]"
func initDir(dirArg string) { func initDir(dirArg string) {
dir, _ := filepath.Abs(dirArg) dir, _ := filepath.Abs(dirArg)
@ -64,7 +66,7 @@ func main() {
runtime.GOMAXPROCS(4) runtime.GOMAXPROCS(4)
// Parse command line arguments // Parse command line arguments
var debug, init, zerokey, fusedebug, openssl, passwd, foreground bool var debug, init, zerokey, fusedebug, openssl, passwd, foreground, version bool
var masterkey, mountpoint, cipherdir string var masterkey, mountpoint, cipherdir string
flag.Usage = usageText flag.Usage = usageText
@ -75,10 +77,16 @@ func main() {
flag.BoolVar(&openssl, "openssl", true, "Use OpenSSL instead of built-in Go crypto") flag.BoolVar(&openssl, "openssl", true, "Use OpenSSL instead of built-in Go crypto")
flag.BoolVar(&passwd, "passwd", false, "Change password") flag.BoolVar(&passwd, "passwd", false, "Change password")
flag.BoolVar(&foreground, "f", false, "Stay in the foreground") flag.BoolVar(&foreground, "f", false, "Stay in the foreground")
flag.BoolVar(&version, "version", false, "Print version and exit")
flag.StringVar(&masterkey, "masterkey", "", "Mount with explicit master key") flag.StringVar(&masterkey, "masterkey", "", "Mount with explicit master key")
var cpuprofile = flag.String("cpuprofile", "", "Write cpu profile to specified file") var cpuprofile = flag.String("cpuprofile", "", "Write cpu profile to specified file")
flag.Parse() flag.Parse()
if version {
fmt.Printf("%s %s; ", PROGRAM_NAME, GitVersion)
fmt.Printf("on-disk format %d\n", cryptfs.HEADER_CURRENT_VERSION)
os.Exit(0)
}
if !foreground { if !foreground {
daemonize() // does not return daemonize() // does not return
} }