-
Notifications
You must be signed in to change notification settings - Fork 3
/
inst_wp_with_wp-cli_auto.sh
212 lines (153 loc) · 4.92 KB
/
inst_wp_with_wp-cli_auto.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
# Description:
# WordPress installation script using wp-cli.
#
# wp-cli: http://wp-cli.org/
#
# Warning:
# This script is for developing WordPress themes and/or plugins on your LOCAL machine.
# So, when you use this script on a remote server, please revise the script as you need.
#
# Version: 0.1.1
#
# License:
# Released under the GPL license
# http://www.gnu.org/copyleft/gpl.html
#
# Copyright 2013 (email : tekapo@gmail.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# Default parameters you may need to change.
# WEB_SERVER_PROCESS_NAME='httpd'
# MYSQL_PROCESS_NAME='mysqld'
DOCUMENT_ROOT='/var/www' # Anyone knows how to get the document root by any shell command?
WP_LOCALE='ja'
DBUSER='root'
DBPASSWORD='root'
DOMAIN='localhost'
WP_URL=''
WP_TITLE=''
WP_ADMIN_NAME='admin'
WP_ADMIN_PASSWORD='admin'
WP_ADMIN_EMAIL='admin@example.com'
WP_ADDITIONAL_USER_NAME='test1'
WP_ADDITIONAL_USER_PASSWORD='test1'
WP_ADDITIONAL_USER_EMAIL='test1@example.com'
# Set some other default parameters.
SELF_DIR=`dirname $0`
CURRENT_DATE=`date '+%Y%m%d'`
CURRENT_TIME=`date '+%H%M%S'`
CURRENT_DATE_TIME="${CURRENT_DATE}_${CURRENT_TIME}"
DBNAME="wp_test_${CURRENT_DATE_TIME}"
WP_INSATALL_DIR="wp_${CURRENT_DATE_TIME}"
WP_INSTALL_FULL_PATH="${DOCUMENT_ROOT}/${WP_INSATALL_DIR}"
PLUGINS_LIST='plugins-list.txt'
THEMES_LIST='themes-list.txt'
PLUGINS_LIST_FULL_PATH="${SELF_DIR}/${PLUGINS_LIST}"
THEMES_LIST_FULL_PATH="${SELF_DIR}/${THEMES_LIST}"
# Show the warning
cat << HEREDOC
WARNING:
This script is for developing WordPress themes and/or plugins on your LOCAL machine.
So, when you use this script on a remote server, please revise the script as you need.
HEREDOC
# Check if the wp-cli command is installed or not
if ! type "wp" > /dev/null
then
echo 'wp-cli is not installed. Please see wp-cli.org for further information about the installing.'
exit
fi
# Check if the web server is running.
# Ah, the process name may be the one for nginx, so commented out this section.
# if ! ps ax | grep -v grep | grep $WEB_SERVER_PROCESS_NAME > /dev/null
# then
# echo "$WEB_SERVER_PROCESS_NAME service not running. You may check the status."
# exit
# fi
# TODO: Check if MySQL is running.
# if ! ps ax | grep -v grep | grep $MYSQL_PROCESS_NAME > /dev/null
# then
# echo "$MYSQL_PROCESS_NAME service not running. You may check the status."
# exit
# fi
# TODO: Show the parameters, and press Y to go, N to exit.
# echo "Current date and time: ${CURRENT_DATE_TIME}"
# echo "Making directory based on the current date and time as follows: ${WP_INSTALL_FULL_PATH}"
#if [N]
# then
# exit
#fi
# Start installing.
# Making the directory for the WordPress installation.
mkdir ${WP_INSTALL_FULL_PATH}
# Downloading the latest WordPress.
echo "Downloading the latest WordPress to: ${WP_INSTALL_FULL_PATH}"
wp core download \
--locale=${WP_LOCALE} \
--path=${WP_INSTALL_FULL_PATH}
# cd to the WordPress root directory just installed.
cd ${WP_INSTALL_FULL_PATH}
# Create wp-config.php.
wp core config \
--dbname=${DBNAME} \
--dbuser=${DBUSER} \
--dbpass=${DBPASSWORD}
# Create a database.
# TODO: If it doesn't work, show the error message and exit
wp db create
# Install WordPress
if ["${WP_URL}" = '']
then
WP_URL="${DOMAIN}/${WP_INSATALL_DIR}"
fi
if ["${WP_TITLE}" = '']
then
WP_TITLE="wp_test_${CURRENT_DATE_TIME}"
fi
wp core install \
--url=${WP_URL} \
--title=${WP_TITLE} \
--admin_name=${WP_ADMIN_NAME} \
--admin_password=${WP_ADMIN_PASSWORD} \
--admin_email=${WP_ADMIN_EMAIL}
# Install and activate plugins.
if [ -e "${PLUGINS_LIST_FULL_PATH}" ]
then
for PLUGIN in $(cat ${PLUGINS_LIST_FULL_PATH})
do
wp plugin install ${PLUGIN} --activate
done
fi
# Install themes
# TODO: activate one of them.
if [ -e "${THEMES_LIST_FULL_PATH}" ]
then
for THEME in $(cat ${THEMES_LIST_FULL_PATH})
do
wp theme install ${THEME}
done
fi
# TODO: Add other users.
# while read USERS
# do
wp user create ${WP_ADDITIONAL_USER_NAME} ${WP_ADDITIONAL_USER_EMAIL} ${WP_ADDITIONAL_USER_PASSWORD}
# done <${WP_ADDITIONAL_USERS_LSIT}
# TODO: Set the settings like the permalink structure and so on.
# TODO: Show the install results.
cat << HEREDOC
WordPress is installed as below:
Now you can open http://${WP_URL}
HEREDOC
cd