-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwp-new.sh
executable file
·83 lines (74 loc) · 2.28 KB
/
wp-new.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
#!/bin/bash
# Create a fresh wordpres install
# Generate a Password
genpasswd() {
local l=$1
[ "$l" == "" ] && l=16
openssl rand -base64 $l
}
#check that wordpress-cli is installed
# asssumes you have installed wp-cli into your path and renamed it to wp
checkwpcli() {
if hash wp 2>/dev/null; then
echo 'wp-cli installed.';
else
echo 'wp-cli is required. Download and install available from http://wp-cli.org/';
fi
}
# Generate a database name or user
gendbdetails(){
local l=$1
[ "$l" == "" ] && l='dev'
DATE=`date +"%Y-%m-%d"`
echo $l'-'$DATE
}
# Create the database and user, grant privileges.
createdb() {
MYSQL=`which mysql`
Q1="CREATE DATABASE IF NOT EXISTS \`$1\`;"
Q2="GRANT USAGE ON *.* TO \`$2\`@localhost IDENTIFIED BY '$3';"
Q3="GRANT ALL PRIVILEGES ON \`$1\`.* TO \`$2\`@localhost;"
Q4="FLUSH PRIVILEGES;"
SQL="${Q1}${Q2}${Q3}${Q4}"
$MYSQL -u$4 -p$5 -e "$SQL"
}
EXPECTED_ARGS=3
E_BADARGS=65
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: $0 mysqluser mysqlpass installdir"
exit $E_BADARGS
fi
# Set the Variables
MYSQLUSER=$1
MYSQLPASS=$2
DBUSER=`gendbdetails user`
DBPASS=`genpasswd 8`
DBNAME=`gendbdetails`
INSTALLDIR=$3
SITEURL="http://localhost/$3"
echo '---------------------------------------------'
echo 'WP New - The simple wordpress create script'
echo '---------------------------------------------'
echo 'Checking if WP-CLI is installed....'
checkwpcli
echo '---------------------------------------------'
echo 'Creating new site.....'
echo '---------------------------------------------'
echo 'Creating web-root'
mkdir $INSTALLDIR; cd $INSTALLDIR;
createdb $DBNAME $DBUSER $DBPASS $MYSQLUSER $MYSQLPASS
echo 'Database created....'
wp core download
rm -rf license.txt readme.html wp-config-sample.php
echo 'WP clean up complete...'
wp core config --dbname=$DBNAME --dbuser=$DBUSER --dbpass=$DBPASS --dbhost=localhost --extra-php <<PHP
define( 'WP_MEMORY_LIMIT', '256M' );
PHP
wp core install --url="$SITEURL" --title="New Site" --admin_user="admin" --admin_password="password" --admin_email="test@test.com"
echo 'Base Wordpress configuration completed....'
echo '---------------------------------------------'
echo 'New site created.'
echo "Link $SITEURL"
echo '---------------------------------------------'
open $SITEURL