-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.sh
More file actions
587 lines (511 loc) · 17.4 KB
/
functions.sh
File metadata and controls
587 lines (511 loc) · 17.4 KB
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
if [ -f "$SCRIPTDIR"/local_function.sh ]; then
source "$SCRIPTDIR"/local_function.sh
fi
debug() {
if [[ "$DEBUG" == true ]]; then
echo "DEBUG: $1"
fi
}
init() {
local SITENAME="$1"
TMPDIR="$TMPDIRBASE/$SITENAME"
LOGDIR="$LOGDIRBASE/$SITENAME"
SESSIONDIR="$SESSIONDIRBASE/$SITENAME"
SITEDIR="$MULTISITE/sites/$SITENAME"
}
# Runs first phase of subsite creation.
phase_1 () {
init "$SITENAME"
validate_sitename "$SITENAME"
validate_email "$USEREMAIL"
check_existence_create "$SITENAME"
create_db "$DBNAME"
create_dirs
create_vhost
add_to_hosts "$SITENAME"
create_creadentials_source "$SITENAME"
}
# Pick ups credentials from source file and continuing subsite creation.
phase_2 () {
read_creadentials_source "$SITENAME"
init "$SITENAME"
install_drupal
set_permissions
add_to_crontab
add_subsiteadmin
}
# Creates credentials source file for external provisioning usage.
create_creadentials_source () {
local SITENAME="$1"
if [ -v EXTERNAL_DB_PROVISIONING ]
then
# Checking if credentials sources path is defined
check SOURCES_PATH_EXISTS
echo "SITENAME=${SITENAME}
DBNAME=${DBNAME}
DBUSER=${DBUSER}
DBPASS=${DBPASS}" > $PROVISIONING_SOURCES_PATH/$SITENAME
chown $APACHEUSER:$APACHEUSER $PROVISIONING_SOURCES_PATH/$SITENAME
else
echo "NOTICE: Internal DB provisioning. No need for credentials sources file."
fi
}
# Read credentials from source file.
read_creadentials_source () {
local SITENAME="$1"
if [ -v EXTERNAL_DB_PROVISIONING ]
then
# Checking if credentials sources path is defined
check CREDENTIALS_SOURCES
source $PROVISIONING_SOURCES_PATH/$SITENAME
else
echo "NOTICE: Internal DB provisioning. No need to read credentials sources file."
fi
}
validate_sitename() {
local SITENAME="$1"
debug "Checking site name ($SITENAME)"
if [[ ! $SITENAME =~ (([a-zA-Z](-?[a-zA-Z0-9])*)\.)*[a-zA-Z](-?[a-zA-Z0-9])+\.[a-zA-Z]{2,}$ ]]; then
echo "ERROR: Domain not valid"
exit 10
fi
}
validate_domainname() {
local DOMAIN="$1"
debug "Checking domain name ($DOMAIN)"
if [[ ! $DOMAIN =~ (([a-zA-Z](-?[a-zA-Z0-9])*)\.)*[a-zA-Z](-?[a-zA-Z0-9])+\.[a-zA-Z]{2,}$ ]]; then
echo "ERROR: Domain not valid"
exit 10
fi
}
validate_email() {
local EMAIL="$1"
debug "Checking email address ($EMAIL)"
if [[ ! "$EMAIL" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$ ]]
then
echo "ERROR: Email $EMAIL not valid"
exit 10
fi
}
# Generic check function.
# Example of using check [check_type]
check() {
local CHECK_TYPE="$1"
case $CHECK_TYPE in
SITE_DIR_EXISTS)
if [ -d "$MULTISITE/sites/$SITENAME" ]
then
echo "Sitedir, $MULTISITE/sites/$SITENAME already exists"
exit 10
fi
;;
VHOST_EXISTS)
if [ -f "$VHOST" ]
then
echo "ERROR: Vhost, $VHOST already exists"
exit 10
fi
;;
DB_CONNECTION)
ERROR=$(mysql -u$DBUSER -p$DBPASS $DBNAME -h$DBHOST -e ";")
if ! [ -z "$ERROR" ]
then
echo $ERROR
exit 10
fi
;;
SOURCES_PATH_EXISTS)
if ! [ -v PROVISIONING_SOURCES_PATH ]
then
echo "ERROR: Credentials sources directory is not defined"
exit 10
else
mkdir -p $PROVISIONING_SOURCES_PATH
if ! [ -d "$PROVISIONING_SOURCES_PATH" ]
then
echo "ERROR: Credentials sources directory doesn't exist and can not be created."
exit 10
fi
fi
;;
CREDENTIALS_SOURCES)
check SOURCES_PATH_EXISTS
if ! [ -f "$PROVISIONING_SOURCES_PATH/$SITENAME" ]
then
echo "ERROR: Credentials sources file is not exists"
exit 10
fi
;;
esac
}
check_existence_create() {
debug "Checking if site already exists ($SITENAME)"
# Check if site dir already exists
check SITE_DIR_EXISTS
# Check if site vhost alias already exists
check VHOST_EXISTS
if [ -v EXTERNAL_DB_PROVISIONING ]
then
echo "NOTICE: External DB provisioning is used. Can not check if database or database user exists."
else
# Check if database already exists
if [ -d "$DBDIR/$DBNAME" ]
then
echo "ERROR: Database, $DBDIR/$DBNAME already exists"
exit 10
fi
# Check if database user already exists
local DBNAME=${SITENAME//\./_}
local DBNAME=${DBNAME//\-/_}
DBUSER=$(echo "$DBNAME" | cut -c 1-16)
EXISTS=$(mysql -ss mysql -e "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = \"$DBUSER\");")
if [ $EXISTS -ne 0 ]
then
echo "ERROR: Database user, $DBUSER already exists"
exit 10
fi
fi
}
check_existence_delete() {
debug "Checking if site exists ($SITENAME)"
# Check if site dir already exists
if [ ! -d "$MULTISITE/sites/$SITENAME" ]
then
echo "ERROR: Sitedir, $MULTISITE/sites/$SITENAME doesn't exists"
exit 10
fi
# Check if site vhost alias already exists
if [ ! -f "$VHOST" ]
then
echo "ERROR: Vhost, $VHOST doesn't exists"
exit 10
fi
if [ -v EXTERNAL_DB_PROVISIONING ]
then
echo "NOTICE: External DB provisioning is used. Can not check if database or database user exists."
else
# Check if database already exists
if [ ! -d "$DBDIR/$DBNAME" ]
then
echo "ERROR: Database, $DBDIR/$DBNAME doesn't exists"
exit 10
fi
fi
}
check_existence_add() {
debug "Checking if site exists ($SITENAME)"
# Check if site dir already exists
if [ ! -d "$MULTISITE/sites/$SITENAME" ]
then
echo "ERROR: Sitedir, $MULTISITE/sites/$SITENAME doesn't exists"
exit 10
fi
# Check if site vhost exists
if [ ! -f "$VHOST" ]
then
echo "ERROR: Vhost, $VHOST doesn't exists"
exit 10
fi
debug "Checking if the new domain already exists ($NEWDOMAIN)"
# Check if new domain already exists
egrep -q "ServerName $NEWDOMAIN" /etc/apache2/sites-enabled/* && EXISTSSERVERNAME=$? || EXISTSSERVERNAME=$?
egrep -q "ServerAlias $NEWDOMAIN" /etc/apache2/sites-enabled/* && EXISTSSERVERALIAS=$? || EXISTSSERVERALIAS=$?
if [[ "$EXISTSSERVERALIAS" -eq 0 || $EXISTSSERVERNAME -eq 0 ]]
then
echo "ERROR: Domain, $NEWDOMAIN already exists in a vhost"
exit 10
fi
}
check_existence_remove() {
debug "Checking if site exists ($SITENAME)"
# Check if site dir already exists
if [ ! -d "$MULTISITE/sites/$SITENAME" ]
then
echo "ERROR: Sitedir, $MULTISITE/sites/$SITENAME doesn't exists"
exit 10
fi
# Check if site vhost exists
if [ ! -f "$VHOST" ]
then
echo "ERROR: Vhost, $VHOST doesn't exists"
exit 10
fi
debug "Checking if the domain exists ($REMOVEDOMAIN)"
# Check if new domain exists
EXISTSSERVERALIAS=$(egrep -c "ServerAlias $REMOVEDOMAIN" "/etc/apache2/sites-enabled/$SITENAME" || true)
if [[ "$EXISTSSERVERALIAS" -eq 0 ]]
then
echo "ERROR: Vhost, $REMOVEDOMAIN doesn't exists in the vhost for $SITENAME"
exit 10
fi
}
add_to_hosts() {
local DOMAIN="$1"
debug "Adding $DOMAIN to /etc/hosts"
echo "$SERVERIP $DOMAIN" >> /etc/hosts
}
remove_from_hosts() {
local DOMAIN="$1"
# TODO, also remove all ServerAlias lines?
debug "Removing $DOMAIN from /etc/hosts"
sed -i "/$SERVERIP $DOMAIN/d" /etc/hosts
}
remove_from_sites() {
local DOMAIN="$1"
debug "Removing $DOMAIN from $SITESFILE"
sed -i "/'$DOMAIN'/d" $SITESFILE
}
create_db() {
local DBNAME=$1
DBUSER=$(echo "$DBNAME" | cut -c 1-16)
# check for pwgen
command -v pwgen >/dev/null 2>&1 || { echo >&2 "ERROR: pwgen is required but not installed. Aborting."; exit 20; }
DBPASS=$(pwgen -s 10 1)
if [ -v EXTERNAL_DB_PROVISIONING ]
then
echo "NOTICE: External DB provisioning is used. The file with DB credentials would be created.."
else
debug "Creating database ($DBNAME) and database user ($DBUSER)"
# this requires a /root/.my.cnf with password set
/usr/bin/mysql -u root -e "CREATE DATABASE $DBNAME;"
/usr/bin/mysql -u root -e "GRANT ALL ON $1.* TO $DBUSER@localhost IDENTIFIED BY \"$DBPASS\"";
fi
}
create_dirs() {
debug "Creating dirs"
mkdir -p "$TMPDIR"
mkdir -p "$LOGDIR"
mkdir -p "$SESSIONDIR"
if [ -n "$(type -t ${FUNCNAME[0]}_local)" ] && [ "$(type -t ${FUNCNAME[0]}_local)" = function ]; then
${FUNCNAME[0]}_local
fi
}
create_vhost() {
debug "Adding and enabling $SITENAME vhost"
cp "$VHOSTTEMPLATE" "/etc/apache2/sites-available/$SITENAME.conf"
perl -p -i -e "s~\[basedir\]~$BASEDIR~g" "/etc/apache2/sites-available/$SITENAME.conf"
perl -p -i -e "s/\[domain\]/$SITENAME/g" "/etc/apache2/sites-available/$SITENAME.conf"
#a2ensite "$SITENAME" >/dev/null
ln -s /etc/apache2/sites-available/$SITENAME.conf /etc/apache2/sites-enabled/$SITENAME.conf
debug "Reloading Apache2..."
if [ -f /etc/init.d/apache2 ]; then
/etc/init.d/apache2 reload >/dev/null
else
echo "apachectl graceful"
fi
debug "Done!"
}
install_drupal() {
debug "Installing drupal ($SITENAME)"
install_drupal$DRUPAL
}
install_drupal7() {
# Do a drush site install
$DRUSH -q -y -r $MULTISITE site-install $PROFILE --locale=da --db-url="mysql://$DBUSER:$DBPASS@$DBHOST/$DBNAME" --sites-subdir="$SITENAME" --account-mail="$EMAIL" --site-mail="$EMAIL" --site-name="$SITENAME" --account-pass="$ADMINPASS"
# Set tmp
$DRUSH -q -y -r "$MULTISITE" --uri="$SITENAME" vset file_temporary_path "$TMPDIR"
# Do some drupal setup here. Could also be done in the install profile.
$DRUSH -q -y -r "$MULTISITE" --uri="$SITENAME" vset user_register 0
$DRUSH -q -y -r "$MULTISITE" --uri="$SITENAME" vset error_level 1
$DRUSH -q -y -r "$MULTISITE" --uri="$SITENAME" vset preprocess_css 1
$DRUSH -q -y -r "$MULTISITE" --uri="$SITENAME" vset preprocess_js 1
#$DRUSH -q -y -r "$MULTISITE" --uri="$SITENAME" vset cache 1
$DRUSH -q -y -r "$MULTISITE" --uri="$SITENAME" vset page_cache_maximum_age 10800
# translation updates - takes a long time
#$DRUSH -q -y -r "$MULTISITE" --uri="$SITENAME" l10n-update-refresh
#$DRUSH -q -y -r "$MULTISITE" --uri="$SITENAME" l10n-update
$DRUSH -q -y -r "$MULTISITE" --uri="$SITENAME" dis update
if [ -n "$(type -t ${FUNCNAME[0]}_local)" ] && [ "$(type -t ${FUNCNAME[0]}_local)" = function ]; then
${FUNCNAME[0]}_local
fi
}
install_drupal8() {
debug "Checking db connection before staring installation process."
check DB_CONNECTION
debug "Starting install Drupal"
# Preparing site folder
mkdir -p "$MULTISITE/sites/$SITENAME"
chown www-data: "$MULTISITE/sites/$SITENAME"
cp $MULTISITE/sites/default/default.settings.php $MULTISITE/sites/$SITENAME/settings.php
if [ $(echo ${PROFILE} | cut -d"=" -f1) == '--existing-config' ]; then
CONFIG_DIR=$(echo ${PROFILE} | cut -d"=" -f2)
PROFILE=$(echo ${PROFILE} | cut -d"=" -f1)
else
CONFIG_DIR=$BASEDIR/config/$SITENAME/sync
mkdir -p $CONFIG_DIR
fi
echo "\$settings['config_sync_directory'] = \"$CONFIG_DIR\";" >> $MULTISITE/sites/$SITENAME/settings.php
echo "\$settings['file_temp_path'] = \"$TMPDIR\";" >> $MULTISITE/sites/$SITENAME/settings.php
# Do a drush site install
$DRUSH -y -r $MULTISITE site-install $PROFILE --locale=da --db-url="mysql://$DBUSER:$DBPASS@$DBHOST/$DBNAME" --sites-subdir="$SITENAME" --account-mail="$EMAIL" --site-mail="$EMAIL" --site-name="$SITENAME" --account-pass="$ADMINPASS" $INSTALL_OPTIONS
debug "Drupal install phase succesfuly finished"
# Set tmp
$DRUSH -y -r "$MULTISITE" --uri="$SITENAME" config-set system.file path.temporary "$TMPDIR"
# Do some drupal setup here. Could also be done in the install profile.
$DRUSH -y -r "$MULTISITE" --uri="$SITENAME" cset user.settings register admin_only
$DRUSH -y -r "$MULTISITE" --uri="$SITENAME" cset system.logging error_level some
$DRUSH -y -r "$MULTISITE" --uri="$SITENAME" config-set system.performance css.preprocess 1
$DRUSH -y -r "$MULTISITE" --uri="$SITENAME" config-set system.performance js.preprocess 1
$DRUSH -y -r "$MULTISITE" --uri="$SITENAME" config-set system.performance cache.max.age 10800
$DRUSH -y -r "$MULTISITE" --uri="$SITENAME" pm:uninstall update
debug "Update translations"
$DRUSH -y -r "$MULTISITE" --uri="$SITENAME" locale-check
$DRUSH -y -r "$MULTISITE" --uri="$SITENAME" locale-update
if [ -n "$(type -t ${FUNCNAME[0]}_local)" ] && [ "$(type -t ${FUNCNAME[0]}_local)" = function ]; then
${FUNCNAME[0]}_local
fi
}
set_permissions() {
debug "Setting correct permissions"
/bin/chgrp -R $APACHEUSER "$MULTISITE/sites/$SITENAME"
/bin/chmod -R g+rwX "$MULTISITE/sites/$SITENAME"
/bin/chmod g-w "$MULTISITE/sites/$SITENAME" "$MULTISITE/sites/$SITENAME/settings.php"
/bin/chown -R $APACHEUSER "$TMPDIR"
/bin/chmod -R g+rwX "$TMPDIR"
/bin/chown -R $APACHEUSER "$BASEDIR/config"
/bin/chmod -R g+rwX "$BASEDIR/config"
if [ -n "$(type -t ${FUNCNAME[0]}_local)" ] && [ "$(type -t ${FUNCNAME[0]}_local)" = function ]; then
${FUNCNAME[0]}_local
fi
}
add_to_crontab() {
debug "Adding Drupal cron.php to $APACHEUSER crontab"
# if shuf is available, then run cron at random minutes
if [ -x "/usr/bin/shuf" ]; then
CRONMINUTE=$(shuf -i 0-59 -n 1)
else
CRONMINUTE=0
fi
set_crontab$DRUPAL
}
set_crontab7() {
CRONKEY=$($DRUSH -r "$MULTISITE" --uri="$SITENAME" vget cron_key | cut -d \' -f 2)
CRONLINE="$CRONMINUTE */2 * * * /usr/bin/wget -O - -q -t 1 http://$SITENAME/cron.php?cron_key=$CRONKEY"
if [ -n "$(type -t ${FUNCNAME[0]}_local)" ] && [ "$(type -t ${FUNCNAME[0]}_local)" = function ]; then
${FUNCNAME[0]}_local
fi
(/usr/bin/crontab -u $APACHEUSER -l; echo "$CRONLINE") | /usr/bin/crontab -u $APACHEUSER -
}
set_crontab8() {
CRONLINE="$CRONMINUTE */2 * * * $DRUSH --root=$MULTISITE --uri=$SITENAME cron -q"
if [ -n "$(type -t ${FUNCNAME[0]}_local)" ] && [ "$(type -t ${FUNCNAME[0]}_local)" = function ]; then
${FUNCNAME[0]}_local
fi
(/usr/bin/crontab -u $APACHEUSER -l; echo "$CRONLINE") | /usr/bin/crontab -u $APACHEUSER -
}
mail_status() {
debug "Sending statusmail ($SITENAME)"
}
add_subsiteadmin() {
debug "Create subsiteadmin user with email ($USEREMAIL)"
# This function compatible with Drupal 7/8
# Create user with email specified in subsitecreator.
$DRUSH -y -r "$MULTISITE" --uri="$SITENAME" user-create subsiteadmin --mail="$USEREMAIL"
# Add the role "subsiteadmin"
if [ -z "$(${DRUSH} -r "$MULTISITE" --uri="$SITENAME" role:list | grep subsiteadmin)" ]; then
debug "Role subsiteadmin is not created yet. You have to create it manually."
else
debug "Add the role subsiteadmin"
$DRUSH -y -r "$MULTISITE" --uri="$SITENAME" user-add-role subsiteadmin subsiteadmin
fi
# Send single-use login link.
$DRUSH -y -r "$MULTISITE" --uri="$SITENAME" ev "_user_mail_notify('password_reset', user_load_by_mail('$USEREMAIL'));"
if [ -n "$(type -t ${FUNCNAME[0]}_local)" ] && [ "$(type -t ${FUNCNAME[0]}_local)" = function ]; then
${FUNCNAME[0]}_local
fi
}
delete_vhost() {
debug "Disabling and deleting $SITENAME vhost files if present"
if [ -f "/etc/apache2/sites-enabled/$SITENAME.conf" ]
then
rm -f "/etc/apache2/sites-enabled/$SITENAME.conf"
fi
if [ -f "/etc/apache2/sites-available/$SITENAME.conf" ]
then
rm -f "/etc/apache2/sites-available/$SITENAME.conf"
fi
debug "Reloading Apache2"
if [ -f /etc/init.d/apache2 ]; then
/etc/init.d/apache2 reload >/dev/null
else
echo "apachectl graceful"
fi
}
delete_db() {
if [ -z "$1" ]; then
echo "ERROR: delete_db called without an argument"
exit 10
fi
if [ -v EXTERNAL_DB_PROVISIONING ]
then
echo "NOTICE: External DB provisioning is used. Can not check if database or database user exists."
else
local DBNAME=$1
DBUSER=$(echo "$DBNAME" | cut -c 1-16)
debug "Backing up, then deleting database ($DBNAME) and database user ($DBUSER)"
# backup first, just in case
#/usr/local/sbin/mysql_backup.sh "$DBNAME"
/usr/bin/mysql -u root -e "DROP DATABASE $DBNAME;"
/usr/bin/mysql -u root -e "DROP USER $DBUSER@$DBHOST";
fi
}
delete_dirs() {
if [ -d "$TMPDIR" ]; then
rm -rf "$TMPDIR"
fi
if [ -d "$LOGDIR" ]; then
rm -rf "$LOGDIR"
fi
if [ -d "$SESSIONDIR" ]; then
rm -rf "$SESSIONDIR"
fi
if [ -d "$SITEDIR" ]; then
rm -rf "$SITEDIR"
fi
if [ -d "$BASEDIR/config/$SITENAME" ]; then
rm -rf "$BASEDIR/config/$SITENAME"
fi
if [ -n "$(type -t ${FUNCNAME[0]}_local)" ] && [ "$(type -t ${FUNCNAME[0]}_local)" = function ]; then
${FUNCNAME[0]}_local
fi
}
remove_from_crontab() {
debug "Removing Drupal cron.php from $APACHEUSER crontab ($SITENAME) if present"
crontab -u $APACHEUSER -l | sed "/$SITENAME/d" | crontab -u $APACHEUSER -
}
add_to_vhost() {
debug "Adding $NEWDOMAIN to vhost for $SITENAME"
/usr/bin/perl -p -i -e "s/ServerName $SITENAME/ServerName $SITENAME\n ServerAlias $NEWDOMAIN/g" "$VHOST"
debug "Reloading Apache2"
if [ -f /etc/init.d/apache2 ]; then
/etc/init.d/apache2 reload >/dev/null
else
echo "apachectl graceful"
fi
}
add_to_sites() {
debug "Adding $NEWDOMAIN to sites.php"
echo "\$sites['$NEWDOMAIN'] = '$SITENAME';" >> $SITESFILE
if [ -n "$(type -t ${FUNCNAME[0]}_local)" ] && [ "$(type -t ${FUNCNAME[0]}_local)" = function ]; then
${FUNCNAME[0]}_local
fi
}
remove_from_vhost() {
debug "Removing $REMOVEDOMAIN from vhost for $SITENAME"
sed -i "/ServerAlias\ $REMOVEDOMAIN\$/d" "$VHOST"
debug "Reloading Apache2"
if [ -f /etc/init.d/apache2 ]; then
/etc/init.d/apache2 reload >/dev/null
else
apachectl graceful
fi
}
transfer_base_files() {
if [[ -n "$BASE_SUBSITE_DIR" ]]
debug "Base subsite dir: ${BASE_SUBSITE_DIR}"
debug "Copying files from base subsite dir to new subsite"
/usr/bin/rsync -rtOXpal "$BASE_SUBSITE_DIR/files/" "$MULTISITE/sites/$SITENAME/files"
else
debug "BASE_SUBSITE_DIR not set, not copying files"
fi
}