diff options
author | Jakob Unterwurzacher | 2016-07-03 16:49:42 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2016-07-03 16:50:52 +0200 |
commit | 0d5d6fc99bf84ff583e7ebf0283c4d0efe4245be (patch) | |
tree | b27e0e4b9cf7a68c133ef766f65f13cabdc01f41 /main.go | |
parent | e021b9d00cf1daad6342fa557ee3c36a5a303efb (diff) |
main: bake build date into version string
$ gocryptfs -version
gocryptfs v0.12-36-ge021b9d-dirty; go-fuse a4c968c; 2016-07-03 go1.6.2
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -51,9 +51,16 @@ type argContainer struct { var flagSet *flag.FlagSet -// GitVersion will be set by the build script "build.bash" -var GitVersion = "[version not set - please compile using ./build.bash]" -var GitVersionFuse = "[version not set - please compile using ./build.bash]" +const pleaseBuildBash = "[not set - please compile using ./build.bash]" + +// gocryptfs version according to git, set by build.bash +var GitVersion = pleaseBuildBash + +// go-fuse library version, set by build.bash +var GitVersionFuse = pleaseBuildBash + +// Unix timestamp, set by build.bash +var BuildTime = "0" // initDir initializes an empty directory for use as a gocryptfs cipherdir. func initDir(args *argContainer) { @@ -145,11 +152,17 @@ func changePassword(args *argContainer) { os.Exit(0) } -// printVersion - print a version string like -// "gocryptfs v0.3.1-31-g6736212-dirty; on-disk format 2" +// printVersion prints a version string like this: +// gocryptfs v0.12-36-ge021b9d-dirty; go-fuse a4c968c; 2016-07-03 go1.6.2 func printVersion() { + humanTime := "0000-00-00" + if i, _ := strconv.ParseInt(BuildTime, 10, 64); i > 0 { + t := time.Unix(i, 0).UTC() + humanTime = fmt.Sprintf("%d-%02d-%02d", t.Year(), t.Month(), t.Day()) + } + built := fmt.Sprintf("%s %s", humanTime, runtime.Version()) fmt.Printf("%s %s; go-fuse %s; %s\n", - tlog.ProgramName, GitVersion, GitVersionFuse, runtime.Version()) + tlog.ProgramName, GitVersion, GitVersionFuse, built) } func main() { |