From 10877ee6756c4be31ca60bbb3bdebb3c5a97d147 Mon Sep 17 00:00:00 2001 From: hulamy Date: Sun, 25 Sep 2022 22:11:05 +0200 Subject: [PATCH] added protections when installing wp --- Makefile | 9 ++--- srcs/.env | 5 +-- srcs/docker-compose.yml | 8 ++-- .../wordpress/conf/wp_entrypoint.sh | 39 +++++++++++++++++-- 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 03230d2..9c9a752 100644 --- a/Makefile +++ b/Makefile @@ -24,11 +24,11 @@ RESET = "\e[0m" COMPOSE = ./srcs/docker-compose.yml -#V_USER = hulamy #V_USER = $(shell echo $(USER)) # gives root when make is run with sudo #V_USER = $(shell who | head -1 | tr " " "\n" | head -1) # gives bad result when in `sudo su` #V_USER = $(shell who | head -1 | cut -d " " -f 1) # gives bad result when in `sudo su` -V_USER = $(shell who | head -1 | cut -d " " -f 1) +#V_USER = $(shell users | tr " " "\n" | head -1) +V_USER = hulamy # same as 'LOGIN' var in .env file VOLUMES_D = /home/$(V_USER)/data/wp_volume \ /home/$(V_USER)/data/db_volume @@ -43,13 +43,13 @@ VOLUMES = $(shell docker volume ls -q) all: build up -$(VOLUMES_D): +volumes: mkdir -p $(VOLUMES_D) build: docker-compose -f $(COMPOSE) build -up: $(VOLUMES_D) +up: volumes docker-compose -f $(COMPOSE) up # list images, containers, volumes @@ -78,7 +78,6 @@ fclean-images: clean docker system prune -af fclean-volumes: clean - docker volume rm $(VOLUMES) -fclean-test: - rm -rf $(VOLUMES_D) fclean: fclean-images fclean-volumes diff --git a/srcs/.env b/srcs/.env index 1c6b75a..2562296 100644 --- a/srcs/.env +++ b/srcs/.env @@ -1,15 +1,14 @@ # DOCKER-COMPOSE -LOGIN=$USER +LOGIN=hulamy # MARIADB SETUP DB_HOST=mariadb DB_NAME=db_wp_inception DB_USER=user_wp_inception -DB_PSWD="if you read this i will have to erase your memory" -#ROOT_PSWD="root passphrase" +DB_PSWD="too bad you have read this now i have to erase your memory" # WORDPRESS SETUP diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index b24bb1b..ed69e5b 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -10,12 +10,12 @@ version: "3.8" services: # --------------------------------- nginx: -# restart: on-failure + #restart: on-failure networks: - inception ports: - "443:443" -# - "80:80" + #- "80:80" volumes: - wp_volume:/var/www/html build: ./requirements/nginx @@ -26,7 +26,7 @@ services: condition: service_started # --------------------------------- mariadb: -# restart: on-failure + #restart: on-failure env_file: .env networks: - inception @@ -48,7 +48,7 @@ services: container_name: mariadb_container # --------------------------------- wordpress: -# restart: on-failure + #restart: on-failure env_file: ./.env networks: - inception diff --git a/srcs/requirements/wordpress/conf/wp_entrypoint.sh b/srcs/requirements/wordpress/conf/wp_entrypoint.sh index 16524c1..4e2818e 100644 --- a/srcs/requirements/wordpress/conf/wp_entrypoint.sh +++ b/srcs/requirements/wordpress/conf/wp_entrypoint.sh @@ -1,22 +1,45 @@ #!/bin/sh +GRAY="\e[0;30m" +RED="\e[0;31m" +GREEN="\e[0;32m" +YELLOW="\e[0;33m" +BLUE="\e[0;34m" +PURPLE="\e[0;35m" +CYAN="\e[0;36m" +WHITE="\e[0;37m" +RESET="\e[0m" + # install wordpress with cli : https://make.wordpress.org/cli/handbook/how-to-install/ # commands : https://developer.wordpress.org/cli/commands/ -mkdir -p ${WP_DIR} - wp core download --path="${WP_DIR}" --allow-root +#if ! wp core version --path="${WP_DIR}" --quiet; then +echo -e ${YELLOW}download wordpress :${RESET} +if ! wp core version --path="${WP_DIR}" 2> /dev/null +then + mkdir -p ${WP_DIR} + wp core download --path="${WP_DIR}" --allow-root +else + echo -e ${GREEN}already there !${RESET} +fi # create config file : -if ! wp core version --path="${WP_DIR}"; then +echo -e ${YELLOW}config wordpress :${RESET} +if ! wp config path --path="${WP_DIR}" --quiet 2> /dev/null +then wp config create \ --dbhost="${DB_HOST}" \ --dbname="${DB_NAME}" \ --dbuser="${DB_USER}" \ --dbpass="${DB_PSWD}" \ --path="${WP_DIR}" --allow-root +else + echo -e ${GREEN}already configured !${RESET} fi # install wordpress : -if ! wp core is-installed --path="${WP_DIR}"; then +echo -e ${YELLOW}install wordpress :${RESET} +if ! wp core is-installed --path="${WP_DIR}" 2> /dev/null +then wp core install \ --url="${WP_URL}" \ --title="${WP_TITLE}" \ @@ -25,13 +48,21 @@ if ! wp core is-installed --path="${WP_DIR}"; then --admin_password="${WP_ADMIN_PSWD}" \ --skip-email \ --path="${WP_DIR}" --allow-root +else + echo -e ${GREEN}already installed !${RESET} fi # create user : +echo -e ${YELLOW}create wordpress user :${RESET} +if ! wp user get ${WP_USER} --path="${WP_DIR}" --field=login 2> /dev/null +then wp user create \ "${WP_USER}" "${WP_USER_EMAIL}" \ --user_pass="${WP_USER_PSWD}" \ --path="${WP_DIR}" --allow-root +else + echo -e ${GREEN}already created !${RESET} +fi # change owner and permissions to wp files chown -R www-data:www-data /var/www/*