-
Notifications
You must be signed in to change notification settings - Fork 4
/
wp.sh
296 lines (245 loc) · 8.46 KB
/
wp.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
#! /usr/bin/env bash
#sudo
if [[ "$(whoami)" = "root" ]] && [[ "$(command -v sudo)" = "" ]]; then
echo "performing update -> -> -> -> ->"
apt update
echo "installing sudo -> -> -> -> ->"
apt install sudo -y
elif [[ "$(whoami)" = "root" ]] && [[ "$(command -v sudo)" != "" ]]; then
echo "sudo is already installed"
apt update
else
echo "you are not root"
sudo apt update
fi
#wget
if [ "$(command -v wget)" != "" ]; then
echo "wget installed"
else
sudo apt install wget -y
fi
echo "
## ##### ## #### # # ######
# # # # # # # # # # #
# # # # # # # ###### #####
###### ##### ###### # # # #
# # # # # # # # # #
# # # # # #### # # ######
"
#apache remove
if [ "$(command -v apache2)" != "" ]; then
echo "apache found and removing"
sudo apt purge apache2 -y
sudo apt autoremove -y
else
echo "Everything is good for apache"
fi
#ppa apache
if [[ "$(grep -iR ondrej/apache2 /etc/apt)" = "" ]]; then
echo "Checking apache2 PPA status"
echo " PPA missing so adding it"
sudo apt install software-properties-common dirmngr apt-utils wget gnupg2 ca-certificates curl apt-transport-https -y
sudo add-apt-repository ppa:ondrej/apache2 -y
sudo apt update
elif [[ "$(grep -iR ondrej/apache2 /etc/apt)" != "" ]]; then
echo "PPA already added"
sudo apt update
else
echo "Aborted"
fi
#apache install
if [ "$(command -v apache2)" = "" ] && [[ "$(grep -iR ondrej/apache2 /etc/apt)" != "" ]]; then
echo "Installing Apache"
sudo apt install apache2 -y
else
echo "Aborted"
fi
echo "
##### # # #####
# # # # # #
# # ###### # #
##### # # #####
# # # #
# # # #
"
#php remove
if [ "$(command -v php)" != "" ] && [ "$(command -v apache2)" != "" ]; then
echo "php found and removing"
sudo apt purge php* -y
sudo apt autoremove -y
else
echo "Everything is good again"
fi
#ppa php
if [[ "$(grep -iR ondrej/php /etc/apt)" = "" ]] && [ "$(command -v apache2)" != "" ]; then
echo "Checking php PPA status"
echo " PPA missing so adding it"
sudo apt install software-properties-common dirmngr apt-transport-https -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
elif [[ "$(grep -iR ondrej/php /etc/apt)" != "" ]]; then
echo "PPA already added"
sudo apt update
else
echo "Aborted"
fi
#php 8 install
if [ "$(command -v php)" = "" ] && [ "$(command -v apache2)" != "" ]; then
echo "Installing PHP 8"
sudo apt install php8.0 php8.0-cli php8.0-common php8.0-curl php8.0-gd php8.0-intl php8.0-mbstring php8.0-mysql php8.0-imagick php8.0-opcache php8.0-readline php8.0-xml php8.0-xsl php8.0-zip php8.0-bz2 php8.0-bcmath libapache2-mod-php8.0 -y
else
echo "Aborted"
fi
echo "
###### ######
# # ## ##### # ## # # # #
## ## # # # # # # # # # # #
# ## # # # # # # # # # # ######
# # ###### ##### # ###### # # # #
# # # # # # # # # # # # #
# # # # # # # # # ###### ######
"
#mariadb remove
if [ "$(command -v mariadb)" != "" ] && [ "$(command -v apache2)" != "" ] && [ "$(command -v php)" != "" ]; then
echo "mariaDB found and removing"
sudo apt purge mariadb-* -y
sudo apt autoremove -y
else
echo "Everything is good for mariadb"
fi
#ppa mariaDB
if [[ "$(grep -iR https://dlm.mariadb.com /etc/apt/)" = "" ]] && [ "$(command -v mariadb)" = "" ] && [ "$(command -v apache2)" != "" ] && [ "$(command -v php)" != "" ]; then
echo "Checking MariaDB PPA status"
echo " PPA missing so adding it"
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod +x mariadb_repo_setup
sudo ./mariadb_repo_setup
sudo apt update
sudo apt upgrade -y
elif [[ "$(grep -iR https://dlm.mariadb.com /etc/apt/)" != "" ]]; then
echo "MariaDB PPA already added"
sudo apt update
else
echo "Aborted"
fi
#mariadb install
if [ "$(command -v mariadb)" = "" ] && [[ "$(grep -iR https://dlm.mariadb.com /etc/apt/)" != "" ]] && [ "$(command -v apache2)" != "" ] && [ "$(command -v php)" != "" ]; then
echo "Installing MariaDB"
sudo apt update
sudo apt install mariadb-server mariadb-client mariadb-backup -y
echo "
## ##### ##### ###### # # ##### # #### # #
# # # # # ## # # # # # ## #
# # # # ##### # # # # # # # # # #
###### # # # # # # # # # # # # #
# # # # # # ## # # # # # ##
# # # # ###### # # # # #### # #
"
echo "-> -> -> You must have to set root password now for securing mariadb"
echo "-> -> -> Make sure to enable Switch to unix_socket authentication"
sleep 2
sudo mysql_secure_installation
else
echo "Aborted"
fi
echo "
# # #### ##### ##### ##### ##### ###### #### ####
# # # # # # # # # # # # # # #
# # # # # # # # # # # # ##### #### ####
# ## # # # ##### # # ##### ##### # # #
## ## # # # # # # # # # # # # # #
# # #### # # ##### # # # ###### #### ####
"
#wordpress part
FILE=/var/www/html/index.html
if [[ -f "$FILE" ]] && [ "$(command -v apache2)" != "" ] && [ "$(command -v php)" != "" ] && [ "$(command -v mariadb)" != "" ]; then
echo "$FILE exists."
sudo rm /var/www/html/index.html
echo "Removed"
else
echo "$FILE not exists."
fi
#cleaning
if [[ -d /var/www/html ]] && [ "$(command -v apache2)" != "" ] && [ "$(command -v php)" != "" ] && [ "$(command -v mariadb)" != "" ]; then
echo "var/www/html exists"
DIR="/var/www/html"
if [ "$(ls -A "$DIR")" ] && [ "$(command -v apache2)" != "" ] && [ "$(command -v php)" != "" ] && [ "$(command -v mariadb)" != "" ]; then
echo "$DIR contains files"
read -r -p "Do you want to delete every files in apache root directory (var/www/html)? [y/n] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]] || [[ "$response" = "" ]]; then
sudo rm -r /var/www/html/*
echo "Ok, deleted"
fi
else
echo "$DIR is empty"
fi
else
echo "var/www/html doesn't exist"
fi
#downloading and setting wp
FILE=/var/www/html
if [[ -d "$FILE" ]] && [ "$(command -v apache2)" != "" ] && [ "$(command -v php)" != "" ] && [ "$(command -v mariadb)" != "" ]; then
echo "$FILE found."
echo "Installing WordPress"
sleep 1
sudo wget -P /var/www/html https://wordpress.org/latest.tar.gz
echo "downloading wordpress archive to apache directory"
echo "extracting wordpress"
sudo tar -zvxf /var/www/html/latest.tar.gz -C /var/www/html
echo "the archive has a folder named wordpress"
sudo mv /var/www/html/wordpress/* /var/www/html
echo "moving wp files to apache root directory from wordpress folder"
sudo rm /var/www/html/latest.tar.gz
echo "deleting the archive"
sudo rmdir /var/www/html/wordpress
echo "deleting the folder named wordpress"
echo "Done...."
echo "Setting permission"
sudo find /var/www/html -type d -exec chmod 750 {} \;
sudo find /var/www/html -type f -exec chmod 640 {} \;
sudo systemctl restart apache2
sudo adduser "$USER" www-data
sudo chown -R www-data:www-data /var/www/html
sudo chmod u=rwX,g=srX,o=rX -R /var/www/html
else
echo "$FILE not exists, so wp installaion aborted"
fi
echo "
# # ###### # #
# # # # #
# # ##### # #
# # # # ## #
# # # ## ##
#### # # #
"
#ufw
if [ "$(command -v ufw)" != "" ] && [ "$(command -v apache2)" != "" ] && [ "$(command -v php)" != "" ] && [ "$(command -v mariadb)" != "" ]; then
echo "ufw installed"
echo "updating ufw rules"
sudo ufw enable
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo systemctl reload apache2
elif [ "$(command -v ufw)" = "" ] && [ "$(command -v apache2)" != "" ] && [ "$(command -v php)" != "" ] && [ "$(command -v mariadb)" != "" ]; then
echo "installing ufw"
echo "updating ufw rules"
sudo apt install ufw -y
sudo ufw enable
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo systemctl reload apache2
else
echo "ufw installation aborted"
fi
#script remove
FILE=~/wp.sh
if [[ -f "$FILE" ]]; then
echo "$FILE exists"
sudo rm ~/wp.sh
echo "$FILE is cleaned"
else
echo "$FILE not found"
fi
exit