-
Notifications
You must be signed in to change notification settings - Fork 4
/
wp-create.sh
163 lines (129 loc) · 5.24 KB
/
wp-create.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
#!/bin/sh
# WP-Create Creates a new client WP installation via svn quickly.
# Use wp-mass-upgrade.sh to upgrade sites, i.e. One script to do quick WP svn checkouts,
# database setup, etc. and another to mass upgrade all WP installations on a server.
# See the readme for information on why this script no longer creates databases.
# Scot Hacker :: http://birdhouse.org/blog
# This script performs the following tasks:
# * Gather installation info
# * Create install dir and check out a copy of WordPress
# * Create database (not currently doing this), db user, set db privs via external .sql file
# * Create WP config file
# * Create upload dir and set filesystem permissions
# * Generate array line for wp-sites.sh
# Final setup is done via browser
# Database root pass - protect this script with chmod 700 !!!
DBROOT="dppass"
# Full path to the svn binary on your system (use 'which svn' to obtain if not sure)
svnpath='/usr/bin/svn'
####################################################
# Gather data
echo
echo -n "WordPress version? "; read wpver
echo -n "System account (e.g. fred) "; read owner
echo -n "Install path (e.g. /home/fred/public_html/blog)? "; read install_path
echo -n "URL (without http, e.g. somedomain.com/blog)? " ; read url
echo -n "Owner email? "; read email
echo -n "Database user? (n.b.: username will be prepended) "; read dbuser
echo -n "Database name? (n.b.: username will be prepended) "; read dbname
echo -n "Database pass? "; read dbpass
# Modify the db and db account names as necessary for the server you're on. For
# example this can be used to prepend "wp-" to the start of WordPress database
# names, or to use cPanel db naming format.
# For one server, we use the format wp-dbname
# thedb=wp\-${dbname}
# thedbacct=$dbuser
# Concatenate db name and username in cPanel standard format
# Weird quirk: In cPanel, the database name will not appear associated with the username in the
# graphical control panel unless you escape the underscore in the database name in the GRANT
# statement. So we have two variants for $thedb - one with the underscore escaped and the other not.
# If you're not on a cPanel system, season to taste.
thedb1=${owner}_${dbname}
thedb2=${owner}\\_${dbname}
thedbacct=${owner}_${dbuser}
echo
echo "
Version: $wpver
Owner: $owner
Path: $install_path
URL: http://$url
Owner email: $email
Database name: $thedb1
Database user: $thedbacct
Database pass: $dbpass
"
# Verify
echo
echo -n "Is this correct? (y/n) " ; read correct
if [ $correct != "y" ]; then
echo "Bzzzzt. Start over."
exit;
else
echo
echo "Installing WordPress..."
echo
fi
####################################################
# Create install dir and check out a copy of WordPress
if [ ! -d $install_path ]; then
mkdir -p $install_path
fi
cd $install_path
$svnpath co http://svn.automattic.com/wordpress/tags/$wpver/ .
####################################################
# Create database, db user, set db privs via external .sql file
# Temporarily not working until cPanel db API problems are worked out.
cat <<EOT >$install_path/wp-db.sql
CREATE DATABASE \`$thedb1\`;
GRANT ALL ON \`$thedb2\`.* TO '$thedbacct'@'localhost' IDENTIFIED BY '$dbpass';
FLUSH PRIVILEGES;
EOT
# Feed the db
# This is temporarily commented out until the cPanel db API problems are worked out
# mysql -u root -p$DBROOT < $install_path/wp-db.sql
# Clean up
rm $install_path/wp-db.sql
####################################################
# Create WP config file
cat <<EOT >wp-config.php
<?php
// ** MySQL settings ** //
define('DB_NAME', '$thedb1'); // The name of the database
define('DB_USER', '$thedbacct'); // Your MySQL username
define('DB_PASSWORD', '$dbpass'); // ...and password
define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
// Change SECRET_KEY to a unique phrase. You won't have to remember it later,
// so make it long and complicated. You can visit https://www.grc.com/passwords.htm
// to get a phrase generated for you, or just make something up.
define('SECRET_KEY', '$email $thedb1 $owner $thedbacct'); // Unique set of strings to create key
// You can have multiple installations in one database if you give each a unique prefix
\$table_prefix = 'wp_'; // Only numbers, letters, and underscores please!
// Change this to localize WordPress. A corresponding MO file for the
// chosen language must be installed to wp-content/languages.
// For example, install de.mo to wp-content/languages and set WPLANG to 'de'
// to enable German language support.
define ('WPLANG', '');
/* That's all, stop editing! Happy blogging. */
define('ABSPATH', dirname(__FILE__).'/');
require_once(ABSPATH.'wp-settings.php');
?>
EOT
####################################################
# Create upload dir and set filesystem permissions.
# Note that perms are set for phpsuexec systems - this
# will need to be tweaked if not using phpsuexec.
mkdir -p wp-content/uploads
chown -R $owner:$owner *
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
chmod 600 wp-config.php
####################################################
# Report
echo
echo "Installation complete. Please visit http://$url to complete setup."
echo
echo "Add this line to wp-sites.sh:"
echo "\"$install_path|$url|$email|$owner\""
echo