-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp-install.sh
More file actions
101 lines (78 loc) · 3.02 KB
/
wp-install.sh
File metadata and controls
101 lines (78 loc) · 3.02 KB
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
#!/bin/bash -e
wpuser='ankoadmin'
echo "================================================================="
echo "Awesome WordPress Installer!!"
echo "================================================================="
#accept the dbpass
echo "MySQL root Password: "
read -e dbpass
# accept the name of our website
echo "Site Name (google.com): "
read -e sitename
echo "SSH Git:"
read -e git
dbname=${sitename//./_}
vhost_name=$dbname
# add a simple yes/no confirmation before we proceed
echo "Run Install? (y/n)"
read -e run
# if the user didn't say no, then go ahead an install
if [ "$run" == n ] ; then
exit
else
mysqlclient_username=${dbname:0:10}$(LC_CTYPE=C tr -dc A-Za-z0-9 < /dev/urandom | head -c 5)
mysqlclient_password=$(LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= < /dev/urandom | head -c 12)
git clone $git "/var/www/$dbname.git" --bare
mkdir "/var/www/$dbname"
sudo chmod 777 -R "/var/www/$dbname"
cd "/var/www/$dbname"
# download the WordPress core files
wp core download
# create the wp-config file
wp core config --dbname=$dbname --dbuser=root --dbpass=$dbpass
# parse the current directory name
currentdirectory=${PWD##*/}
# generate random 12 character password
password=$(LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= < /dev/urandom | head -c 12)
# create database, and install WordPress
wp db create
#create mysql user for wp site
mysql -uroot -p${dbpass} -e "CREATE USER ${mysqlclient_username}@localhost IDENTIFIED BY '${mysqlclient_password}';"
mysql -uroot -p${dbpass} -e "GRANT ALL PRIVILEGES ON ${dbname}.* TO '${mysqlclient_username}'@'localhost';"
mysql -uroot -p${dbpass} -e "FLUSH PRIVILEGES;"
#change username and password
rm wp-config.php
wp core config --dbname=$dbname --dbuser=$mysqlclient_username --dbpass=$mysqlclient_password
wp core install --url="http://$sitename" --title="$sitename" --admin_user="$wpuser" --admin_password="$password" --admin_email="user@example.org"
# configure vhost
sudo bash -c "cat > /etc/apache2/sites-available/$vhost_name.conf" <<EOF
<VirtualHost *:80>
ServerAdmin support@ankocorp.com
ServerName $sitename
DocumentRoot /var/www/$vhost_name/
<Directory />
Options None
AllowOverride None
Order deny,allow
deny from all
</Directory>
<Directory /var/www/$vhost_name>
Order allow,deny
allow from all
AllowOverride FileInfo
Options +FollowSymLinks
</Directory>
</VirtualHost>
EOF
sudo a2ensite $vhost_name
sudo service apache2 reload
wp plugin install https://s3.amazonaws.com/public-anko/plugins/wp-sync-db.zip --activate
wp plugin install https://s3.amazonaws.com/public-anko/plugins/wp-sync-db-media-files.zip --activate
echo "================================================================="
echo "Installation is complete. Your username/password is listed below."
echo ""
echo "Username: $wpuser"
echo "Password: $password"
echo ""
echo "================================================================="
fi