From 0ce7da17c494f32dd9b7a325a0dfd551fba97906 Mon Sep 17 00:00:00 2001 From: Manuel Messner Date: Fri, 16 Feb 2018 09:49:39 +0100 Subject: Makefile: move check for ROOTPW out of target context We want to minimize complexity of the targets. --- Makefile | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 0a09188..eec8c62 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,7 @@ BOOTTARGETS := $(foreach template, $(TEMPLATES), $(template)/base/boot) BOOTTARGETS += $(foreach prov, $(PROVTARGETS), $(prov)/boot) + PACKER_OPTS := -var-file=base.json ifdef DEBUG VERBOSE := 1 @@ -51,6 +52,22 @@ endif TIMESTAMP := $(shell date "+%Y-%m-%d_%H-%M-%S") +# The ROOTPW is only needed for the base, boot and provisioning targets. +# In every other case it must not be checked as it should be possible to call +# help or cleanup without the need of defining the password. +PW_NEEDED := $(filter $(strip $(PROVTARGETS) $(BOOTTARGETS)),$(MAKECMDGOALS)) +ifneq ($(PW_NEEDED),) + ifeq ($(strip $(ROOTPW)),) + $(error No root password is set, set it as ROOTPW in your environment.) + else + $(foreach cur,$(PW_NEEDED),\ + $(shell printf "$(ROOTPW)" | $(HASHER) --check --status "$(firstword $(subst /, ,$(cur)))/base/rootpw.$(HASHER)")\ + $(if $(filter 1,$(.SHELLSTATUS)),\ + $(error The wrong ROOTPW is set. Please correct it))) + endif +endif + + ifdef VERBOSE PACKER_OPTS += -var='headless=false' @@ -74,23 +91,12 @@ ifdef VERBOSE endif -check_rootpw = $(if $(strip $(ROOTPW)),\ - $(if $1,\ - $(if $(shell echo "$(ROOTPW)" | $(HASHER) --check --quiet $1/base/rootpw.$(HASHER)),\ - $(error ROOTPW password hash does not match $1/base/rootpw.$(HASHER)),\ - ),\ - ),\ - $(error No root password is set, set it as ROOTPW in your environment.) \ -) - - .PHONY: help clean_except_last clean_bases clean_all help: # Creating base images $(BASETARGETS): - $(call check_rootpw) $(info ** Building template '$(@D)' using '$(BUILDER)' **) $(PACKER) build -only=$(BUILDER) \ $(PACKER_OPTS) \ @@ -103,7 +109,6 @@ $(BASETARGETS): # Provisioning images $(PROVTARGETS): $(foreach flav, $(FLAVORS), %/$(flav)): %/base - $(call check_rootpw,$(@D)) $(eval BUILD_DIR := $(@D)/$(@F).$(TIMESTAMP)) $(info ** Provisioning '$(@D)' with '$(@F)' **) @mkdir -p $(BUILD_DIR) @@ -121,7 +126,6 @@ $(foreach flav, $(FLAVORS), %/$(flav)): %/base # Generating boot files $(BOOTTARGETS): %/boot: % - $(call check_rootpw,$(dir $(@D))) $(eval BUILD_DIR := $(@D).$(TIMESTAMP)) $(info ** Generating boot files for '$(BUILD_DIR)') $(PACKER) build -only=$(BUILDER) \ -- cgit v1.2.3-55-g7522