added protections when installing wp
This commit is contained in:
9
Makefile
9
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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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/*
|
||||
|
||||
Reference in New Issue
Block a user