forked from jeremycastelli/Wordpress-new-project-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewproject.command
executable file
·324 lines (277 loc) · 7.56 KB
/
newproject.command
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/bin/sh
# Version = 1.3.2
#
# --------------------
# Load Variables
# --------------------
CURRENTDIRECTORY=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
source $CURRENTDIRECTORY/config.cfg
# --------------------
# Set directory
# --------------------
cd $DIRECTORY
# --------------------
# Set project name
# --------------------
echo "What is the project name ?"
read PROJECT_NAME
while [[ -z "$PROJECT_NAME" ]]; do
echo "Please, type your project name:"
read PROJECT_NAME
done
# --------------------
# Create database
# --------------------
echo "For local database configuration, I will use project name as database name, I just need table prefix (default : wp_)"
read TABLE_PREFIX
if [[ $TABLE_PREFIX == "" ]]; then
TABLE_PREFIX="wp_"
fi
$MYSQL_PATH -u$DB_USER -p$DB_PASSWORD -e "create database "$PROJECT_NAME
# --------------------
# Set FTP parmmeters for sublime SFTP mapping
# --------------------
echo "If you want to configure sFTP now, please enter FTP host. Type Q to skip sFTP configuration"
read FTP_HOST
if [[ $FTP_HOST =~ ^[Qq]$ ]]; then
FTP_HOST=''
fi
if [[ -n "$FTP_HOST" ]]; then
ABORT_SFTP=false
echo "FTP user ? (or Q to quit sFTP configuration)"
read FTP_USER
while [[ -z "$FTP_USER" ]]; do
echo "Please, type your FTP user (or Q to quit sFTP configuration):"
read FTP_USER
done
if [[ $FTP_USER =~ ^[Qq]$ ]]; then
ABORT_SFTP=true
fi
if [[ $ABORT_SFTP == false ]]; then
echo "FTP password ? (or Q to quit sFTP configuration)"
read FTP_PASS
while [[ -z "$FTP_PASS" ]]; do
echo "Please, type your FTP password (or Q to quit sFTP configuration):"
read FTP_PASS
done
fi
if [[ $FTP_PASS =~ ^[Qq]$ ]]; then
ABORT_SFTP=true
fi
if [[ $ABORT_SFTP == false ]]; then
echo "FTP remote path ? (or Q to quit sFTP configuration)"
read FTP_ROOT
while [[ -z "$FTP_ROOT" ]]; do
echo "Please, type your FTP remote path (or Q to quit sFTP configuration):"
read FTP_ROOT
done
fi
if [[ $FTP_ROOT =~ ^[Qq]$ ]]; then
ABORT_SFTP=true
fi
# If sFTP has been aborted, set $FTP_HOST to null
# so FTP files are not created
if [[ $ABORT_SFTP == true ]]; then
FTP_HOST=''
fi
fi
# --------------------
# Function
# Download unzip and remove
# --------------------
function fetch_zip()
{
curl -o file.zip $1
unzip -q file.zip
rm file.zip
}
# --------------------
# Create project directory
# --------------------
mkdir $PROJECT_NAME
PROJECT_DIR=$DIRECTORY"/"$PROJECT_NAME
cd $PROJECT_NAME
# --------------------
# Fetch Wordpress latest build
# --------------------
echo 'Download Wordpress...'
fetch_zip $WORDPRESS_URL
cp -R wordpress/* .
rm -rf wordpress && rm readme.html && rm license.txt
# --------------------
# Fetch H5BP server-config .htaccess
# --------------------
git clone https://github.com/h5bp/server-configs-apache.git
cp server-configs-apache/.htaccess .htaccess
rm -rf server-configs
# --------------------
# Fetch base theme & remove default themes
# --------------------
echo 'Remove default themes and fetch your starter theme'
cd wp-content/themes/
git clone $THEME_URL $PROJECT_NAME
rm -r twentyten
rm -r twentyeleven
rm -r twentytwelve
rm -r twentythirteen
rm -r twentyfourteen
# --------------------
# Remove Hello Dolly plugin and fetch plugins
# --------------------
echo 'Remove Hello Dolly and fetch your plugins'
cd ../plugins/
rm hello.php
for PLUGIN in ${PLUGINS_URL[@]}
do
fetch_zip $PLUGIN
done
# --------------------
# Create Wordpress wp-config.php
# --------------------
echo 'Create wp-config...'
cd $PROJECT_DIR
touch wp-config-local.php
echo "<?php
define( 'DB_NAME', '"$PROJECT_NAME"' );
define( 'DB_USER', '"$DB_USER"' );
define( 'DB_PASSWORD', '"$DB_PASSWORD"' );
define( 'DB_HOST', '"$DB_HOST"' );" >wp-config-local.php
touch db.txt
echo "if ( file_exists( dirname( __FILE__ ) . '/wp-config-local.php' ) ) {
include( dirname( __FILE__ ) . '/wp-config-local.php' );
} else {
define( 'DB_NAME', '' );
define( 'DB_USER', '' );
define( 'DB_PASSWORD', '' );
define( 'DB_HOST', '' ); // Probably 'localhost'
}" > db.txt
sed -e'
/DB_NAME/,/localhost/ c\
hello
' \
<wp-config-sample.php >wp-config-temp.php
sed '/hello/ {
r db.txt
d
}'<wp-config-temp.php >wp-config.php
mv wp-config.php wp-config-temp.php
curl -o salt.txt https://api.wordpress.org/secret-key/1.1/salt/
sed '/#@-/r salt.txt' <wp-config-temp.php >wp-config.php
mv wp-config.php wp-config-temp.php
sed "/#@+/,/#@-/d" <wp-config-temp.php >wp-config.php
mv wp-config.php wp-config-temp.php
sed s/wp_/$TABLE_PREFIX/ <wp-config-temp.php >wp-config.php
rm wp-config-temp.php
rm db.txt
rm salt.txt
# --------------------
# Create Sublime Project config file
# --------------------
echo 'Create Sublime text 2 project file...'
SUBLIME_PROJECT_FILE=$PROJECT_NAME".sublime-project"
touch $SUBLIME_PROJECT_FILE
echo '{
"folders":
[
{
"path": "./wp-content/themes/'$PROJECT_NAME'",
"name": "My theme",
"file_exclude_patterns":[
"._*"
],
"folder_exclude_patterns": [".sass-cache"]
},
{
"path": "./wp-content/plugins",
"file_exclude_patterns":[
"._*"
]
},
{
"path": ".",
"name": "All website",
"file_exclude_patterns":[
"._*",
"*.sublime-project",
"*.sublime-workspace"
],
"folder_exclude_patterns": [".sass-cache"]
}
]
}' > $SUBLIME_PROJECT_FILE
# --------------------
# Create sFTP config files
# --------------------
echo 'Create FTP files...'
function create_FTP_file()
{
touch sftp-config.json
echo '{
// The tab key will cycle through the settings when first created
// Visit http://wbond.net/sublime_packages/sftp/settings for help
// sftp, ftp or ftps
"type": "ftp",
"save_before_upload": true,
"upload_on_save": false,
"sync_down_on_open": false,
"sync_skip_deletes": false,
"confirm_downloads": false,
"confirm_sync": true,
"confirm_overwrite_newer": false,
"host": "'$FTP_HOST'",
"user": "'$FTP_USER'",
"password": "'$FTP_PASS'",
//"port": "22",
"remote_path": "'$1'",
"ignore_regexes": [
"\\\\.sublime-(project|workspace)", "sftp-config(-alt\\\\d?)?\\\\.json",
"sftp-settings\\\\.json", "/venv/", "\\\\.svn", "\\\\.hg", "\\\\.git",
"\\\\.bzr", "_darcs", "CVS", "\\\\.DS_Store", "Thumbs\\\\.db", "desktop\\\\.ini","wp-config-local.php"
],
//"file_permissions": "664",
//"dir_permissions": "775",
//"extra_list_connections": 0,
"connect_timeout": 30,
//"keepalive": 120,
//"FTP_PASSive_mode": true,
//"ssh_key_file": "~/.ssh/id_rsa",
//"sftp_flags": ["-F", "/path/to/ssh_config"],
//"preserve_modification_times": false,
//"remote_time_offset_in_hours": 0,
//"remote_encoding": "utf-8",
//"remote_locale": "C",
}' > sftp-config.json
}
if [[ $FTP_HOST != "" ]]; then
create_FTP_file $FTP_ROOT
cd "wp-content/themes/"$PROJECT_NAME
create_FTP_file $FTP_ROOT"/wp-content/themes/"$PROJECT_NAME
cd ../../plugins
create_FTP_file $FTP_ROOT"/wp-content/plugins"
fi
# --------------------
# Launch sublime project
# --------------------
echo 'Launch Sublime text 2'
cd $PROJECT_DIR
"$SUBLIME_PATH" $SUBLIME_PROJECT_FILE
# --------------------
# Create a new project in CodeKit
# --------------------
echo 'Create codekit project'
open -a /Applications/CodeKit.app $PROJECT_DIR"/wp-content/themes/"$PROJECT_NAME
# --------------------
# git init
# --------------------
echo 'git init'
git init
echo ".DS_Store
wp-config-local.php
.sass-cache" > .gitignore
# --------------------
# Launch default browser
# --------------------
echo 'Launch browser'
open $LOCAL_URL$PROJECT_NAME
echo 'Installation Complete, press enter to quit'
read