diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 79ab53f3..08ea3a44 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,6 +26,5 @@ jobs: with: packages: gcc rpm alien rsync pkg-config libudev-dev - uses: actions/checkout@v3 - - run: make init-config-host - run: make rpm diff --git a/Makefile b/Makefile index 78fc67a5..1aa33d97 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,9 @@ BINARY=keymaster # These are the values we want to pass for Version and BuildTime VERSION=1.15.3 +DEFAULT_HOST?= +DEFAULT_LDFLAGS=-X main.Version=${VERSION} +CLIENT_LDFLAGS=${DEFAULT_LDFLAGS} -X main.defaultHost=${DEFAULT_HOST} #BUILD_TIME=`date +%FT%T%z` # keymaster client requires special tags on linux @@ -20,40 +23,45 @@ ifneq ($(OS),Windows_NT) ifeq ($(UNAME_S),Linux) EXTRA_BUILD_FLAGS+= -tags=hidraw endif + CLIENT_DEST?="./cmd./keymaster/" +else + CLIENT_DEST?=".\\\\cmd\\\\keymaster\\\\" endif # Setup the -ldflags option for go build here, interpolate the variable values #LDFLAGS=-ldflags "-X github.com/ariejan/roll/core.Version=${VERSION} -X github.com/ariejan/roll/core.BuildTime=${BUILD_TIME}" -all: init-config-host cmd/keymasterd/binData.go - cd cmd/keymaster; go install ${EXTRA_BUILD_FLAGS} -ldflags "-X main.Version=${VERSION}" - cd cmd/keymasterd; go install -ldflags "-X main.Version=${VERSION}" - cd cmd/keymaster-unlocker; go install -ldflags "-X main.Version=${VERSION}" - cd cmd/keymaster-eventmond; go install -ldflags "-X main.Version=${VERSION}" +all: install-client + cd cmd/keymasterd; go install -ldflags "${DEFAULT_LDFLAGS}" + cd cmd/keymaster-unlocker; go install -ldflags "${DEFAULT_LDFLAGS}" + cd cmd/keymaster-eventmond; go install -ldflags "${DEFAULT_LDFLAGS}" build: cmd/keymasterd/binData.go - go build ${EXTRA_BUILD_FLAGS} -ldflags "-X main.Version=${VERSION}" -o bin/ ./... + go build ${EXTRA_BUILD_FLAGS} -ldflags "${CLIENT_LDFLAGS}" -o bin/ ./... 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 + cd cmd/keymaster; go install ${EXTRA_BUILD_FLAGS} -ldflags "${CLIENT_LDFLAGS}" + +build-client: cmd/keymasterd/binData.go + go build -ldflags "${CLIENT_LDFLAGS}" -o bin $(CLIENT_DEST) + win-client: client-test - go build -ldflags "-X main.Version=${VERSION}" -o bin .\cmd\keymaster\ + go build -ldflags "${CLIENT_LDFLAGS}" -o bin .\cmd\keymaster\ client-test: go test -v ./cmd/keymaster/... -get-deps: init-config-host +get-deps: go get -t ./... clean: rm -f bin/* rm -f keymaster-*.tar.gz -init-config-host: - @test -f cmd/keymaster/config_host.go || (cp -p templates/config_host_go cmd/keymaster/config_host.go && echo 'Created initial cmd/keymaster/config_host.go') - ${BINARY}-${VERSION}.tar.gz: mkdir ${BINARY}-${VERSION} rsync -av --exclude="config.yml" --exclude="*.pem" --exclude="*.out" lib/ ${BINARY}-${VERSION}/lib/ @@ -71,11 +79,11 @@ rpm: ${BINARY}-${VERSION}.tar.gz tar: ${BINARY}-${VERSION}.tar.gz -test: init-config-host +test: make -f makefile.certs go test ./... -verbose-test: init-config-host +verbose-test: go test -v ./... format: diff --git a/cmd/keymaster/main.go b/cmd/keymaster/main.go index 17f6e343..d9adef69 100644 --- a/cmd/keymaster/main.go +++ b/cmd/keymaster/main.go @@ -40,12 +40,14 @@ const ( const userAgentAppName = "keymaster" const defaultVersionNumber = "No version provided" +const defaultConfigHost = "" var ( // Must be a global variable in the data segment so that the build // process can inject the version number on the fly when building the // binary. Use only from the Usage() function. Version = defaultVersionNumber + defaultHost = defaultConfigHost userAgentString = userAgentAppName ) @@ -110,10 +112,10 @@ func loadConfigFile(client *http.Client, logger log.Logger) ( if err != nil { logger.Fatal(err) } - } else if len(defaultConfigHost) > 1 { // if there is a configHost AND there is NO config file, create one + } else if len(defaultHost) > 1 { // if there is a configHost AND there is NO config file, create one if _, err := os.Stat(*configFilename); os.IsNotExist(err) { err = config.GetConfigFromHost( - *configFilename, defaultConfigHost, client, logger) + *configFilename, defaultHost, client, logger) if err != nil { logger.Fatal(err) } diff --git a/templates/config_host_go b/templates/config_host_go deleted file mode 100644 index 6ecd2133..00000000 --- a/templates/config_host_go +++ /dev/null @@ -1,3 +0,0 @@ -package main - -const defaultConfigHost = ""