-
Notifications
You must be signed in to change notification settings - Fork 1
/
iovagrantf
229 lines (185 loc) · 6.46 KB
/
iovagrantf
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
function wpinitHelp(){
echo "To use this, enter the command wpinit"
echo "More informations is asked in process...\n\n"
echo "Available Parameters:\n"
echo " -cvd = Change your Vagrant Directory"
echo " -h = Help\n\n"
}
function makeVagrantDirectory(){
touch ~/.iovagrantd
vDirectory=""
vared -p 'Set your Vagrant Directory (NO WWW!): ' -c vDirectory
echo -e "$vDirectory" > ~/.iovagrantd
}
function changeVagrantDirectory(){
echo "Change your Vagrant Directory!\n\n"
vDirectory=""
vared -p 'Set your NEW Vagrant Directory (NO WWW!): ' -c vDirectory
echo -e "$vDirectory" > ~/.iovagrantd
echo "Vagrant directory has been changed!\n\n"
return 1
}
function wpinit(){
# Printing hello message
echo -e "\n\nIOVagrant Creator v2.2.0\n\n"
sleep 1
if [ -n "$1" ]
then
if [ "$1" = "-cvd" ]
then
changeVagrantDirectory
return 1
elif [ "$1" = "-h" ]
then
wpinitHelp
return 1
else
echo "Invalid Parameters!\n\n"
echo "Try wpinit -h to get help"
return 1
fi
fi
# Checking if Vagrant Directory is set
if [ ! -f ~/.iovagrantd ]; then
makeVagrantDirectory
fi
# Getting Vagrant Directory from File
vagrantDirectory=$(<~/.iovagrantd)
# Getting project name
projectName=""
vared -p 'Project name: ' -c projectName
# Getting Parameter 2
removeContent=""
vared -p 'Remove wp-content? (y | n) ' -c removeContent
while [ "$removeContent" != "y" ] && [ "$removeContent" != "n" ];
do
echo "\nInvalid option...\n"
removeContent=""
vared -p 'Remove wp-content? (y | n) ' -c removeContent
done
# Getting Parameter 4
configOption=""
vared -p 'Edit default or create custom wp-config file? (e | c) ' -c configOption
while [ "$configOption" != "e" ] && [ "$configOption" != "c" ];
do
echo "\nInvalid option...\n"
configOption=""
vared -p 'Edit default or create custom wp-config file? (e | c) ' -c configOption
done
# Getting complementary parameters to parameter 4 (if this is create)
if [ "$configOption" = "c" ]
then
dbName=""
dbUser=""
dbPass=""
tablePrefix=""
vared -p 'Database Name: ' -c dbName
vared -p 'Database User: ' -c dbUser
echo -n 'Database Password: '
read -s dbPass
echo ''
vared -p 'Table prefix: (wp_) ' -c tablePrefix
if [ "$tablePrefix" = "" ]
then
tablePrefix="wp_"
fi
fi
# Getting Parameter 5
makeDb=""
vared -p 'Do you want a automatically database creation? (y | n) ' -c makeDb
while [ "$makeDb" != "y" ] && [ "$makeDb" != "n" ];
do
echo "\nInvalid option...\n"
makeDb=""
vared -p 'You want a automatically database creation? (y | n) ' -c makeDb
done
# Entering in vagrant directory
cd $vagrantDirectory
# Making wordpress default folder from project
cp -r www/wordpress-default www/$projectName
# Removing WP-CONTENT
if [ "$removeContent" != "n" ]
then
rm -rf www/$projectName/public_html/wp-content/
mkdir www/$projectName/public_html/wp-content/
fi
if [ "$configOption" = "c" ]
then
# Making wp-config file
rm www/$projectName/public_html/wp-config.php
touch www/$projectName/public_html/wp-config.php
wpConfig="www/$projectName/public_html/wp-config.php"
echo -e "<?php" >> $wpConfig
echo -e "// Created by IOVagrant Creator" >> $wpConfig
echo -e "\ndefine( 'DB_NAME', '$dbName' );" >> $wpConfig
echo -e "define( 'DB_USER', '$dbUser' );" >> $wpConfig
echo -e "define( 'DB_PASSWORD', '$dbPass' );" >> $wpConfig
echo -e "define( 'DB_HOST', 'localhost' );" >> $wpConfig
echo -e "define( 'DB_CHARSET', 'utf8' );" >> $wpConfig
echo -e "define( 'DB_COLLATE', '' );" >> $wpConfig
echo -e "\$table_prefix = '$tablePrefix';" >> $wpConfig
# Printing default conf options
echo -e "\n\ndefine( 'WP_DEBUG', true );" >> $wpConfig
echo -e "define( 'WP_DEBUG_DISPLAY', false );" >> $wpConfig
echo -e "define( 'WP_DEBUG_LOG', true );" >> $wpConfig
echo -e "define( 'WP_AUTO_UPDATE_CORE', false );" >> $wpConfig
echo -e "define ( 'AUTOMATIC_UPDATER_DISABLED' , true);" >> $wpConfig
echo -e "define('WPCF7_AUTOP', false);" >> $wpConfig
echo -e "define( 'WPCF7_ADMIN_READ_CAPABILITY', 'manage_options');" >> $wpConfig
echo -e "define( 'WPCF7_ADMIN_READ_WRITE_CAPABILITY', 'manage_options');" >> $wpConfig
# Default security access options
echo -e "\n\nif ( ! defined( 'ABSPATH' ) )" >> $wpConfig
echo -e "\tdefine( 'ABSPATH', dirname( __FILE__ ) . '/' );" >> $wpConfig
echo -e "\nrequire_once ABSPATH . 'wp-settings.php';" >> $wpConfig
else
# Opening default wp-config file
vim www/$projectName/public_html/wp-config.php
fi
# Question to host
#vared -p 'Host Name: ($projectName.idx) ' -c host
if [ "$host" = "" ]
then
host="$projectName.idx"
fi
if [ "$(uname -s)" = "Darwin" ]
then
sed -i '' '/# The following commented out site configuration will create a standard WordPress/i\
\
\'" $projectName"':\
\ hosts:\
\ -'" $host"'\
\ ' vvv-custom.yml
elif [ "$(uname -s)" = "Linux" ]
then
sed -i '/# The following commented out site configuration will create a standard WordPress/i\
\
\'" $projectName"':\
\ hosts:\
\ -'" $host"'\
\ ' vvv-custom.yml
fi
# Making .conf file into nginx-config
touch config/nginx-config/sites/$projectName.conf
nginxConf="config/nginx-config/sites/$projectName.conf"
echo -e "# Created by IOVagrant Creator" >> $nginxConf
echo -e "\nserver {" >> $nginxConf
echo -e "\tlisten 80;" >> $nginxConf
echo -e "\tlisten 443 ssl;" >> $nginxConf
echo -e "\tserver_name $host ~^$projectName\.\d+\.\d+\.\d+\.\d+\.xip\.io$;" >> $nginxConf
echo -e "\troot /srv/www/$projectName/public_html;" >> $nginxConf
echo -e "\tinclude /etc/nginx/nginx-wp-common.conf;" >> $nginxConf
echo -e "}" >> $nginxConf
command="# Created by IOVagrant Creator \nserver { \n\tlisten 80; \n\tlisten 443 ssl; \n\tserver_name $host ~^$projectName\.\d+\.\d+\.\d+\.\d+\.xip\.io$; \n\troot /srv/www/$projectName/public_html; \n\tinclude /etc/nginx/nginx-wp-common.conf; \n}"
echo "\nCreating Configurantions into Vagrant-box...\n"
vagrant up
vagrant ssh -- -t "sudo echo -e '$command' >> '$projectName.conf' && sudo mv '$projectName.conf' /etc/nginx/custom-sites/"
# Create DB
if [ $makeDb != "n" ]
then
echo "\nCreating Database...\n"
query="create database $dbName;"
vagrant ssh -- -t "mysql -e ' $query '"
fi
vagrant reload
echo "\n\nFinished!\n\n"
}