summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild.bash7
-rw-r--r--main.go25
2 files changed, 24 insertions, 8 deletions
diff --git a/build.bash b/build.bash
index 115a2ae..2316345 100755
--- a/build.bash
+++ b/build.bash
@@ -24,6 +24,9 @@ GITVERSIONFUSE=$(
fi
)
+# Build Unix timestamp, something like 1467554204.
+BUILDTIME=$(date +%s)
+
# Make sure we have the go binary
go version > /dev/null
@@ -32,10 +35,10 @@ V=$(go version | cut -d" " -f3 | cut -c3-5)
if [ $V == "1.3" -o $V == "1.4" ]
then
- go build -ldflags="-X main.GitVersion $GITVERSION -X main.GitVersionFuse $GITVERSIONFUSE"
+ go build -ldflags="-X main.GitVersion $GITVERSION -X main.GitVersionFuse $GITVERSIONFUSE -X main.BuildTime $BUILDTIME"
else
# Go 1.5 wants an "=" here
- go build -ldflags="-X main.GitVersion=$GITVERSION -X main.GitVersionFuse=$GITVERSIONFUSE"
+ go build -ldflags="-X main.GitVersion=$GITVERSION -X main.GitVersionFuse=$GITVERSIONFUSE -X main.BuildTime=$BUILDTIME"
fi
./gocryptfs -version
diff --git a/main.go b/main.go
index d5f269e..e176ae5 100644
--- a/main.go
+++ b/main.go
@@ -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() {