-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathcivibuild.lib.sh
1435 lines (1270 loc) · 54.3 KB
/
civibuild.lib.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
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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
## Bash helper functions
## Coding conventions:
## - Function names are "{prefix}_{name}"; prefixes are "cvutil", "civicrm", "wp", etc
## - Options are set as (global) environment variables
## - Functions declare dependencies on (global) environment variables (cvutil_assertvars).
## If a variable missing, the application dies.
###############################################################################
## Assert that shell variables are defined. If not defined, exit with an error.
## usage: assertvars <context> <var1> <var2> <var3> ...
## exmple: cvutil_assertvars civibuild_app_download WEB_ROOT PRJDIR CACHE_DIR SITE_NAME SITE_TYPE
function cvutil_assertvars() {
_cvutil_assertvars_back="$-"
# disable verbose output:
set +x
# the calling function name:
context="$1"
shift
while [ "$1" ]; do
var="$1"
eval "val=\$$var"
if [ -z "$val" ]; then
echo "missing variable: $var [in $context]"
exit 98
fi
shift
done
#restore previous bash options (revert set +x)
set -${_cvutil_assertvars_back}
}
###############################################################################
## Run a PHP program and explicitly disable debugging.
## usage: cvutil_php_nodbg <program name> [<args>...]
function cvutil_php_nodbg() {
local cmd=$(which "$1")
[ -z "$cmd" ] && cvutil_fatal "Failed to locate $cmd"
shift
php -d xdebug.remote_enable=off "$cmd" "$@"
}
###############################################################################
## Find the location of <item> in a list of paths.
## usage: cvutil_path_search <item> <parent1>:<parent2>:...
## example: cvutil_path_search ls /usr/local/bin:/usr/bin:/bin
function cvutil_path_search() {
local search_target="$1"
local search_paths="$2"
printf %s "$search_paths" | awk 'BEGIN {RS=":"}; 1' | while read candidate ; do
if [ -n "$candidate" -a -e "$candidate/$search_target" ]; then
echo "$candidate/$search_target"
break
fi
done
}
###############################################################################
## Prompt user for confirmation
## (In automated scripts or blank response, use default)
##
## usage: cvutil_confirm <message> <interactive-default> <script-default>
## example: cvutil_confirm "Are you sure? [Y/n] " y y
function cvutil_confirm() {
local msg="$1"
local i_default="$2"
local s_default="$3"
if tty -s ; then
echo -n "$msg"
read _cvutil_confirm
if [ "x$_cvutil_confirm" == "x" ]; then
_cvutil_confirm="$i_default"
fi
else
echo "${msg}${s_default}"
_cvutil_confirm="$s_default"
fi
case "$_cvutil_confirm" in
y|Y|1)
return 0
;;
*)
return 1
;;
esac
}
###############################################################################
## Save a list of environment variables to a file
## usage: cvutil_save() <filename> <var1> <var2> ...
function cvutil_save() {
file="$1"
shift
echo "#!/bin/bash" > $file
for var in "$@" ; do
eval "val=\$$var"
echo "$var=\"$val\"" >> $file
done
}
###############################################################################
## Export environment variables for use by a sub-process
## usage: cvutil_export() <var1> <var2> ...
function cvutil_export() {
for var in "$@" ; do
export $var
done
}
###############################################################################
## usage: cvutil-fatal <message>
function cvutil_fatal() {
echo "$@" >&2
exit 90
}
###############################################################################
## Delete a file try, overriding any unwriteable file permissions
function cvutil_rmrf() {
local folder="$1"
if [ -z "$folder" ]; then
return
fi
if [ ! -e "$folder" ]; then
return
fi
find "$folder" -type d -print0 | xargs -0 -n 20 chmod u+w
rm -rf "$folder"
}
###############################################################################
## Summarize the content of key environment variables
## usage: cvutil_summary <message> <var1> <var2> ...
function cvutil_summary() {
# Not asserting any vars because then we can't report that they are in fact empty.
if [ -n "$1" ]; then
echo $1
fi
shift
for var in "$@" ; do
eval "val=\$$var"
echo " - $var: $val"
done
}
###############################################################################
## usage: cvutil_makepasswd <strlen>
function cvutil_makepasswd() {
cvutil_php_nodbg mkpasswd.php "$@"
}
###############################################################################
## Ensure that the parent directory exists
## usage: cvutil_makeparent <file>
function cvutil_makeparent() {
parent=$(dirname "$1")
if [ ! -d "$parent" ]; then
mkdir -p "$parent"
fi
}
###############################################################################
## Ensure that a directory exists
## cvutil_mkdir <dir1> <dir2> ...
function cvutil_mkdir() {
for f in "$@" ; do
if [ ! -d "$f" ]; then
mkdir -p "$f"
fi
done
}
###############################################################################
## Compose a new URL For a site
## Usage: myurl=$(cvutil_mkurl <shortname>)
function cvutil_mkurl() {
local subsite_name="$1"
cvutil_assertvars cvutil_mkurl URL_TEMPLATE
if [ "%AUTO%" == "$URL_TEMPLATE" ]; then
echo "http://%subsite_name%.test" | sed "s;%SITE_NAME%;$subsite_name;g"
else
echo "$URL_TEMPLATE" | sed "s;%SITE_NAME%;$subsite_name;g"
fi
}
###############################################################################
## Combine host and port to a single string
## usage: MY_VAR=$(cvutil_build_hostport $MY_HOST $MY_PORT )
function cvutil_build_hostport() {
local host=$1
local port=$2
if [ -z "$port" ]; then
echo "$host"
else
echo "$host:$port"
fi
}
###############################################################################
## Parse the name and ID from
## usage: eval $(cvutil_parse_site_name_id "NAME[/ID]")
## example: $(cvutil_parse_site_name_id "drupal-demo/2") ==> SITE_NAME=drupal-demo SITE_ID=2
## example: $(cvutil_parse_site_name_id "drupal-demo") ==> SITE_NAME=drupal-demo
function cvutil_parse_site_name_id() {
php -r '$parts=explode("/", $argv[1]);echo "SITE_NAME=" . $parts[0]."\n"; if (isset($parts[1])) echo "SITE_ID=" . $parts[1] . "\n";' -- "$1"
}
###############################################################################
## Append the civibuild settings directives to a file
## usage: cvutil_inject_settings <php-file> <settings-dir-name> [<preamble>]
## example: cvutil_inject_settings "/var/www/build/drupal/sites/foo/civicrm.settings.php" "civicrm.settings.d"
## example: cvutil_inject_settings "/var/www/build/drupal/sites/foo/settings.php" "drupal.settings.d" 'global $settings;'
function cvutil_inject_settings() {
local FILE="$1"
local NAME="$2"
local PREAMBLE="$3"
cvutil_assertvars cvutil_inject_settings PRJDIR CIVI_CRED_KEY CIVI_SIGN_KEY SITE_NAME SITE_TYPE SITE_CONFIG_DIR SITE_ID SITE_TOKEN PRIVATE_ROOT FILE NAME
# Note: CMS_VERSION ought to be defined for use in $civibuild['CMS_VERSION'], but it hasn't always been, and for most build-types its absence would be non-fatal.
## Prepare temp file
local TMPFILE="${TMPDIR}/${SITE_TYPE}/${SITE_NAME}/${SITE_ID}.settings.tmp"
cvutil_makeparent "$TMPFILE"
cat > "$TMPFILE" << EOF
<?php
#### If deployed via civibuild, include any "pre" scripts
global \$civibuild;
\$civibuild['PRJDIR'] = '$PRJDIR';
\$civibuild['SITE_CONFIG_DIR'] = '$SITE_CONFIG_DIR';
\$civibuild['SITE_TYPE'] = '$SITE_TYPE';
\$civibuild['SITE_NAME'] = '$SITE_NAME';
\$civibuild['SITE_ID'] = '$SITE_ID';
\$civibuild['SITE_TOKEN'] = '$SITE_TOKEN';
\$civibuild['PRIVATE_ROOT'] = '$PRIVATE_ROOT';
\$civibuild['WEB_ROOT'] = '$WEB_ROOT';
\$civibuild['CMS_ROOT'] = '$CMS_ROOT';
\$civibuild['CMS_VERSION'] = '$CMS_VERSION';
$PREAMBLE
if (file_exists(\$civibuild['PRJDIR'].'/src/civibuild.settings.php')) {
require_once \$civibuild['PRJDIR'].'/src/civibuild.settings.php';
_civibuild_settings(__FILE__, '$NAME', \$civibuild, 'pre');
}
EOF
# Don't know if FILE has good newlines, so prefix/postfix both have extras
sed 's/^<?php//' < "$FILE" >> "$TMPFILE"
cat >> "$TMPFILE" << EOF
#### If deployed via civibuild, include any "post" scripts
if (file_exists(\$civibuild['PRJDIR'].'/src/civibuild.settings.php')) {
require_once \$civibuild['PRJDIR'].'/src/civibuild.settings.php';
_civibuild_settings(__FILE__, '$NAME', \$civibuild, 'post');
}
EOF
## Replace main file with temp file
cat < "$TMPFILE" > "$FILE"
}
###############################################################################
## usage: cvutil_is_action <string-to-test>
function cvutil_is_action() {
local action=$1
ACTION_VALIDATED=0
for a in $DECLARED_ACTIONS; do
if [ $a == $action ]; then
ACTION_VALIDATED=1
fi
done
}
###############################################################################
## usage: http_download <url> <local-file>
function http_download() {
#php -r "echo file_get_contents('$1');" > $2
if which wget >> /dev/null ; then
timeout.php $SCM_TIMEOUT wget -O "$2" "$1"
elif which curl >> /dev/null ; then
timeout.php $SCM_TIMEOUT curl -L -o "$2" "$1"
else
echo "error: failed to locate curl or wget"
fi
}
## usage: http_cache_setup <url> <local-file> [<ttl-minutes>]
function http_cache_setup() {
local url="$1"
local cachefile="$2"
local lock="${cachefile}.lock"
local lastrun="${cachefile}.lastrun"
local ttl=${3:-$CACHE_TTL}
if [ -f "$cachefile" -a -f "$lastrun" ]; then
if php -r 'exit($argv[1] + file_get_contents($argv[2]) < time() ? 1 : 0);' -- "$ttl" "$lastrun" ; then
echo "SKIP: http_cache_setup '$url' $cachefile' (recently updated; ttl=$ttl)"
return
fi
fi
cvutil_makeparent "$lock"
if cvutil_php_nodbg pidlockfile.php "$lock" $$ $CACHE_LOCK_WAIT ; then
php -r 'echo time();' > $lastrun
if [ ! -f "$cachefile" -o -z "$OFFLINE" ]; then
echo "[[Update HTTP cache: $url => $cachefile]]"
cvutil_makeparent "$cachefile"
http_download "$url" "$cachefile"
else
echo "[[Offline mode. Skip cache update: $cachefile]]"
fi
rm -f "$lock"
else
echo "ERROR: http_cache_setup '$url' '$cachdir': failed to acquire lock"
fi
}
###############################################################################
## Setup HTTP and MySQL services
## This outputs several variables: CMS_URL, CMS_DB_*, CIVI_DB_*, and TEST_DB_*
function amp_install() {
## TODO: single-db support
_amp_install_cms
_amp_install_civi
_amp_install_test
}
function _amp_install_cms() {
echo "[[Setup MySQL and HTTP for CMS]]"
cvutil_assertvars _amp_install_cms CMS_ROOT SITE_NAME SITE_ID TMPDIR
local amp_vars_file_path=$(cvutil_php_nodbg mktemp.php ampvar)
local amp_name="cms$SITE_ID"
[ "$SITE_ID" == "default" ] && amp_name=cms
if [ -n "$CMS_URL" ]; then
cvutil_php_nodbg amp create -f --root="$CMS_ROOT" --name="$amp_name" --prefix=CMS_ --url="$CMS_URL" --output-file="$amp_vars_file_path" --perm="$CMS_DB_PERM"
else
cvutil_php_nodbg amp create -f --root="$CMS_ROOT" --name="$amp_name" --prefix=CMS_ --output-file="$amp_vars_file_path" --perm="$CMS_DB_PERM"
fi
source "$amp_vars_file_path"
rm -f "$amp_vars_file_path"
}
function _amp_install_civi() {
echo "[[Setup MySQL for Civi]]"
cvutil_assertvars _amp_install_civi CMS_ROOT SITE_NAME SITE_ID TMPDIR
local amp_vars_file_path=$(cvutil_php_nodbg mktemp.php ampvar)
local amp_name="civi$SITE_ID"
[ "$SITE_ID" == "default" ] && amp_name=civi
cvutil_php_nodbg amp create -f --root="$CMS_ROOT" --name="$amp_name" --prefix=CIVI_ --skip-url --output-file="$amp_vars_file_path" --perm="$CIVI_DB_PERM"
source "$amp_vars_file_path"
rm -f "$amp_vars_file_path"
}
function _amp_install_test() {
echo "[[Setup MySQL for Test]]"
cvutil_assertvars _amp_install_test CMS_ROOT SITE_NAME SITE_ID TMPDIR
local amp_vars_file_path=$(cvutil_php_nodbg mktemp.php ampvar)
local amp_name="test$SITE_ID"
[ "$SITE_ID" == "default" ] && amp_name=test
cvutil_php_nodbg amp create -f --root="$CMS_ROOT" --name="$amp_name" --prefix=TEST_ --skip-url --output-file="$amp_vars_file_path" --perm="$TEST_DB_PERM"
source "$amp_vars_file_path"
rm -f "$amp_vars_file_path"
}
## Create a headless clone DB
## usage: _amp_install_clone <name> <shell-prefix>
## example: _amp_install_clone cms CLONE_CMS
## example: _amp_install_clone civi CLONE_CIVI
function _amp_install_clone() {
echo "[[Setup MySQL for \"$2\"]]"
cvutil_assertvars _amp_install_cms CLONE_DIR SITE_NAME SITE_ID TMPDIR
local amp_vars_file_path=$(cvutil_php_nodbg mktemp.php ampvar)
cvutil_php_nodbg amp create -f --root="$CLONE_DIR" --name=$1 --prefix=$2_ --skip-url --output-file="$amp_vars_file_path" --perm="$CIVI_DB_PERM"
source "$amp_vars_file_path"
rm -f "$amp_vars_file_path"
}
## Export the description of an amp install and import as shell variables
## usage: _amp_import <root> <name> <shell-prefix>
## example: _amp_imprt /var/www/build/myproject civi CIVI
function _amp_import() {
cvutil_assertvars _amp_import SITE_NAME SITE_ID TMPDIR
local amp_vars_file_path=$(cvutil_php_nodbg mktemp.php ampvar)
cvutil_php_nodbg amp export --root="$1" --name=$2 --prefix=$3_ --output-file="$amp_vars_file_path"
source "$amp_vars_file_path"
rm -f "$amp_vars_file_path"
}
###############################################################################
## Backup the databases & http config (using the same structure as amp_install)
function amp_snapshot_create() {
## TODO: single-db support
if [ -z "$CMS_SQL_SKIP" ]; then
echo "[[Save CMS DB ($CMS_DB_NAME) to file ($CMS_SQL)]]"
cvutil_assertvars amp_snapshot_create CMS_SQL CMS_DB_ARGS CMS_DB_NAME
cvutil_makeparent "$CMS_SQL"
cvutil_php_nodbg amp sql:dump --root="$CMS_ROOT" --passthru="--no-tablespaces" -Ncms | gzip > "$CMS_SQL"
fi
if [ -z "$CIVI_SQL_SKIP" ]; then
echo "[[Save Civi DB ($CIVI_DB_NAME) to file ($CIVI_SQL)]]"
cvutil_assertvars amp_snapshot_create CIVI_SQL CIVI_DB_ARGS CIVI_DB_NAME
cvutil_makeparent "$CIVI_SQL"
cvutil_php_nodbg amp sql:dump --root="$CMS_ROOT" --passthru="--no-tablespaces" -Ncivi | gzip > "$CIVI_SQL"
fi
}
###############################################################################
## Restore the databases & http config (using the same structure as amp_install)
function amp_snapshot_restore() {
## TODO: single-db support
if [ -z "$CMS_SQL_SKIP" ]; then
_amp_snapshot_restore_cms
fi
if [ -z "$CIVI_SQL_SKIP" ]; then
_amp_snapshot_restore_civi
fi
if [ -z "$TEST_SQL_SKIP" ]; then
_amp_snapshot_restore_test
fi
}
function _amp_snapshot_restore_cms() {
local orig_CMS_DB_DSN="$CMS_DB_DSN"
_amp_install_cms
if [ "$CMS_DB_DSN" != "$orig_CMS_DB_DSN" ]; then
## shouldn't happen unless someone has been mucking around...
echo "WARNING: CMS DB has changed! Config files may be stale!" 1>&2
echo " OLD: $orig_CMS_DB_DSN" 1>&2
echo " NEW: $CMS_DB_DSN" 1>&2
fi
_amp_snapshot_restore "$CMS_ROOT" cms "$CMS_SQL"
}
function _amp_snapshot_restore_civi() {
local orig_CIVI_DB_DSN="$CIVI_DB_DSN"
_amp_install_civi
if [ "$CIVI_DB_DSN" != "$orig_CIVI_DB_DSN" ]; then
## shouldn't happen unless someone has been mucking around...
echo "WARNING: Civi DB has changed! Config files may be stale!" 1>&2
echo " OLD: $orig_CIVI_DB_DSN" 1>&2
echo " NEW: $CIVI_DB_DSN" 1>&2
fi
_amp_snapshot_restore "$CMS_ROOT" civi "$CIVI_SQL"
}
function _amp_snapshot_restore_test() {
local orig_TEST_DB_DSN="$TEST_DB_DSN"
_amp_install_test
if [ "$TEST_DB_DSN" != "$orig_TEST_DB_DSN" ]; then
## shouldn't happen unless someone has been mucking around...
echo "WARNING: TEST DB has changed! Config files may be stale!" 1>&2
echo " OLD: $orig_TEST_DB_DSN" 1>&2
echo " NEW: $TEST_DB_DSN" 1>&2
fi
_amp_snapshot_restore "$CMS_ROOT" test "$CIVI_SQL"
}
## Load a sql snapshot into the given DB
## usage: _amp_snapshot_restore <DB_PREFIX> <sql-file>
## example: _amp_snapshot_restore_clone CMS "/path/to/cms.sql.gz"
## example: _amp_snapshot_restore_clone CIVI "/path/to/civi.sql.gz"
function _amp_snapshot_restore_clone() {
cvutil_assertvars amp_snapshot_restore_X $1_DB_ARGS $1_DB_NAME
local db_name=$(eval echo \$${1}_DB_NAME)
local db_args=$(eval echo \$${1}_DB_ARGS)
local sql_file="$2"
echo "[[Restore \"$1\" DB ($db_name) from file ($sql_file)]]"
if [ ! -f "$sql_file" ]; then
echo "Missing SQL file: $sql_file" 1>&2
exit 1
fi
gunzip --stdout "$sql_file" | eval mysql $db_args
}
## Load a sql snapshot into the given DB
## usage: _amp_snapshot_restore <amproot> <ampname> <sql-file>
## example: _amp_snapshot_restore "$CMS_ROOT" civi "/path/to/cms.sql.gz"
function _amp_snapshot_restore() {
cvutil_assertvars amp_snapshot_restore_X $1_DB_ARGS $1_DB_NAME
local db_root="$1"
local db_name="$2"
local sql_file="$3"
echo "[[Restore \"$1\" DB ($db_name) from file ($sql_file)]]"
if [ ! -f "$sql_file" ]; then
echo "Missing SQL file: $sql_file" 1>&2
exit 1
fi
gunzip --stdout "$sql_file" | cvutil_php_nodbg amp sql --root="$db_root" --name="$db_name"
}
###############################################################################
## Tear down HTTP and MySQL services
function amp_uninstall() {
echo "WARNING: amp_uninstall: Retaining DB & site config to provide continuity among rebuilds"
}
###############################################################################
## Download APIv4, if it's not built into the target version of Civi
## usage: api4_download_conditional <civicrm-path> <api4-path>
function api4_download_conditional() {
cvutil_assertvars api4_download_conditional CIVI_VERSION CACHE_DIR
local civi_path="$1"
local api4_path="$2"
if [ -z "$api4_path" -o -z "$civi_path" ]; then
cvutil_fatal "Cannot download api4: Target path not specified"
fi
if [ ! -e "$civi_path" ]; then
cvutil_fatal "Cannot download api4: Must download civicrm-core first"
fi
if [ -e "$civi_path/Civi/Api4" ]; then
## Circa 5.19.alpha, api4 is merged into core.
echo "Found api4 in core: "$civi_path/Civi/Api4""
return;
fi
case "$CIVI_VERSION" in
## Circa v5.16 (3e20c1acb397d6dfe?), api4+core got into a bidrectional dependency, and api4@~4.5
## seems to be the closest release that corresponds to the dev-periods of 5.16-5.18.
## Circa v5.19.alpha1 (#15309), api4 should be merged into core.
master|5.16*|5.17*|5.18*|5.19*) git clone "${CACHE_DIR}/civicrm/api4.git" -b "4.5" "$api4_path" ;;
# 5.14*|5.15*) git clone "${CACHE_DIR}/civicrm/api4.git" -b "4.4" "$api4_path" ;;
*) echo "Skipping api4 download" ;; ## Shrug
##EXTCIVIVER=$( php -r '$x=simplexml_load_file("civicrm/xml/version.xml"); echo $x->version_no;' )
##cv dl -b "@https://civicrm.org/extdir/ver=$EXTCIVIVER|cms=Drupal|status=|ready=/org.civicrm.api4.xml" --to="$WEB_ROOT/web/sites/all/modules/civicrm/ext/api4" --dev
esac
}
###############################################################################
## Download CiviCRM (via composer, into an existing D8/composer project)
##
## This function shouldn't be necessary in the long-term; but for testing
## right now across different versions, we need some hackery/backporting,
## and this allows one to avoid copy-pasting those fiddly bits.
##
## Be sure to "cd" into the root of the composer project, then call `civicrm_download_composer_d8`
function civicrm_download_composer_d8() {
cvutil_assertvars civicrm_download_composer_d8 CIVI_VERSION CMS_VERSION
composer config 'extra.enable-patching' true
## Ensure that we compile all our js as necessary
composer config extra.compile-mode all
composer config minimum-stability dev
local CIVI_VERSION_COMP=$(civicrm_composer_ver "$CIVI_VERSION")
local EXTRA_COMPOSER=()
local EXTRA_PATCH=()
case "$CIVI_VERSION" in
5.21*) EXTRA_COMPOSER+=( 'civicrm/civicrm-asset-plugin:~1.1' ) ; EXTRA_COMPOSER+=( "civicrm/civicrm-setup:0.4.0 as 0.2.99" ) ; EXTRA_COMPOSER+=( 'cache/integration-tests:dev-master#b97328797ab199f0ac933e39842a86ab732f21f9' ) ; EXTRA_PATCH+=( "https://github.com/civicrm/civicrm-core/pull/16328" ); ;;
5.22*) EXTRA_COMPOSER+=( 'civicrm/civicrm-asset-plugin:~1.1' ) ; EXTRA_COMPOSER+=( "civicrm/civicrm-setup:0.4.0 as 0.2.99" ) ; EXTRA_COMPOSER+=( 'cache/integration-tests:dev-master#b97328797ab199f0ac933e39842a86ab732f21f9' ) ; EXTRA_PATCH+=( "https://github.com/civicrm/civicrm-core/pull/16413" ); ;;
5.23*) EXTRA_COMPOSER+=( 'civicrm/civicrm-asset-plugin:~1.1' ) ; EXTRA_COMPOSER+=( 'cache/integration-tests:dev-master#b97328797ab199f0ac933e39842a86ab732f21f9' ); ;;
5.24*) EXTRA_COMPOSER+=( 'civicrm/civicrm-asset-plugin:~1.1' ) ; ;;
5.25*) EXTRA_COMPOSER+=( 'civicrm/civicrm-asset-plugin:~1.1' ) ; ;;
5.26*) EXTRA_COMPOSER+=( 'civicrm/civicrm-asset-plugin:~1.1' ) ; ;;
5.27*) EXTRA_COMPOSER+=( 'civicrm/civicrm-asset-plugin:~1.1' ) ; ;;
5.28*) EXTRA_COMPOSER+=( 'civicrm/civicrm-asset-plugin:~1.1' ) ; ;;
5.29*) EXTRA_COMPOSER+=( 'civicrm/civicrm-asset-plugin:~1.1' ) ; ;;
5.30*) EXTRA_COMPOSER+=( 'civicrm/civicrm-asset-plugin:~1.1' ) ; ;;
*) echo "No extra patches required" ; ;;
esac
case "$CMS_VERSION" in
9.2*) echo 'No Extra Patch required' ; ;;
9.1*) echo 'No Extra Patch required' ; ;;
9*) echo 'No Extra Patch required' ; ;;
8.9*) echo 'No Extra Patch required' ; ;;
*) EXTRA_COMPOSER+=( 'pear/pear_exception:1.0.1 as 1.0.0') ## weird conflict in drupal-composer/drupal-project
esac
composer require "${EXTRA_COMPOSER[@]}" civicrm/civicrm-{core,packages,drupal-8}:"$CIVI_VERSION_COMP" --prefer-source
[ -n "$EXTRA_PATCH" ] && git scan am -N "${EXTRA_PATCH[@]}"
local civicrm_version_php=$(find -name civicrm-version.php)
if [ -f "$civicrm_version_php" ]; then
local civi_root=$(dirname "$civicrm_version_php")
#extract-url --cache-ttl 172800 vendor/civicrm/civicrm-core=http://download.civicrm.org/civicrm-l10n-core/archives/civicrm-l10n-daily.tar.gz ## Issue: Don't write directly into vendor tree
extract-url --cache-ttl 172800 "$civi_root=http://download.civicrm.org/civicrm-l10n-core/archives/civicrm-l10n-daily.tar.gz" ## Issue: Don't write directly into vendor tree
else
cvutil_fatal "Cannot download l10n data - failed to locate civicrm-core"
fi
}
###############################################################################
## Generate config files and setup database
function civicrm_install() {
cvutil_assertvars civicrm_install CIVI_CORE CIVI_FILES CIVI_TEMPLATEC
if [ ! -d "$CIVI_CORE/bin" -o ! -d "$CIVI_CORE/CRM" ]; then
cvutil_fatal "Failed to locate valid civi root: $CIVI_CORE"
fi
## Create CiviCRM data dirs
cvutil_php_nodbg amp datadir "$CIVI_FILES" "$CIVI_TEMPLATEC"
if [ -n "$CIVI_EXT_DIR" ]; then
cvutil_php_nodbg amp datadir "$CIVI_EXT_DIR"
fi
## Create CiviCRM config files
civicrm_make_settings_php
civicrm_make_setup_conf
civicrm_make_test_settings_php
pushd "$CIVI_CORE" >> /dev/null
## Does this build include development support (eg git or tarball-based)?
if [ -e "xml" -a -e "bin/setup.sh" -a -n "$NO_SAMPLE_DATA" ]; then
env SITE_ID="$SITE_ID" bash ./bin/setup.sh -Dgsdf
elif [ -e "xml" -a -e "bin/setup.sh" -a -z "$NO_SAMPLE_DATA" ]; then
env SITE_ID="$SITE_ID" bash ./bin/setup.sh
elif [ -e "sql/civicrm.mysql" -a -e "sql/civicrm_generated.mysql" -a -z "$NO_SAMPLE_DATA" ]; then
cat sql/civicrm.mysql sql/civicrm_generated.mysql | cvutil_php_nodbg amp sql -Ncivi --root="$CMS_ROOT"
elif [ -e "sql/civicrm.mysql" -a -e "sql/civicrm_data.mysql" -a -n "$NO_SAMPLE_DATA" ]; then
cat sql/civicrm.mysql sql/civicrm_data.mysql | cvutil_php_nodbg amp sql -Ncivi --root="$CMS_ROOT"
else
echo "Failed to locate civi SQL files"
fi
popd >> /dev/null
civicrm_update_domain
}
###############################################################################
## Generate config files and setup database (via cv)
function civicrm_install_cv() {
cvutil_assertvars civicrm_install CIVI_CORE CIVI_DB_DSN CMS_URL CIVI_SITE_KEY
if [ ! -d "$CIVI_CORE/bin" -o ! -d "$CIVI_CORE/CRM" ]; then
cvutil_fatal "Failed to locate valid civi root: $CIVI_CORE"
fi
local loadGenOpt
[ -n "$NO_SAMPLE_DATA" ] && loadGenOpt="" || loadGenOpt="-m loadGenerated=1"
cv core:install -vv -f --cms-base-url="$CMS_URL" --db="$CIVI_DB_DSN" -m "siteKey=$CIVI_SITE_KEY" $loadGenOpt
local settings=$( cv ev 'echo CIVICRM_SETTINGS_PATH;' )
cvutil_inject_settings "$settings" "civicrm.settings.d"
civicrm_update_domain
## Enable development
civicrm_make_setup_conf
civicrm_make_test_settings_php
}
###############################################################################
## Update the CiviCRM domain's name+email
function civicrm_update_domain() {
cvutil_assertvars civicrm_install CIVI_DOMAIN_NAME CIVI_DOMAIN_EMAIL
cvutil_php_nodbg amp sql -Ncivi --root="$CMS_ROOT" <<EOSQL
UPDATE civicrm_domain SET name = '$CIVI_DOMAIN_NAME';
SELECT @option_group_id := id
FROM civicrm_option_group n
WHERE name = 'from_email_address';
UPDATE civicrm_option_value
SET label = '$CIVI_DOMAIN_EMAIL'
WHERE option_group_id = @option_group_id
AND value = '1';
EOSQL
}
###############################################################################
## Get a list of default permissions for anonymous users
function civicrm_apply_d8_perm_defaults() {
## FIXME: The lists need a better home.
drush8 -y role-create demoadmin
drush8 -y role-add-perm anonymous "access CiviMail subscribe/unsubscribe pages,access all custom data,access uploaded files,make online contributions,profile create,profile view,register for events"
drush8 -y role-add-perm demoadmin "access AJAX API,access all custom data,access CiviContribute,access CiviCRM,access CiviEvent,access CiviMail,access CiviMail subscribe/unsubscribe pages,access CiviMember,access CiviReport,access Contact Dashboard,access contact reference fields,access deleted contacts,access Report Criteria,save Report Criteria,access uploaded files,add contacts,administer CiviCRM,administer dedupe rules,administer Reports,administer reserved groups,administer reserved reports,administer reserved tags,administer Tagsets,delete activities,delete contacts,delete in CiviContribute,delete in CiviEvent,delete in CiviMail,delete in CiviMember,edit all contacts,view my contact,edit my contact,edit all events,edit contributions,edit event participants,edit message templates,edit groups,edit memberships,import contacts,make online contributions,manage tags,merge duplicate contacts,profile create,profile edit,profile listings,profile listings and forms,profile view,register for events,translate CiviCRM,view all activities,view all contacts,view all notes,view event info,view event participants,view public CiviMail content,administer payment processors,create manual batch,edit own manual batches,edit all manual batches,view own manual batches,view all manual batches,delete own manual batches,delete all manual batches,export own manual batches,export all manual batches"
drush8 -y role-add-perm demoadmin "access toolbar"
}
###############################################################################
## Appy more default values
function civicrm_apply_demo_defaults() {
if cv ev 'exit(version_compare(CRM_Utils_System::version(), "4.7.0", "<") ?0:1);' ; then
cv api setting.create versionCheck=0 debug=1
fi
cv api MailSettings.create id=1 is_default=1 domain=example.org debug=1
if [ -z "$NO_SAMPLE_DATA" ]; then
cv -vv ev 'eval(file_get_contents("php://stdin"));' <<EOPHP
\$cid = civicrm_api3('Domain', 'getvalue', array(
'id' => 1,
'return' => 'contact_id'
));
civicrm_api3('Address', 'create', array(
'contact_id' => \$cid,
'location_type_id' => 1,
'street_address' => '123 Some St',
'city' => 'Hereville',
'country_id' => 'US',
'state_province_id' => 'California',
'postal_code' => '94100',
'options' => array(
'match' => array('contact_id', 'location_type_id'),
),
));
EOPHP
fi
if cv ev 'exit(version_compare(CRM_Utils_System::version(), "5.19.alpha", "<") ?0:1);' ; then
cv en --ignore-missing api4
fi
}
###############################################################################
## Generate a "civicrm.settings.php" file
function civicrm_make_settings_php() {
cvutil_assertvars civicrm_make_settings_php CIVI_SETTINGS CIVI_CORE CIVI_UF CIVI_TEMPLATEC CMS_URL CIVI_SITE_KEY
cvutil_assertvars civicrm_make_settings_php CMS_DB_HOST CMS_DB_NAME CMS_DB_PASS CMS_DB_USER
cvutil_assertvars civicrm_make_settings_php CIVI_DB_HOST CIVI_DB_NAME CIVI_DB_PASS CIVI_DB_USER
cvutil_assertvars civicrm_make_settings_php SITE_CONFIG_DIR
local tpl
for tpl in templates/CRM/common/civicrm.settings.php.template templates/CRM/common/civicrm.settings.php.tpl ; do
if [ -f "$CIVI_CORE/$tpl" ]; then
break
fi
done
if [ ! -f "$CIVI_CORE/$tpl" ]; then
echo "Failed to locate template for civicrm.settings.php"
exit 96
fi
CMS_DB_HOSTPORT=$(cvutil_build_hostport "$CMS_DB_HOST" "$CMS_DB_PORT")
CIVI_DB_HOSTPORT=$(cvutil_build_hostport "$CIVI_DB_HOST" "$CIVI_DB_PORT")
TEST_DB_HOSTPORT=$(cvutil_build_hostport "$TEST_DB_HOST" "$TEST_DB_PORT")
cat "$CIVI_CORE/$tpl" \
| sed "s;%%baseURL%%;${CMS_URL};" \
| sed "s;%%cms%%;${CIVI_UF};" \
| sed "s;%%CMSdbHost%%;${CMS_DB_HOSTPORT};" \
| sed "s;%%CMSdbName%%;${CMS_DB_NAME};" \
| sed "s;%%CMSdbPass%%;${CMS_DB_PASS};" \
| sed "s;%%CMSdbUser%%;${CMS_DB_USER};" \
| sed "s;%%crmRoot%%;${CIVI_CORE}/;" \
| sed "s;%%dbHost%%;${CIVI_DB_HOSTPORT};" \
| sed "s;%%dbName%%;${CIVI_DB_NAME};" \
| sed "s;%%dbPass%%;${CIVI_DB_PASS};" \
| sed "s;%%dbUser%%;${CIVI_DB_USER};" \
| sed "s;%%testHost%%;${TEST_DB_HOSTPORT};" \
| sed "s;%%testName%%;${TEST_DB_NAME};" \
| sed "s;%%testPass%%;${TEST_DB_PASS};" \
| sed "s;%%testUser%%;${TEST_DB_USER};" \
| sed "s;%%siteKey%%;${CIVI_SITE_KEY};" \
| sed "s;%%credKeys%%;aes-cbc::${CIVI_CRED_KEY};" \
| sed "s;%%signKeys%%;jwt-hs256::${CIVI_SIGN_KEY};" \
| sed "s;%%templateCompileDir%%;${CIVI_TEMPLATEC};" \
> "$CIVI_SETTINGS"
echo >> "$CIVI_SETTINGS"
if [ -n "$CIVI_EXT_DIR" ]; then
cat >> "$CIVI_SETTINGS" << EOF
global \$civicrm_setting;
\$civicrm_setting['Directory Preferences']['extensionsDir'] = '$CIVI_EXT_DIR';
\$civicrm_setting['URL Preferences']['extensionsURL'] = '$CIVI_EXT_URL';
EOF
fi
cvutil_inject_settings "$CIVI_SETTINGS" "civicrm.settings.d"
}
###############################################################################
## Generate a "setup.conf" file
function civicrm_make_setup_conf() {
cvutil_assertvars civicrm_make_setup_conf PRJDIR CMS_ROOT CIVI_CORE CIVI_UF CIVI_DB_NAME CIVI_DB_USER CIVI_DB_PASS
cat > "$CIVI_CORE/bin/setup.conf" << EOF
## INFRA-114
PRJDIR="$PRJDIR"
CMS_ROOT="$CMS_ROOT"
SITE_ID="\${SITE_ID:-$SITE_ID}"
AMP_NAME=civi\${SITE_ID}
[ "\$SITE_ID" == "default" ] && AMP_NAME=civi
eval \`\$PRJDIR/bin/amp export --root="\$CMS_ROOT" -N\${AMP_NAME}\`
DBNAME="\$AMP_DB_NAME"
DBUSER="\$AMP_DB_USER"
DBPASS="\$AMP_DB_PASS"
DBHOST="\$AMP_DB_HOST"
DBPORT="\$AMP_DB_PORT"
##
SVNROOT="$CIVI_CORE"
CIVISOURCEDIR="$CIVI_CORE"
SCHEMA=schema/Schema.xml
DBARGS=""
PHP5PATH=
DBLOAD="$DBLOAD"
# DBADD=
GENCODE_CMS="$CIVI_UF"
EOF
if [ -n "$GENCODE_CONFIG_TEMPLATE" ]; then
echo "GENCODE_CONFIG_TEMPLATE=\"$GENCODE_CONFIG_TEMPLATE\"" >> "$CIVI_CORE/bin/setup.conf"
echo "export GENCODE_CONFIG_TEMPLATE" >> "$CIVI_CORE/bin/setup.conf"
fi
}
###############################################################################
## Generate civicrm.settings.php and CiviSeleniumSettings.php for testing
function civicrm_make_test_settings_php() {
cvutil_assertvars civicrm_make_test_settings_php CIVI_CORE CIVI_DB_NAME CIVI_DB_USER CIVI_DB_PASS CIVI_DB_HOST CMS_URL CMS_DB_USER CMS_DB_PASS CMS_DB_HOST CMS_DB_NAME ADMIN_USER ADMIN_PASS DEMO_USER DEMO_PASS CIVI_SITE_KEY
## Does this build include development support (eg git or tarball-based)?
if [ -d "$CIVI_CORE/tests/phpunit/CiviTest" ]; then
## TODO: REVIEW
cat > "$CIVI_CORE/tests/phpunit/CiviTest/civicrm.settings.local.php" << EOF
<?php
if (!defined('CIVICRM_DSN')) {
if (defined('CIVICRM_WEBTEST')) {
// For Selenium tests, use normal DB
define('CIVICRM_DSN', "mysql://${CIVI_DB_USER}:${CIVI_DB_PASS}@${CIVI_DB_HOST}:${CIVI_DB_PORT}/${CIVI_DB_NAME}");
define('CIVICRM_UF_DSN', "mysql://${CMS_DB_USER}:${CMS_DB_PASS}@${CMS_DB_HOST}:${CMS_DB_PORT}/${CMS_DB_NAME}");
} else {
// For unit tests, use headless test DB
define('CIVICRM_DSN', "mysql://${TEST_DB_USER}:${TEST_DB_PASS}@${TEST_DB_HOST}:${TEST_DB_PORT}/${TEST_DB_NAME}");
}
}
if (!defined('CIVICRM_TEMPLATE_COMPILEDIR')) {
define('CIVICRM_TEMPLATE_COMPILEDIR', '${CIVI_TEMPLATEC}');
}
if (!defined('DONT_DOCUMENT_TEST_CONFIG')) {
define('DONT_DOCUMENT_TEST_CONFIG', TRUE);
}
EOF
cvutil_inject_settings "$CIVI_CORE/tests/phpunit/CiviTest/civicrm.settings.local.php" "civitest.settings.d"
## TODO: REVIEW
cat > "$CIVI_CORE/tests/phpunit/CiviTest/CiviSeleniumSettings.php" << EOF
<?php
class CiviSeleniumSettings {
var \$publicSandbox = false;
var \$browser = '*firefox';
var \$sandboxURL = '${CMS_URL}';
var \$sandboxPATH = '';
var \$username = '${DEMO_USER}';
var \$password = '${DEMO_PASS}';
var \$adminUsername = '${ADMIN_USER}';
var \$adminPassword = '${ADMIN_PASS}';
var \$adminApiKey = 'apikey${ADMIN_PASS}';
var \$siteKey = '${CIVI_SITE_KEY}';
var \$UFemail = 'noreply@civicrm.org';
var \$cookies;
function __construct() {
\$this->fullSandboxPath = \$this->sandboxURL . \$this->sandboxPATH;
\$this->cookies = array(
\$this->createConstCookie(),
);
}
/**
* @return array
*/
function createConstCookie() {
global \$civibuild;
\$now = time();
\$civiConsts = array(
'CIVICRM_DSN' => CIVICRM_DSN,
'CIVICRM_UF_DSN' => CIVICRM_UF_DSN,
'ts' => \$now,
'sig' => md5(implode(';;', array(CIVICRM_DSN, CIVICRM_UF_DSN, \$civibuild['SITE_TOKEN'], \$now))),
);
return array(
'name' => 'civiConsts',
'value' => urlencode(json_encode(\$civiConsts)),
);
}
}
EOF
fi
}
###############################################################################
## Determine the version# of the CiviCRM codebase
## usage: civicrm_get_ver <path>
## ex: ver=$(civicrm_get_ver .)
## ex: ver=$(civicrm_get_ver /var/www/sites/all/modules/civicrm)
function civicrm_get_ver() {
pushd "$1" >> /dev/null
if [ -f xml/version.xml ]; then
## Works in any git-based build, even if gencode hasn't run yet.
php -r 'echo simplexml_load_file("xml/version.xml")->version_no;'
else
## works in any tar-based build.
php -r 'require "civicrm-version.php"; $a = civicrmVersion(); echo $a["version"];'
fi
popd >> /dev/null
}
###############################################################################
## usage: civicrm_ext_download_bare <key> <path>
function civicrm_ext_download_bare() {
local civiVer=$(civicrm_get_ver .)
cv dl -b "@https://civicrm.org/extdir/ver=$civiVer|cms=Drupal/$1.xml" --to="$2"
}
###############################################################################
## usage: Convert a CiviCRM version branch/tag expression to a composer version expression
## example: civicrm_composer_ver master ==> "dev-master"
function civicrm_composer_ver() {
local branchTag="$1"
if [[ "$branchTag" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
## Specific tag versions don't need to be changed.
echo "$branchTag"
elif [[ "$branchTag" =~ ^[0-9]+\.[0-9]+$ ]]; then
## Numeric branches get a dev suffix
echo "$branchTag.x-dev"
elif [[ "$branchTag" =~ dev ]]; then
## "dev-" indicates that the caller has already put into composer notation.
echo "$branchTag"
else
## Non-numeric branches get a dev prefix
echo "dev-$branchTag"
fi
}
###############################################################################
## Generate config files and setup database
function wp_install() {
cvutil_assertvars wp_install CMS_ROOT CMS_DB_NAME CMS_DB_USER CMS_DB_PASS CMS_DB_HOST CMS_URL ADMIN_USER ADMIN_PASS ADMIN_EMAIL CMS_TITLE
CMS_DB_HOSTPORT=$(cvutil_build_hostport $CMS_DB_HOST $CMS_DB_PORT)
pushd "$CMS_ROOT" >> /dev/null
[ -f "wp-config.php" ] && rm -f "wp-config.php"
wp core config \
--dbname="$CMS_DB_NAME" \
--dbuser="$CMS_DB_USER" \
--dbpass="$CMS_DB_PASS" \
--dbhost="$CMS_DB_HOSTPORT" \
--skip-salts \
--extra-php <<PHP
define('AUTH_KEY', '$(cvutil_makepasswd 32)');
define('SECURE_AUTH_KEY', '$(cvutil_makepasswd 32)');
define('LOGGED_IN_KEY', '$(cvutil_makepasswd 32)');
define('NONCE_KEY', '$(cvutil_makepasswd 32)');
define('AUTH_SALT', '$(cvutil_makepasswd 32)');
define('SECURE_AUTH_SALT', '$(cvutil_makepasswd 32)');
define('LOGGED_IN_SALT', '$(cvutil_makepasswd 32)');
define('NONCE_SALT', '$(cvutil_makepasswd 32)');
PHP
wp core install \
--url="$CMS_URL" \
--admin_user="$ADMIN_USER" \
--admin_password="$ADMIN_PASS" \
--admin_email="$ADMIN_EMAIL" \
--title="$CMS_TITLE"
## Create WP data dirs
cvutil_mkdir "wp-content/plugins/modules"
cvutil_php_nodbg amp datadir "wp-content/plugins/files" "wp-content/uploads/"
cvutil_inject_settings "wp-config.php" "wp-config.d"
popd >> /dev/null
}
###############################################################################
## Destroy config files and database tables
function wp_uninstall() {
cvutil_assertvars wp_uninstall CMS_ROOT
pushd "$CMS_ROOT" >> /dev/null
[ -f "wp-config.php" ] && rm -f "wp-config.php"
[ -f "wp-content/plugins/files" ] && rm -rf "wp-content/plugins/files"
popd >> /dev/null
}
###############################################################################
## Backdrop -- Generate config files and setup database
## usage: backdrop_install <extra-drush-args>
## To use an "install profile", simply pass it as part of <extra-drush-args>
function backdrop_install() {
cvutil_assertvars backdrop_install CMS_ROOT SITE_ID CMS_TITLE CMS_DB_USER CMS_DB_PASS CMS_DB_HOST CMS_DB_NAME ADMIN_USER ADMIN_PASS CMS_URL
pushd "$CMS_ROOT" >> /dev/null