-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-install.sh
236 lines (182 loc) · 6.11 KB
/
wp-install.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
#!/bin/bash
showHelp() {
# `cat << EOF` This means that cat should stop reading when EOF is detected
cat << EOF
Usage: ./wp-install [-hdi]
Easy installation of WordPress via the console directly on the server.
-h, --help Display help
-d, --del Deletes the WordPress installation (without any warning)
-i, --interactive Asks interactive your environment for the WordPress installation
EOF
# EOF is found above and hence cat command stops reading. This is equivalent to echo but much neater when printing out.
}
###
### Check for wp cli
###
wp cli version 1>/dev/null
if [ $? -ne 0 ]; then
echo "Unfortunately, the WP-CLI is not available, so I have to abort."
exit 1
fi
###
### Check for package aaemnnosttv/wp-cli-dotenv-command
###
wp cli has-command "dotenv" 2>/dev/null
if [ $? -ne 0 ]; then
wp package install aaemnnosttv/wp-cli-dotenv-command
# plan b in case the memory runs out
if [ $? -ne 0 ]; then
php -d memory_limit=512M "$(which wp)" package install aaemnnosttv/wp-cli-dotenv-command
fi
fi
no_htaccess=false
self_destruct=false
###
### What work is waiting for me?
###
# $@ is all command line parameters passed to the script.
# -o is for short options like -v
# -l is for long options with double dash like --version
# the comma separates different long options
# -a is for long options with single dash like -version
options=$(getopt -l "help,del,delete,interactive,no-htaccess,self-destruct,sd" -o "hdi" -a -- "$@")
# set --:
# If no arguments follow this option, then the positional parameters are unset. Otherwise, the positional parameters
# are set to the arguments, even if some of them begin with a ‘-’.
eval set -- "$options"
while true
do
case $1 in
-h | --help)
showHelp
exit 0;;
-d | --del | --delete)
if [ -f '../wp-cron.php' ]; then
echo "The WordPress installation will be deleted..."
wp db clean --yes
rm -f -d -r ../wp-admin
rm -f -d -r ../wp-content
rm -f -d -r ../wp-includes
rm ../*
rm ../.htaccess
else
echo "There is nothing to delete!"
fi
exit;;
-i | --interactive)
wp dotenv init --template=.env.wordpress --interactive
break;;
--no-htaccess)
no_htaccess=true
break;;
--sd | --self-destruct)
self_destruct=true
break;;
--)
shift
break;;
esac
shift
done
if [ -f '../wp-cron.php' ]; then
echo "WordPress files seem to already be present here, so I have to abort."
exit 1
fi
if ! [ -f './.env.wordpress' ]; then
echo "The information for the WordPress installation is missing. Therefore the query starts now..."
wp dotenv init --template=.env.wordpress --interactive
fi
wp_locale=$(wp dotenv get wp_locale)
wp_version=$(wp dotenv get wp_version)
wp_dbname=$(wp dotenv get wp_dbname)
wp_dbuser=$(wp dotenv get wp_dbuser)
wp_dbpass=$(wp dotenv get wp_dbpass)
wp_dbhost=$(wp dotenv get wp_dbhost)
wp_dbprefix=$(wp dotenv get wp_dbprefix)
wp_url=$(wp dotenv get wp_url)
wp_title=$(wp dotenv get wp_title)
wp_admin_user=$(wp dotenv get wp_admin_user)
wp_admin_email=$(wp dotenv get wp_admin_email)
wp_memory_limit=$(wp dotenv get wp_memory_limit)
wp_environment=$(wp dotenv get wp_environment)
wp_blogdescription=$(wp dotenv get wp_blogdescription)
wp_plugin_install=$(wp dotenv get wp_plugin_install)
wp_theme_install=$(wp dotenv get wp_theme_install)
wp_theme_delete=$(wp dotenv get wp_theme_delete)
## change directory to the doc-root
cd ..
## download and install wordpress
wp core download --locale=$wp_locale --version=$wp_version
wp config create --dbname=$wp_dbname --dbuser=$wp_dbuser --dbpass=$wp_dbpass --dbhost=$wp_dbhost --dbprefix=$wp_dbprefix
if [ $? -ne 0 ]; then
echo "I guess there was a download error. That's why we're stopping here..."
exit 1
fi
wp core install --url=$wp_url --title="$wp_title" --admin_user=$wp_admin_user --admin_email=$wp_admin_email
## empties a site of its content (posts, comments, terms, and meta)
wp site empty --uploads --yes
## delete all default plugins
wp plugin delete --all
## get new salts for your wp-config.php file
wp config shuffle-salts
## more ram
wp config set WP_MEMORY_LIMIT $wp_memory_limit
wp config set WP_MAX_MEMORY_LIMIT $wp_memory_limit
## set the environment type
wp config set WP_ENVIRONMENT_TYPE $wp_environment
wp config set WP_ENV $wp_environment
## Automatic Database Optimizing
wp config set WP_ALLOW_REPAIR false --raw
## HTTPS for all
wp config set FORCE_SSL_LOGIN true --raw
wp config set FORCE_SSL_ADMIN true --raw
## Performance
wp config set WP_CACHE false --raw
wp config set COMPRESS_CSS false --raw
wp config set COMPRESS_SCRIPTS false --raw
wp config set CONCATENATE_SCRIPTS false --raw
wp config set ENFORCE_GZIP true --raw
## Content
wp config set AUTOSAVE_INTERVAL 30
wp config set WP_POST_REVISIONS 5
wp config set MEDIA_TRASH true --raw
wp config set EMPTY_TRASH_DAYS 7
## File edition
wp config set DISALLOW_FILE_MODS false --raw
wp config set DISALLOW_FILE_EDIT true --raw
wp config set IMAGE_EDIT_OVERWRITE true --raw
## Debug
wp config set WP_DEBUG false --raw
wp config set WP_DEBUG_DISPLAY true --raw
wp config set WP_DEBUG_LOG true --raw
wp config set SCRIPT_DEBUG false --raw
wp config set SAVEQUERIES false --raw
## change permalinks
wp rewrite structure '/%postname%/'
## delete the default blogdescription
wp option update blogdescription "$wp_blogdescription"
## hide for the search engines
wp option update blog_public 0
## disable the avatars
wp option update show_avatars 0
## install and activate plugins
wp plugin install $wp_plugin_install --activate
## after installing all plugins, update the language
wp language plugin install --all $wp_locale
## install and activate theme
wp theme install $wp_theme_install
wp theme activate $wp_theme_install
wp theme delete $wp_theme_delete
## Removes all widgets from the sidebar and places them in Inactive Widgets.
wp widget reset --all
## htaccess
## https://gist.github.com/seoagentur-hamburg/c96bc796764baaa64d43b70731013f8a
## Andreas Hecht
if ! $no_htaccess; then
git clone https://gist.github.com/c96bc796764baaa64d43b70731013f8a.git
mv ./c96bc796764baaa64d43b70731013f8a/.htaccess .htaccess
rm -f -d -r ./c96bc796764baaa64d43b70731013f8a/
fi
if $self_destruct; then
rm -f -d -r .wp-install/
fi