This repository was archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcreate-wordpress-site.sh
More file actions
executable file
·98 lines (83 loc) · 3.13 KB
/
create-wordpress-site.sh
File metadata and controls
executable file
·98 lines (83 loc) · 3.13 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
#!/bin/bash -e
#
# create-wordpress-site.sh
#
# Automatically creates a domain, DB, and installs the latest version of WordPress.
vst_newdomain="$1"
vst_newdomain_ip="$2"
### Get Hostname
if [ -z "$vst_hostname" ]; then
echo "Your VestaCP hostname, followed by [ENTER]:"
read vst_hostname
fi
### Get Username
if [ -z "$vst_username" ]; then
echo "Your VestaCP username, followed by [ENTER]:"
read vst_username
fi
### Get Password
if [ -z "$vst_password" ]; then
echo "Your VestaCP user password, followed by [ENTER]:"
read -s vst_password
fi
if [ -z "$vst_newdomain" ]; then
echo "Desired domain name for WordPress, followed by [ENTER]:"
read vst_newdomain
fi
echo '[create-wordpress-site] Creating domain via API call'
## Execute API Call to create domain
curl -s -X POST https://$vst_hostname:8083/api/ \
-d user="$vst_username" \
-d password="$vst_password" \
-d returncode="yes" \
-d cmd="v-add-domain" \
-d arg1="$vst_username" \
-d arg2="$vst_newdomain" \
-d arg3="$vst_newdomain_ip"
echo '[create-wordpress-site] Rebuilding the web configs via API call'
## Execute API Call to rebuild web configs
curl -s -X POST https://$vst_hostname:8083/api/ \
-d user="$vst_username" \
-d password="$vst_password" \
-d returncode="yes" \
-d cmd="v-rebuild-web-domains" \
-d arg1="$vst_username"
vst_newdomain_publichtml="~/web/$vst_newdomain/public_html"
echo '[create-wordpress-site] Downloading WordPress latest.tar.gz'
curl -s -O https://wordpress.org/latest.tar.gz
echo '[create-wordpress-site] Unpacking wordpress latest.tar.gz'
tar -zxf latest.tar.gz
echo "[create-wordpress-site] Uploading wordpress files to ~/web/$vst_newdomain/public_html"
rsync -e ssh -azh wordpress/* $vst_username@$vst_hostname:$vst_newdomain_publichtml
# Cleanup
rm -rf latest.tar.gz wordpress
echo "[create-wordpress-site] Removing $vst_newdomain_publichtml/index.html"
ssh $vst_username@$vst_hostname "rm $vst_newdomain_publichtml/index.html"
echo "[create-wordpress-site] Creating Database via API call"
## Generate DB Name
mysql_db_name="wp_${vst_newdomain//./}"
## Generate MySQL Username
mysql_username=$vst_username"_"$mysql_db_name
#### Shorten the MySQL username to make sure it's shorter than 16 chars (including the username)
mysql_username=${mysql_username:${#vst_username}+1:15-${#vst_username}}
## Generate a MySQL Password
mysql_password=$(openssl rand -base64 12)
curl -s -X POST https://$vst_hostname:8083/api/ \
-d user="$vst_username" \
-d password="$vst_password" \
-d returncode="yes" \
-d cmd="v-add-database" \
-d arg1="$vst_username" \
-d arg2="$mysql_db_name" \
-d arg3="$mysql_username" \
-d arg4="$mysql_password" \
-d arg5="mysql"
echo "[create-wordpress-site] ********************************************"
echo "[create-wordpress-site] MySQL DB Credentials"
echo "[create-wordpress-site] Database: $vst_username"_"$mysql_db_name"
echo "[create-wordpress-site] Username: $vst_username"_"$mysql_username"
echo "[create-wordpress-site] Password: $mysql_password"
echo "[create-wordpress-site] ********************************************"
echo "[create-wordpress-site] Completed!"
echo "[create-wordpress-site] You can now visit the website to finish the installation."
exit 0