-
Notifications
You must be signed in to change notification settings - Fork 11
/
wordpress.sh
executable file
·248 lines (206 loc) · 7.34 KB
/
wordpress.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
#!/bin/bash -e
#
# WordPress Installer
# ------------------
# This script installs the latest version of WordPress as well as various useful plugins and a boilerplate theme.
#
# To use this script, go to the directory you want to install Wordpress to and run this command:
#
# curl -O https://raw.githubusercontent.com/jasewarner/wordpress-installer/master/wordpress.sh
#
# Run the script with: sh ./wordpress.sh
#
#
# Output colours
# ------------------
#
GREEN='\033[0;32m'
NC='\033[0m' # No Color
#
# Install WordPress
# ------------------
#
clear
echo "${GREEN}"
echo "+---------------------+"
echo "| WordPress Installer |"
echo "+---------------------+"
echo "${NC}"
read -r -p $'\e[34mDatabase Name: \e[0m' dbname
read -r -p $'\e[34mDatabase Username: \e[0m' dbuser
read -r -s -p $'\e[34mDatabase Password: \e[0m' dbpass; echo
stty echo
read -r -p $'\e[34mDatabase Hostname: \e[0m' dbhost
read -r -p $'\e[34mTheme name (e.g. My WP Theme): \e[0m' theme_name
read -r -p $'\e[34mTheme author: \e[0m' theme_author
read -r -p $'\e[34mTheme author URI: \e[0m' theme_author_uri
read -r -p $'\e[34mTheme description: \e[0m' theme_description
read -r -p $'\e[34mRun install? (Y/n) \e[0m' run
if [ "$run" == n ] ; then
exit
else
printf '\n'
echo "Downloading the latest version of Wordpress... "
curl --remote-name --silent --show-error https://wordpress.org/latest.tar.gz
echo "${GREEN}Done! ✅${NC}"
printf '\n'
echo "Decompressing the file... "
tar --extract --gzip --file latest.tar.gz
rm latest.tar.gz
echo "${GREEN}Done! ✅${NC}"
printf '\n'
echo "Putting the files in place... "
cp -R -f wordpress/* .
rm -R wordpress
echo "${GREEN}Done! ✅${NC}"
printf '\n'
echo "Configuring WordPress... "
cp wp-config-sample.php wp-config.php
sed -i "" "s/database_name_here/$dbname/g" wp-config.php
sed -i "" "s/username_here/$dbuser/g" wp-config.php
sed -i "" "s/password_here/$dbpass/g" wp-config.php
sed -i "" "s/localhost/$dbhost/g" wp-config.php
# Set authentication unique keys and salts in wp-config.php
perl -i -pe '
BEGIN {
@chars = ("a" .. "z", "A" .. "Z", 0 .. 9);
push @chars, split //, "!@#$%^&*()-_ []{}<>~\`+=,.;:/?|";
sub salt { join "", map $chars[ rand @chars ], 1 .. 64 }
}
s/put your unique phrase here/salt()/ge
' wp-config.php
echo "${GREEN}Done! ✅${NC}"
printf '\n'
echo "Applying folder and file permissions... "
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
echo "${GREEN}Done! ✅${NC}"
printf '\n'
#
# Install plugins
# ------------------
#
# ACF
echo "Fetching Advanced Custom Fields plugin...";
wget --quiet https://downloads.wordpress.org/plugin/advanced-custom-fields.zip;
unzip -q advanced-custom-fields.zip;
mv advanced-custom-fields/ wp-content/plugins/
echo "${GREEN}Done! ✅${NC}"
printf '\n'
# ACF for Yoast SEO
echo "Fetching ACF Content Analysis for Yoast SEO plugin...";
wget --quiet https://downloads.wordpress.org/plugin/acf-content-analysis-for-yoast-seo.zip;
unzip -q acf-content-analysis-for-yoast-seo.zip;
mv acf-content-analysis-for-yoast-seo/ wp-content/plugins/
echo "${GREEN}Done! ✅${NC}"
printf '\n'
# Wordfence Security
echo "Fetching Wordfence Security plugin...";
wget --quiet https://downloads.wordpress.org/plugin/wordfence.zip;
unzip -q wordfence.zip;
mv wordfence/ wp-content/plugins/
echo "${GREEN}Done! ✅${NC}"
printf '\n'
# WordPress SEO a.k.a. Yoast
echo "Fetching WordPress SEO (a.k.a. Yoast) plugin...";
wget --quiet https://downloads.wordpress.org/plugin/wordpress-seo.zip;
unzip -q wordpress-seo.zip;
mv wordpress-seo/ wp-content/plugins/
echo "${GREEN}Done! ✅${NC}"
printf '\n'
#
# Remove default WP plugins
# ------------------
#
echo "Removing default WordPress plugins..."
rm -rf wp-content/plugins/akismet
rm -rf wp-content/plugins/hello.php
echo "${GREEN}Done! ✅${NC}"
printf '\n'
#
# Remove older WordPress default themes
# ------------------
#
echo "Removing default WordPress themes..."
rm -rf wp-content/themes/twentyfifteen
rm -rf wp-content/themes/twentysixteen
rm -rf wp-content/themes/twentyseventeen
rm -rf wp-content/themes/twentynineteen
rm -rf wp-content/themes/twentytwenty
rm -rf wp-content/themes/twentytwentyone
rm -rf wp-content/themes/twentytwentytwo
rm -rf wp-content/themes/twentytwentythree
echo "${GREEN}Done! ✅${NC}"
printf '\n'
#
# Install boilerplate theme (packaged with Gulp.js)
#
# https://github.com/jasewarner/gulp-wordpress
# ------------------
#
theme_slug=$(echo "${theme_name}" | sed -e 's/[^[:alnum:]]/-/g' \
| tr -s '-' | tr '[:upper:]' '[:lower:]')
echo "Downloading boilerplate theme packaged with Gulp.js..."
curl -LOk --silent https://github.com/jasewarner/gulp-wordpress/archive/master.zip
echo "${GREEN}Done! ✅${NC}"
printf '\n'
echo "Decompressing the zip file and moving it to the correct location..."
unzip -q master.zip
mv gulp-wordpress-master/ wp-content/themes/"${theme_slug}"
echo "${GREEN}Done! ✅${NC}"
printf '\n'
echo "Updating the theme details..."
# remove theme git files
rm wp-content/themes/"${theme_slug}"/.gitignore
# style.css
sed -i "" "s?<Theme_Name>?$theme_name?g" wp-content/themes/"${theme_slug}"/style.css
sed -i "" "s?<Theme_Author>?$theme_author?g" wp-content/themes/"${theme_slug}"/style.css
sed -i "" "s?<Theme_Author_URI>?$theme_author_uri?g" wp-content/themes/"${theme_slug}"/style.css
sed -i "" "s?<Theme_Description>?$theme_description?g" wp-content/themes/"${theme_slug}"/style.css
sed -i "" "s?<Theme_Text_Domain>?$theme_slug?g" wp-content/themes/"${theme_slug}"/style.css
# gulp.js
sed -i "" "s?package-name?$theme_slug?g" wp-content/themes/"${theme_slug}"/assets/package.json
sed -i "" "s?package-description?$theme_description?g" wp-content/themes/"${theme_slug}"/assets/package.json
sed -i "" "s?author-name?$theme_author?g" wp-content/themes/"${theme_slug}"/assets/package.json
# wp script handle
sed -i "" "s?theme-name?$theme_slug?g" wp-content/themes/"${theme_slug}"/functions/func-script.php
# wp style handle
sed -i "" "s?theme-name?$theme_slug?g" wp-content/themes/"${theme_slug}"/functions/func-style.php
# php theme files
sed -i "" "s?<Author>?$theme_author?g" wp-content/themes/"${theme_slug}"/*.php
sed -i "" "s?<Package>?$theme_slug?g" wp-content/themes/"${theme_slug}"/*.php
sed -i "" "s?<Author>?$theme_author?g" wp-content/themes/"${theme_slug}"/functions/*.php
sed -i "" "s?<Package>?$theme_slug?g" wp-content/themes/"${theme_slug}"/functions/*.php
# add author admin credit to backend
sed -i "" "s?http://author.com?$theme_author_uri?g" wp-content/themes/"${theme_slug}"/functions/func-admin.php
sed -i "" "s?Author Name?$theme_author?g" wp-content/themes/"${theme_slug}"/functions/func-admin.php
echo "${GREEN}Done! ✅${NC}"
printf '\n'
#
# Tidy up
# ------------------
#
# The final few steps
echo "And now the final few steps:"
# Cleanup
printf '\n'
echo "Cleaning up temporary files and directories...";
rm -- *.zip
# Remove installation script file
rm -rf wordpress.sh;
# Disable the built-in file editor
echo "Disabling the file editor...";
echo "
/** Disable the file editor */
define( 'DISALLOW_FILE_EDIT', true );" >> wp-config.php
# Define the default theme
echo "Defining the default theme...";
echo "
/** Define the default theme */
define( 'WP_DEFAULT_THEME', '${theme_slug}' );" >> wp-config.php
# Remove wp-config-sample.php
echo "Removing wp-config-sample.php..."
rm -rf wp-config-sample.php
printf '\n'
echo "${GREEN}Fantastisch! All done 🙌${NC}";
fi