#!/bin/bash

version=`git log --date=iso --pretty=format:"%cd @%H" -1`
if [ $? -ne 0 ]; then
    version="unknown version"
fi

compile=`date +"%F %T %z"`" by "`go version`
if [ $? -ne 0 ]; then
    compile="unknown datetime"
fi

describe=`git describe --tags 2>/dev/null`
if [ $? -eq 0 ]; then
    version="${version} @${describe}"
fi

cat << EOF | gofmt > pkg/utils/version.go
package utils

const (
    Version = "$version"
    Compile = "$compile"
)
EOF

cat << EOF > bin/version
version = $version
compile = $compile
EOF
