-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwp-init
More file actions
71 lines (61 loc) · 2.98 KB
/
Copy pathwp-init
File metadata and controls
71 lines (61 loc) · 2.98 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
#!/bin/bash
################################################################################
#
# A script to ease the process of setting up users and WordPress installs
# in a test hosting environment. It does the following:
#
# * Creates a user on the linux system with .ssh directory with the right privs
# * Creates /var/www/html/$USERNAME and a symlink to /home/$USERNAME/wordpress
# * Dumps WP 4.6 into the directory with passwords, etc., specified in the vars
# below.
# * Creates the needed mysql database and privs.
# * Adds custom salts to wp-config.php and runs the install script.
#
# The script doesn't do much validation and could be destructive. It's useful
# for bootstrapping a bunch of quick throwaway WP installs in a testing environment,
# but I wouldn't get anywhere near a production environment with this.
#
################################################################################
if [ -z $1 ]
then
echo "Please pass a username."
exit
fi
if [ -e /var/www/html/$1 ]
then
echo "Oops, we already have a WP install for that user."
exit
fi
USERNAME=$1
DBP=" ---------- REPLACE ME ----------"
WPP=" ---------- REPLACE ME ----------"
EMAIL=" ---------- REPLACE ME ----------"
DOMAIN=" ---------- REPLACE ME ----------"
SITE_TITLE=" ---------- REPLACE ME ----------"
echo "Initializing account for $USERNAME..."
useradd --home /home/$USERNAME --create-home --shell /bin/bash $USERNAME
chown -R $USERNAME:$USERNAME /home/$USERNAME/.ssh/
chmod -R go-rwx /home/$USERNAME/.ssh/
echo "Setting up WordPress..."
mkdir -p /var/www/html/$USERNAME
cp -R /root/wordpress/* /var/www/html/$USERNAME/
chown -R www-data:$USERNAME /var/www/html/$USERNAME/
ln -s /var/www/html/$USERNAME /home/$USERNAME/wordpress
# Clone and update config file.
cp ~/wordpress/wp-config-sample.php /var/www/html/$USERNAME/wp-config.php
chown $USERNAME /var/www/html/$USERNAME/wp-config.php
mkdir -p /var/www/html/$USERNAME/wp-content/uploads && chown www-data /var/www/html/$USERNAME/wp-content/uploads
perl -pi.bak -e "s/database_name_here/wp_$USERNAME/" /var/www/html/$USERNAME/wp-config.php
perl -pi.bak -e "s/username_here/wpdbuser/" /var/www/html/$USERNAME/wp-config.php
perl -pi.bak -e "s/password_here/$DBP/" /var/www/html/$USERNAME/wp-config.php
rm /var/www/html/$USERNAME/wp-config.php.bak
curl --silent https://api.wordpress.org/secret-key/1.1/salt/ > /tmp/salts
sed -i -e "/__SALTS__/r /tmp/salts" -e "//d" /var/www/html/$USERNAME/wp-config.php
# Create database
mysql -e "create database wp_$USERNAME"
mysql -e "grant insert, update, delete, select, index, alter, drop, create on wp_$USERNAME.* to wpdbuser@localhost identified by '$DBP'"
# Complete the install
curl --output /tmp/out --silent --data "weblog_title=$SITE_TITLE&user_name=$USERNAME&admin_password=$WPP&admin_password2=$WPP&pw_weak=1&admin_email=$EMAIL&blog_public=0&language=en&submit=Submit" http://$DOMAIN/$USERNAME/wp-admin/install.php?step=2
echo "URL: http://$DOMAIN/$USERNAME/"
echo "Don't forget to get the user's public key."
echo "Done!"