-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
156 lines (128 loc) · 4.51 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
#!/bin/bash -e
red='\e[31m'
cyan='\e[33m'
blue='\e[34m'
bgRed='\e[41m'
bgBlue='\e[44m'
bgCyan='\e[46m'
fullpath=${PWD}
baseSiteDirectory=$(echo $fullpath | sed 's/.*workspace//g')
echo "================================================================="
echo -e "$blue 4Geeks Academy\e[0m WordPress Installer!!"
echo "================================================================="
print_error () {
echo -e "$bgRed Error!\e[0m $red $1\e[0m"
}
print_info () {
echo -e "$cyan $1\e[0m"
}
print_hint () {
echo -e "$bgBlue Hint:\e[0m $1"
}
print_question () {
echo -e "$bgCyan input>\e[0m $cyan $1 \e[0m"
}
git --version > /dev/null
GIT_IS_AVAILABLE=$?
if [ $GIT_IS_AVAILABLE -eq 0 ];
then echo ""
else print_error "git not found, but is required. Please install git"
fi
if [ -d "./wp-content" ];
then
echo "Wordpress installation was found, proceeding..."
else
print_error "No wordpress installation found"
print_hint "Make sure you have a wp-content folder in the current directory:"
ls -a
exit
fi
echo ""
if [ -d "./vendor" ];
then
echo "Composer was found, proceeding with the installation..."
else
print_error "You need to install the composer packages first"
print_hint "Run: $ composer install\e[0m"
exit
fi
wp --info > /dev/null
WP_IS_AVAILABLE=$?
if [ $WP_IS_AVAILABLE -eq 0 ];
then echo ""
else
print_info "Installing wordpress cli..."
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
fi
echo "Running MySQL"
mysql-ctl start
phpmyadmin-ctl install
# add a simple yes/no confirmation before we proceed
print_question "Do you want to run the whole installation? (y/n)"
read -e run
# if the user didn't say no, then go ahead an install
if [ "$run" != y ] ; then
echo "Exiting the installation"
exit
else
if [ -d "./wp-includes" ]; then
print_error "WordPress is already installed"
exit
fi
# accept the name of our website
print_question "What is going to be your site name or title? "
read -e sitename
while [[ $sitename == '' ]] # While string is different or empty...
do
print_error "Please enter a valid string" # Ask the user to enter a valid string
read -e sitename
done
# accept the name of our website
print_question "Choose a password for your WordPress admin:"
read -s sitepassword
while [[ $sitepassword == '' ]] # While string is different or empty...
do
print_error "Please enter a valid password" # Ask the user to enter a valid string
read -s sitepassword
done
# download the WordPress core files
wp core download
# create the wp-config file with our standard setup
wp core config --dbname="c9" --dbuser=$C9_USER --dbpass= --extra-php <<PHP
define( 'WP_DEBUG', true );
define( 'DISALLOW_FILE_EDIT', true );
PHP
# parse the current directory name
wp core install --url="https://$C9_HOSTNAME/$baseSiteDirectory" --title="$sitename" --admin_user="$C9_USER" --admin_password="$sitepassword" --admin_email=$C9_EMAIL
# create database, and install WordPress
# discourage search engines
wp option update blog_public 0
# 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)
wp post create --post_type=page --post_title=Home --post_status=publish --post_author=$(wp user get $C9_USER --field=ID --format=ids)
# 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)
# set pretty urls
wp rewrite structure '/%postname%/' --hard
wp rewrite flush --hard
# delete akismet and hello dolly
wp plugin delete akismet
wp plugin delete hello
wp theme activate rigo
wp plugin activate advanced-custom-fields
phpmyadminPath = "phpmyadmin"
echo "================================================================="
echo "Installation is complete. Your WordPress username/password is listed below."
echo ""
echo "Username: $C9_USER (for wordpress and your database)"
echo "Password: (whatever you specified earlier)"
echo ""
echo -e "To access your database: $blue\e[4mhttps://$C9_HOSTNAME/$baseSiteDirectory$phpmyadminPath\e[0m"
echo -e "To access your site: $blue\e[4mhttps://$C9_HOSTNAME/$baseSiteDirectory\e[0m"
echo ""
echo "================================================================="
fi