diff --git a/.gitignore b/.gitignore index 1d3ed4c..fc3317a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ config.yml +keymaster.spec diff --git a/Makefile b/Makefile index 89cd86a..6c212a6 100644 --- a/Makefile +++ b/Makefile @@ -10,9 +10,15 @@ endif BINARY=keymaster # These are the values we want to pass for Version and BuildTime -VERSION=1.15.3 +VERSION?=1.15.3 DEFAULT_HOST?= -DEFAULT_LDFLAGS=-X main.Version=${VERSION} +VERSION_FLAVOUR?= +EXTRA_LDFLAGS?= +PRINTVERSION=${VERSION} +ifneq ($(VERSION_FLAVOUR),) +PRINTVERSION=${VERSION}-${VERSION_FLAVOUR} +endif +DEFAULT_LDFLAGS=-X main.Version=${PRINTVERSION} ${EXTRA_LDFLAGS} CLIENT_LDFLAGS=${DEFAULT_LDFLAGS} -X main.defaultHost=${DEFAULT_HOST} #BUILD_TIME=`date +%FT%T%z` @@ -39,16 +45,25 @@ all: install-client cd cmd/keymaster-unlocker; go install -ldflags "${DEFAULT_LDFLAGS}" cd cmd/keymaster-eventmond; go install -ldflags "${DEFAULT_LDFLAGS}" -build: cmd/keymasterd/binData.go +build: prebuild go build ${EXTRA_BUILD_FLAGS} -ldflags "${CLIENT_LDFLAGS}" -o $(OUTPUT_DIR) ./... cmd/keymasterd/binData.go: -go-bindata -fs -o cmd/keymasterd/binData.go -prefix cmd/keymasterd/data cmd/keymasterd/data/... -install-client: cmd/keymasterd/binData.go +keymaster.spec: + ifeq ($(OS), Windows_NT) + powershell -Command "Get-Content keymaster.spec.tpl | ForEach-Object { \$$_.Replace('{{VERSION}}', '$(VERSION)') } | Set-Content keymaster.spec" + else + sed 's/{{VERSION}}/$(VERSION)/g' keymaster.spec.tpl > keymaster.spec; + endif + +prebuild: keymaster.spec cmd/keymasterd/binData.go + +install-client: prebuild cd cmd/keymaster; go install ${EXTRA_BUILD_FLAGS} -ldflags "${CLIENT_LDFLAGS}" -build-client: cmd/keymasterd/binData.go +build-client: prebuild go build -ldflags "${CLIENT_LDFLAGS}" -o $(OUTPUT_DIR) $(CLIENT_DEST) win-client: client-test @@ -64,7 +79,7 @@ clean: rm -f bin/* rm -f keymaster-*.tar.gz -${BINARY}-${VERSION}.tar.gz: +${BINARY}-${VERSION}.tar.gz: prebuild mkdir ${BINARY}-${VERSION} rsync -av --exclude="config.yml" --exclude="*.pem" --exclude="*.out" lib/ ${BINARY}-${VERSION}/lib/ rsync -av --exclude="config.yml" --exclude="*.pem" --exclude="*.out" --exclude="*.key" cmd/ ${BINARY}-${VERSION}/cmd/ diff --git a/cmd/keymaster/main.go b/cmd/keymaster/main.go index 0e12122..2640762 100644 --- a/cmd/keymaster/main.go +++ b/cmd/keymaster/main.go @@ -68,7 +68,8 @@ var ( "If true, use the smart round-robin dialer") webauthBrowser = flag.String("webauthBrowser", "", "Browser command to use for webauth") - + printVersion = flag.Bool("version", false, + "Print version and exit") FilePrefix = "keymaster" ) @@ -496,6 +497,10 @@ func main() { flag.Usage = Usage flag.Parse() logger := cmdlogger.New() + if *printVersion { + fmt.Println(Version) + return + } rootCAs, err := maybeGetRootCas(*rootCAFilename, logger) if err != nil { logger.Fatal(err) diff --git a/keymaster.spec b/keymaster.spec.tpl similarity index 99% rename from keymaster.spec rename to keymaster.spec.tpl index 58b384b..d7b78a6 100644 --- a/keymaster.spec +++ b/keymaster.spec.tpl @@ -1,5 +1,5 @@ Name: keymaster -Version: 1.15.3 +Version: {{VERSION}} Release: 1%{?dist} Summary: Short term access certificate generator and client @@ -74,5 +74,3 @@ systemctl daemon-reload %config(noreplace) %{_datarootdir}/keymasterd/customization_data/web_resources/* %config(noreplace) %{_datarootdir}/keymasterd/customization_data/templates/* %changelog - -