This repository has been archived by the owner on Jun 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 88
/
vv
executable file
·1870 lines (1687 loc) · 54.9 KB
/
vv
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
#!/usr/bin/env bash
#
# Variable VVV - A VVV Site Setup Script
# By Brad Parbs <brad@bradparbs.com>
# Originally by Alison Barrett <alison@barre.tt>
#
# Version 1.13
#
# Varying Vagrant Vagrants (https://github.com/Varying-Vagrant-Vagrants/VVV).
#
# ██ ██ ██ ██
# ░██ ░██░██ ░██ ▓▓▓▓▓▓▓▓▓▓
# ░░██ ░██ ░░██ ░██ ░▓ author ▓ Brad Parbs <brad@bradparbs.com>
# ░░████ ░░████ ░▓ github ▓ http://github.com/bradp/vv
# ░░██ ░░██ ░▓▓▓▓▓▓▓▓▓▓
# ░░ ░░ ░░░░░░░░░░
#
# This script automates the creation & deletion of new WordPress sites using
# Varying Vagrant Vagrants (https://github.com/Varying-Vagrant-Vagrants/VVV).
#
# Copyright (C) 2015 Brad Parbs
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.1.6.0
#
version_number=1.13
if [[ "$1" == "vv_internal_debug" ]]; then
# We check this before anything else, so we can debug all of vv
# This will output all the commands that are being run
set -x
shift
fi
# Airplane mode. Pass x as the first argument to kill all internet things
# vv x create, vv x list, etc. This will probably break the creation scripts
# and stuff though.
if [[ "$1" == "x" ]]; then
# if our first argument is 'x', kill all the internet-enabled checks.
internet=false
shift
fi
# Verify we have a home variable set, and force it if we can
if [ -z "$HOME" ]; then
home="~";
else
home="$HOME"
fi
declare HOME="$home"
# If we have tput, let's set our colors
if [[ ! -z $(which tput 2>/dev/null) ]]; then
normal=$(tput sgr0)
bold=$(tput bold)
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
magenta=$(tput setaf 5)
cyan=$(tput setaf 6)
fi
__vv__about() {
cat <<ABOUT
${magenta}
██ ██ ██ ██
░██ ░██░██ ░██ ▓▓▓▓▓▓▓▓▓▓
░░██ ░██ ░░██ ░██ ░▓ author ▓ Brad Parbs <brad@bradparbs.com>
░░████ ░░████ ░▓ github ▓ http://github.com/bradp/vv
░░██ ░░██ ░▓▓▓▓▓▓▓▓▓▓
░░ ░░ ░░░░░░░░░░
${normal}
ABOUT
}
# Usage: __vv__show_help [exit_code]
# Example: __vv__show_help 254
__vv__show_help() {
__vv__hook "pre_help_output"
cat <<HELP
${bold} USAGE: ${normal}
vv [--help|-h] [--version] [--about] [--path|-p <path>] [--force-path|-fp] <command> [<site-options>] ...
${bold} OPTIONS: ${normal}
--help, -h Show this help and usage
--version Show current vv version
--about Show project info
--debug-vv Outputs all debugging info needed for bug reporting
--path, -p Path to VVV installation
--force-path, -fp Override vv auto-VVV locating
--force-sites-folder, -fsf Override sites folder directory locating
--use_defaults Accept all default options and skip the wizard
${bold} COMMANDS: ${normal}
list List all VVV sites
create Create a new site
remove Remove a site
vagrant, v Pass vagrant command through to VVV
deployment-create Create a deployment
deployment-remove Remove a deployment
deployment-config Manually configure deployment
blueprint-init Initialize blueprint file
upgrade Update all the site of VV
${bold} SITE OPTIONS: ${normal}
--domain, -d Domain of new site
--live-url, -u Live URL of site
--files, -f Do not provision Vagrant, just create the site directory and files
--images, -i Load images by proxy from the live site
--name, -n Desired name for the site directory (e.g. mysite)
--web-root, -wr Subdirectory used for web server root
--wp-version, -wv Version of WordPress to install
--debug, -x Turn on WP_DEBUG and WP_DEBUG_LOG
--multisite, -m Install as a multisite
--sample-content, -sc Add sample content to site
--username Admin username
--password Admin password
--email Admin email
--prefix Database prefix to use
--git-repo, -gr Git repo to clone as wp-content
--bedrock, -bed Creates Roots.io Bedrock install
--blueprint, -b Name of blueprint to use
--blank Creates blank VVV site, with no WordPress
--blank-with-db Adds a blank VVV site, with a database
--wpskeleton, --skel Creates a new site with the structure of WP Skeleton
--database, -db Import a local database file
--remove-defaults, -rd Remove default themes and plugins
--language,--locale, Install WP in another locale.
${bold} EXAMPLE:${normal}
vv create --domain mysite.dev --name mysite --debug
vv create -d mysite.dev -n mysite -x
HELP
__vv__hook "post_help_output"
}
# Usage: __vv__show_commands
# Example: __vv__show_commands
__vv__show_commands() {
__vv__hook "pre_help_output"
cat <<COMMANDS
--help
--version
--about
--debug-vv
--path
--force-path
-fp
--force-sites-folder
-fsf
--use_defaults
list
create
remove
vagrant
v
deployment-create
deployment-remove
deployment-config
blueprint-init
upgrade
--domain
-d
--live-url
-u
--files
-f
--images
-i
--name
-n
--web-root
-wr
--wp-version
-wv
--debug
-x
--multisite
-m
--sample-content
-sc
--username
--password
--email
--prefix
--git-repo
-gr
--bedrock
-bed
--blueprint
-b
--blank
--blank-with-db
--wpskeleton
--skel
--database
-db
--remove-defaults
-rd
--language
--locale
COMMANDS
}
__vv__version() {
__vv__hook "pre_version_output"
echo "vv version $version_number"
__vv__hook "post_version_output"
}
# Usage: __vv__info "message"
# Example: __vv__info "doing thing"
# Output (to STDOUT): doing thing
__vv__info() {
__vv__hook "pre_info_output"
printf "%b" "${bold}${yellow}$1${normal} \n"
__vv__hook "post_info_output"
}
# Usage: __vv__success "message"
# Example: __vv__success "It's Working"
# Output (to STDOUT): [...] It's Working
__vv__success() {
__vv__hook "pre_success_output"
printf "%b" "[${green}Success${normal}]${green} $1 ${normal}\n"
__vv__hook "post_success_output"
}
# Usage: __vv__warning "message"
# Example: __vv__warning "some warning"
# Output (to STDOUT): [...] some warning
__vv__warning() {
__vv__hook "pre_warning_output"
printf "%b" "${red} $1 ${normal}\n"
__vv__hook "post_warning_output"
}
# Usage: __vv__prompt "question"
# Example: __vv__prompt "Site name"
# Output (to STDOUT): Site Name:
__vv__prompt() {
__vv__hook "pre_prompt_output"
printf "%b" "${magenta} $1: ${normal}"
__vv__hook "post_prompt_output"
}
# Usage: __vv__error "message"
# Example: __vv__error "this is an error"
# Output (to STDERR): [ERROR] this is an error
__vv__error() {
__vv__hook "pre_error_output"
printf "%b" "[${bold}${red}Error${normal}]${bold}${red} ${1:-'Unknown Error'}${normal}\n" >&2
__vv__hook "post_error_output"
}
# Usage: __vv__fail "message"
# Example: __vv__fail "Unknown Option"
__vv__fail() {
__vv__error "$1"
__vv__hook "fail_and_exit"
exit 1
}
__vv__check_for_update() {
__vv__hook "pre_update_check"
if [[ ! -z $(which curl) ]]; then
__vv__hook "pre_github_update_check"
github_version=$(curl -s https://api.github.com/repos/bradp/vv/tags | grep --color=never "\"name\": \"" | head -n 1 | sed 's/"name": "//' | sed 's/",//' | sed 's/ //g' )
__vv__hook "post_github_update_check"
if [[ ! -z "$github_version" ]]; then
if [[ ! "$version_number" = "$github_version" ]]; then
__vv__hook "pre_out_of_date_vv"
__vv__info "Your version of vv ( $version_number ) does not match the current Github version ( $github_version ). Please update with vv --update"
__vv__hook "post_out_of_date_vv"
fi
fi
fi
__vv__hook "post_update_check"
}
__vv__check_how_installed() {
__vv__hook "pre_check_how_installed"
if [[ ! -z $(which brew) ]]; then
brew_install_location=$(brew --prefix)
if [[ -f $brew_install_location"/bin/vv" ]]; then
installed_with_brew="true"
else
installed_with_brew="false"
fi
fi
__vv__hook "post_check_how_installed"
}
__vv__install_update() {
__vv__hook "pre_install_update"
__vv__check_how_installed
__vv__update_vv
__vv__hook "post_install_update"
}
__vv__sites_upgrade() {
__vv__hook "pre_upgrade"
cd "$path"/"$sites_folder" || __vv__error "Could not change directory."
for filename in */; do
# Cut the end slash
filename=${filename::-1}
if [[ -f "$path"/"$sites_folder"/"$filename"/vvv-hosts ]]; then
echo "Upgrade in progress on $filename.dev"
# Wait for the process else will execute the command and the loop will continue to run the command outside the script
vagrant ssh --command "cd /srv/www/$filename; wp core update; wp plugin update --all" > /dev/null 2>&1 &
wait $!
echo "Upgrade done for $filename.dev"
fi
done
__vv__hook "post_upgrade"
exit
}
__vv__update_vv() {
__vv__hook "pre_update_vv"
if [[ $installed_with_brew = "true" ]]; then
__vv__info "Updating vv via Brew..."
__vv__hook "pre_brew_update_vv"
brew cleanup
brew reinstall vv
__vv__hook "post_brew_update_vv"
else
__vv__hook "pre_bootstrap_update_vv"
__vv__info "Updating vv..."
__vv__vv_bootstrap_update
__vv__hook "post_bootstrap_update_vv"
fi
__vv__hook "post_update_vv"
}
__vv__vv_bootstrap_update() {
__vv__hook "pre_vv_bootstrap_update"
github_version=$(curl -s https://api.github.com/repos/bradp/vv/tags | grep --color=never "\"name\": \"" | head -n 1 | sed 's/"name": "//' | sed 's/",//' | sed 's/ //g' )
download_link=https://github.com/bradp/vv/archive/"$github_version".tar.gz
vv_install_location=$(which vv)
curl -L -o "$home/$github_version.tar.gz" "$download_link" 2>/dev/null
tar -C "$home" -zxvf "$home/$github_version.tar.gz" 2>/dev/null
rm "$home/$github_version.tar.gz"
cat "$home/vv-$github_version/vv" > "$vv_install_location"
rm -r "$home/vv-$github_version"
__vv__success "vv has been updated to the latest version. Thanks!"
__vv__hook "post_vv_bootstrap_update"
}
__vv__auto_update_main() {
__vv__hook "pre_auto_update_vv"
if [[ ! $auto_update_disable = "true" ]]; then
if [ ! -f "$home"/.vv-update ]; then
__vv___update_vv_update
else
# TODO fix shellcheck error
# shellcheck disable=SC1090
source "$home"/.vv-update
epoch_diff=$(($(__vv___current_epoch) - DAYS_SINCE_UPDATE_CHECK))
epoch_target=7
if [[ $epoch_diff -gt $epoch_target ]]; then
__vv__info "vv is out of date. Checking for update."
github_version=$(curl -s https://api.github.com/repos/bradp/vv/tags | grep "\"name\": \"" | head -n 1 | sed 's/"name": "//' | sed 's/",//' | sed 's/ //g' )
if [[ ! "$version_number" = "$github_version" ]]; then
__vv__update_vv
fi
rm "$home"/.vv-update
__vv___update_vv_update
fi
fi
fi
__vv__hook "post_auto_update_vv"
}
__vv___current_epoch() {
seconds=$(date +%s)
echo $((seconds/60/60/24))
}
__vv___update_vv_update() {
__vv__hook "pre_vv_auto_update_update"
touch "$home"/.vv-update
echo "DAYS_SINCE_UPDATE_CHECK=$(__vv___current_epoch)" > "$home"/.vv-update
__vv__hook "post_vv_auto_update_update"
}
__vv__argument_expected() {
__vv__hook "pre_arg_expected"
if [ -z "$2" ] || [[ "$2" == -* ]]; then
__vv__hook "error_no_arg_$1"
__vv__fail "$1 expected an argument"
fi
__vv__hook "post_arg_expected"
}
__vv__check_for_config_file() {
__vv__hook "pre_vv_config_check"
test -f "$home"/.vv-config && vv_config="${HOME}/.vv-config"
test -f ./.vv-config && vv_config="./.vv-config"
if [ ! -z "$vv_config" ]; then
__vv__load_config_values
else
if [[ ! $showing_help = "true" ]]; then
__vv__info " "
__vv__info "Looks like it's your first time running ${magenta}vv${normal}. "
__vv__info "${magenta}vv${normal} couldn't find a config file, so we will create one now."
__vv__info "This step only needs to be done once."
__vv__info " "
__vv__get_vvv_path
fi
fi
__vv__hook "post_vv_config_check"
}
__vv__create_config_file() {
__vv__hook "pre_create_vv_config"
{
echo "{"
echo " \"path\": \"$path\""
echo "}"
} > "$home"/.vv-config
__vv__info "$home/.vv-config was created."
__vv__info " "
__vv__info "If for some reason, vv still fails to find the path, please run the following command:"
__vv__info " ";
# shellcheck disable=SC2028
echo " sudo printf \"{\\n\"\\\\tpath\": \"$path\"\\n}\" > ~/.vv-config"
__vv__info " ";
__vv__hook "post_create_vv_config"
}
__vv__get_config_value() {
value=$(grep --color=never "$1" "$vv_config" | sed 's/"//g' | sed "s/$1://g" | sed "s/,//g" )
echo "$value"
}
__vv__load_config_values() {
path=$(__vv__get_config_value path)
}
__vv__load_config_autopdate_config_values() {
#Load path from config file
auto_update_disble_config_var=$(__vv__get_config_value auto_update_disable)
auto_update_disable_config="$(echo "$auto_update_disble_config_var" | sed -e 's/^"//' -e 's/"$//')"
if [[ $auto_update_disable_config = "true" ]]; then
auto_update_disable="true"
fi
}
load_default_values() {
defaults=$(__vv__get_config_value defaults)
defaults="$(echo "$defaults" | sed -e 's/^"//' -e 's/"$//')"
}
__vv__get_vvv_path(){
if [ ! -z "$force_path" ]; then
unset path
fi
if [ ! -z "$path" ]; then
if [ ! -e "$(eval echo "${path//>}")/Vagrantfile" ]; then
__vv__error "Path specified is not a VVV root directory. Where is VVV installed?"
unset path
while [ -z "$path" ]; do
read -r -e -p "VVV install directory: " path
# Make sure directory is actually a VVV root
if [ ! -e "$(eval echo "${path//>}")/Vagrantfile" ]; then
__vv__error "Path specified is not a VVV root directory. Where is VVV installed?"
unset path
fi
path=$(eval echo "${path//>}")
done
else
path=$path
path=$(eval echo "${path//>}")
fi
else
current_dir=$(pwd)
if [ -e "$current_dir/Vagrantfile" ]; then
path=$(pwd)
elif [ -e "$home"/Sites/Vagrantfile ] && [ -z "$force_path" ]; then
path="$home"/Sites
elif [ -e "$home"/Sites/Vagrant/Vagrantfile ] && [ -z "$force_path" ]; then
path="$home"/Sites/Vagrant
elif [ -e "$home"/vagrant/Vagrantfile ] && [ -z "$force_path" ]; then
path="$home"/vagrant
elif [ -e "$home"/vagrant-local/Vagrantfile ] && [ -z "$force_path" ]; then
path="$home"/vagrant-local
elif [ -e "$home"/projects/vvv/Vagrantfile ] && [ -z "$force_path" ]; then
path="$home"/projects/vvv
elif [ -e "$home"/working/vvv/Vagrantfile ] && [ -z "$force_path" ]; then
path="$home"/working/vvv
elif [ -e "$home"/vvv/Vagrantfile ] && [ -z "$force_path" ]; then
path="$home"/vvv
fi
if [ ! -z "$path" ]; then
__vv__info "Automagically found $path"
__vv__prompt "Is this where VVV is installed? (Y/n)"
read -r path_confirmation
if [ "$path_confirmation" = 'y' ]; then
__vv__create_config_file
elif [ "$path_confirmation" = 'Y' ]; then
__vv__create_config_file
elif [ "$path_confirmation" != 'n' ]; then
__vv__create_config_file
else
unset path
fi
fi
while [ -z "$path" ]; do
read -r -e -p "VVV install directory: " path
# Make sure directory is actually a VVV root
if [ ! -e "$(eval echo "${path//>}")/Vagrantfile" ]; then
__vv__error "Path specified is not a VVV root directory. Where is VVV installed?"
unset path
fi
path=$(eval echo "${path//>}")
if [ ! -z "$path" ]; then
__vv__create_config_file
fi
done
fi
path=${path%/}
}
__vv__setup_scripts_folder() {
vv_scripts_folder="$path"/vv/
}
__vv__init_vv_hooks() {
mkdir "$path"/vv/
}
__vv__run_hook() {
__vv__hook "$@"
}
__vv__hook() {
# Display all hooks to screen if the show_hooks flag is set
if [[ $show_hooks = 'true' ]]; then
echo "${magenta}[Hook]${normal}" "$1" "$2" "$3" "$4"
fi
if [[ -f "$vv_scripts_folder""$1" ]]; then
cd "$vv_scripts_folder" || __vv__error "Could not change directory."
script_type="$(head -n 1 "$1")"
case "$script_type" in
*bash*)
bash "$1" "$2" "$3" "$4"
;;
*php*)
php "$1" "$2" "$3" "$4"
;;
*python*)
python "$1" "$2" "$3" "$4"
;;
*node*)
node "$1" "$2" "$3" "$4"
;;
*ruby*)
ruby "$1" "$2" "$3" "$4"
;;
*)
__vv__error "Could not parse file hooked into $1"
;;
esac
fi
# test -f "$vv_scripts_folder"hooks && source "$vv_scripts_folder"hooks && which "$1" && $("$1" "$2")
# this is currently not working
}
__vv__get_list_sites() {
clean_saved=$clean
clean="true"
__vv__list_sites
clean=$clean_saved
}
__vv__list_sites() {
cd "$path"/"$sites_folder" || __vv__error "Could not change directory."
__vv__hook "pre_list_sites"
find . -maxdepth 2 -mindepth 1 -type d -print0 | while IFS= read -r -d '' filename; do
filename=${filename:2}
if [[ $filename != 'default' && $filename != 'phpcs' && $filename != 'wp-cli' ]]; then
if [[ $filename = 'wordpress-default' || $filename = 'wordpress-develop' || $filename = 'wordpress-trunk' ]]; then
__vv__hook "pre_list_site_$filename"
__vv__hook "list_site" "$filename"
if [[ $filename = 'wordpress-default' ]]; then
url=local.wordpress.dev
elif [[ $filename = 'wordpress-develop' ]]; then
url=src.wordpress-develop.dev
elif [[ $filename = 'wordpress-trunk' ]]; then
url=local.wordpress-trunk.dev
fi
if [[ ! $clean = "true" ]]; then
printf " * %-30s %s %s\n" "${green}$filename${normal}" "${yellow}( $url )${normal}" "${cyan}[VVV default]${normal}"
__vv__hook "post_list_site_$filename"
fi
else
if [[ -f "$path"/"$sites_folder"/"$filename"/vvv-hosts ]]; then
__vv__hook "pre_list_site_$filename"
__vv__hook "list_site" "$filename"
__vv__hook "list_custom_site" "$filename"
url=$(<"$path"/"$sites_folder"/"$filename"/vvv-hosts)
url=$(echo "$url" | sed -e 's/#.*$//' -e '/^$/d')
urls=$(echo "$url" | wc -l)
if (( "$urls" > 1 )); then
url_seq=$(seq 1 "$urls")
dashes=($( for _ in $url_seq; do echo '-'; done ))
url="$(echo "$url" | paste -d ' ' "${dashes[@]}" )"
fi
if [[ ! $clean = "true" ]]; then
printf " * %-30s %s\n" "${green}$filename${normal}" "${yellow}( $url )${normal}"
__vv__hook "post_list_site_$filename"
fi
fi
fi
fi
done
__vv__hook "post_list_sites"
exit
}
__vv__site_creation_questions() {
__vv__hook "pre_site_creation_wizard"
files_only_text=''
if [[ "$files_only" = "true" ]]; then
files_only_text=" (file creation only)"
fi
__vv__info "New VVV Site Setup$files_only_text"
# Prompt user for vars
# =============================================================================
# Get site dir name if not supplied as argument
if [ ! -z "$site" ]; then
if [ -f "$path/config/nginx-config/sites/$site.conf" ]; then
__vv__error "Site $site already exists. Remove config/nginx-config/sites/$site.conf to run setup again."
unset site
elif [ -d "$path/$sites_folder/$site" ]; then
__vv__warning "Directory $path/$sites_folder/$site already exists. Existing VVV configuration files will be overwritten."
fi
fi
while [ -z "$site" ]; do
__vv__prompt "Name of new site directory"
read -r site
if [ -z "$site" ]; then
__vv__error "You must enter a directory name."
elif [ -f "$path/config/nginx-config/sites/$site.conf" ]; then
__vv__error "Site $site already exists. Remove config/nginx-config/sites/$site.conf to run setup again."
unset site
elif [ -d "$path/$sites_folder/$site" ]; then
__vv__warning "Directory $path/$sites_folder/$site already exists. Existing VVV configuration files will be overwritten."
fi
done
# Get database name
db_name=$site
# Get web root of site
if [ -z "$web_root" ]; then
web_root="htdocs"
fi
if [ "$no_wp" = "false" ]; then
if [[ -f "$path"/vv-blueprints.json ]]; then
# Get local URL
if [ "$use_defaults" = "false" ]; then
if [ -z "$blueprint" ]; then
if which python >/dev/null; then
first=$(python -c "import json,sys;obj=json.loads(open('$path/vv-blueprints.json').read());print ', '.join(obj.keys());")
__vv__prompt "Blueprint to use (leave blank for none or use $first)"
elif which node 2>/dev/null; then
first=$(node -p "name='';for (var parent in JSON.parse(require('fs').readFileSync('$path/vv-blueprints.json').toString())){name += parent + ', '} name.slice(0,-2);")
__vv__prompt "Blueprint to use (leave blank for none or use $first)"
else
__vv__prompt "Blueprint to use (leave blank for none)"
fi
read -r blueprint
if [ -z "$blueprint" ]; then
unset blueprint
fi
fi
fi
fi
fi
# Get local URL
while [ -z "$domain" ]; do
if [ "$use_defaults" = "false" ]; then
__vv__prompt "Domain to use (leave blank for ${site// /-}.dev)"
read -r domain
fi
if [ -z "$domain" ]; then
domain="${site// /-}.dev"
fi
done
if [ "$no_wp" = "false" ]; then
if [ ! -z "$version" ]; then
# Attempt to verify the existence of the version (hacky)
if curl -s http://codex.wordpress.org/Version_"$version" | grep --color=never 'currently no text' > /dev/null; then
__vv__error "Version $version not found, try again"
unset version
else
installversion=" --version=$version"
fi
fi
use_trunk="false"
while [[ -z "$version" ]]; do
# Get WordPress version
if [ "$use_defaults" = "false" ]; then
__vv__prompt "WordPress version to install (leave blank for latest version or trunk for trunk/nightly version)"
read -r version
fi
if [ -z "$version" ]; then
installversion=""
version="(release version)"
elif [ "$version" = "trunk" ]; then
installversion=""
version="(trunk)"
use_trunk="true"
else
# Attempt to verify the existence of the version (hacky)
if curl -s http://codex.wordpress.org/Version_"$version" | grep --color=never 'currently no text' > /dev/null; then
__vv__error "Version \"$version\" not found, try again"
unset version
else
installversion=" --version=$version"
fi
fi
done
if [ -z "$multisite" ]; then
if [ "$use_defaults" = "false" ]; then
__vv__prompt "Install as multisite? (y/N)"
read -r multisite
fi
if [[ $multisite = 'y' ]]; then
install_text='multisite-install'
else
install_text='install'
fi
fi
if [[ $multisite = "y" ]]; then
while [[ -z $ms_type ]]; do
if [ "$use_defaults" = "false" ]; then
__vv__prompt "Install as subdomain or subdirectory? "
read -r ms_type
fi
if [[ $ms_type != 'subdomain' && $ms_type != 'subdirectory' ]]; then
__vv__error "Type must be subdomain or subdirectory."
unset ms_type
fi
done
fi
if [[ $ms_type = 'subdomain' ]]; then
install_text='multisite-install --subdomains'
fi
if [[ ! -z $git_repo && -d "$path/$sites_folder/$site" ]]; then
__vv__error "$path/$sites_folder/$site already exists. Skipping git clone."
unset git_repo
elif [[ -z "$git_repo" && ! -d "$path/$sites_folder/$site" ]]; then
if [ "$use_defaults" = "false" ]; then
__vv__prompt "Git repo to clone as wp-content (leave blank to skip)"
read -r git_repo
fi
fi
if [ -z "$db_import" ]; then
if [ "$use_defaults" = "false" ]; then
__vv__prompt "Local SQL file to import for database (leave blank to skip)"
read -r db_import
fi
fi
if [ -z "$remove_defaults" ]; then
if [ "$use_defaults" = "false" ]; then
__vv__prompt "Remove default themes and plugins? (y/N)"
read -r remove_defaults
fi
fi
add_placeholder_content="";
if [ -z "$placeholder_content" ]; then
if [ "$use_defaults" = "false" ]; then
__vv__prompt "Add sample content to site (y/N)"
read -r placeholder_content
fi
if [[ $placeholder_content = "y" ]]; then
add_placeholder_content="curl -s https://raw.githubusercontent.com/manovotny/wptest/master/wptest.xml > import.xml && wp plugin install wordpress-importer --allow-root && wp plugin activate wordpress-importer --allow-root && wp import import.xml --authors=skip --allow-root && rm import.xml"
fi
fi
# Ask if WP_DEBUG should be turned on
while [ -z "$wp_debug" ]; do
if [ "$use_defaults" = "false" ]; then
__vv__prompt "Enable WP_DEBUG and WP_DEBUG_LOG (y/N)"
read -r wp_debug
fi
if [[ $wp_debug != 'y' && $wp_debug != 'n' ]]; then
wp_debug="n"
fi
done
if [[ $image_proxy = "true" ]]; then
while [ -z "$live_site_url" ]; do
if [ "$use_defaults" = "false" ]; then
__vv__prompt "Live site URL (no http:// or trailing slash)"
read -r live_site_url
fi
done
fi
fi
if [[ -z "$username" ]]; then
username="admin"
fi
if [[ -z "$password" ]]; then
password="password"
fi
if [[ -z "$email" ]]; then
email="admin@localhost.dev"
fi
__vv__hook "post_site_creation_wizard"
}
__vv__confirm_site_creation() {
# Inform the user of what's about to happen and give them a chance to back out
# =============================================================================
__vv__info "\nAbout to perform the following:"
# @ TODO
echo -e "* Halt Vagrant (if running)\n* Create directory $site in $path/$sites_folder\n* Create files vvv-init.sh, wp-cli.yml, and vvv-hosts in directory $site\n* Create file $site.conf in $path/config/nginx-config/sites"
if [[ -z "$files_only" ]]; then
echo -e "* Run \`vagrant up --provision\` to initialize site"
else
__vv__warning "\nNote: You will need to run \`vagrant up --provision\` to initialize the new site before $domain will load in a browser."
fi
__vv__info "\nProvisioning Vagrant will do the following:"
if [ "$no_wp" = "false" ]; then
echo -e "* Create database $site\n* Install WordPress $version in the $web_root directory\n* Make the site visible at $domain"
fi
__vv__info "\n"
while [ -z "$continue_create" ]; do
__vv__prompt "Continue (y/n)? "
read -r continue_create
if [[ $continue_create = 'n' ]]; then
__vv__error "Site setup aborted."
exit
elif [[ $continue_create != 'y' ]]; then
__vv__error "Answer y or n."
unset continue_create
fi
done
__vv__success "New VVV setup starting for site '$site'"
cd "$path" || __vv__error "Could not change directory."
if [[ -z "$files_only" ]]; then
__vv__info "Checking to see if vagrant halt should be run..."
__vv__hook "pre_creation_pre_vagrant_halt"
__vv__vagrant_maybe_halt
fi
}
__vv__create_site_files(){
__vv__hook "pre_create_site_files" "$site" "$domain" "$path"
# Create site folder with vvv-init.sh file
# =============================================================================
cd "$path"/"$sites_folder" || __vv__error "Could not change directory."
__vv__info "Creating site directory, wp-cli.yml, and vvv-init.sh file... "
if [ ! -d "$site" ]; then
mkdir -p "$site"
fi
cd "$site" || __vv__error "Could not change directory."
if [ "$no_wp" = "false" ]; then
if [ "$bedrock_init" = "true" ]; then
printf "path: %s" "$web_root/web" > wp-cli.yml
else
printf "path: %s" "$web_root" > wp-cli.yml
fi
fi
wp_debug_text=''
if [[ $wp_debug = 'y' ]]; then
wp_debug_text=" --extra-php <<PHP
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'WP_DEBUG_LOG', true );
define( 'SCRIPT_DEBUG', true );
define( 'JETPACK_DEV_DEBUG', true );
if ( isset( \\\$_SERVER['HTTP_HOST'] ) && preg_match('/^($site.)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(.xip.io)\z/', \\\$_SERVER['HTTP_HOST'] ) ) {
define( 'WP_HOME', 'http://' . \\\$_SERVER['HTTP_HOST'] );
define( 'WP_SITEURL', 'http://' . \\\$_SERVER['HTTP_HOST'] );
}
PHP"
else
wp_debug_text=" --extra-php <<PHP
if ( isset( \\\$_SERVER['HTTP_HOST'] ) && preg_match('/^($site.)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(.xip.io)\z/', \\\$_SERVER['HTTP_HOST'] ) ) {
define( 'WP_HOME', 'http://' . \\\$_SERVER['HTTP_HOST'] );
define( 'WP_SITEURL', 'http://' . \\\$_SERVER['HTTP_HOST'] );
}
PHP"
fi
blueprint_text=''
if [[ ! -z "$blueprint" ]]; then
cp "$path"/vv-blueprints.json "$path"/"$sites_folder"/"$site"/vv-blueprints.json
__vv__hook "pre_blueprint_text_output"
blueprint_text="curl -o vv-install -s https://raw.githubusercontent.com/bradp/vv/vv-install/vv-install && php vv-install $blueprint $web_root $site $domain && rm vv-blueprints.json vv-install"
__vv__hook "post_blueprint_text_output"
fi
if [[ ! -z "$db_import" ]]; then
__vv__hook "pre_site_creation_db_import"
cp "$db_import" "$path"/"$sites_folder"/"$site"/"$site".sql
__vv__hook "post_site_creation_db_import"
fi
db_init=""
if [[ ! -z "$db_import" ]]; then
db_init="wp db import ../$site.sql --allow-root && rm ../$site.sql"
fi
hooked_pre_vvv_init_no_wp=$(__vv__hook "hooked_pre_vvv_init_no_wp")
hooked_extra_wp_vvv_init_no_wp=$(__vv__hook "hooked_extra_wp_vvv_init_no_wp")
hooked_post_vvv_init_no_wp=$(__vv__hook "hooked_post_vvv_init_no_wp")
if [ "$no_wp" = "true" ]; then
{
echo "$hooked_pre_vvv_init_no_wp"
echo "if [ ! -d \"./$web_root\" ]; then"
echo " mkdir ./$web_root"
echo "fi"
echo "cd ./$web_root" || __vv__error "Could not change directory."
echo "$hooked_extra_wp_vvv_init_no_wp"
echo "$hooked_post_vvv_init_no_wp"
} >> vvv-init.sh
chmod +x vvv-init.sh
fi
if [ "$no_wp_with_db" = "true" ]; then
if [ ! -e "$path"/database/init-custom.sql ]; then
touch "$path"/database/init-custom.sql
fi
printf "\nCREATE DATABASE IF NOT EXISTS \`%s\`;\n GRANT ALL PRIVILEGES ON \`%s\`.* TO 'wp'@'localhost' IDENTIFIED BY 'wp';\n" "$db_name" "$db_name" >> "$path"/database/init-custom.sql
if [[ ! -z "$db_import" ]]; then
{
echo "$hooked_pre_vvv_init_no_wp"
echo "if [ ! -d \"$web_root/wp-admin\" ]; then"
echo " echo 'Making the correct directories and adding DB in $site/$web_root...'"
echo " if [ ! -d \"./$web_root\" ]; then"
echo " mkdir ./$web_root"
echo " fi"
echo " cd ./$web_root" || __vv__error "Could not change directory."
echo " $db_init"
echo " "
echo " $hooked_extra_wp_vvv_init_no_wp"