From 9b9c3c13575f07dd54fa1895ec1822e38299bd9e Mon Sep 17 00:00:00 2001 From: asus Date: Tue, 12 Sep 2023 10:31:45 +0200 Subject: [PATCH] modified makefile to produce same home dir in sudo mode --- Makefile | 16 +++++++++++++++- srcs/.env | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index df88142..ccfa68e 100644 --- a/Makefile +++ b/Makefile @@ -24,12 +24,26 @@ RESET = "\e[0m" COMPOSE = ./srcs/docker-compose.yml +# in makefile you can use an env variable directly as a make variable : +# -> https://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_6.html#SEC68 +# so if you want to get the home directory you can use $(HOME) +# however, this will not give the same result if you run make in sudo, ex : +# make : /home/asususus +# sudo make : /root +# but you can use this command `eval echo "~$SUDO_USER"` to get +# the home directory of the user using sudo, it works in non-sudo also : +# - $SUDO_USER : +# - in normal mode its value is "" +# - in sudo mode its value is the user (same as $USER in normal mode) +# - ~$SUDO_USER : +# - in linux "~USER" print the home directory of a user +USER_HOME := $(shell echo ~$$SUDO_USER) # extract env variables in .env file # then expend the home path # then expend the pwd path # and finally remove the leading "EXPEND_" word EXPENDED_ENV_VAR := $(shell grep "^#EXPEND_" ./srcs/.env) -EXPENDED_ENV_VAR := $(subst $$HOME_PATH,$(HOME),$(EXPENDED_ENV_VAR)) +EXPENDED_ENV_VAR := $(subst $$HOME_PATH,$(USER_HOME),$(EXPENDED_ENV_VAR)) EXPENDED_ENV_VAR := $(subst $$PWD_PATH,$(shell pwd),$(EXPENDED_ENV_VAR)) EXPENDED_ENV_VAR := $(EXPENDED_ENV_VAR:#EXPEND_%=%) diff --git a/srcs/.env b/srcs/.env index 6ae0172..0a1ad99 100644 --- a/srcs/.env +++ b/srcs/.env @@ -44,6 +44,6 @@ EXECUTION_TIME=300 # EXPENDED LINES : HOST_VOLUME_CERTS=/home/asususus/Nextcloud/informatique/lejourduprof/srcs/requirements/nginx/conf/ssl HOST_VOLUME_PLUGINS=/home/asususus/Nextcloud/informatique/lejourduprof/srcs/plugins -HOST_VOLUME_DB=/home/asususus/data/lejourduprof/db_volume -HOST_VOLUME_WP=/home/asususus/data/lejourduprof/wp_volume +HOST_VOLUME_DB=/root/data/lejourduprof/db_volume +HOST_VOLUME_WP=/root/data/lejourduprof/wp_volume