-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
151 lines (128 loc) · 4.16 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
#!/bin/bash
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 "$blue \e[0m WordPress Installer!!"
echo "================================================================="
print_error () {
echo "$bgRed Error!\e[0m $red $1\e[0m"
}
print_info () {
echo "$bgBlue $1\e[0m"
}
print_hint () {
echo "$bgBlue Hint:\e[0m $1"
}
print_question () {
echo "$bgCyan input>\e[0m $cyan $1 \e[0m"
}
if [ -f ./.env ]; then
print_info "Loading (.env) environment file..."
. ./.env
else
print_error "No .env file was found"
exit 1
fi
git --version > /dev/null
GIT_IS_AVAILABLE=$?
if [ $GIT_IS_AVAILABLE -eq 0 ];
then echo ""
else
print_error "Git is required, but not installed"
exit 1
fi
composer --version > /dev/null
COMPOSER_IS_AVAILABLE=$?
if [ $COMPOSER_IS_AVAILABLE -eq 0 ];
then echo ""
else
print_error "Composer is required, but not installed"
exit 1
fi
if [ -d "./wp-content" ];
then
print_info "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 1
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
if [ -d "./wp-includes" ]; then
if [ "$1" == "--force" ]; then
print_info "WordPress is already installed, proceeding with the rest of the installation..."
else
print_info "WordPress is already installed"
exit 1
fi
else
# download the WordPress core files
rm $fullpath/index.php
wp core download
fi
# create the wp-config file with our standard setup
wp core config --dbname=$DB_NAME --dbuser=$DB_USER --dbpass=$DB_PASS --extra-php <<PHP
define( 'WP_DEBUG', true );
define( 'DISALLOW_FILE_EDIT', true );
PHP
echo ""
if [ -f "./wp-config.php" ];
then
print_info "wp-config.php successfully created..."
else
print_error "The wp-config.php file could not be created, make sure your database credentials are ok."
exit 1
fi
# parse the current directory name
wp core install --url="$SITE_URL" --title="$SITE_NAME" --admin_user="$SITE_USER" --admin_password="$SITE_PASS" --admin_email="$SITE_EMAIL"
echo ""
if [ -d "./vendor" ];
then
print_info "/vendor folder found, udating packages..."
composer update
else
print_info "NO /vendor folder found, installing packages from scratch..."
composer install
fi
# 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 $SITE_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
echo "================================================================="
print_info "Installation is complete."
echo "You can go ahead and chech your website at $SITE_URL"
echo ""
echo "Login to your wordpress with the following credentials:"
echo "User: $SITE_USER"
echo "Password: $SITE_PASS"
echo "================================================================="
exit 0