-
Notifications
You must be signed in to change notification settings - Fork 0
/
dwiz
executable file
·433 lines (362 loc) · 12.9 KB
/
dwiz
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#!/bin/bash
clear
#check if drush is installed, otherwise exit.
command -v drush >/dev/null 2>&1 || { echo "I require drush but it's not installed. Aborting." >&2; exit 1; }
startdir=$(pwd)
sdir=$(dirname "$0")
sdir=${sdir#*/}
globalDirectory="$HOME/.drupal-wizard"
globalConfig="$globalDirectory/global.cfg"
globalModules="${globalDirectory}/modules"
globalCommands="${globalDirectory}/commands"
foundPath=""
#
# Search for file existence
# @param file to check
#
function fileExists() {
if [ -f "$1/$2" ]; then
return 1;
else
return 0;
fi
}
#
# Get the file location, searching from the current working directory up to the global directory.
# @param string: must be either 'module' or 'command'
#
function getFileLocation() {
#First check if the file exists in the script working directory
fileExists "${startdir}" "$1"
if [ $? -eq 1 ]; then
foundPath="$startdir/$1"
return
fi
#if not the check is performed in the .drupalwizard user's home directory
#either 'module' or 'command' must be specified.
if [ "$2" == "module" ]; then
searchIn=$globalModules
else
searchIn=$globalCommands
fi
fileExists "$searchIn" "$1"
if [ $? -eq 1 ]; then
foundPath="$searchIn/$1"
return
else
echo "file $1 not found"
foundPath=""
exit
fi
}
# Parse optional arguments to read the module list and command list file.
# @parameters
# -m The modules list filename to parse. The wizard will start searching
# from the script working directory, falling back to the global .drupalwizard directory
# -c The commands list filename to parse. The wizard will start searching
# from the script working directory, falling back to the global .drupalwizard directory
# for both -c and -m and empty value means to search for the default filename (modules.list and commands.list)
while getopts "m:c:v" option; do
case "$option" in
m)
if [ -n "$OPTARG" ]; then
getFileLocation "$OPTARG" 'module'
m="$foundPath"
fi
;;
c)
if [[ -n "$OPTARG" ]]; then
getFileLocation "$OPTARG" 'command'
c="$foundPath"
fi
;;
v)
verbodeMode=1
;;
\?)
echo "Invalid option: - $OPTARG" >&2
exit
;;
esac
done
#If the argument "-v" is passed the global configuration file
#is ignored. We're gonna ask for all the required information.
if [[ -z "${verbodeMode}" ]]; then
source "${globalConfig}"
fi
echo "Welcome to the Drupal Installation Wizard"
echo
if [[ ! "$verbodeMode" ]]; then
echo "All the required information will be loaded from the global configuration file."
echo "Information not provided in the configuration file will be asked in the next page."
else
echo "You requested to skip loading the global configuration file."
echo "All the required information must be manually provided."
fi
echo
if [ ! -z "$m" ]; then
echo -e "\e[31mAdditional modules to install are listed in the file $m\e[0m"
fi
echo
if [ ! -z "$c" ]; then
echo -e "\e[31mPost installation commands are listed in the file $c\e[0m"
fi
read -r -p "Do you wish to continue?[y/n] [y] " goahed
if [[ "$goahed" == "y" || "$goahed" == "" ]]; then # yes, continue
clear
else
echo "Exiting.."
echo "Bye."
exit
fi
echo -en '\E[47;31m'"\033[1mPlease be careful.
Database and folder with the same name will be overwritten.\033[0m\n\n"
##################### The script is running, declare some variables ############
# Default values come from the global.cfg file
site_name="My Drupal Site"
#Database Server settings
install_path="$wsRoot"
sub_path="$wsSubPath"
db_url="$dbUrl"
db_host="$dbAddress"
db_root_name="$dbRootUsername"
db_root_pw="$dbRootPassword"
#Drupal database configuration
db_user="$drupalDbUsername"
db_pass="$drupalDbPassword"
if [[ "$drupalDbName" ]]; then
db_name="${drupalDbPrefix}${drupalDbName}"
if [[ "$drupalDbPrefix" ]]; then
db_name="${drupalDbPrefix}${drupalDbName}"
fi
fi
#Drupal Installation settings
version="$drupalDefaultVersion"
webSiteEmail="$drupalEmail"
locale="$drupalLocale"
#Administrator settings
account_name="$adminUsername"
account_passw="$adminPassword"
account_email="$adminEmail"
###################### WebSite informations ##################################
#Informations about the website drush is going to create
################################################################################
#Drupal Version
if [ -z "$version" ]; then
version="7"
read -r -p "Enter the Drupal version you want to install [$version]: " ver
[[ $ver = '' ]] && version="$version" || version="$ver"
fi
#Web Site language
if [[ -z $locale ]]; then
locale="en"
read -r -p "Enter the 2 characters language code. [$locale]: " loc
[[ $loc = '' ]] && locale="$locale" || locale="$loc"
fi
#Web Site Name
#if [[ -z $site_name ]]; then
site_name="My Drupal Site"
read -r -p "Enter the website name [$site_name]: " sitename
[[ $sitename = '' ]] && site_name="$site_name" || site_name="$sitename"
#fi
#Web site email
if [[ -z $webSiteEmail ]]; then
webSiteEmail="email@example.com"
read -r -p "Enter the website email [$webSiteEmail]: " webMail
[[ $webMail = '' ]] && webSiteEmail="$webSiteEmail" || webSiteEmail="$webMail"
echo
fi
#Web Server Root
if [[ -z "$install_path" ]]; then
install_path="/var/www"
read -r -p "Enter the web server absolute root path [$install_path]: " path
[[ $path = '' ]] && install_path="$install_path" || install_path="$path"
fi
#Web Server Sub Path
if [[ -z "$sub_path" ]]; then
sub_path="public"
read -r -p "Enter the web server relative sub path where drupal will be installed [$sub_path]: " subPath
[[ $subPath = '' ]] && sub_path="$sub_path" || sub_path="$subPath"
echo
fi
#Administrator username
if [[ -z $account_name ]]; then
account_name="admin"
read -r -p "Enter the administrator account name for the website [$account_name]: " name
[[ $name = '' ]] && account_name="$account_name" || account_name="$name"
fi
#Administrator password
if [[ -z $account_passw ]]; then
account_passw="admin"
read -r -p "Enter the administrator account password for the website [$account_passw]: " passw
[[ $passw = '' ]] && account_passw="$account_passw" || account_passw="$passw"
fi
#Administrator email
if [[ -z $account_email ]]; then
account_email="admin@example.com"
read -r -p "Enter the administrator email for the website [$account_email]: " mail
[[ $mail = '' ]] && account_email="$account_email" || account_email="$mail"
echo
fi
###################### Database Server Informations ##########################
#Database server connection informations
################################################################################
#Database Server Url
if [[ -z $db_url ]]; then
db_url="mysql://"
read -r -p "Enter the database server URL [$db_url]: " dburl
[[ $dburl = '' ]] && db_url="$db_url" || db_url="$dburl"
fi
#Database Server Address
if [[ -z $db_host ]]; then
db_host="localhost"
read -r -p "Enter the database server host address [$db_host]: " dbhost
[[ $dbhost = '' ]] && db_host="$db_host" || db_host="$dbhost"
fi
#Database Server Root username
if [[ -z $db_root_name ]]; then
db_root_name="root"
read -r -p "Enter the database server root username [$db_root_name]: " dbrootname
[[ $dbrootname = '' ]] && db_root_name="$db_root_name" || db_root_name="$dbrootname"
fi
#Database Server Root Password
if [[ -z $db_root_pw ]]; then
db_root_pw="root"
read -r -p "Enter the database server root password [$db_root_pw]: " dbrootpassw
[[ $dbrootpassw = '' ]] && db_root_pw="$db_root_pw" || db_root_pw="$dbrootpassw"
echo
fi
##################### Website Database Information ###########################
# Informations about the database drush is going to create for the website
################################################################################
#Drupal Database Name
if [[ -z $db_name ]]; then
db_name="drupal"
read -r -p "Enter the database name drupal will be connected to [$db_name]: " dbname
[[ $dbname = '' ]] && db_name="$db_name" || db_name="$dbname"
fi
#Drupal Database Username
if [[ -z $db_user ]]; then
db_user="drupal"
read -r -p "Enter the username the website uses to access the database [$db_user]: " dbuser
[[ $dbuser = '' ]] && db_user="$db_user" || db_user="$dbuser"
fi
#Drupal Database Password
if [[ -z $db_pass ]]; then
db_pass="drupal"
read -r -p "Enter the password the website uses to access the database [$db_pass]: " dbpass
[[ $dbpass = '' ]] && db_pass="$db_pass" || db_pass="$dbpass"
fi
#Concatenated Installation path [Root + sub path]
completeInstallPath="${install_path}/${sub_path}"
#echo "The script is located at: ${startdir}"
#workingdir=$(echo $completeInstallPath)
#echo "The working directory is: $workingdir"
module_file=$m
if [[ "$m" ]]; then
echo "The file name containing the list of modules to download is located at: $module_file"
fi
commands_file=$c
if [[ "$c" ]]; then
echo "The post-installation commands file is located at: $commands_file"
fi
clear
echo "Review below informations before staring installation:"
echo "*********************************************************"
echo "* Website related information: *"
echo "*********************************************************"
echo "Installation path : $completeInstallPath"
echo "Drupal Version : $version"
echo "Website language : $locale"
echo "Website name : $site_name"
echo "Website email : $webSiteEmail"
echo "********************************************************"
echo "* Administrator *"
echo "********************************************************"
echo "Administrator username : $account_name"
echo "Administrator password : $account_passw"
echo "Administrator email : $account_email"
echo "********************************************************"
echo "* Database Server *"
echo "********************************************************"
echo "Database Server url : $db_url"
echo "Database Server address : $db_host"
echo "Database Server root username : $db_root_name"
echo "Database Server root password : $db_root_pw"
echo "********************************************************"
echo "* Drupal database *"
echo "********************************************************"
echo "- The following new database will be created"
echo "New database name : $db_name"
echo "Database username : $db_user"
echo "Database password : $db_pass"
echo
echo "A new Drupal ${version} website will be installed in: ${completeInstallPath}"
while true; do
read -r -p "Are these informations correct? [y/n]" correct
case $correct in
[Yy]* ) echo "Installation is staring...."; break;;
[Nn]* ) echo "Please start the script again and make needed corrections."; exit;;
* ) echo "Please answer yes[y] or not[n].";;
esac
done
echo
echo
echo "Downloading latest Drupal ${version} release"
echo "Please wait until the task is completed. This may take a few minutes."
echo "....."
### Download latest drupal release #########
drush dl -y drupal-"${version}" --destination="${install_path}" --drupal-project-rename="${sub_path}"
echo
echo
echo "Latest Drupal ${version} release has been downloaded at ${completeInstallPath}"
echo
echo
cd "$completeInstallPath" || exit
### Install Drupal using drush ########
drush -y site-install standard --account-name="${account_name}" --account-pass="${account_passw}" --account-mail="${account_email}" --locale="${locale}" --db-url="${db_url}${db_user}:${db_pass}@${db_host}/${db_name}" --db-su="${db_root_name}" --db-su-pw="${db_root_pw}" --site-name="${site_name}" --notify
if [ $? != 0 ]; then
echo "Drush has encountered a problem. Please review the information you provide and try again."
exit
fi
## Recursively download and (if set [y]) enable modules from the .modules file.
if [ $m ]; then
echo
echo "Downloading additional modules.."
echo
while read module enabled
do
case $module in \#*) continue ;; esac
if [[ $module ]]; then
echo "drush is downloading $module module"
drush dl -n "$module"
if [[ $enabled == "y" ]]; then
echo "Enabling module $module"
drush en -y "$module"
fi
echo
fi
done < "$module_file"
fi
### Perform recursively additional drush commands listed in commands files.
if [ $c ]; then
echo
echo "Performing post installation commands.."
echo
while IFS=$'\n': read action
do
case $action in \#*) continue ;; esac
if [[ $action ]]; then
echo
echo "drush is performing [drush $action]"
drush $action
fi
done < "$commands_file"
fi
echo
echo
echo "Review if there were errors during the process."
echo "If not you can visit your new website at ${completeInstallPath}"
echo
echo "All tasks are completed."
echo