-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-init.sh
executable file
·308 lines (261 loc) · 5.98 KB
/
wp-init.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/bin/bash
# Script to automate the setup of a new WP project
# Author: Troy McGinnis
# Updated: August 21, 2015
# URL: troymcginnis.com
# Usage: wp_init.sh [-scrdbwtvoiz] project-name
# TODO: Automate setting up Sage Theme:
# - change Sage title
# - activate Sage
install_wp ()
{
printf "Installing WP...\n"
# Move into directory
cd $PROJECT
if $DEBUG
then
~/install-updated.sh
else
~/install-updated.sh &> /dev/null
if [ ! $? -eq 0 ]
then
printf '\nFailed to install WP!\n' ; exit 1;
fi
fi
}
wp_config ()
{
printf "Editing WP config...\n"
# Let's edit that wp-config file
perl -pi -e "s/database_name_here/${DB_NAME}_wp/g" wp-config.php
perl -pi -e "s/username_here/root/g" wp-config.php
perl -pi -e "s/password_here/root/g" wp-config.php
echo "define('WP_ENV', 'development');" >> wp-config.php
}
create_database()
{
printf "Create database...\n"
if $DEBUG
then
/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot -e "create database ${DB_NAME}_wp"
else
/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot -e "create database ${DB_NAME}_wp" &> /dev/null
fi
if [ $? -ne 0 ]
then
printf "\nFailed to create database. Chances are that the database exists.\n"
fi
}
sage_theme ()
{
printf "Installing Sage Theme...\n"
THEME_DIR=wp-content/themes/
FILE="master.zip"
EXTRACTED_DIR="sage-master"
if [ ! -d $THEME_DIR ]
then
echo "Directory does not exist."
exit
fi
cd $THEME_DIR
if $DEBUG
then
wget -P $TEMP_DIR https://github.com/roots/sage/archive/$FILE
else
wget -P $TEMP_DIR https://github.com/roots/sage/archive/$FILE &> /dev/null
fi
if [ $? -ne 0 ]
then
echo "ERROR: wget Failed!"
exit
fi
if [ ! -f ${TEMP_DIR}${FILE} ]
then
echo "ERROR: wget Failed! No file found."
exit
fi
if $DEBUG
then
unzip ${TEMP_DIR}${FILE}
else
unzip ${TEMP_DIR}${FILE} &> /dev/null
fi
mv $EXTRACTED_DIR $PROJECT
# Install and compile stuff
sage_install_compile
# Customizations
sage_customizations
# Clear
clear_tmp
}
sage_install_compile()
{
# Do some Sage specific stuff
cd $PROJECT
# Install Bower requirements
printf "Installing bower requirements...\n"
if $DEBUG
then
bower install
else
bower install &> /dev/null
fi
# Install npm requirements
printf "Installing npm requirements...\n"
if $DEBUG
then
npm install
else
npm install &> /dev/null
fi
# Try installing npm again incase it failed
printf "Double checking...\n"
if $DEBUG
then
npm install
else
npm install &> /dev/null
fi
# Compile all the gulp files
printf "Compile da files...\n"
if $DEBUG
then
gulp
else
gulp &> /dev/null
fi
}
sage_customizations()
{
# Change the manifest for BrowserSync (change this to what you use in your dev environment)
printf "Updating manifest.json...\n"
perl -pi -e "s/example.dev/localhost:8888/g" assets/manifest.json
# Change the manifest for BrowserSync (change this to what you use in your dev environment)
printf "Updating style.css...\n"
perl -pi -e "s/Sage Starter Theme/[${PROJECT_HUMAN}]/g" style.css
}
soil ()
{
FILE="master.zip"
if $DEBUG
then
wget -P $TEMP_DIR https://github.com/roots/soil/archive/$FILE
else
wget -P $TEMP_DIR https://github.com/roots/soil/archive/$FILE &> /dev/null
fi
cd ${WP_ROOT_DIR}/wp-content/plugins
if $DEBUG
then
unzip ${TEMP_DIR}${FILE}
else
unzip ${TEMP_DIR}${FILE} &> /dev/null
fi
clear_tmp
}
clear_tmp ()
{
rm -rf ${TEMP_DIR}/*
}
# Create Bit Bucket repo and init
create_bitbucket ()
{
printf "Creating Git repo...\n"
if $DEBUG
then
RESPONSE=$(bitbucket_init $PROJECT)
echo $RESPONSE
else
RESPONSE=$(bitbucket_init $PROJECT) &> /dev/null
if [ ! $? -eq 0 ]
then
printf '\nFailed to create Git repo!\n' ; exit 1;
fi
if echo "$RESPONSE" | grep -q '{"error":'
then
printf '\nFailed to create Git repo!\n' ; exit 1;
fi
fi
}
# ------ DO STUFF ------ #
source ~/.bash_profile
PROJECT=$2
PROJECT_HUMAN=$3
WP_ROOT_DIR=$(pwd)/${PROJECT}
DB_NAME=$(echo $PROJECT | tr - _)
TEMP_DIR="/tmp/sage-tmp/"
while getopts "scrdbwtvoiz" arg
do
case $arg in
r)
SAGE=true
;;
s)
SAGE=true
;;
v)
DEBUG=true
;;
d)
create_database
exit
;;
b)
create_bitbucket
exit
;;
w)
install_wp
exit
;;
c)
wp_config
exit
;;
t)
sage_theme
exit
;;
o)
soil
exit
;;
i)
sage_install_compile
exit
;;
z)
sage_customizations
exit
;;
esac
done
DB_NAME=$(echo $PROJECT | tr - _)
SAGE=${SAGE:-false}
DEBUG=${DEBUG:-false}
# Check for project name
if [ -z $PROJECT ]
then
echo "Please provide a project name."
exit
fi
# Check for project human name
if [ -z $PROJECT_HUMAN ]
then
PROJECT_HUMAN=$PROJECT
fi
# Feedback
printf "\nCreating new WP project for $PROJECT:\n\n"
# Create Bit Bucket
create_bitbucket
# Install latest version of WP
install_wp
# Edit wp-config
wp_config
# Create Database
create_database
# Install Roots Theme
if $SAGE
then
sage_theme
soil
fi