BOOTSTRAP_OPENSHIFT_4_GITHUB_USER ?= $(GITHUB_USER)
BOOTSTRAP_OPENSHIFT_4_GITHUB_TOKEN ?= $(GITHUB_TOKEN)
BOOTSTRAP_OPENSHIFT_4_GIT_BOOTSTRAP_PROJECT ?= "https://$(BOOTSTRAP_OPENSHIFT_4_GITHUB_USER):$(BOOTSTRAP_OPENSHIFT_4_GITHUB_TOKEN)@github.com/open-cluster-management/bootstrap.git"
BOOTSTRAP_OPENSHIFT_4_GIT_BOOTSTRAP_BRANCH ?= master
BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR ?= .deploy-bootstrap-openshift4/
BOOTSTRAP_OPENSHIFT_4_VARS_FILE ?= .deploy-bootstrap-openshift4.rc

.PHONY: deploy/bootstrap-openshift4
## Deploy openshift using the bootstrap project
deploy/bootstrap-openshift4:
	@$(GIT) clone -b $(BOOTSTRAP_OPENSHIFT_4_GIT_BOOTSTRAP_BRANCH) $(BOOTSTRAP_OPENSHIFT_4_GIT_BOOTSTRAP_PROJECT) $(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR)
	@cp $(BOOTSTRAP_OPENSHIFT_4_VARS_FILE) $(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR)/local.rc
	@cd $(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR); ./start.sh; cd ..;

.PHONY: deploy/bootstrap-openshift4/destroy
## Destroy openshift deployment resources using the bootstrap project
deploy/bootstrap-openshift4/destroy: %destroy:
	@if grep -q "export OPENSHIFT_CLEANUP" "$(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR)/local.rc"; then \
		sed -i "s/export OPENSHIFT_CLEANUP=false/export OPENSHIFT_CLEANUP=true/g" $(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR)/local.rc; \
	else \
		echo "export OPENSHIFT_CLEANUP=true" >> $(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR)/local.rc; \
	fi;
	@if grep -q "export OPENSHIFT_INSTALL" "$(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR)/local.rc"; then \
		sed -i "s/export OPENSHIFT_INSTALL=true/export OPENSHIFT_INSTALL=false/g" $(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR)/local.rc; \
	else \
		echo "export OPENSHIFT_INSTALL=false" >> $(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR)/local.rc; \
	fi;
	@if grep -q "export OPENSHIFT_POST_INSTALL" "$(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR)/local.rc"; then \
		sed -i "s/export OPENSHIFT_POST_INSTALL=true/export OPENSHIFT_POST_INSTALL=false/g" $(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR)/local.rc; \
	else \
		echo "export OPENSHIFT_POST_INSTALL=false" >> $(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR)/local.rc; \
	fi;
	@if grep -q "export OPENSHIFT_POST_CONFIG" "$(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR)/local.rc"; then \
		sed -i "s/export OPENSHIFT_POST_CONFIG=true/export OPENSHIFT_POST_CONFIG=false/g" $(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR)/local.rc; \
	else \
		echo "export OPENSHIFT_POST_CONFIG=false" >> $(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR)/local.rc; \
	fi;
	@cd $(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR); ./start.sh; cd ..;

.PHONY: deploy/bootstrap-openshift4/clean
## Clean up all openshift deployment resources using the bootstrap project
deploy/bootstrap-openshift4/clean: %clean: %destroy
ifeq ($(shell test -d $(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR) && echo -n yes),yes)
	@rm -rf $(BOOTSTRAP_OPENSHIFT_4_DEPLOY_DIR)
endif
