-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·208 lines (169 loc) · 4.39 KB
/
install.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env bash
# Daintree - WP install script
#
# A simple bash script to automate installation of WordPress with some settings.
#
# Dependencies:
# 1: WP-CLI
# 2: Bash
# 3: Composer
# 4: WP-CLI DotEnv Command (https://github.com/aaemnnosttv/wp-cli-dotenv-command)
##
# Set up the shell variables for colors
# http://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
yellow=`tput setaf 3`;
green=`tput setaf 2`;
red=`tput setaf 1`;
clear=`tput sgr0`;
function hr ()
{
echo ""
echo "-------------------------------------------------------------------------------"
echo ""
}
function title {
echo -n "${green}$1${clear}"
}
function error {
echo -n "${red}$1${clear}"
}
function question {
echo
echo "${yellow}$1${clear}"
}
function bitbucket {
title "Bitbucket git repository helper"
echo "Create a new git repo on your BitBucket account."
echo 'Your Bitbucket username:'
read username
echo 'Your Bitbucket password:'
read -s password # -s flag hides password text
echo 'Your Bitbucket repository name:'
read repo_name
echo 'Your Bitbucket team:'
read repo_name
curl --user $username:$password https://api.bitbucket.org/2.0/repositories/ --data name=$repo_name --data is_private='true' --data owner=$team
git remote add origin git@bitbucket.org:$username/$reponame.git
git push -u origin --all
git push -u origin --tags
}
clear
hr
echo "WordPress Install Script"
hr
#Check composer installed
if [ ! -x "$(command -v composer)" ]; then
error "Composer is not installed."
echo
exit 1
fi
#Check wp-cli installed
if [ ! -x "$(command -v wp)" ]; then
error "wp-cli is not installed."
echo
exit 1
fi
# Check wp-cli dotenv command
target_dir="~/.wp-cli"
if [ ! -d $target_dir ]; then
error ".wp-cli in home directory does not exist."
echo
#exit 1
fi
echo
title "Create config file"
echo
#First check if config file exsts... wp dotenv list
wp dotenv init --template=.env.example --interactive --with-salts
question "Have you already created a database? (Y/n) "
read -e response
response=${response:-n}
if [[ $response =~ ^[Nn]$ ]]
then
echo "You need to create a database first."
echo
exit
fi
unset response
# accept the name of our website
question "Site name: "
read -e sitename
echo
title "Admin credentials"
echo
# accept admin email
question "Admin email address: "
read -i ${admin_email} -e admin_email
# accept admin username
question "Admin username: "
read -i ${wpuser} -e wpuser
# accept admin password
question "Admin Password: "
read -e pass
if [[ -z "$pass" ]]
then
echo "Generating a random password..."
# generate random 12 character password
pass=$(LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\$\%\^\&\*\(\)-+= < /dev/urandom | head -c 12)
echo "Admin Password is: ${pass}"
fi
hr
# add a simple yes/no confirmation before we proceed
question "Run Install? (Y/n) "
read -e run
run=${run:-Y}
# if the user didn't say no, then go ahead an install
if [ "$run" == n ] ; then
exit
else
if composer install$1; then
echo "Nice one."
else
exit $?
fi
fi
#Get the site URL for the installer
URL="$(wp dotenv get WP_SITEURL)"
wp core install --url="${URL}" --title="${sitename}" --admin_user="${wpuser}" --admin_password="${pass}" --admin_email="${admin_email}" --debug
title "Blocking search engines..."
echo
# discourage search engines
wp option update blog_public 0 --url="${URL}"
echo
title "Deleting sample pages..."
echo
# delete sample page, and create homepage
wp post delete $(wp post list --post_type=page --posts_per_page=1 --post_status=publish --pagename="sample-page" --field=ID --format=ids) --url="${URL}"
echo
title "Creating home page..."
echo
wp post create --post_type=page --post_title=Home --post_status=publish --post_author=$(wp user get $wpuser --field=ID --format=ids) --url="${URL}"
# set homepage as front page
wp option update show_on_front 'page'
# set homepage to be the new page
wp option update page_on_front $(wp post list --post_type=page --post_status=publish --posts_per_page=1 --pagename=home --field=ID --format=ids) --url="${URL}"
echo
# Delete sample post
title "Deleting sample post..."
echo
wp post delete 1 --force --url="${URL}"
echo
# set pretty urls
title "Setting up pretty urls..."
echo
wp rewrite structure '/%postname%/'
wp rewrite flush
echo
hr
title "Installation is complete. :)"
echo
echo
title "Website: "
echo $URL
title "Admin: "
echo $URL"/wp-admin"
title "Username: "
echo "$wpuser"
title "Password: "
echo "$pass"
bitbucket