-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.bash_terminus.sh
948 lines (746 loc) · 21.9 KB
/
.bash_terminus.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
##############
## Terminus ##
##############
# Show time for terminus commands
# alias terminus='time terminus'
# Globals
# if you need to customize consider a symlink to this location
ISTDRUPAL_NEW_SITE=$HOME/bin/istdrupal-new-site.php
CLONE_PATH=$HOME/Sites/pantheon
_terminus-hostname() {
SITE=$1
if [ x$SITE = x ]; then
echo "terminus-hostname Must pass a site shortname as the first argument, for example: site-name"
exit 1
fi
ENV=$2
if [ x$ENV = x ]; then
echo "terminus-hostname: Must pass an environment as the second argument."
exit 1
fi
TYPE=$3
if [ x$TYPE = x ]; then
echo "terminus-hostname: Must pass server type as the third argument."
exit 1
fi
ID=$(terminus site:info --field=id $SITE)
HOSTNAME=""
if [ -n "$ID" ]; then
HOSTNAME="$ENV.$ID@$TYPE.$ENV.$ID.drush.in"
else
echo ""
echo "Site '$SITE' not found."
fi
}
_terminus-validate-site () {
SITE=$1
if [ x$SITE = x ]; then
echo "Must pass the site shortname of the site from which you want to validate."
echo ""
return
fi
terminus site:info $SITE &>/dev/null
local STATUS=$?
echo $STATUS
}
terminus-site-connection-info () {
SITE=$1
FIELD=$2
ENV=$3
if [ -z "$ENV" ]; then
ENV="dev"
fi
if [ "x$SITE" == "x" ] || [ "x$FIELD" == "x" ]; then
echo "USAGE:
terminus-site-connection-info site-shortname command field
Open a mysql connection to a site.
site-shortname: REQUIRED: If your site is dev-example.pantheon.io
this would be \"example\" .
field: E.g. \"git_command\", \"mysql_command\"
environment Defaults to \"dev\"
"
return
fi
terminus connection:info $SITE.$ENV --field=$FIELD
}
alias tsci=terminus-site-connection-info
terminus-sql-cli() {
SITE=$1
if [ x$SITE = x ]; then
echo "USAGE:
terminus-sql-cli site-shortname environment
Open a mysql connection to a site.
site-shortname: REQUIRED: If your site is dev-example.pantheon.io
this would be \"example\" .
environment: Defaults to \"dev\".
"
return
fi
ENV=$2
if [ -z "$ENV" ]; then
ENV="dev"
fi
if [ "$ENV" != "live" ]; then
terminus env:wake $SITE.$ENV
fi
if [[ $(mysql --version) =~ 'MariaDB' ]];then
OPTIONS='--ssl'
else
OPTIONS='--ssl-mode=VERIFY_IDENTITY'
fi
$(terminus-site-connection-info $SITE mysql_command $ENV) -A $OPTIONS
}
alias tsqlc=terminus-sql-cli
alias tsql=terminus-sql-cli
terminus-site-wake() {
SITE=$1
if [ x$SITE = x ]; then
echo "Must pass a site shortname as the first argument, for example: site-name"
return
fi
ENV=$2
if [ x$ENV = x ]; then
terminus env:wake $SITE.dev
terminus env:wake $SITE.test
else
terminus env:wake $SITE.$ENV
fi
}
alias tsite-wake=terminus-site-wake
alias tsw=terminus-site-wake
terminus-mysql-dump() {
SITE=$1
if [ x$SITE = x ]; then
echo "USAGE:
terminus-mysql-dump <site-shortname> <table> <environment>
Dump a mysql table on for a site.
site-shortname: REQUIRED: If your site is dev-example.pantheon.io
this would be \"example\" .
table: Name of the table. Leave blank for whole db.
environment: Defaults to \"dev\".
"
return
fi
TABLE=$2
ENV=$3
if [ -z "$ENV" ]; then
ENV="dev"
fi
if [ "$ENV" != "live" ]; then
terminus-site-wake $SITE $ENV
fi
CMD=$(terminus-site-connection-info $SITE mysql_command $ENV)
CMD="${CMD/mysql /mysqldump }"
$CMD --ssl $TABLE
}
alias tmd=terminus-mysql-dump
terminus-sftp() {
SITE=$1
if [ x$SITE = x ]; then
echo "USAGE:
terminus-sftp site-shortname
Make an sftp connection to a site.
site-shortname: REQUIRED: If your site is dev-example.pantheon.io
this would be \"example\" .
environment: Defaults to \"dev\".
"
return
fi
ENV=$2
if [ -z "$ENV" ]; then
ENV="dev"
fi
# TODO use terminus-site-connection-info()
_terminus-hostname "$SITE" $ENV "appserver"
if [ -n "$HOSTNAME" ]; then
CMD="sftp -o Port=2222 $HOSTNAME"
echo $CMD
$CMD
fi
}
alias tsftp=terminus-sftp
terminus-logs() {
SITE=$1
if [ x$SITE = x ]; then
echo "USAGE:
terminus-logs site-shortname
Gets the logs for the site
site-shortname: REQUIRED: If your site is dev-example.pantheon.io
this would be "example"
env: dev, test, live
"
return
fi
if [ x$2 = x ]; then
ENV='dev'
else
ENV=$2
fi
DIR="/tmp"
SFTP_CMDS="cd logs
lcd $DIR/$SITE.$ENV
mget *.log"
# mget php*
# get nginx-access.log"
_terminus-hostname "$SITE" "$ENV" "appserver"
if [ -n "$HOSTNAME" ]; then
# if the log directory exists delete it
if [ ! -d "$DIR/$SITE.$ENV" ]; then
mkdir "$DIR/$SITE.$ENV"
fi
echo ""
echo "Connecting to $SITE..."
CMD="sftp -o Port=2222 $HOSTNAME"
echo "$SFTP_CMDS" | $CMD
echo ""
echo "Logs downloaded to $DIR/$SITE.$ENV"
echo ""
cd "$DIR/$SITE.$ENV"
ls -l
fi
}
alias tlogs=terminus-logs
terminus-git-clone() {
USAGE="
terminus-git-clone $SITE_NAME $DEPTH $FRESH $LOCATION
Required:
$SITE_NAME Pantheon shortname for the site
Optional:
$DEPTH Value for --depth= for git clone.
Default: 1
$FRESH If \"1\" delete and reclone the repo. Otherwise
'git pull' to get the latest.
$LOCATION Full path to where you want to clone this.
Default: ~/Sites/pantheon
"
SITE=$1
if [ x$SITE = x ]; then
echo "Must pass a site shortname as the first argument, for example: site-name"
return
fi
DEPTH=$2
if [ -z $DEPTH ]; then
# default
DEPTH=1
fi
FRESH=$3
LOCATION=$4
if [ -z $LOCATION ]; then
if [ -z $CLONE_PATH ]; then
echo "Please add
export CLONE_PATH=/path/to/site/clones
to your ~/.bash_profile."
return
fi
LOCATION=$CLONE_PATH
fi
if [ ! -d "$LOCATION" ]; then
echo "Error: Not a directory: $LOCATION"
return
fi
cd $LOCATION
if [ "$FRESH" == "1" ]; then
if [ -d "$SITE" ]; then
echo "Removing and re-cloning $SITE..."
rm -rf $SITE
fi
elif [ -d "$SITE" ]; then
echo "You already cloned $SITE. Doing a git pull..."
cd $SITE
git pull
return
fi
echo ""
echo "Git cloning $SITE with --depth=$DEPTH"
X="$(terminus-site-connection-info $SITE git_command dev) --depth=$DEPTH"
echo $X
$X
cd $LOCATION/$SITE
}
alias tgc=terminus-git-clone
terminus-dashboard() {
SITE=$1
if [ x$SITE = x ]; then
echo "Must pass a site shortname as the first argument, for example: site-name"
return
fi
terminus dashboard:view --yes $SITE.dev
}
alias tdash=terminus-dashboard
alias tal="terminus auth:login --email $EMAIL_WORK"
#source /Users/bwood/bin/terminus-completion.bash
terminus-cache-clear () {
$TERMINUS cli cache-clear
$TERMINUS auth login $EMAIL_WORK
$TERMINUS sites list |head -3 # warm the terminus cache
}
alias tcc=terminus-cache-clear
terminus-deploy-code() {
SITE=$1
if [ x$SITE = x ]; then
echo "Must pass the site shortname of the site."
return
fi
ENV=$2
if [ x$ENV = x ]; then
echo "Must pass the target environment. (If \"live\" code will also be deployed to \"test.\")"
return
fi
if [ "$ENV" == "test" ]; then
ENVS=( test )
elif [ "$ENV" == "live" ]; then
ENVS=( test live )
else
echo "The second argument must be \"test\" or \"live\""
return
fi
for TO_ENV in "${ENVS[@]}"; do
echo ""
echo "$SITE: Deploying code to $TO_ENV."
$TERMINUS site deploy --site=$SITE --env=$TO_ENV --note="Deployed via bash $FUNCNAME()."
done
}
alias tdcode=terminus-deploy-code
terminus-deploy-content() {
SITE=$1
if [ x$SITE = x ]; then
echo "Must pass the site shortname of the site."
return
fi
ENV=$2
if [ x$ENV = x ]; then
echo "Must pass the target environment. (If \"live\" code will also be deployed to \"test.\")"
return
fi
if [ "$ENV" == "test" ]; then
ENVS=( test )
elif [ "$ENV" == "live" ]; then
ENVS=( test live )
else
echo "The second argument must be \"test\" or \"live\""
return
fi
for TO_ENV in "${ENVS[@]}"; do
echo ""
echo "$SITE: Deploying content to $TO_ENV."
$TERMINUS site clone-content --from-env=dev --to-env=$TO_ENV --site=$SITE --yes
done
}
alias tdcontent=terminus-deploy-content
terminus-backup-site-envs() {
USAGE="
terminus-backup-site-envs SITE ENV ELEMENT
Required:
SITE: Site name
ENV: if 'dev' backs up dev
if 'test' backups dev and test
if 'live' backs up dev, test and live
Optional:
ELEMENT: [code|files|db|all]
Default: all
"
SITE=$1
if [ x$SITE = x ]; then
echo "Must pass the site shortname of the site."
echo $USAGE
return
fi
ENV=$2
if [ x$ENV = x ]; then
echo "Must pass the target environment. (If \"live\" code will also be deployed to \"test.\")"
echo $USAGE
return
fi
ELEMENT=$3
if [ -z $ELEMENT ]; then
ELEMENT=all
fi
if [ "$ENV" == "dev" ]; then
ENVS=( dev )
elif [ "$ENV" == "test" ]; then
ENVS=( dev test )
elif [ "$ENV" == "live" ]; then
ENVS=( dev test live )
else
echo "The third argument must be \"dev,\" \"test\" or \"live\""
echo $USAGE
return
fi
for ITEM in "${ENVS[@]}"; do
echo ""
echo "$SITE: Backing up $ITEM element=$ELEMENT."
$TERMINUS site backups create --site=$SITE --env=$ITEM --element=$ELEMENT
done
}
clone-content-between-sites() {
SOURCE=$1
if [ x$SOURCE = x ]; then
echo "Must pass the site shortname of the SOURCE site FROM which to which you want to clone."
return
fi
# Validate the site
VALID=$(_terminus-validate-site $SOURCE)
if [ "$VALID" != "0" ]; then
echo "$SOURCE not found. If name is correct try '$TERMINUS sites list'."
return
fi
TARGET=$2
if [ x$TARGET = x ]; then
echo "Must pass the site shortname of the TARGET site TO which you want to clone."
return
fi
# Validate the site
VALID=$(_terminus-validate-site $TARGET)
if [ "$VALID" != "0" ]; then
echo "$TARGET not found. If name is correct try '$TERMINUS sites list'."
return
fi
ELEMENTS=$3
if [ x$ELEMENTS = x ]; then
echo "Must pass the (comma-separated) elements that you want to clone. (E.g. \"files,database\")"
return
fi
# replace the ',' with a space and evaluate the string with in '()' to create an array. Yea bash. :-/
ELEMENTS=(${ELEMENTS//,/ })
ENV=$4
if [ x$ENV = x ]; then
echo "Must pass the enviornment from which to copy conten from the source site"
return
fi
DB_TASKS=0
for ELEMENT in "${ELEMENTS[@]}"; do
if [ "$ELEMENT" == "database" ]; then
DB_TASKS=1
fi
echo "Cloning $ELEMENT $SOURCE --> $TARGET"
$TERMINUS site import-content --site=$TARGET --url=$($TERMINUS site backups get --site=$SOURCE --env=$ENV --element=$ELEMENT --latest) --element=$ELEMENT
done
if [ "$DB_TASKS" -eq "1" ]; then
# clear caches
echo ""
echo "Clearing caches on $TARGET."
echo ""
$TERMINUS site clear-cache --site=$TARGET --env=dev
# update pathologic
echo ""
echo "Updating pathologic paths on $TARGET."
echo ""
NEW="http://dev-$TARGET.pantheon.berkeley.edu/
http://test-$TARGET.pantheon.berkeley.edu/
http://live-$TARGET.pantheon.berkeley.edu/
http://dev-$TARGET.pantheonsite.io/
http://test-$TARGET.pantheonsite.io/
http://live-$TARGET.pantheonsite.io/
http://$TARGET.berkeley.edu
http://$TARGET.localhost"
EXISTING=$($TERMINUS drush "vget openberkeley_wysiwyg_override_pathologic_paths" --site=$SOURCE --env=$ENV 2>/dev/null)
# Strip out varilable name
EXISTING=${EXISTING/openberkeley_wysiwyg_override_pathologic_paths: /}
# //\" = replace all instances of "
EXISTING=${EXISTING//\"/}
UPDATED_PATHS="$EXISTING
$NEW
"
$TERMINUS drush "vset openberkeley_wysiwyg_override_pathologic_paths '$UPDATED_PATHS'" --site=$TARGET --env=dev
fi
# disable SMTP (until we have a better solution)
echo ""
echo "Disabling SMTP so mail isn't inadvertently sent from this site."
echo ""
$TERMINUS drush --site=$TARGET --env=dev "vset smtp_host 'NOEMAIL-FROM-CLONED-SITE.berkeley.edu'"
# since SMTP isn't enabled on some sites also remove the user emails
echo ""
echo "Remove user emails."
echo ""
$TERMINUS drush --site=$TARGET --env=dev "sqlq \"update users set mail='' where uid <> 0\""
}
reset-repo-to-tag() {
USAGE="
reset-repo-to-tag $SITE $TAG
$SITE Pantheon short name for the site
$TAG A valid tag in the repository.
e.g: 7.x-0.7.2
"
if [ -z $CLONE_PATH ]; then
echo "Please add
export CLONE_PATH=/path/to/site/clones
to your ~/.env file."
return
fi
SITE=$1
if [ x$SITE = x ]; then
echo "Must pass the site shortname of the site."
echo ""
echo "$USAGE"
return
fi
TAG=$2
if [ x$TAG = x ]; then
echo "Must indicate tag to which you want to reset."
echo ""
echo "$USAGE"
return
fi
SITE_PATH="$CLONE_PATH/$SITE"
if [ ! -d "$SITE_PATH" ]; then
echo "Error: $SITE_PATH is not a directory."
return
fi
# cd into the repo
cd $SITE_PATH
echo "'git rev-list -n 1 $TAG'"
git rev-list -n 1 "$TAG"
if [ $? -ne 0 ]; then
echo ""
echo "Error: $TAG not found in site repo ($SITE_PATH)."
return
fi
SHA=$(git rev-list -n 1 "$TAG")
echo ""
echo "Resetting the repository to $TAG and forcing a git push..."
echo "($TAG = $SHA)"
git reset --hard $SHA
git push -f
echo ""
}
terminus-clone-site() {
# Other users need to customize ISTDRUPAL_NEW_SITE at top of file
USAGE="USAGE:
terminus-clone-site SOURCE_SITE TARGET_SITE ENV TAG [UCB]
Required Arguments:
SORUCE_SITE: Pantheon short name for source site
TARGET_SITE: Pantheon short name for target site
ENV: Environment to which to deploy the target site.
Optional Arguments:
TAG: Git tag for reset --hard and git push -f
Nothing will be done if omitted.
UCB: UCB will put the target site in the live organization.
If not present, will put target site in the test org.
"
if [ -z $CLONE_PATH ]; then
echo "Please add
export CLONE_PATH=/path/to/site/clones
to your ~/.env file."
return
fi
if [ -z $ISTDRUPAL_MACHINE ]; then
echo "Please add
export [email protected]
to your ~/.env file."
return
fi
FROM_SITE=$1
if [ x$FROM_SITE = x ]; then
echo "Must pass the site shortname of the site from which you want to clone."
echo ""
echo "$USAGE"
return
fi
# Validate the site
VALID=$(_terminus-validate-site $FROM_SITE)
if [ "$VALID" != "0" ]; then
echo "$FROM_SITE not found. If name is correct try '$TERMINUS sites list'."
return
fi
TO_SITE=$2
if [ x$TO_SITE = x ]; then
echo "Must pass the site shortname of the site to which you want to clone."
echo ""
echo "$USAGE"
return
fi
ENV=$3
if [ x$ENV = x ]; then
echo "Must indicate the environment to which you want to deploy on the target site."
echo ""
echo "$USAGE"
return
fi
if [ -z $ISTDRUPAL_ORG ] || [ -z $ISTDRUPAL_UPSTREAM ]; then
echo "Error: both ISTDRUPAL_ORG and ISTDRUPAL_UPSTREAM must be defined in your environment."
return
fi
# Create a basic target site
CMD="$TERMINUS --yes sites create --site=$TO_SITE --name=$TO_SITE --label=$TO_SITE --upstream=$ISTDRUPAL_UPSTREAM --org=$ISTDRUPAL_TEST_ORG"
echo ""
echo "Creating site $TO_SITE"
echo $CMD
$CMD
# Was the site created or did something fail
VALID=$(_terminus-validate-site $TO_SITE)
if [ "$VALID" != "0" ]; then
echo "$TO_SITE not found. Running '$TERMINUS sites list'..."
$TERMINUS sites list
VALID2=$(_terminus-validate-site $TO_SITE)
if [ "$VALID2" != "0" ]; then
echo "$TO_SITE STILL not found. Aborting."
return
fi
fi
# This argument puts the site in the real organization. Else it's put in the test organization.
LIVE_ORG=$5
if [[ -n $LIVE_ORG && "$LIVE_ORG" == "UCB" ]]; then
echo ""
echo "Moving site to main organization."
# add main org
CMD="$TERMINUS site organizations add --site=$TO_SITE --org=$ISTDRUPAL_ORG --role=admin"
echo $CMD
$CMD
# set instrument
CMD="$TERMINUS site set-instrument --instrument=$ISTDRUPAL_INSTRUMENT --site=$TO_SITE"
echo $CMD
$CMD
# remove test org
CMD="$TERMINUS site organizations remove --site=$TO_SITE --org=$ISTDRUPAL_TEST_ORG"
echo $CMD
$CMD
fi
# Add team member
echo ""
echo "Adding team members $ISTDRUPAL_MACHINE, $EMAIL_WORK"
$TERMINUS site team add-member --member=$ISTDRUPAL_MACHINE --role=admin --site=$TO_SITE
$TERMINUS site team add-member --member=$EMAIL_WORK --role=admin --site=$TO_SITE
# clone the sites down
echo "Creating git clones..."
terminus-git-clone $FROM_SITE 100
# We always want to get this fresh, so rm -rf if it exists
terminus-git-clone $TO_SITE 100 1
# Reset and git push -f, if desired
TAG=$4
if [ -n $TAG ]; then
reset-repo-to-tag $TO_SITE $TAG
fi
# copy over custom data in sites/all/modules
CUSTOMIZATIONS=$(ls -1 $CLONE_PATH/$FROM_SITE/sites/all/modules | wc -l)
if [ $CUSTOMIZATIONS -gt 1 ]; then
echo "Found customizations in $CLONE_PATH/$FROM_SITE/sites/all/modules. Copying..."
cp -r $CLONE_PATH/$FROM_SITE/sites/all/modules/* $CLONE_PATH/$TO_SITE/sites/all/modules
echo "Adding customizations and pushing to git remote..."
cd $CLONE_PATH/$TO_SITE
# git pull #erroring. just cloned the site, so should be ok
git add -A > /dev/null
git commit -m "Adding customizations from $CLONE_PATH/$FROM_SITE/sites/all/modules" > /dev/null
git push
fi
# Deploy code to environments
terminus-deploy-code $TO_SITE $ENV
# Clone the db and files from the source to the target site
clone-content-between-sites $FROM_SITE $TO_SITE "database,files" $ENV
terminus-deploy-content $TO_SITE $ENV
echo "Site created:"
echo "http://dev-$TO_SITE.pantheon.berkeley.edu"
echo "http://test-$TO_SITE.pantheon.berkeley.edu"
echo "http://live-$TO_SITE.pantheon.berkeley.edu"
echo ""
echo "Site dashboard url:"
echo $($TERMINUS site dashboard --site=$TO_SITE --env=dev --print)
# take backups
echo "Creating initial backups of site environments"
terminus-backup-site-envs $TO_SITE $ENV
# Tag the site on the dashbaord.
if [[ "$TO_SITE" =~ "upgrade-testing" ]];then
echo ""
echo "Since this is an upgrade-testing site, we will add the 'Upgrade Testing' tag."
$TERMINUS site tags add --tag='Upgrade Testing' --site=$TO_SITE --org=$($TERMINUS site info --site=$TO_SITE --field=holder_id)
fi
echo "Done."
}
alias tcsite=terminus-clone-site
# Resetting a cloned site to an older commit and then using 'git push -f' is
# problematic when you try to deploy between environments. It's cleaner to
# blow away the clone and start fresh.
############
# WARNING!!! Be very careful when editing this. Potential for disaster. Runs 'site delete --force'
############
terminus-reset-cloned-site () {
USAGE="USAGE:
terminus-reset-cloned-site upgrade-testing-example-site live -y
Required:
site_name Pantheon shortname of site to delete and re-clone.
(Will refuse to delete sites without \"upgrade-testing\"
in their name.)
environment The environment to which to deploy the clone.
Values other than [dev|test|live] will fail.
Optional:
tag Git tag to which to reset the repository and git push -f.
-y Skip confirmation before site deletion.
Not using getopts. This needs to be the 3rd argument.
"
SITE=$1
if [ x$SITE = x ]; then
echo "Must pass the site shortname of the site from which you want to clone."
echo ""
echo "$USAGE"
return
fi
ENV=$2
if [ x$ENV = x ]; then
echo "Must indicate the environment to which you want to deploy on the target site."
echo ""
echo "$USAGE"
return
fi
TAG=$3
CONFIRM=$4
if [[ ! "$SITE" =~ "upgrade-testing" ]];then
echo "I only work on 'upgrade-testing' sites. Aborting."
return
fi
# Validate the site
VALID=$(_terminus-validate-site $SITE)
if [ "$VALID" != "0" ]; then
echo "$SITE not found. If name is correct try '$TERMINUS sites list'."
return
fi
if [ -z $CONFIRM ]; then
echo "Are you sure you want to DELETE and recreate $SITE? (y/n)"
read CONFIRM
# Prepend a dash to make it look like an option
CONFIRM="-$CONFIRM"
fi
if [ "$CONFIRM" != "-y" ]; then
echo "Aborting."
return
fi
# WARNING!!!
echo "Deleting $SITE..."
$TERMINUS site delete --force --site=$SITE
# Remove the git working copy
# if this dir is the user's pwd the rm will work and the user will be in a ghost directory
# after the subshell for the script exits.
echo "Preparing to remove $CLONE_PATH/$SITE."
if [[ -n "$CLONE_PATH" && -d "$CLONE_PATH/$SITE" && -d "$CLONE_PATH/$SITE/.git" ]]; then
# make sure that the subshell's pwd is not this dir
cd $HOME
rm -rf "$CLONE_PATH/$SITE"
else
echo "Error: Not safe to remove this directory."
return
fi
# replace the 'upgrade-testing-' substring with null
FROM_SITE="${SITE/upgrade-testing-/}"
echo "Re-cloning $FROM_SITE --> $SITE..."
terminus-clone-site $FROM_SITE $SITE $ENV $TAG
}
# We get gateway timeouts using '$TERMINUS sites aliases' with individual accounts.
# This workaround gets the aliases for the machine user account which is a team member
# on fewer sites.
terminus-managed-site-aliases () {
if [ -z "ISTDRUPAL_MACHINE" ]; then
echo "Please set the correct value:"
echo " export ISTDRUPAL_MACHINE="
return
fi
if [ -z "$EMAIL_WORK" ]; then
echo "Please set the correct value:"
echo " export EMAIL_WORK="
return
fi
LOCATION=$HOME/.drush/ms.aliases.drushrc.php
terminus auth:login --email $ISTDRUPAL_MACHINE
terminus aliases --location=$LOCATION
terminus auth:login --email $EMAIL_WORK
echo "Managed site aliases refreshed: $LOCATION"
}
alias tms-aliases=terminus-managed-site-aliases
alias tmsa=terminus-managed-site-aliases