-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-base.sh
executable file
·119 lines (101 loc) · 3.3 KB
/
wp-base.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
#!/bin/bash
# Usage: ./wc-base.sh sitedir sitename
# This script will create a local wordpress installation and install some commonly used plugins.
# Tested on MAMP.
# Author: Jamie Madden (https://digitalchild.info / https://github.com/digitalchild )
# This script was created to demonstrate how to use WordPress on the command line.
# Change these variables to suit your environment
MYSQLUSER='wordpress'
MYSQLPASS='wordpress'
WPADMINUSER='devadmin'
WPADMINEMAIL='test@test.com'
WEBROOT='/Users/jamie/Sites'
BASE_PLUGINS='jetpack wordfence wordpress-seo wordpress-importer contact-form-7'
##### DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING !!!! #####
EXPECTED_ARGS=2
E_BADARGS=65
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: $0 sitedir sitename"
exit $E_BADARGS
fi
# 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 and it is in your $PATH
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/';
exit 0;
fi
}
# Generate a database name or user
gendbdetails(){
local l=$1
[ "$l" == "" ] && l='development'
DATE=`date +"%Y-%m-%d"`
echo $l'-'$DATE
}
# Create the database and user, grant privileges.
createdb() {
# Does the database already exist?
RESULT=`mysqlshow --user=$4 --password=$5 $1 > /dev/null 2>&1 && echo $1`
if [ "$RESULT" == "$1" ]; then
echo "Database already exists, exiting."
exit 0;
fi
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"
}
DBUSER=`gendbdetails dev`
DBPASS=`genpasswd 8`
DBNAME=`gendbdetails $1`
THEDATE=`date +"%Y-%m-%d"`
INSTALLDIR=$1'-'$THEDATE
SITEURL='http://localhost/'$INSTALLDIR
SITENAME=$2
SITEDIR=$WEBROOT/$INSTALLDIR
ADMINUSER=$WPADMINUSER
ADMINEMAIL=$WPADMINEMAIL
ADMINPASS=`genpasswd 8`
echo '---------------------------------------------'
echo 'Creating new site.....'
echo '---------------------------------------------'
# Does the directory already exist?
if [[ -d "${SITEDIR}" && ! -L "${SITEDIR}" ]] ; then
echo "This sites directory already exists, exiting..."
exit 0;
fi
mkdir -p $SITEDIR;
echo "Site directory created in $WEBROOT";
createdb $DBNAME $DBUSER $DBPASS $MYSQLUSER $MYSQLPASS
echo "Database $DBNAME created...."
cd $SITEDIR;
wp core download
rm -rf wp-config-sample.php
wp core config --dbname=$DBNAME --dbuser=$DBUSER --dbpass=$DBPASS --dbhost=localhost
IFS='%'
wp core install --url=""$SITEURL"" --title="$SITENAME" --admin_user="$ADMINUSER" --admin_password="$ADMINPASS" --admin_email="$ADMINEMAIL"
unset IFS
echo 'Base Wordpress configuration completed....'
wp plugin install --activate $BASE_PLUGINS
wp plugin delete hello
wp post delete 2
echo 'Common plugins install completed....'
echo "---------------------------------------------"
echo "New site created."
echo "Link $SITEURL"
echo "Username: $ADMINUSER"
echo "Password: $ADMINPASS"
echo "---------------------------------------------"