-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWordPress_Install.sh
executable file
·185 lines (149 loc) · 5.6 KB
/
WordPress_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
#!/bin/bash
#
# Install WordPress on a Ubuntu 13+ VPS
#
# run as root
if [[ $UID != 0 ]]; then
echo "Please run this script with sudo:"
echo "sudo $0 $*"
exit 1
fi
# set colors
green=`tput setaf 2`
red=`tput setaf 1`
normal=`tput sgr0`
bold=`tput bold`
# start
echo "${normal}${bold}UBUNTU SITE INSTALLER${normal}"
read -p "Installer adds site files to /var/www, are you ready (y/n)? "
[ "$(echo $REPLY | tr [:upper:] [:lower:])" == "y" ] || exit
# Install WP
read -p "Install WordPress (y/n)? " wpFiles
if [ $wpFiles == "y" ]; then
read -p "Database name: " dbname
read -p "Database username: " dbuser
# If you are going to use root ask about it
if [ $dbuser == 'root' ]; then
read -p "${red}root is not recommended. Use it (y/n)?${normal} " useroot
if [ $useroot == 'n' ]; then
read -p "Database username: " dbuser
fi
else
useroot='n'
fi
read -s -p "Enter a password for user $dbuser: " userpass
echo " "
# Create MySQL database
read -p "Add MySQL DB user and tables (y/n)? " dbadd
if [ $dbadd == "y" ]; then
read -s -p "Enter your MySQL root password: " rootpass
echo " "
if [ ! -d /var/lib/mysql/$dbname ]; then
echo "CREATE DATABASE $dbname;" | mysql -u root -p$rootpass
if [ -d /var/lib/mysql/$dbname ]; then
echo "${green}New MySQL database ($dbname) was successfully created${normal}"
else
echo "${red}New MySQL database ($dbname) faild to be created${normal}"
fi
else
echo "${red}Your MySQL database ($dbname) already exists${normal}"
fi
# if [ $useroot == 'y' ]; then
# echo "${red}You're using root as DB user. ${normal}"
# else
# # TODO: check if user exists
# echo "CREATE USER '$dbuser'@'localhost' IDENTIFIED BY '$userpass';" | mysql -u root -p$rootpass
# echo "GRANT ALL PRIVILEGES ON $dbname.* TO '$dbuser'@'localhost';" | mysql -u root -p$rootpass
# echo "FLUSH PRIVILEGES;" | mysql -u root -p$rootpass
# echo "${green}New MySQL user ($dbuser) was successfully created${normal}"
# fi
# fork of https://drupal.org/node/1681250
echo "Checking whether the $dbuser exists and has privileges"
user_exists=`mysql -u root -p$rootpass -e "SELECT user FROM mysql.user WHERE user = '$dbuser'" | wc -c`
if [ $user_exists = 0 ]; then
echo "CREATE USER '$dbuser'@'localhost' IDENTIFIED BY '$userpass';" | mysql -u root -p$rootpass
echo "${green}New MySQL user ($dbuser) was successfully created${normal}"
else
echo "${red}This MySQL user ($dbuser) already exists${normal}"
fi
user_has_privilage=`mysql -u root -p$rootpass -e "SELECT User FROM mysql.db WHERE db = '$dbname' AND user = '$dbuser'" | wc -c`
if [ $user_has_privilage = 0 ]; then
echo "GRANT ALL PRIVILEGES ON $dbname.* TO '$dbuser'@'localhost';" | mysql -u root -p$rootpass
echo "FLUSH PRIVILEGES;" | mysql -u root -p$rootpass
echo "${green}Add privilages for user ($dbuser) to DB $dbname${normal}"
else
echo "${red}User ($dbuser) already has privilages to DB $dbname${normal}"
fi
fi
# Download, unpack and configure WordPress
read -r -p "Enter your URL without www [e.g. example.com]: " wpURL
if [ ! -d /var/www/$wpURL ]; then
cd /var/www
wget http://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz --transform s/wordpress/$wpURL/
rm latest.tar.gz
if [ -d /var/www/$wpURL ]; then
echo "${green}WordPress downloaded.${normal}"
cd /var/www/$wpURL
cp wp-config-sample.php wp-config.php
sed -i "s/database_name_here/$dbname/;s/username_here/$dbuser/;s/password_here/$userpass/" wp-config.php
mkdir wp-content/uploads
chmod 640 wp-config.php
chmod 775 wp-content/uploads
chown www-data: -R /var/www/$wpURL
if [ -f /var/www/$wpURL/wp-config.php ]; then
echo "${green}WordPress has been configured."
echo "${red}Go to wp-config.php and add authentication unique keys and salts.${normal}"
else
echo "${red}Created WP files. wp-config.php setup faild, do this manually.${normal}"
fi
else
echo "${red}Failed to create WP files. Install them manually.${normal}"
fi
else
echo "${red}Site folder already exists.${normal}"
fi
else
echo "Skipping WordPress install."
fi
# Create Apache virtual host
read -p "Do you want to install Apache vhost (y/n)? " apacheFiles
if [ $apacheFiles == "y" ]; then
if [ -f /etc/apache2/sites-enabled/$wpURL."conf" ]; then
echo "${red}This site already has a vhost file.${normal}"
else
echo "
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName $wpURL
ServerAlias www.$wpURL
DocumentRoot /var/www/$wpURL
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
" > /etc/apache2/sites-enabled/$wpURL."conf"
if [ -f /etc/apache2/sites-enabled/$wpURL."conf" ]; then
echo "${green}Apache vhost file created${normal}"
else
echo "${red}Apache vhost failed to install${normal}"
fi
fi
# Enable the site
a2ensite $wpURL
service apache2 reload
curlText=`curl --user-agent "fogent" --silent "http://$wpURL/wp-admin/install.php" | grep -o -m 1 "Welcome to the famous five minute WordPress installation process" | wc -c`
# http://www.cyberciti.biz/faq/how-to-find-out-the-ip-address-assigned-to-eth0-and-display-ip-only/
yourip=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
if [ $curlText == '65' ]; then
echo "${green}Go to http://$wpURL and finish install.${normal}";
else
echo "${green}Go to http://$yourip/$wpURL and config your DNS after.${normal}";
fi
else
echo "Skipping Apache site install."
fi
# Output
echo "${green}Finished!${normal}"