added protections when installing wp

This commit is contained in:
hulamy
2022-09-25 22:11:05 +02:00
parent 7a6734045c
commit 10877ee675
4 changed files with 45 additions and 16 deletions

View File

@@ -24,11 +24,11 @@ RESET = "\e[0m"
COMPOSE = ./srcs/docker-compose.yml COMPOSE = ./srcs/docker-compose.yml
#V_USER = hulamy
#V_USER = $(shell echo $(USER)) # gives root when make is run with sudo #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 | 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) # 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 \ VOLUMES_D = /home/$(V_USER)/data/wp_volume \
/home/$(V_USER)/data/db_volume /home/$(V_USER)/data/db_volume
@@ -43,13 +43,13 @@ VOLUMES = $(shell docker volume ls -q)
all: build up all: build up
$(VOLUMES_D): volumes:
mkdir -p $(VOLUMES_D) mkdir -p $(VOLUMES_D)
build: build:
docker-compose -f $(COMPOSE) build docker-compose -f $(COMPOSE) build
up: $(VOLUMES_D) up: volumes
docker-compose -f $(COMPOSE) up docker-compose -f $(COMPOSE) up
# list images, containers, volumes # list images, containers, volumes
@@ -78,7 +78,6 @@ fclean-images: clean
docker system prune -af docker system prune -af
fclean-volumes: clean fclean-volumes: clean
- docker volume rm $(VOLUMES) - docker volume rm $(VOLUMES)
fclean-test:
- rm -rf $(VOLUMES_D) - rm -rf $(VOLUMES_D)
fclean: fclean-images fclean-volumes fclean: fclean-images fclean-volumes

View File

@@ -1,15 +1,14 @@
# DOCKER-COMPOSE # DOCKER-COMPOSE
LOGIN=$USER LOGIN=hulamy
# MARIADB SETUP # MARIADB SETUP
DB_HOST=mariadb DB_HOST=mariadb
DB_NAME=db_wp_inception DB_NAME=db_wp_inception
DB_USER=user_wp_inception DB_USER=user_wp_inception
DB_PSWD="if you read this i will have to erase your memory" DB_PSWD="too bad you have read this now i have to erase your memory"
#ROOT_PSWD="root passphrase"
# WORDPRESS SETUP # WORDPRESS SETUP

View File

@@ -10,12 +10,12 @@ version: "3.8"
services: services:
# --------------------------------- # ---------------------------------
nginx: nginx:
# restart: on-failure #restart: on-failure
networks: networks:
- inception - inception
ports: ports:
- "443:443" - "443:443"
# - "80:80" #- "80:80"
volumes: volumes:
- wp_volume:/var/www/html - wp_volume:/var/www/html
build: ./requirements/nginx build: ./requirements/nginx
@@ -26,7 +26,7 @@ services:
condition: service_started condition: service_started
# --------------------------------- # ---------------------------------
mariadb: mariadb:
# restart: on-failure #restart: on-failure
env_file: .env env_file: .env
networks: networks:
- inception - inception
@@ -48,7 +48,7 @@ services:
container_name: mariadb_container container_name: mariadb_container
# --------------------------------- # ---------------------------------
wordpress: wordpress:
# restart: on-failure #restart: on-failure
env_file: ./.env env_file: ./.env
networks: networks:
- inception - inception

View File

@@ -1,22 +1,45 @@
#!/bin/sh #!/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/ # install wordpress with cli : https://make.wordpress.org/cli/handbook/how-to-install/
# commands : https://developer.wordpress.org/cli/commands/ # commands : https://developer.wordpress.org/cli/commands/
mkdir -p ${WP_DIR} #if ! wp core version --path="${WP_DIR}" --quiet; then
wp core download --path="${WP_DIR}" --allow-root 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 : # 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 \ wp config create \
--dbhost="${DB_HOST}" \ --dbhost="${DB_HOST}" \
--dbname="${DB_NAME}" \ --dbname="${DB_NAME}" \
--dbuser="${DB_USER}" \ --dbuser="${DB_USER}" \
--dbpass="${DB_PSWD}" \ --dbpass="${DB_PSWD}" \
--path="${WP_DIR}" --allow-root --path="${WP_DIR}" --allow-root
else
echo -e ${GREEN}already configured !${RESET}
fi fi
# install wordpress : # 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 \ wp core install \
--url="${WP_URL}" \ --url="${WP_URL}" \
--title="${WP_TITLE}" \ --title="${WP_TITLE}" \
@@ -25,13 +48,21 @@ if ! wp core is-installed --path="${WP_DIR}"; then
--admin_password="${WP_ADMIN_PSWD}" \ --admin_password="${WP_ADMIN_PSWD}" \
--skip-email \ --skip-email \
--path="${WP_DIR}" --allow-root --path="${WP_DIR}" --allow-root
else
echo -e ${GREEN}already installed !${RESET}
fi fi
# create user : # 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 create \
"${WP_USER}" "${WP_USER_EMAIL}" \ "${WP_USER}" "${WP_USER_EMAIL}" \
--user_pass="${WP_USER_PSWD}" \ --user_pass="${WP_USER_PSWD}" \
--path="${WP_DIR}" --allow-root --path="${WP_DIR}" --allow-root
else
echo -e ${GREEN}already created !${RESET}
fi
# change owner and permissions to wp files # change owner and permissions to wp files
chown -R www-data:www-data /var/www/* chown -R www-data:www-data /var/www/*