From fdba54cdb75503153bb76ad87e6dd20c1293f790 Mon Sep 17 00:00:00 2001 From: asus Date: Thu, 1 Feb 2024 02:24:47 +0100 Subject: [PATCH] resolve an error in makefile when trying to add url to host --- Makefile | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 0eb1535..884b52f 100644 --- a/Makefile +++ b/Makefile @@ -28,13 +28,14 @@ RESET := "\e[0m" COMPOSE_FILE := ./srcs/docker-compose.yml ENV_PATH := ./srcs/.env -# list of volumes +# get env variables from .env file : SOURCE_ENV := . $(ENV_PATH) +# list of volumes VOLUME_ENV := set | grep "^HOST_VOLUME_" | cut -d "=" -f 2 VOLUMES_D = $(shell $(SOURCE_ENV) ; $(VOLUME_ENV) ) - # url for wordpress, use in makefile to change local -WP_URL := $(shell grep "WP_URL" $(ENV_PATH) | cut -d "=" -f 2) +WP_URL = $(shell $(SOURCE_ENV) ; echo $$WP_URL ) +WP_COMPLETE_URL = $(shell $(SOURCE_ENV) ; echo $$WP_COMPLETE_URL ) # list of running containers, see : https://stackoverflow.com/questions/10024279/how-to-use-shell-commands-in-makefile RUNNING := $(shell docker ps -q) @@ -62,9 +63,14 @@ require: mkdir -p $(VOLUMES_D) # verify if the wordpress url is added to the local path @echo $(B_PURPLE)"verify if the wordpress url is added to the local path"$(RESET) - - if ! grep "127.0.0.1 $(WP_URL)" /etc/hosts 2> /dev/null; then \ - echo $(B_PURPLE)"nop ! adding it"$(RESET) \ - bash -c 'echo -e "\n# adding for lejourduprof (you can delete it)\n127.0.0.1 $(WP_URL)" >> /etc/hosts'; \ + -@ if ! awk "/127.0.0.1/ && /$(WP_URL)/" /etc/hosts 2> /dev/null; then \ + echo $(B_PURPLE)"nop ! trying to add it (might need sudo)"$(RESET); \ + bash -c 'echo -e "\n adding for lejourduprof (you can delete it)\n127.0.0.1 $(WP_URL)" >> /etc/hosts'; \ + if ! awk "/127.0.0.1/ && /$(WP_URL)/" /etc/hosts 2> /dev/null; then \ + echo $(B_RED)"it didn't succeed :/ try again with sudo"$(RESET); \ + else \ + echo $(B_GREEN)"it has been succesfully added :)"$(RESET); \ + fi \ fi build: @@ -112,13 +118,10 @@ fclean: fclean-images fclean-volumes re: fclean all # !! remove everything everything -erase_v: +erase: - rm -rf $(VOLUMES_D) $(MAKE) fclean -new: erase_v $(NAME) +new: erase $(NAME) -try: - ./test.sh - -.PHONY : all $(VOLUMES_D) require build up list clean fclean re erase_v new +.PHONY : all $(VOLUMES_D) require build up list clean fclean re erase new require