-
Notifications
You must be signed in to change notification settings - Fork 2
/
install_wp.sh
84 lines (73 loc) · 2.68 KB
/
install_wp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /bin/bash
# Install WordPress
#
# Install WordPress, configure the database and harden file permissions
#
# @author Connor Bär
# @copyright Copyright (c) 2017 Connor Bär
# @link https://madebyconnor.co/
# @package wordpress-scripts
# @since 1.0.0
# @license MIT
# Get the directory of the currently executing script
DIR="$(dirname "${BASH_SOURCE[0]}")"
# Include files
INCLUDE_FILES=(
"common/defaults.sh"
".env.sh"
"common/common_env.sh"
"common/common_db.sh"
)
for INCLUDE_FILE in "${INCLUDE_FILES[@]}"
do
if [ -f "${DIR}/${INCLUDE_FILE}" ]
then
source "${DIR}/${INCLUDE_FILE}"
else
echo "File ${DIR}/${INCLUDE_FILE} is missing, aborting."
exit 1
fi
done
# The permissions for all files & directories in the WordPress install
GLOBAL_DIR_PERMS=755 # `-rwxr-xr-x`
GLOBAL_FILE_PERMS=644 # `-rw-r--r--`
# The permissions for files & directories that need to be writeable
WRITEABLE_DIR_PERMS=775 # `-rwxrwxr-x`
WRITEABLE_FILE_PERMS=664 # `-rw-rw-r--`
# Download WP Core.
echo "Download and installing WordPress..."
wp core download --path=${LOCAL_ROOT_PATH}
# Generate the wp-config.php file
wp core config --path=${LOCAL_ROOT_PATH} --dbname=${LOCAL_DB_NAME} --dbuser=${LOCAL_DB_USER} --dbpass=${LOCAL_DB_PASSWORD} --extra-php <<PHP
define('SP_REQUEST_URL', ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', SP_REQUEST_URL);
define('WP_HOME', SP_REQUEST_URL);
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', true);
define('WP_MEMORY_LIMIT', '256M');
PHP
# Install the WordPress database.
wp core install --path=${LOCAL_ROOT_PATH} --url=${LOCAL_SITE_URL} --title=${LOCAL_DB_NAME} --admin_user=connorbaer --admin_password=developer --admin_email=connor.baer@me.com
# Set project permissions
echo "Setting base permissions..."
chown -R ${LOCAL_CHOWN_USER}:${LOCAL_CHOWN_GROUP} "${LOCAL_ROOT_PATH}"
chmod -R ${GLOBAL_DIR_PERMS} "${LOCAL_ROOT_PATH}"
find "${LOCAL_ROOT_PATH}" -type d -exec chmod $GLOBAL_DIR_PERMS {} \;
find "${LOCAL_ROOT_PATH}" -type f ! -name "*.sh" -exec chmod $GLOBAL_FILE_PERMS {} \;
for DIR in ${LOCAL_ASSETS_DIRS[@]}
do
FULLPATH=${LOCAL_ROOT_PATH}${DIR}
if [ -d "${FULLPATH}" ]
then
echo "Fixing permissions for ${FULLPATH}"
chmod -R $WRITEABLE_DIR_PERMS "${FULLPATH}"
find "${FULLPATH}" -type f ! -name "*.sh" -exec chmod $WRITEABLE_FILE_PERMS {} \;
else
echo "Creating directory ${FULLPATH}"
mkdir "${FULLPATH}"
chmod -R $WRITEABLE_DIR_PERMS "${FULLPATH}"
fi
done
# Normal exit
exit 0